protected void processUserDefinitions(Map<String, String> userDefs) { if (userDefs == null || userDefs.isEmpty()) { return; } for (String username : userDefs.keySet()) { String value = userDefs.get(username); String[] passwordAndRolesArray = StringUtils.split(value); String password = passwordAndRolesArray[0]; SimpleAccount account = getUser(username); if (account == null) { account = new SimpleAccount(username, password, getName()); add(account); } account.setCredentials(password); if (passwordAndRolesArray.length > 1) { for (int i = 1; i < passwordAndRolesArray.length; i++) { String rolename = passwordAndRolesArray[i]; account.addRole(rolename); SimpleRole role = getRole(rolename); if (role != null) { account.addObjectPermissions(role.getPermissions()); } } } else { account.setRoles(null); } } }
/** * Merges the specified <code>AuthenticationInfo</code> into this <code>Account</code>. * <p/> * If the specified argument is also an instance of {@link SimpleAccount SimpleAccount}, the * {@link #isLocked()} and {@link #isCredentialsExpired()} attributes are merged (set on this instance) as well * (only if their values are <code>true</code>). * * @param info the <code>AuthenticationInfo</code> to merge into this account. */ public void merge(AuthenticationInfo info) { authcInfo.merge(info); // Merge SimpleAccount specific info if (info instanceof SimpleAccount) { SimpleAccount otherAccount = (SimpleAccount) info; if (otherAccount.isLocked()) { setLocked(true); } if (otherAccount.isCredentialsExpired()) { setCredentialsExpired(true); } } }
/** * Returns {@link #getPrincipals() principals}.toString() if they are not null, otherwise prints out the string * "empty" * * @return the String representation of this Account object. */ public String toString() { return getPrincipals() != null ? getPrincipals().toString() : "empty"; }
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; SimpleAccount account = getUser(upToken.getUsername()); if (account != null) { if (account.isLocked()) { throw new LockedAccountException("Account [" + account + "] is locked."); } if (account.isCredentialsExpired()) { String msg = "The credentials for account [" + account + "] are expired"; throw new ExpiredCredentialsException(msg); } } return account; }
public void addAccount(String username, String password, String... roles) { Set<String> roleNames = CollectionUtils.asSet(roles); SimpleAccount account = new SimpleAccount(username, password, getName(), roleNames, null); add(account); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) { UsernamePasswordToken upToken = (UsernamePasswordToken) token; UserDefault user = userRepository.findByUserId(upToken.getUsername()); if (user != null) { SimpleAccount account = new SimpleAccount(user, user.getCredentials(), getName()); account.addRole(user.getRoles()); return account; } return null; }
private void addRootAccount(String username, String password) { LOG.debug("Adding root account named {}, having all permissions", username); add(new SimpleAccount( username, password, getName(), CollectionUtils.asSet("root"), CollectionUtils.<Permission>asSet(new AllPermission()) )); }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) { JWTAuthenticationToken upToken = (JWTAuthenticationToken) token; UserDefault user = userRepository.findById(upToken.getUserId()); if (user != null && userRepository.validateToken(upToken.getToken())) { SimpleAccount account = new SimpleAccount(user, upToken.getToken(), getName()); account.addRole(user.getRoles()); return account; } return null; }
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; SimpleAccount account = getUser(upToken.getUsername()); if (account != null) { if (account.isLocked()) { throw new LockedAccountException("Account [" + account + "] is locked."); } if (account.isCredentialsExpired()) { String msg = "The credentials for account [" + account + "] are expired"; throw new ExpiredCredentialsException(msg); } } return account; }
protected void processUserDefinitions(Map<String, String> userDefs) { if (userDefs == null || userDefs.isEmpty()) { return; } for (String username : userDefs.keySet()) { String value = userDefs.get(username); String[] passwordAndRolesArray = StringUtils.split(value); String password = passwordAndRolesArray[0]; SimpleAccount account = getUser(username); if (account == null) { account = new SimpleAccount(username, password, getName()); add(account); } account.setCredentials(password); if (passwordAndRolesArray.length > 1) { for (int i = 1; i < passwordAndRolesArray.length; i++) { String rolename = passwordAndRolesArray[i]; account.addRole(rolename); SimpleRole role = getRole(rolename); if (role != null) { account.addObjectPermissions(role.getPermissions()); } } } else { account.setRoles(null); } } }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { AccessTokenAuthToken authToken = (AccessTokenAuthToken) token; final AccessToken accessToken = accessTokenService.load(String.valueOf(authToken.getToken())); if (accessToken == null) { return null; } final User user = userService.load(accessToken.getUserName()); if (user == null) { return null; } if (LOG.isDebugEnabled()) { LOG.debug("Found user {} for access token.", user); } try { accessTokenService.touch(accessToken); } catch (ValidationException e) { LOG.warn("Unable to update access token's last access date.", e); } ShiroSecurityContext.requestSessionCreation(false); return new SimpleAccount(user.getName(), null, "access token realm"); } }
/** * Merges the specified <code>AuthenticationInfo</code> into this <code>Account</code>. * <p/> * If the specified argument is also an instance of {@link SimpleAccount SimpleAccount}, the * {@link #isLocked()} and {@link #isCredentialsExpired()} attributes are merged (set on this instance) as well * (only if their values are <code>true</code>). * * @param info the <code>AuthenticationInfo</code> to merge into this account. */ public void merge(AuthenticationInfo info) { authcInfo.merge(info); // Merge SimpleAccount specific info if (info instanceof SimpleAccount) { SimpleAccount otherAccount = (SimpleAccount) info; if (otherAccount.isLocked()) { setLocked(true); } if (otherAccount.isCredentialsExpired()) { setCredentialsExpired(true); } } }
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; SimpleAccount account = getUser(upToken.getUsername()); if (account != null) { if (account.isLocked()) { throw new LockedAccountException("Account [" + account + "] is locked."); } if (account.isCredentialsExpired()) { String msg = "The credentials for account [" + account + "] are expired"; throw new ExpiredCredentialsException(msg); } } return account; }
/** * If the {@link #getPrincipals() principals} are not null, returns <code>principals.hashCode()</code>, otherwise * returns 0 (zero). * * @return <code>principals.hashCode()</code> if they are not null, 0 (zero) otherwise. */ public int hashCode() { return (getPrincipals() != null ? getPrincipals().hashCode() : 0); }
protected void processUserDefinitions(Map<String, String> userDefs) { if (userDefs == null || userDefs.isEmpty()) { return; } for (String username : userDefs.keySet()) { String value = userDefs.get(username); String[] passwordAndRolesArray = StringUtils.split(value); String password = passwordAndRolesArray[0]; SimpleAccount account = getUser(username); if (account == null) { account = new SimpleAccount(username, password, getName()); add(account); } account.setCredentials(password); if (passwordAndRolesArray.length > 1) { for (int i = 1; i < passwordAndRolesArray.length; i++) { String rolename = passwordAndRolesArray[i]; account.addRole(rolename); SimpleRole role = getRole(rolename); if (role != null) { account.addObjectPermissions(role.getPermissions()); } } } else { account.setRoles(null); } } }
return new SimpleAccount(principal, null, "ldap realm"); } catch (LdapException e) { LOG.error("LDAP error", e);
/** * Merges the specified <code>AuthenticationInfo</code> into this <code>Account</code>. * <p/> * If the specified argument is also an instance of {@link SimpleAccount SimpleAccount}, the * {@link #isLocked()} and {@link #isCredentialsExpired()} attributes are merged (set on this instance) as well * (only if their values are <code>true</code>). * * @param info the <code>AuthenticationInfo</code> to merge into this account. */ public void merge(AuthenticationInfo info) { authcInfo.merge(info); // Merge SimpleAccount specific info if (info instanceof SimpleAccount) { SimpleAccount otherAccount = (SimpleAccount) info; if (otherAccount.isLocked()) { setLocked(true); } if (otherAccount.isCredentialsExpired()) { setCredentialsExpired(true); } } }
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authToken) throws AuthenticationException { OAuth2Token token = (OAuth2Token) authToken; SimpleAccount account = authorizationServer.getAccountFromAccessToken(token.getToken()); if (account != null) { if (account.isLocked()) { throw new LockedAccountException("Account [" + account + "] is locked."); } if (account.isCredentialsExpired()) { String msg = "The credentials for account [" + account + "] are expired"; throw new ExpiredCredentialsException(msg); } } return account; }
/** * Returns <code>true</code> if the specified object is also a {@link SimpleAccount SimpleAccount} and its * {@link #getPrincipals() principals} are equal to this object's <code>principals</code>, <code>false</code> otherwise. * * @param o the object to test for equality. * @return <code>true</code> if the specified object is also a {@link SimpleAccount SimpleAccount} and its * {@link #getPrincipals() principals} are equal to this object's <code>principals</code>, <code>false</code> otherwise. */ public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof SimpleAccount) { SimpleAccount sa = (SimpleAccount) o; //principal should be unique across the application, so only check this for equality: return (getPrincipals() != null ? getPrincipals().equals(sa.getPrincipals()) : sa.getPrincipals() == null); } return false; }
return new SimpleAccount(user.getName(), null, "session authenticator");