/** * The name of the ContextFactory class to use. This defaults to the SUN LDAP JNDI implementation * but can be overridden to use custom LDAP factories. * <p/> * This is a wrapper method for setting the JNDI environment's {@link Context#INITIAL_CONTEXT_FACTORY} property. * * @param contextFactoryClassName the context factory that should be used. */ public void setContextFactoryClassName(String contextFactoryClassName) { setEnvironmentProperty(Context.INITIAL_CONTEXT_FACTORY, contextFactoryClassName); }
/** * Returns the LDAP url to connect to. (e.g. ldap://<ldapDirectoryHostname>:<port>). * This must be configured. * * @return the LDAP url to connect to. (e.g. ldap://<ldapDirectoryHostname>:<port>) */ public String getUrl() { return (String) getEnvironmentProperty(Context.PROVIDER_URL); }
/** * Returns the User Distinguished Name (DN) template to use when creating User DNs at runtime - see the * {@link #setUserDnTemplate(String) setUserDnTemplate} JavaDoc for a full explanation. * * @return the User Distinguished Name (DN) template to use when creating User DNs at runtime. */ public String getUserDnTemplate() { return getUserDn(USERDN_SUBSTITUTION_TOKEN); }
@Test(expected = AuthenticationException.class) public void testEmptyCharArrayCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", new char[0]); }
/** * This implementation delegates to {@link #getLdapContext(Object, Object)} using the * {@link #getSystemUsername() systemUsername} and {@link #getSystemPassword() systemPassword} properties as * arguments. * * @return the system LdapContext * @throws NamingException if there is a problem connecting to the LDAP directory */ public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext((Object)getSystemUsername(), getSystemPassword()); }
/** * Default no-argument constructor that defaults the internal {@link LdapContextFactory} instance to a * {@link JndiLdapContextFactory}. */ public DefaultLdapRealm() { //Credentials Matching is not necessary - the LDAP directory will do it automatically: setCredentialsMatcher(new AllowAllCredentialsMatcher()); //Any Object principal and Object credentials may be passed to the LDAP provider, so accept any token: setAuthenticationTokenClass(AuthenticationToken.class); this.contextFactory = new JndiLdapContextFactory(); }
@Test(expected = AuthenticationException.class) public void testEmptyByteArrayCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", new byte[0]); }
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { AuthorizationInfo info; try { info = queryForAuthorizationInfo(principals, ensureContextFactory()); } catch (NamingException e) { String msg = "LDAP naming error while attempting to retrieve authorization for user [" + principals + "]."; throw new AuthorizationException(msg, e); } return info; }
public LdapContext getSystemLdapContext() throws NamingException { return getLdapContext(systemUsername, systemPassword); }
@Override protected String getUserDn(final String principal) throws IllegalArgumentException, IllegalStateException { if (dnSearchFilter != null) { return findUserDN(principal, getContextFactory()); } else { // Use template return super.getUserDn(principal); } }
protected DefaultLdapRealm getNewRealmUnderTest() { return new JndiLdapRealm(); }
protected DefaultLdapRealm getNewRealmUnderTest() { return new DefaultLdapRealm(); }
@Test(expected = AuthenticationException.class) public void testEmptyStringCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", ""); }
@Test(expected = AuthenticationException.class) public void testEmptyNullCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", null); }
/** * The LDAP url to connect to. (e.g. ldap://<ldapDirectoryHostname>:<port>). This must be configured. * * @param url the LDAP url to connect to. (e.g. ldap://<ldapDirectoryHostname>:<port>) */ public void setUrl(String url) { setEnvironmentProperty(Context.PROVIDER_URL, url); }
/** * Sets the name of the ContextFactory class to use. This defaults to the SUN LDAP JNDI implementation * but can be overridden to use custom LDAP factories. * <p/> * This is a wrapper method for getting the JNDI environment's {@link Context#INITIAL_CONTEXT_FACTORY} property. * * @return the name of the ContextFactory class to use. */ public String getContextFactoryClassName() { return (String) getEnvironmentProperty(Context.INITIAL_CONTEXT_FACTORY); }
@Test(expected = AuthenticationException.class) public void testEmptyNullCredentials() throws NamingException { factory.setUrl("ldap://localhost:389"); factory.getLdapContext((Object)"jcoder", null); }
/** * Sets the LDAP referral behavior when creating a connection. Defaults to {@code follow}. See the Sun/Oracle LDAP * <a href="http://java.sun.com/products/jndi/tutorial/ldap/referral/jndi.html">referral documentation</a> for more. * * @param referral the referral property. * @see <a href="http://java.sun.com/products/jndi/tutorial/ldap/referral/jndi.html">Referrals in JNDI</a> */ public void setReferral(String referral) { setEnvironmentProperty(Context.REFERRAL, referral); }
/** * Returns the LDAP referral behavior when creating a connection. Defaults to {@code follow}. * See the Sun/Oracle LDAP * <a href="http://java.sun.com/products/jndi/tutorial/ldap/referral/jndi.html">referral documentation</a> for more. * * @return the LDAP referral behavior when creating a connection. * @see <a href="http://java.sun.com/products/jndi/tutorial/ldap/referral/jndi.html">Referrals in JNDI</a> */ public String getReferral() { return (String) getEnvironmentProperty(Context.REFERRAL); }
/** * Sets the type of LDAP authentication mechanism to use when connecting to the LDAP server. * This is a wrapper method for setting the JNDI {@link #getEnvironment() environment template}'s * {@link Context#SECURITY_AUTHENTICATION} property. * <p/> * "none" (i.e. anonymous) and "simple" authentications are supported automatically and don't need to be configured * via this property. However, if you require a different mechanism, such as a SASL or External mechanism, you * must configure that explicitly via this property. See the * <a href="http://download-llnw.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html">JNDI LDAP * Authentication Mechanisms</a> for more information. * * @param authenticationMechanism the type of LDAP authentication to perform. * @see <a href="http://download-llnw.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html"> * http://download-llnw.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html</a> */ public void setAuthenticationMechanism(String authenticationMechanism) { setEnvironmentProperty(Context.SECURITY_AUTHENTICATION, authenticationMechanism); }