Example #1
0
  private Set<UserPermissionDTO> getUserPermissions(UserDTO user) {

    Authentication authenticator =
        new Authentication() {

          @Override
          public Collection<? extends GrantedAuthority> getAuthorities() {
            List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
            auths.add(new GrantedPermission("ROLE_USER_AUTHENTICATOR"));
            return auths;
          }

          @Override
          public Object getCredentials() {
            return null;
          }

          @Override
          public Object getDetails() {
            return null;
          }

          @Override
          public Object getPrincipal() {
            return null;
          }

          @Override
          public boolean isAuthenticated() {
            return true;
          }

          @Override
          public void setAuthenticated(boolean arg0) throws IllegalArgumentException {}

          @Override
          public String getName() {
            return "AUTHENTICATOR";
          }
        };
    SecurityContextHolder.getContext().setAuthentication(authenticator);
    Set<UserPermissionDTO> permissions = userManager.getGrantedPermissionsForUser(user);
    SecurityContextHolder.getContext().setAuthentication(null);

    return permissions;
  }
Example #2
0
  public UserDTO getUser(LoginCredentials credentials)
      throws BadCredentialsException, AccountStatusException, UserRetrievalException {

    UserDTO user = getUserByName(credentials.getUserName());

    if (user != null) {
      if (checkPassword(credentials.getPassword(), userManager.getEncodedPassword(user))) {

        try {
          userDetailsChecker.check(user);
        } catch (AccountStatusException ex) {
          throw ex;
        }
        return user;

      } else {
        throw new BadCredentialsException("Bad username and password combination.");
      }
    } else {
      throw new BadCredentialsException("Bad username and password combination.");
    }
  }