in core-jndi/src/main/java/org/apache/directory/server/core/jndi/LdapJndiProperties.java [101:260]
public static LdapJndiProperties getLdapJndiProperties( Hashtable env ) throws NamingException
{
if ( env == null )
{
throw new ConfigurationException( "environment cannot be null" );
}
LdapJndiProperties props = new LdapJndiProperties();
Object principal = env.get( Context.SECURITY_PRINCIPAL );
Object credobj = env.get( Context.SECURITY_CREDENTIALS );
Object authentication = env.get( Context.SECURITY_AUTHENTICATION );
// -------------------------------------------------------------------
// check for the provider URL property
// -------------------------------------------------------------------
if ( !env.containsKey( Context.PROVIDER_URL ) )
{
String msg = I18n.err( I18n.ERR_484, Context.PROVIDER_URL );
throw new ConfigurationException( msg );
}
String url = ( String ) env.get( Context.PROVIDER_URL );
if ( url == null )
{
String msg = I18n.err( I18n.ERR_485, Context.PROVIDER_URL );
throw new ConfigurationException( msg );
}
if ( url.trim().equals( "" ) )
{
props.providerDn = Dn.ROOT_DSE;
}
else
{
try
{
props.providerDn = new Dn( url );
}
catch ( LdapInvalidDnException lide )
{
String msg = I18n.err( I18n.ERR_733, url );
throw new ConfigurationException( msg );
}
}
// -------------------------------------------------------------------
// Figure out and set the authentication level and mechanisms
// -------------------------------------------------------------------
if ( authentication == null )
{
// if the property is not set but Context.SECURITY_CREDENTIALS is then SIMPLE
if ( credobj == null )
{
props.level = AuthenticationLevel.NONE;
}
else
{
props.level = AuthenticationLevel.SIMPLE;
}
}
else if ( !( authentication instanceof String ) )
{
throw new ConfigurationException( I18n.err( I18n.ERR_483, authentication.getClass(),
Context.SECURITY_AUTHENTICATION ) );
}
else
{
if ( AuthenticationLevel.NONE.toString().equals( authentication ) )
{
props.level = AuthenticationLevel.NONE;
}
else if ( AuthenticationLevel.SIMPLE.toString().equals( authentication ) )
{
props.level = AuthenticationLevel.SIMPLE;
}
else
{
props.level = AuthenticationLevel.STRONG;
props.saslMechanism = ( String ) authentication;
}
}
// -------------------------------------------------------------------
// Figure out and set the security principal bindDn and saslAuthId
// -------------------------------------------------------------------
if ( principal == null && props.level == AuthenticationLevel.SIMPLE )
{
throw new ConfigurationException( I18n.err( I18n.ERR_487, Context.SECURITY_PRINCIPAL ) );
}
else if ( principal == null && props.level == AuthenticationLevel.NONE )
{
props.bindDn = Dn.EMPTY_DN;
}
else if ( !( principal instanceof String ) )
{
throw new ConfigurationException( I18n.err( I18n.ERR_483, principal.getClass(), Context.SECURITY_PRINCIPAL ) );
}
else if ( ( ( String ) principal ).trim().equals( "" ) )
{
props.bindDn = Dn.EMPTY_DN;
}
else
{
try
{
props.providerDn = new Dn( ( String ) principal );
}
catch ( LdapInvalidDnException lide )
{
String msg = I18n.err( I18n.ERR_733, principal );
throw new ConfigurationException( msg );
}
}
if ( env.get( SASL_AUTHID ) != null && props.level == AuthenticationLevel.STRONG )
{
Object obj = env.get( SASL_AUTHID );
if ( obj instanceof String )
{
props.saslAuthId = ( String ) obj;
}
else
{
throw new ConfigurationException( I18n.err( I18n.ERR_483, obj.getClass(), SASL_AUTHID ) );
}
props.saslAuthId = ( String ) principal;
}
// -------------------------------------------------------------------
// Figure out the credentials
// -------------------------------------------------------------------
if ( props.level == AuthenticationLevel.SIMPLE && credobj == null )
{
throw new ConfigurationException( I18n.err( I18n.ERR_489 ) );
}
else if ( credobj != null )
{
if ( credobj instanceof String )
{
props.credentials = Strings.getBytesUtf8( ( String ) credobj );
}
else if ( credobj instanceof byte[] )
{
props.credentials = ( byte[] ) credobj;
}
else
{
throw new ConfigurationException( I18n.err( I18n.ERR_483, credobj.getClass(),
Context.SECURITY_CREDENTIALS ) );
}
}
return props;
}