Esempio n. 1
0
  @Override
  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
      throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;

    User user = userDAO.getUserByUsername(upToken.getUsername());

    if (user == null) {
      throw new AuthenticationException("Login name [" + upToken.getUsername() + "] not found!");
    }

    return new SimpleAuthenticationInfo(user, user.getPassword(), getName());
  }
Esempio n. 2
0
  @Override
  protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    Set<String> roles = new HashSet<String>();
    Set<Permission> permissions = new HashSet<Permission>();
    Collection<User> principalsList = principals.byType(User.class);

    for (User userPrincipal : principalsList) {
      try {
        User user = userDAO.getById(userPrincipal.getId());
        Set<Role> userRoles = user.getRoles();
        for (Role role : userRoles) {
          roles.add(role.getRole());
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roles);
    info.setRoles(roles);
    info.setObjectPermissions(permissions);

    return info;
  }