예제 #1
0
 protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
     throws AuthenticationException {
   UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
   Useraccount user = userAccountService.getUserAccount(token.getUsername());
   if (user != null) {
     ByteSource salt = ByteSource.Util.bytes(user.getSalt());
     return new SimpleAuthenticationInfo(user, user.getPassword(), salt, getName());
   } else {
     return null;
   }
 }
예제 #2
0
  protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    // Long userId = (Long)
    // principals.fromRealm(getName()).iterator().next();
    // Useraccount user = userAccountService.getUserAccount(userId);
    Object u = principals.iterator().next();
    Useraccount user = null;
    if (u instanceof Useraccount) {
      // re-retrieve the useraccount instance as the one enclosed in
      // principal
      // does not carry roles in it
      logger.info("user is a user");
      int userid = ((Useraccount) u).getId();
      user = userAccountService.getUserAccount(userid);
    } else {
      logger.info("user is not user");
    }

    if (user != null) {
      SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
      // FIXME add roles
      // for (Role role : user.getRoles()) {
      // info.addRole(role.getName());
      // info.addStringPermissions(role.getPermissions());
      // }
      List<Userrole> roles = user.getRoles();
      logger.info("id:" + user.getId());
      logger.info("uname:" + user.getUsername());
      logger.info("email:" + user.getEmail());
      if (roles == null) {
        logger.info("roles is null");
      } else if (roles.size() == 0) {
        logger.info("has no roles");
      } else {
        for (Userrole role : roles) {
          logger.info("role:" + role.getRolename());
          info.addRole(role.getRolename());
          // info.addStringPermissions(role.getPermissions());
        }
      }
      return info;
    } else {
      return null;
    }
  }