statement.close(); return dbCredential==null ? null : new UserInfo (userName, Credential.getCredential(dbCredential), roles);
statement.close(); return dbCredential==null ? null : new UserInfo (userName, Credential.getCredential(dbCredential), roles);
/** * Don't implement this as we want to pre-fetch all of the users. * * @param userName * @throws Exception */ public UserInfo getUserInfo(String userName) throws Exception { PropertyUserStore propertyUserStore = _propertyUserStores.get(_filename); if (propertyUserStore == null) throw new IllegalStateException("PropertyUserStore should never be null here!"); LOG.debug("Checking PropertyUserStore "+_filename+" for "+userName); UserIdentity userIdentity = propertyUserStore.getUserIdentity(userName); if (userIdentity==null) return null; Set<Principal> principals = userIdentity.getSubject().getPrincipals(); List<String> roles = new ArrayList<String>(); for ( Principal principal : principals ) { roles.add( principal.getName() ); } Credential credential = (Credential)userIdentity.getSubject().getPrivateCredentials().iterator().next(); LOG.debug("Found: " + userName + " in PropertyUserStore "+_filename); return new UserInfo(userName, credential, roles); }
/** * Don't implement this as we want to pre-fetch all of the users. * * @param userName * @throws Exception */ public UserInfo getUserInfo(String userName) throws Exception { PropertyUserStore propertyUserStore = _propertyUserStores.get(_filename); if (propertyUserStore == null) throw new IllegalStateException("PropertyUserStore should never be null here!"); LOG.debug("Checking PropertyUserStore "+_filename+" for "+userName); UserIdentity userIdentity = propertyUserStore.getUserIdentity(userName); if (userIdentity==null) return null; Set<Principal> principals = userIdentity.getSubject().getPrincipals(); List<String> roles = new ArrayList<String>(); for ( Principal principal : principals ) { roles.add( principal.getName() ); } Credential credential = (Credential)userIdentity.getSubject().getPrivateCredentials().iterator().next(); LOG.debug("Found: " + userName + " in PropertyUserStore "+_filename); return new UserInfo(userName, credential, roles); }
/** * binding authentication check * This method of authentication works only if the user branch of the DIT (ldap tree) * has an ACI (access control instruction) that allow the access to any user or at least * for the user that logs in. * * @param username * @param password * @return true always * @throws LoginException */ public boolean bindingLogin(String username, Object password) throws LoginException, NamingException { SearchResult searchResult = findUser(username); String userDn = searchResult.getNameInNamespace(); LOG.info("Attempting authentication: " + userDn); Hashtable<Object,Object> environment = getEnvironment(); environment.put(Context.SECURITY_PRINCIPAL, userDn); environment.put(Context.SECURITY_CREDENTIALS, password); DirContext dirContext = new InitialDirContext(environment); List<String> roles = getUserRolesByDn(dirContext, userDn); UserInfo userInfo = new UserInfo(username, null, roles); setCurrentUser(new JAASUserInfo(userInfo)); setAuthenticated(true); return true; }
/** * get the available information about the user * <p/> * for this LoginModule, the credential can be null which will result in a * binding ldap authentication scenario * <p/> * roles are also an optional concept if required * * @param username * @return the userinfo for the username * @throws Exception */ public UserInfo getUserInfo(String username) throws Exception { String pwdCredential = getUserCredentials(username); if (pwdCredential == null) { return null; } pwdCredential = convertCredentialLdapToJetty(pwdCredential); Credential credential = Credential.getCredential(pwdCredential); List<String> roles = getUserRoles(_rootContext, username); return new UserInfo(username, credential, roles); }
/** * binding authentication check * This method of authentication works only if the user branch of the DIT (ldap tree) * has an ACI (access control instruction) that allow the access to any user or at least * for the user that logs in. * * @param username * @param password * @return true always * @throws LoginException */ public boolean bindingLogin(String username, Object password) throws LoginException, NamingException { SearchResult searchResult = findUser(username); String userDn = searchResult.getNameInNamespace(); LOG.info("Attempting authentication: " + userDn); Hashtable<Object,Object> environment = getEnvironment(); environment.put(Context.SECURITY_PRINCIPAL, userDn); environment.put(Context.SECURITY_CREDENTIALS, password); DirContext dirContext = new InitialDirContext(environment); List<String> roles = getUserRolesByDn(dirContext, userDn); UserInfo userInfo = new UserInfo(username, null, roles); setCurrentUser(new JAASUserInfo(userInfo)); setAuthenticated(true); return true; }
/** * get the available information about the user * <p/> * for this LoginModule, the credential can be null which will result in a * binding ldap authentication scenario * <p/> * roles are also an optional concept if required * * @param username * @return the userinfo for the username * @throws Exception */ public UserInfo getUserInfo(String username) throws Exception { String pwdCredential = getUserCredentials(username); if (pwdCredential == null) { return null; } pwdCredential = convertCredentialLdapToJetty(pwdCredential); Credential credential = Credential.getCredential(pwdCredential); List<String> roles = getUserRoles(_rootContext, username); return new UserInfo(username, credential, roles); }