contextFactory.setSystemUsername(securityConfig.getShiroLDAPSystemUsername());
@Test public void testGetSystemLdapContext() throws NamingException { factory = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { assertEquals("ldap://localhost:389", env.get(Context.PROVIDER_URL)); assertEquals("foo", env.get(Context.SECURITY_PRINCIPAL)); assertEquals("bar", env.get(Context.SECURITY_CREDENTIALS)); assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION)); assertNotNull(env.get(SUN_CONNECTION_POOLING_PROPERTY)); return createNiceMock(LdapContext.class); } }; factory.setSystemUsername("foo"); factory.setSystemPassword("bar"); factory.setUrl("ldap://localhost:389"); factory.getSystemLdapContext(); }
@Test public void testGetSystemLdapContextPoolingDisabled() throws NamingException { factory = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { assertEquals("ldap://localhost:389", env.get(Context.PROVIDER_URL)); assertEquals("foo", env.get(Context.SECURITY_PRINCIPAL)); assertEquals("bar", env.get(Context.SECURITY_CREDENTIALS)); assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION)); assertNull(env.get(SUN_CONNECTION_POOLING_PROPERTY)); return createNiceMock(LdapContext.class); } }; factory.setSystemUsername("foo"); factory.setSystemPassword("bar"); factory.setPoolingEnabled(false); factory.setUrl("ldap://localhost:389"); factory.getSystemLdapContext(); }
@Inject @SuppressWarnings("unchecked") public ConcordLdapContextFactory(LdapConfiguration cfg) { JndiLdapContextFactory f = new JndiLdapContextFactory() { @Override protected LdapContext createLdapContext(Hashtable env) throws NamingException { String url = cfg.getUrl(); if (url != null && url.startsWith("ldaps:")) { env.put("java.naming.ldap.factory.socket", TrustingSslSocketFactory.class.getName()); } return super.createLdapContext(env); } }; f.setUrl(cfg.getUrl()); f.setSystemUsername(cfg.getSystemUsername()); f.setSystemPassword(cfg.getSystemPassword()); f.setPoolingEnabled(true); this.delegate = f; }
protected void initializeLDAP(String ldapUrl, String systemUser, String systemUserPassword, String userNameTemplate) { JndiLdapContextFactory jndiLdapContextFactory = new JndiLdapContextFactory(); jndiLdapContextFactory.setUrl(ldapUrl); jndiLdapContextFactory.setSystemUsername(systemUser); jndiLdapContextFactory.setSystemPassword(systemUserPassword); ldapRealm = new JndiLdapRealm(); ldapRealm.setContextFactory(jndiLdapContextFactory); ldapRealm.setUserDnTemplate(userNameTemplate); ldapRealm.init(); } }
contextFactory.setSystemUsername(securityConfig.getShiroLDAPSystemUsername());
contextFactory.setSystemUsername(securityConfig.getShiroLDAPSystemUsername());
contextFactory.setAuthenticationMechanism( config.get( SecuritySettings.ldap_authentication_mechanism ) ); contextFactory.setReferral( config.get( SecuritySettings.ldap_referral ) ); contextFactory.setSystemUsername( config.get( SecuritySettings.ldap_authorization_system_username ) ); contextFactory.setSystemPassword( config.get( SecuritySettings.ldap_authorization_system_password ) ); contextFactory.setPoolingEnabled( config.get( SecuritySettings.ldap_authorization_connection_pooling ) );