Package org.atomojo.auth.service.db

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


   }
  
   public Representation get()
   {
      try {
         Group group = fetch();
         if (group!=null) {
            if (facet!=null) {
               if (facet.equals(USER_FACET)) {
                  if (facetId!=null) {
                     try {
                        UUID id = UUID.fromString(facetId);
                        User user = db.getUser(id);
                        if (user!=null) {
                           Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,user);
                           entity.setCharacterSet(CharacterSet.UTF_8);
                           return entity;
                        } else {
                           getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                           return new StringRepresentation("Canot find user by id "+facetId);
                        }
                     } 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 while 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 {
                        User user = db.getUser(facetName);
                        if (user!=null) {
                           Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,user);
                           entity.setCharacterSet(CharacterSet.UTF_8);
                           return entity;
                        } else {
                           getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                           return new StringRepresentation("Cannot find user by alias "+facetName);
                        }
                     } catch (SQLException ex) {
                        getContext().getLogger().log(Level.SEVERE,"Cannot get user with alias "+facetName+" from database.",ex);
                        getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
                        return new StringRepresentation("Exception during processing, see logs.");
                     }
                  } else {
                     try {
                        Representation entity = new DBIteratorRepresentation(MediaType.APPLICATION_XML,XML.USERS_NAME,group.getMembers());
                        entity.setCharacterSet(CharacterSet.UTF_8);
                        return entity;
                     } catch (SQLException ex) {
                        getContext().getLogger().log(Level.SEVERE,"Cannot get users from database.",ex);
                        getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
                        return new StringRepresentation("Exception during processing, see logs.");
                     }
                  }
               } else if (facet.equals(ROLE_FACET)) {
                  if (facetId!=null) {
                     try {
                        UUID id = UUID.fromString(facetId);
                        Role role = db.getRole(id);
                        if (role!=null) {
                           Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,role);
                           entity.setCharacterSet(CharacterSet.UTF_8);
                           return entity;
                        } else {
                           getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                           return null;
                        }
                     } catch (SQLException ex) {
                        getContext().getLogger().log(Level.SEVERE,"Cannot get role 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 {
                        Role role = db.getRole(facetName);
                        if (role!=null) {
                           Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,role);
                           entity.setCharacterSet(CharacterSet.UTF_8);
                           return entity;
                        } else {
                           getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                           return null;
                        }
                     } catch (SQLException ex) {
                        getContext().getLogger().log(Level.SEVERE,"Cannot get role with name "+facetName+" from database.",ex);
                        getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
                        return new StringRepresentation("Exception during processing, see logs.");
                     }
                  } else {
                     Representation entity = new DBIteratorRepresentation(MediaType.APPLICATION_XML,XML.ROLES_NAME,group.getRoles());
                     entity.setCharacterSet(CharacterSet.UTF_8);
                     return entity;
                  }
               } else {
                  getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
View Full Code Here


         getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
         return null;
      }
     
      try {
         Group group = fetch();
         Element top = doc.getDocumentElement();
         if (facet.equals(ROLE_FACET)) {
            if (top.getName().equals(XML.ROLE_NAME)) {
               String sid = top.getAttributeValue("id");
               String name = top.getAttributeValue("name");
               Role role = null;
               if (sid!=null) {
                  role = db.getRole(UUID.fromString(sid));
               }
               if (name!=null && role==null) {
                  role = db.getRole(name);
               }
               if (role==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("Cannot find role "+name);
               } else {
                  group.addRole(role);
                  getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                  return null;
               }
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Element "+top.getName()+" is not allowed.");
            }
         } 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);
               }
               if (user==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("Cannot find user.");
               } else {
                  group.addMember(user);
                  getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                  return null;
               }
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
View Full Code Here

               // eat the exception because it is the same as not found
            }
         }
      }
       */
      Group group = null;
      if (realm!=null) {
         if (alias!=null) {
            group = db.getGroup(realm,alias);
         }
         if (suuid!=null) {
View Full Code Here

      return db.getRealmUser(realm,alias);
   }
  
   public Representation delete() {
      try {
         Group group = fetch();
         if (group!=null) {
            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);
                        }
                        return null;
                     } catch (SQLException ex) {
                        getContext().getLogger().log(Level.SEVERE,"Cannot get user with alias "+facetName+" 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 {
                     getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
                     return null;
                  }
               } else if (facet.equals("roles")) {
                  if (facetId!=null) {
                     try {
                        UUID id = UUID.fromString(facetId);
                        Role role = db.getRole(id);
                        if (role!=null && group.removeRole(role)) {
                           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 role 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 {
                        Role role = db.getRole(facetName);
                        if (role!=null && group.removeRole(role)) {
                           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 role with name "+facetName+" 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 {
                     getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
                     return null;
                  }
               } else {
                  getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                  return null;
               }
            } else {
               group.delete();
            }
            getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            return null;
         } else {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
View Full Code Here

            Realm realm = fetchRealm();
            if (realm==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("The realm does not exist.");
            } else {
               Group group = db.createGroup(realm,id,alias);
               Representation responseEntity = new DBObjectRepresentation(MediaType.APPLICATION_XML,group);
               responseEntity.setCharacterSet(CharacterSet.UTF_8);
               getResponse().setStatus(Status.SUCCESS_CREATED);
               return responseEntity;
            }
View Full Code Here

         }
      }
      StringBuilder groupsRep = new StringBuilder();
      if (groups!=null) {
         while (groups.hasNext()) {
            Group group = groups.next();
            groupsRep.append("<group id='"+group.getUUID()+"' alias='"+group.getAlias()+"'/>\n");
            Iterator<Role> groupRoles = group.getRoles();
            while (groupRoles!=null && groupRoles.hasNext()) {
               userRoles.add(groupRoles.next());
            }
         }
      }
View Full Code Here

                  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 {
View Full Code Here

                  getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
                  return null;
               }
               String sid = top.getAttributeValue("id");
               String name = top.getAttributeValue("alias");
               Group group = null;
               if (sid!=null) {
                  group = db.getGroup(user.getRealm(),UUID.fromString(sid));
               }
               if (name!=null && group==null) {
                  group = db.getGroup(user.getRealm(),name);
View Full Code Here

   }
  
   protected Group fetchGroup(RealmUser user)
      throws SQLException,IllegalArgumentException
   {
      Group group = null;
      if (facetName!=null) {
         group = db.getGroup(user.getRealm(),facetName);
      }
      if (facetId!=null) {
         UUID id = UUID.fromString(facetId);
View Full Code Here

               if (facet.equals(GROUP_FACET)) {
                  if (facetName==null && facetId==null) {
                     getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
                     return null;
                  } else {
                     Group group = fetchGroup(user);
                     if (group!=null) {
                        if (user.removeGroup(group)) {
                           getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                           return null;
                        } else {
View Full Code Here

TOP

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

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.