Package org.atomojo.auth.service.db

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


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


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

                  }
               } 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);
                        }
View Full Code Here

   }
  
   public Representation get()
   {
      try {
         Role role = fetch();
         if (role!=null) {
            if (permissionId!=null) {
               getContext().getLogger().info("Getting permission "+permissionId+" for role {"+role.getUUID()+"}"+role.getName());
               // check for permission by id
               try {
                  UUID id = UUID.fromString(permissionId);
                  Permission p = db.getPermission(id);
                  if (p==null) {
                     getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                     return new StringRepresentation("Permission does not exist.");
                  } else if (!role.hasPermission(p)) {
                     getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                     return new StringRepresentation("Role does not have the permission.");
                  } else {
                     getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                     return null;
                  }
               } catch (SQLException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Error retrieving permission "+permissionId,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 "+permissionId);
               }
            } else if (permissionName!=null) {
               // check for permission by name
               try {
                  Permission p = db.getPermission(permissionName);
                  if (p==null) {
                     getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                     return new StringRepresentation("Permission does not exist.");
                  } else if (!role.hasPermission(p)) {
                     getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                     return new StringRepresentation("Role does not have the permission.");
                  } else {
                     getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                     return null;
View Full Code Here

         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("XML parse error: "+ex.getMessage());
      }
     
      try {
         Role role = fetch();
         Element top = doc.getDocumentElement();
         String sid = top.getAttributeValue("id");
         String name = top.getAttributeValue("name");
         Permission p = null;
         if (sid!=null) {
            p = db.getPermission(UUID.fromString(sid));
         }
         if (name!=null) {
            p = db.getPermission(name);
         }
         if (p==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("Cannot find permission.");
         } else {
            role.addPermission(p);
            getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            return null;
         }
      } catch (SQLException ex) {
         getContext().getLogger().log(Level.SEVERE,"Error while adding permission to role.",ex);
View Full Code Here

   }
  
   protected Role fetch()
      throws SQLException
   {
      Role role = null;
      if (name!=null) {
         role = db.getRole(name);
      }
      if (suuid!=null) {
         UUID id = UUID.fromString(suuid);
View Full Code Here

      return role;
   }
  
   public Representation delete() {
      try {
         Role role = fetch();
         if (role!=null) {
            if (permissionId!=null) {
               // delete for permission by id
               try {
                  UUID id = UUID.fromString(permissionId);
                  Permission p = db.getPermission(id);
                  if (p==null || !role.hasPermission(p)) {
                     getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                  } else {
                     role.removePermission(p);
                     getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                  }
                  return null;
               } catch (SQLException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Error deleting permission "+permissionId,ex);
                  getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
                  return new StringRepresentation("Database error retrieving permission, see logs.");
               } catch (IllegalArgumentException ex) {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("Bad UUID value "+permissionId);
               }
            } else if (permissionName!=null) {
               // delete for permission by name
               try {
                  Permission p = db.getPermission(permissionName);
                  if (p==null || !role.hasPermission(p)) {
                     getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                  } else {
                     role.removePermission(p);
                     getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                  }
                  return null;
               } catch (SQLException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Error deleting permission "+permissionName,ex);
                  getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
                  return new StringRepresentation("Database error retrieving permission, see logs.");
               }
            } else {
               role.delete();
               getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
               return null;
            }
         } else {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
View Full Code Here

            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The 'name' attribute must be present.");
         }

         try {
            Role role = db.createRole(name,id);
            Representation responseEntity = new DBObjectRepresentation(MediaType.APPLICATION_XML,role);
            responseEntity.setCharacterSet(CharacterSet.UTF_8);
            getResponse().setStatus(Status.SUCCESS_CREATED);
            return responseEntity;
         } catch (SQLException ex) {
View Full Code Here

   }
  
   public Representation get()
   {
      try {
         Role role = fetchRole();
         if (role==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return new StringRepresentation("Role not found.");
         }
         if (permissionId==null && permissionName==null) {
            Representation entity = new DBObjectRepresentation(MediaType.APPLICATION_XML,role);
            entity.setCharacterSet(CharacterSet.UTF_8);
            getResponse().setStatus(Status.SUCCESS_OK);
            return entity;
         } else {
            Permission p = fetchPermission();
            if (p==null || !role.hasPermission(p)) {
               getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
            } else {
               getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            }
            return null;
View Full Code Here

   }
  
   protected Role fetchRole()
      throws SQLException,IllegalArgumentException
   {
      Role role = null;
      if (roleName!=null) {
         role = db.getRole(roleName);
      }
      if (roleId!=null) {
         UUID id = UUID.fromString(roleId);
View Full Code Here

TOP

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

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.