Showing posts with label Active Directory. Show all posts
Showing posts with label Active Directory. Show all posts

Thursday, 3 May 2018

SonarQube AD authentication setup

User in SonarQube can be validated against ActiveDirectory, once the user is validated it will be automatically created which is useful if there are a lot users who are required to use the tool.

  1. LDAP plugin needs to be installed in SonarQube marketplace
  2. sonar.properties needs to be updated with LDAP configuration details
  3. SonarQube service needs to be restarted. 
  4. Go to SonarQube web. 
    • If there are issues with the configuration check the logs (SonarQube\logs\web.log)
# LDAP configuration
# General Configuration
sonar.security.realm=LDAP
sonar.authenticator.createUsers=true
ldap.url=ldap://ldapserver:389
ldap.bindDn=CN=username,CN=Users,DC=domain,DC=company,DC=com
ldap.bindPassword=password

# User Configuration
ldap.user.baseDn=DC=domain,DC=company,DC=com
ldap.user.request=(&(objectClass=user)(sAMAccountName={login}))
ldap.user.realNameAttribute=cn
ldap.user.emailAttribute=mail

ADExplorer is useful to confirm AD object properties and validate the server address and credentials.
In case it is not clear what are AD server details then use guidance on SO.
More details can be found in SonarQube LDAP plugin documentation.

Tuesday, 24 April 2007

Active directory service interface reference

I needed to retrive some values from Ldap and for some properties I was not able to retrieve its value. I used standard classes from namespace System.DirectoryServices and always got System.Runtime.InteropServices.COMException(0x8000500c). After some investigation I found that for access to Ldap I can use ADSI interface. I found that the property I wanted to get was of octet string datatype. Unfortunatelly I did not managed to find how to retrieve valuo of the property though PropertyCollection. I was able to find that the collection contains the property, but I could not read its value.

At first I used something like that:

// works almost for everything, but not for octet strings (array of bytes)
// properties is of type PropertyCollection from System.DirectoryServices
string value = string.Empty;

if (properties.Contains(key))
{
value = properties[key].Value.ToString();
}


Solution of the problem:

string value = string.Empty;

try
{
// if the item do not exists exception is thrown
ActiveDs.IADsPropertyEntry entry = ActiveDs.IADsPropertyEntry)propertyList.Item(key);

// get types
int propertyType = entry.ADsType;
int valueType = (ActiveDs.IADsPropertyValue)((object[])((ActiveDs.IADsPropertyEntry)propertyList.GetPropertyItem(key, propertyType)).Values)[0]).ADsType;

switch (valueType)
{
// for octet string (array of bytes) we have to create string
case (int)ActiveDs.ADSTYPEENUM.ADSTYPE_OCTET_STRING:
value = Sstem.Text.Encoding.ASCII.GetString((byte[])((ActiveDs.IADsPropertyValue)((object[])((ActiveDs.IADsPropertyEntry)propertyList.GetPropertyItem(key, propertyType)).Values)[0]).OctetString);
break;

// for all others - all current properties are of this type
case (int)ActiveDs.ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING:
value = ((ActiveDs.IADsPropertyValue)((object[])((ActiveDs.IADsPropertyEntry)propertyList.GetPropertyItem(key, propertyType)).Values)[0]).CaseIgnoreString;
break;
// in other cases you can add new section
}
catch (System.Runtime.InteropServices.COMException cex)
{
if (cex.ErrorCode == -2147463155)
Trace.Write(cex);
else throw;
}


In this case you have to add to your references Activeds.dll.