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) 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"); } }
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()) )); }
return new SimpleAccount(principal, null, "ldap realm"); } catch (LdapException e) { LOG.error("LDAP error", e);
return new SimpleAccount(user.getName(), null, "session authenticator");
@Override protected AuthenticationInfo buildAuthenticationInfo(Object principal, Object credentials) { String username = (String) principal; UsernamePrincipal customPrincipal = new UsernamePrincipal(username); return new SimpleAccount(customPrincipal, credentials, getName()); } };
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); } } }
protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException { return new SimpleAccount(token.getPrincipal(), token.getCredentials(), getName()); }
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); }
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); } } }
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) throws AuthenticationException { GithubKey t = (GithubKey) token; try { UUID userId = userManager.getId(USER).orElse(null); if (userId == null) { return null; } return userManager.get(userId) .map(u -> { UserPrincipal p = new UserPrincipal(REALM_NAME, u); return new SimpleAccount(Arrays.asList(p, t), t.getKey(), getName()); }) .orElse(null); } catch (Exception e) { log.error("doGetAuthenticationInfo -> error", e); throw e; } }
@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"); } }
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()) )); }
return new SimpleAccount(user.getName(), null, "session authenticator");
@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; }
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 @WithTimer protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { ApiKey t = (ApiKey) token; UserEntry u = userManager.get(t.getUserId()).orElse(null); if (u == null) { return null; } auditLog.add(AuditObject.SYSTEM, AuditAction.ACCESS) .userId(u.getId()) .field("realm", REALM_NAME) .log(); UserPrincipal p = new UserPrincipal(REALM_NAME, u); return new SimpleAccount(Arrays.asList(p, t), t.getKey(), getName()); }
@Override @WithTimer protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { SessionKey t = (SessionKey) token; PartialProcessKey processKey = PartialProcessKey.from(t.getInstanceId()); try { ProcessEntry p = processQueueDao.get(processKey); if (p == null) { log.warn("doGetAuthenticationInfo -> process not found: {}", t.getInstanceId()); return null; } if (p.initiatorId() == null) { log.warn("doGetAuthenticationInfo -> initiator not found: {}", t.getInstanceId()); return null; } if (isFinished(p)) { log.warn("doGetAuthenticationInfo -> process is finished: {}", t.getInstanceId()); return null; } PrincipalCollection principals = getPrincipals(processKey); return new SimpleAccount(principals, t.getInstanceId(), getName()); } catch (Exception e) { log.error("doGetAuthenticationInfo ['{}'] -> error", t.getInstanceId(), e); throw e; } }
@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; }