Package org.atomojo.auth.service.db

Examples of org.atomojo.auth.service.db.RealmUser


            }
         } else if (facet.equals(USER_FACET)) {
            if (top.getName().equals(XML.USER_NAME)) {
               String sid = top.getAttributeValue("id");
               String alias = top.getAttributeValue("alias");
               RealmUser user = null;
               if (sid!=null) {
                  UUID id = UUID.fromString(sid);
                  user = fetchUser(id);
               } else {
                  user = fetchUser(alias);
View Full Code Here


            if (facet!=null) {
               if (facet.equals("members")) {
                  if (facetId!=null) {
                     try {
                        UUID id = UUID.fromString(facetId);
                        RealmUser user = fetchUser(id);
                        if (user!=null && group.removeMember(user)) {
                           getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                        } else {
                           getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                        }
                        return null;
                     } catch (SQLException ex) {
                        getContext().getLogger().log(Level.SEVERE,"Cannot get user with id "+facetId+" from database.",ex);
                        getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
                        return new StringRepresentation("Exception during processing, see logs.");
                     } catch (IllegalArgumentException ex) {
                        getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                        return new StringRepresentation("Bad UUID value "+facetId);
                     }
                  } else if (facetName!=null) {
                     try {
                        RealmUser user = fetchUser(facetName);
                        if (user!=null && group.removeMember(user)) {
                           getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                        } else {
                           getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                        }
View Full Code Here

            if ((identifier != null) && (secret != null)) {
               getContext().getLogger().info("Authenticating " + identifier);
               try {
                  Realm currentRealm = RealmUserGuard.this.realm == null ? (Realm) request.getAttributes().get(AuthApplication.REALM_ATTR) : RealmUserGuard.this.realm;
                  if (currentRealm != null) {
                     RealmUser user = AuthResource.findRealmUser(RealmUserGuard.this.db, currentRealm, identifier);
                     if (user != null && user.getUser().checkPassword(new String(secret))) {
                        getContext().getLogger().info("Authenticated: " + user.getAlias() + ", checking roles and groups");
                        if (permissions != null) {
                           for (Permission p : permissions) {
                              if (!user.hasPermission(p)) {
                                 user = null;
                                 break;
                              }
                           }
                           if (user != null && group != null) {
                              if (!user.isMemberOf(group)) {
                                 user = null;
                              }
                           }
                        }
                        if (user != null && !hasRealmSpecific(request, user)) {
                           user = null;
                        }
                        if (user != null) {
                           getContext().getLogger().info("Accepted: " + user.getAlias());
                        }
                        if (user != null) {
                           if (user != null) {
                              request.getAttributes().put(AuthApplication.USER_ATTR, user);
                           }
View Full Code Here

      if (realm==null) {
         return null;
      }
      //getContext().getLogger().info("Testing auth...");
      try {
         RealmUser user = null;
         if (email!=null) {
            getLogger().info("Recovery requested for realm "+realm.getName()+" email "+email);
            user = db.findRealmUserByEmail(realm, email);
         } else {
            getLogger().info("Recovery requested for realm "+realm.getName()+" alias "+alias);
            user = db.getRealmUser(realm,alias);
         }
         if (user==null) {
            return null;
         }
         User.Authenticated authd = user.getUser().recover(realm);
         return getSessionEntity(user,authd.getSession());
      } catch (SQLException ex) {
         getContext().getLogger().log(Level.SEVERE,"Cannot get user data from database.",ex);
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
         return new StringRepresentation("Exception during processing, see logs.");
View Full Code Here

   }
  
   static RealmUser findRealmUser(AuthDB db,Realm realm,String authid)
      throws SQLException,IllegalArgumentException
   {
      RealmUser user = null;
      if (authid.startsWith("urn:uuid:")) {
         // by uuid
         UUID userid = UUID.fromString(authid.substring(9));
         user = db.getRealmUser(realm,userid);
      } else if (authid.indexOf('@')>0) {
View Full Code Here

                     String email = authd.getUser().getEmail();
                     Iterator<Group> groups = null;
                     Iterator<Role> roles = authd.getUser().getRoles();
                     // If we have a realm, we need the realm user to get the right alias
                     if (realm!=null) {
                        RealmUser ruser = db.findRealmUser(realm,authd.getUser());
                        if (ruser!=null) {
                           userAlias = ruser.getAlias();
                           name = ruser.getName();
                           email = ruser.getEmail();
                           groups = ruser.getGroups();
                        }
                     }
                     getResponse().setStatus(Status.SUCCESS_OK);
                     return getSessionEntity(authd.getSession(),userId,userAlias,name,email,roles,groups);
                  }
               } catch (IllegalArgumentException ex) {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return null;
               }
            }
            getResponse().setChallengeRequests(Collections.singletonList(new ChallengeRequest(ChallengeScheme.HTTP_BASIC,realm==null ? "users" : "realm "+realm.getName())));
            getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
            return null;
         }
         String authid = authorization.getIdentifier().trim();
         String password = new String(authorization.getSecret());
         User user = null;
         if (realm!=null) {
            RealmUser ruser = findRealmUser(db,realm,authid);
            if (ruser!=null) {
               user = ruser.getUser();
            }
            if (user==null) {
               // see if the user is a super user across realms
               user = findUser(db,authid);
               if (user!=null) {
                  // The user must either be a superuser or have the cross-realm permission
                  Permission superuser = db.getPermission(AuthDB.SUPERUSER_PERMISSION);
                  Permission crossrealm = db.getPermission(AuthDB.ACROSS_REALM_PERMISSION);
                  if (!user.hasPermission(superuser) && !user.hasPermission(crossrealm)) {
                     user = null;
                  }
               }
            }
         } else {
            user = findUser(db,authid);
         }
         if (user!=null) {
            try {
               String seconds = requestForm.getFirstValue("expiration");
               long requestExpiration = seconds==null ? expiration : Long.parseLong(seconds)*1000;
               if ("false".equals(requestForm.getFirstValue("session"))) {
                  requestExpiration = 0;
               }
               User.Authenticated authd = user.authenticate(realm,password,requestExpiration);
               if (authd!=null) {
                  String userAlias = authd.getUser().getAlias();
                  UUID userId = authd.getUser().getUUID();
                  String name = authd.getUser().getName();
                  String email = authd.getUser().getEmail();
                  Iterator<Group> groups = null;
                  Iterator<Role> roles = authd.getUser().getRoles();
                  // If we have a realm, we need the realm user to get the right alias
                  if (realm!=null) {
                     RealmUser ruser = db.findRealmUser(realm,authd.getUser());
                     if (ruser!=null) {
                        userAlias = ruser.getAlias();
                        name = ruser.getName();
                        email = ruser.getEmail();
                        groups = ruser.getGroups();
                     }
                  }
                  getResponse().setStatus(Status.SUCCESS_OK);
                  return getSessionEntity(authd.getSession(),userId,userAlias,name,email,roles,groups);
               }
View Full Code Here

            Realm realm = fetchRealm();
            if (realm==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return new StringRepresentation("Realm not found.");
            }
            RealmUser user = fetchRealmUser(realm);
            if (user==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return new StringRepresentation("User not found.");
            }
            if (user.hasRole(role)) {
               getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
            }
            return null;
           
         } else {
            User user = fetchUser();
            if (user==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return new StringRepresentation("User not found.");
            }
            if (user.hasRole(role)) {
               getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
            }
            return null;
View Full Code Here

   }
  
   protected RealmUser fetchRealmUser(Realm realm)
      throws SQLException,IllegalArgumentException
   {
      RealmUser user = null;
      if (userAlias!=null) {
         user = db.getRealmUser(realm,userAlias);
      }
      if (userId!=null) {
         UUID id = UUID.fromString(userId);
View Full Code Here

               // inherit the alias as it is the same
               alias = null;
            }
           
            if (db.isRealmUserAliasAvailable(realm,user,alias)) {
               RealmUser realmUser = db.createRealmUser(realm,user,alias,name==null ? null : name.getText(),email==null ? null : email.getText());
               if (realmUser==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
                  return new StringRepresentation("The realm user could not be created.");
               } else {
                  Representation responseEntity = new DBObjectRepresentation(MediaType.APPLICATION_XML,realmUser);
View Full Code Here

   }
  
   public Representation get()
   {
      try {
         RealmUser user = fetch();
         if (user!=null) {
            if (facet!=null) {
               if (facet.equals(GROUP_FACET)) {
                  if (facetName==null && facetId==null) {
                     Representation entity = new DBIteratorRepresentation(MediaType.APPLICATION_XML,XML.GROUPS_NAME,user.getGroups(),false);
                     entity.setCharacterSet(CharacterSet.UTF_8);
                     return entity;
                  } else {
                     Group group = fetchGroup(user);
                     if (group!=null && user.isMemberOf(group)) {
                        Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,group);
                        entity.setCharacterSet(CharacterSet.UTF_8);
                        return entity;
                     } else {
                        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
View Full Code Here

TOP

Related Classes of org.atomojo.auth.service.db.RealmUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.