context = open(); } catch (NamingException ne) { FailedLoginException ex = new FailedLoginException("Error opening LDAP connection"); if (!isLoginPropertySet(USER_SEARCH_MATCHING)) return false; userSearchMatchingFormat = new MessageFormat(getLDAPPropertyValue(USER_SEARCH_MATCHING)); userSearchSubtreeBool = Boolean.valueOf(getLDAPPropertyValue(USER_SEARCH_SUBTREE)).booleanValue(); doRFC2254Encoding(username) }); SearchControls constraints = new SearchControls(); if (isLoginPropertySet(USER_ROLE_NAME)) { list.add(getLDAPPropertyValue(USER_ROLE_NAME)); log.debug("Get the user DN."); log.debug("Looking for the user in LDAP with "); log.debug(" base DN: " + getLDAPPropertyValue(USER_BASE)); log.debug(" filter: " + filter); NamingEnumeration<SearchResult> results = context.search(getLDAPPropertyValue(USER_BASE), filter, constraints); Name baseName = parser.parse(getLDAPPropertyValue(USER_BASE)); Name entryName = parser.parse(result.getName()); Name name = contextName.addAll(baseName); close(context);
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("User name"); callbacks[1] = new PasswordCallback("Password", false); try { handler.handle(callbacks); } catch (IOException ioe) { throw (LoginException)new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException)new LoginException().initCause(uce); } String password; String username = ((NameCallback)callbacks[0]).getName(); if (username == null) return false; if (((PasswordCallback)callbacks[1]).getPassword() != null) password = new String(((PasswordCallback)callbacks[1]).getPassword()); else password=""; // authenticate will throw LoginException // in case of failed authentication authenticate(username, password); user = new UserPrincipal(username); succeeded = true; return true; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { String encryptionPassword = (String)options.get(ENCRYPTION_PASSWORD); String passwordEnvName = options.get(PASSWORD_ENV_NAME) != null ? (String)options.get(PASSWORD_ENV_NAME) : DEFAULT_PASSWORD_ENV_NAME; String passwordAlgorithm = options.get(PASSWORD_ALGORITHM) != null ? (String)options.get(PASSWORD_ALGORITHM) : DEFAULT_PASSWORD_ALGORITHM; EnvironmentStringPBEConfig envConfig = new EnvironmentStringPBEConfig(); envConfig.setAlgorithm(passwordAlgorithm); //If the password was set, use it //else look up the password from the environment if (encryptionPassword == null) { envConfig.setPasswordEnvName(passwordEnvName); } else { envConfig.setPassword(encryptionPassword); } configurationEncryptor.setConfig(envConfig); EncryptableProperties encryptableOptions = new EncryptableProperties(configurationEncryptor); encryptableOptions.putAll(options); super.initialize(subject, callbackHandler, sharedState, encryptableOptions); }
protected DirContext open() throws NamingException { try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, getLDAPPropertyValue(INITIAL_CONTEXT_FACTORY)); if (isLoginPropertySet(CONNECTION_USERNAME)) { env.put(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME)); } else { throw new NamingException("Empty username is not allowed"); } if (isLoginPropertySet(CONNECTION_PASSWORD)) { env.put(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD)); } else { throw new NamingException("Empty password is not allowed"); } env.put(Context.SECURITY_PROTOCOL, getLDAPPropertyValue(CONNECTION_PROTOCOL)); env.put(Context.PROVIDER_URL, getLDAPPropertyValue(CONNECTION_URL)); env.put(Context.SECURITY_AUTHENTICATION, getLDAPPropertyValue(AUTHENTICATION)); context = new InitialDirContext(env); } catch (NamingException e) { log.error(e.toString()); throw e; } return context; }
boolean roleSearchSubtreeBool; boolean expandRolesBool; roleSearchMatchingFormat = new MessageFormat(getLDAPPropertyValue(ROLE_SEARCH_MATCHING)); roleSearchSubtreeBool = Boolean.valueOf(getLDAPPropertyValue(ROLE_SEARCH_SUBTREE)).booleanValue(); expandRolesBool = Boolean.valueOf(getLDAPPropertyValue(EXPAND_ROLES)).booleanValue(); if (!isLoginPropertySet(ROLE_NAME)) { return list; doRFC2254Encoding(dn), doRFC2254Encoding(username) }); log.debug("Get user roles."); log.debug("Looking for the user roles in LDAP with "); log.debug(" base DN: " + getLDAPPropertyValue(ROLE_BASE)); log.debug(" filter: " + filter); NamingEnumeration<SearchResult> results = context.search(getLDAPPropertyValue(ROLE_BASE), filter, constraints); while (results.hasMore()) { SearchResult result = results.next(); list = addAttributeValues(getLDAPPropertyValue(ROLE_NAME), attrs, list); MessageFormat expandRolesMatchingFormat = new MessageFormat(getLDAPPropertyValue(EXPAND_ROLES_MATCHING)); while (!pendingNameExpansion.isEmpty()) { String name = pendingNameExpansion.remove(); filter = expandRolesMatchingFormat.format(new String[]{name}); results = context.search(getLDAPPropertyValue(ROLE_BASE), filter, constraints); while (results.hasMore()) {
boolean roleSearchSubtreeBool; boolean expandRolesBool; roleSearchMatchingFormat = new MessageFormat(getLDAPPropertyValue(ROLE_SEARCH_MATCHING)); roleSearchSubtreeBool = Boolean.valueOf(getLDAPPropertyValue(ROLE_SEARCH_SUBTREE)).booleanValue(); expandRolesBool = Boolean.valueOf(getLDAPPropertyValue(EXPAND_ROLES)).booleanValue(); if (!isLoginPropertySet(ROLE_NAME)) { return list; doRFC2254Encoding(dn), doRFC2254Encoding(username) }); log.debug("Get user roles."); log.debug("Looking for the user roles in LDAP with "); log.debug(" base DN: " + getLDAPPropertyValue(ROLE_BASE)); log.debug(" filter: " + filter); NamingEnumeration<SearchResult> results = context.search(getLDAPPropertyValue(ROLE_BASE), filter, constraints); while (results.hasMore()) { SearchResult result = results.next(); list = addAttributeValues(getLDAPPropertyValue(ROLE_NAME), attrs, list); MessageFormat expandRolesMatchingFormat = new MessageFormat(getLDAPPropertyValue(EXPAND_ROLES_MATCHING)); while (!pendingNameExpansion.isEmpty()) { String name = pendingNameExpansion.remove(); filter = expandRolesMatchingFormat.format(new String[]{name}); results = context.search(getLDAPPropertyValue(ROLE_BASE), filter, constraints); while (results.hasMore()) {
if (isLoginPropertySet(CONNECTION_USERNAME)) { context.addToEnvironment(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME)); } else { context.removeFromEnvironment(Context.SECURITY_PRINCIPAL); if (isLoginPropertySet(CONNECTION_PASSWORD)) { context.addToEnvironment(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD)); } else { context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);
context = open(); } catch (NamingException ne) { FailedLoginException ex = new FailedLoginException("Error opening LDAP connection"); if (!isLoginPropertySet(USER_SEARCH_MATCHING)) return false; userSearchMatchingFormat = new MessageFormat(getLDAPPropertyValue(USER_SEARCH_MATCHING)); userSearchSubtreeBool = Boolean.valueOf(getLDAPPropertyValue(USER_SEARCH_SUBTREE)).booleanValue(); doRFC2254Encoding(username) }); SearchControls constraints = new SearchControls(); if (isLoginPropertySet(USER_ROLE_NAME)) { list.add(getLDAPPropertyValue(USER_ROLE_NAME)); log.debug("Get the user DN."); log.debug("Looking for the user in LDAP with "); log.debug(" base DN: " + getLDAPPropertyValue(USER_BASE)); log.debug(" filter: " + filter); NamingEnumeration<SearchResult> results = context.search(getLDAPPropertyValue(USER_BASE), filter, constraints); Name baseName = parser.parse(getLDAPPropertyValue(USER_BASE)); Name entryName = parser.parse(result.getName()); Name name = contextName.addAll(baseName); close(context);
boolean roleSearchSubtreeBool; boolean expandRolesBool; roleSearchMatchingFormat = new MessageFormat(getLDAPPropertyValue(ROLE_SEARCH_MATCHING)); roleSearchSubtreeBool = Boolean.valueOf(getLDAPPropertyValue(ROLE_SEARCH_SUBTREE)).booleanValue(); expandRolesBool = Boolean.valueOf(getLDAPPropertyValue(EXPAND_ROLES)).booleanValue(); if (!isLoginPropertySet(ROLE_NAME)) { return list; doRFC2254Encoding(dn), doRFC2254Encoding(username) }); log.debug("Get user roles."); log.debug("Looking for the user roles in LDAP with "); log.debug(" base DN: " + getLDAPPropertyValue(ROLE_BASE)); log.debug(" filter: " + filter); NamingEnumeration<SearchResult> results = context.search(getLDAPPropertyValue(ROLE_BASE), filter, constraints); while (results.hasMore()) { SearchResult result = results.next(); list = addAttributeValues(getLDAPPropertyValue(ROLE_NAME), attrs, list); MessageFormat expandRolesMatchingFormat = new MessageFormat(getLDAPPropertyValue(EXPAND_ROLES_MATCHING)); while (!pendingNameExpansion.isEmpty()) { String name = pendingNameExpansion.remove(); filter = expandRolesMatchingFormat.format(new String[]{name}); results = context.search(getLDAPPropertyValue(ROLE_BASE), filter, constraints); while (results.hasMore()) {
protected DirContext open() throws NamingException { try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, getLDAPPropertyValue(INITIAL_CONTEXT_FACTORY)); if (isLoginPropertySet(CONNECTION_USERNAME)) { env.put(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME)); } else { throw new NamingException("Empty username is not allowed"); } if (isLoginPropertySet(CONNECTION_PASSWORD)) { env.put(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD)); } else { throw new NamingException("Empty password is not allowed"); } env.put(Context.SECURITY_PROTOCOL, getLDAPPropertyValue(CONNECTION_PROTOCOL)); env.put(Context.PROVIDER_URL, getLDAPPropertyValue(CONNECTION_URL)); env.put(Context.SECURITY_AUTHENTICATION, getLDAPPropertyValue(AUTHENTICATION)); context = new InitialDirContext(env); } catch (NamingException e) { log.error(e.toString()); throw e; } return context; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { String encryptionPassword = (String)options.get(ENCRYPTION_PASSWORD); String passwordEnvName = options.get(PASSWORD_ENV_NAME) != null ? (String)options.get(PASSWORD_ENV_NAME) : DEFAULT_PASSWORD_ENV_NAME; String passwordAlgorithm = options.get(PASSWORD_ALGORITHM) != null ? (String)options.get(PASSWORD_ALGORITHM) : DEFAULT_PASSWORD_ALGORITHM; EnvironmentStringPBEConfig envConfig = new EnvironmentStringPBEConfig(); envConfig.setAlgorithm(passwordAlgorithm); //If the password was set, use it //else look up the password from the environment if (encryptionPassword == null) { envConfig.setPasswordEnvName(passwordEnvName); } else { envConfig.setPassword(encryptionPassword); } configurationEncryptor.setConfig(envConfig); EncryptableProperties encryptableOptions = new EncryptableProperties(configurationEncryptor); encryptableOptions.putAll(options); super.initialize(subject, callbackHandler, sharedState, encryptableOptions); }
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("User name"); callbacks[1] = new PasswordCallback("Password", false); try { handler.handle(callbacks); } catch (IOException ioe) { throw (LoginException)new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException)new LoginException().initCause(uce); } String password; username = ((NameCallback)callbacks[0]).getName(); if (username == null) return false; if (((PasswordCallback)callbacks[1]).getPassword() != null) password = new String(((PasswordCallback)callbacks[1]).getPassword()); else password=""; // authenticate will throw LoginException // in case of failed authentication authenticate(username, password); return true; }
context = open(); } catch (NamingException ne) { FailedLoginException ex = new FailedLoginException("Error opening LDAP connection"); if (!isLoginPropertySet(USER_SEARCH_MATCHING)) return false; userSearchMatchingFormat = new MessageFormat(getLDAPPropertyValue(USER_SEARCH_MATCHING)); userSearchSubtreeBool = Boolean.valueOf(getLDAPPropertyValue(USER_SEARCH_SUBTREE)).booleanValue(); doRFC2254Encoding(username) }); SearchControls constraints = new SearchControls(); if (isLoginPropertySet(USER_ROLE_NAME)) { list.add(getLDAPPropertyValue(USER_ROLE_NAME)); log.debug("Get the user DN."); log.debug("Looking for the user in LDAP with "); log.debug(" base DN: " + getLDAPPropertyValue(USER_BASE)); log.debug(" filter: " + filter); NamingEnumeration<SearchResult> results = context.search(getLDAPPropertyValue(USER_BASE), filter, constraints); Name baseName = parser.parse(getLDAPPropertyValue(USER_BASE)); Name entryName = parser.parse(result.getName()); Name name = contextName.addAll(baseName); close(context);
protected DirContext open() throws NamingException { try { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, getLDAPPropertyValue(INITIAL_CONTEXT_FACTORY)); if (isLoginPropertySet(CONNECTION_USERNAME)) { env.put(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME)); } else { throw new NamingException("Empty username is not allowed"); } if (isLoginPropertySet(CONNECTION_PASSWORD)) { env.put(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD)); } else { throw new NamingException("Empty password is not allowed"); } env.put(Context.SECURITY_PROTOCOL, getLDAPPropertyValue(CONNECTION_PROTOCOL)); env.put(Context.PROVIDER_URL, getLDAPPropertyValue(CONNECTION_URL)); env.put(Context.SECURITY_AUTHENTICATION, getLDAPPropertyValue(AUTHENTICATION)); context = new InitialDirContext(env); } catch (NamingException e) { log.error(e.toString()); throw e; } return context; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { String encryptionPassword = (String)options.get(ENCRYPTION_PASSWORD); String passwordEnvName = options.get(PASSWORD_ENV_NAME) != null ? (String)options.get(PASSWORD_ENV_NAME) : DEFAULT_PASSWORD_ENV_NAME; String passwordAlgorithm = options.get(PASSWORD_ALGORITHM) != null ? (String)options.get(PASSWORD_ALGORITHM) : DEFAULT_PASSWORD_ALGORITHM; EnvironmentStringPBEConfig envConfig = new EnvironmentStringPBEConfig(); envConfig.setAlgorithm(passwordAlgorithm); //If the password was set, use it //else look up the password from the environment if (encryptionPassword == null) { envConfig.setPasswordEnvName(passwordEnvName); } else { envConfig.setPassword(encryptionPassword); } configurationEncryptor.setConfig(envConfig); EncryptableProperties encryptableOptions = new EncryptableProperties(configurationEncryptor); encryptableOptions.putAll(options); super.initialize(subject, callbackHandler, sharedState, encryptableOptions); }
@Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("User name"); callbacks[1] = new PasswordCallback("Password", false); try { handler.handle(callbacks); } catch (IOException ioe) { throw (LoginException)new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException)new LoginException().initCause(uce); } String password; username = ((NameCallback)callbacks[0]).getName(); if (username == null) return false; if (((PasswordCallback)callbacks[1]).getPassword() != null) password = new String(((PasswordCallback)callbacks[1]).getPassword()); else password=""; // authenticate will throw LoginException // in case of failed authentication authenticate(username, password); return true; }
if (isLoginPropertySet(CONNECTION_USERNAME)) { context.addToEnvironment(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME)); } else { context.removeFromEnvironment(Context.SECURITY_PRINCIPAL); if (isLoginPropertySet(CONNECTION_PASSWORD)) { context.addToEnvironment(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD)); } else { context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);
if (isLoginPropertySet(CONNECTION_USERNAME)) { context.addToEnvironment(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME)); } else { context.removeFromEnvironment(Context.SECURITY_PRINCIPAL); if (isLoginPropertySet(CONNECTION_PASSWORD)) { context.addToEnvironment(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD)); } else { context.removeFromEnvironment(Context.SECURITY_CREDENTIALS);