getInitialContext().addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
public Object addToEnvironment(String propName, Object propVal) throws NamingException { return initCtx.addToEnvironment(propName, propVal); }
public Object addToEnvironment(String propName, Object propVal) throws NamingException { return initCtx.addToEnvironment(propName, propVal); }
InitialLdapContext ldapContext = new InitialLdapContext(); ldapContext.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); ldapContext.addToEnvironment(Context.SECURITY_AUTHENTICATION, "simple"); ldapContext.addToEnvironment(Context.SECURITY_PRINCIPAL, userId + "@mydomain.com"); ldapContext.addToEnvironment(Context.SECURITY_CREDENTIALS, password); ldapContext.addToEnvironment(Context.PROVIDER_URL, "ldap://" + ldapHost + ":" + ldapPort);
Hashtable<String,String> environment = new Hashtable<String,String>(); environment.put("java.naming.provider.url", url); environment.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); InitialLdapContext context = new InitialLdapContext(environment, null); ... context.addToEnvironment("java.naming.security.principal", principal); context.addToEnvironment("java.naming.security.credentials", credentials); ... // execute some kind of search, based on your needs
/** * Sets the binary attributes. * * @param binaryAttributes the binary attributes */ public void setBinaryAttributes( Collection<String> binaryAttributes ) { this.binaryAttributes = binaryAttributes; String binaryAttributesString = StringUtils.EMPTY; for ( String string : binaryAttributes ) { binaryAttributesString += string + ' '; } if ( environment != null ) { environment.put( JAVA_NAMING_LDAP_ATTRIBUTES_BINARY, binaryAttributesString ); } if ( context != null ) { try { context.addToEnvironment( JAVA_NAMING_LDAP_ATTRIBUTES_BINARY, binaryAttributesString ); } catch ( NamingException e ) { // TODO: logging e.printStackTrace(); } } }
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDN); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, inputPassword); ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, "simple");
context.removeFromEnvironment( JAVA_NAMING_SECURITY_SASL_REALM ); context.addToEnvironment( Context.SECURITY_AUTHENTICATION, authMethod ); context.addToEnvironment( Sasl.QOP, SaslQoP.AUTH.getValue() ); break; case AUTH_INT: context.addToEnvironment( Sasl.QOP, SaslQoP.AUTH_INT.getValue() ); break; case AUTH_CONF: context.addToEnvironment( Sasl.QOP, SaslQoP.AUTH_CONF.getValue() ); break; context.addToEnvironment( Sasl.SERVER_AUTH, "true" ); //$NON-NLS-1$ context.addToEnvironment( Sasl.STRENGTH, SaslSecurityStrength.HIGH.getValue() ); break; case MEDIUM: context.addToEnvironment( Sasl.STRENGTH, SaslSecurityStrength.MEDIUM.getValue() ); break; case LOW: context.addToEnvironment( Sasl.STRENGTH, SaslSecurityStrength.LOW.getValue() ); break; context.addToEnvironment( Context.SECURITY_PRINCIPAL, bindPrincipal ); context.addToEnvironment( Context.SECURITY_CREDENTIALS, bindCredentials ); context.addToEnvironment( JAVA_NAMING_SECURITY_SASL_REALM, saslRealm );