Package org.atomojo.app.auth

Examples of org.atomojo.app.auth.AuthService


               }
               if (authName==null) {
                  getLogger().warning("Ignoring db entry where auth term "+DB_NAME_TERM+" does not have a value.");
                  return;
               }
               AuthService auth = services.get(authName);
               if (auth==null) {
                  auth = autoServices.get(authName);
               }
               if (auth==null) {
                  getLogger().warning("Cannot configure db entry for "+dbName+" as auth service "+authName+" does not exist.");
View Full Code Here


   }
  
   public void toXML(ItemDestination dest)
      throws AuthException,XMLException
   {
      AuthService auth = (AuthService)getRequest().getAttributes().get(App.AUTH_SERVICE_ATTR);
      AuthCredentials cred = new AuthCredentials(getRequest().getChallengeResponse());
      final Iterator<User> users = auth.getUsers(cred);

      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument());
      dest.send(constructor.createElement(NM_USERS));
      dest.send(constructor.createCharacters("\n"));
View Full Code Here

      dest.send(constructor.createDocumentEnd());
   }
  
   public Representation post(Representation entity)
   {
      AuthService auth = (AuthService)getRequest().getAttributes().get(App.AUTH_SERVICE_ATTR);
      if (!XMLRepresentationParser.isXML(entity.getMediaType())) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
      Document doc = null;
      try {
         doc = parser.load(entity);
      } catch (Exception ex) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("XML parse error: "+ex.getMessage());
      }
     
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(NM_USER)) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Unknown document element: "+top.getName());
      }
      String alias = top.getAttributeValue("alias");
      String password = top.getAttributeValue("password");
      if (password==null) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("The password is missing.");
      }
     
      alias = alias.trim();
      password = password.trim();
      if (alias.length()==0 || password.length()==0) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Empty alias or password.");
      }
     
      Element nameE = top.getFirstElementNamed(NM_NAME);
      String name = null;
      if (nameE!=null) {
         name = nameE.getText();
      } else {
         name = alias;
      }
      Element emailE = top.getFirstElementNamed(NM_EMAIL);
      String email = null;
      if (emailE!=null) {
         email = emailE.getText();
      }
      try {
         AuthCredentials cred = new AuthCredentials(getRequest().getChallengeResponse());
         if (auth.getUser(cred,alias)!=null) {
            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
            return new StringRepresentation("User "+alias+" already exists.");
         } else {
            UUID id = UUID.randomUUID();
            try {
               auth.createUser(cred,alias,name,email,password);
               getResponse().setStatus(Status.SUCCESS_CREATED);
               Reference ref = new Reference(getRequest().getResourceRef().toString()+"/"+alias);
               getResponse().setLocationRef(ref);
               return null;
            } catch (AuthException ex) {
View Full Code Here

     
      public AuthService newInstance()
         throws AuthException
      {
         try {
            AuthService service = serviceClass.newInstance();
            service.init(props);
            return service;
         } catch (InstantiationException ex) {
            throw new AuthException("Cannot instantiate service "+serviceClass.getName(),ex);
         } catch (IllegalAccessException ex) {
            throw new AuthException("Cannot instantiate service "+serviceClass.getName(),ex);
View Full Code Here

      services = new HashMap<String,AuthService>();
      autoServices = new HashMap<String,AuthService>();
     
      for (ServerConfiguration.Auth auth : serverConf.getAuthServices().values()) {
         try {
            AuthService service = auth.newInstance();
            services.put(auth.getName(),service);
         } catch (AuthException ex) {
            getLogger().log(Level.SEVERE,"Cannot instantiate auth service "+auth.getName(),ex);
         }
      }
      ServerAdminApplication admin = new ServerAdminApplication(childContext,dbConfList,autodbList,storageFactory);
      for (ServerConfiguration.AdminHost adminHost : serverConf.getAdminHosts().values()) {
        
         VirtualHost vhost =  createVirtualHost(adminHost);
         getHosts().add(vhost);
         adminRouters.add(vhost);
         String authName = adminHost.getAuthName();
         if (authName==null) {
            getLogger().severe("The admin interface is missing a named auth service.");
            continue;
         }
         AuthService service = services.get(authName);
         if (service==null) {
            getLogger().severe("Cannot find auth service "+authName+" for admin interface.");
            continue;
         }
         UserGuard adminGuard = new UserGuard(childContext,ChallengeScheme.HTTP_BASIC,"Atom Administrator",service);
         adminGuard.getRequiredGroups().add(AuthService.ADMIN_GROUP);
         adminGuard.setNext(admin);
        
         vhost.attach("/admin",adminGuard);
        
      }
     
      admins = new HashMap<String,Restlet>();
      Restlet lastAdmin = null;
      for (final DB adminDB : dbList.values()) {
         getLogger().info("Configuring database "+adminDB.getName()+" for administration");
         ServerConfiguration.Database databaseConf = serverConf.getDatabases().get(adminDB.getName());
         AuthService service = null;
         if (databaseConf==null || databaseConf.getAuthName()==null) {
            service = new DBAuthService();
            Properties props = new Properties();
            props.setProperty("database",adminDB.getName());
            props.setProperty("dir", adminDB.getDatabaseDir().getAbsolutePath());
            try {
               service.init(props);
            } catch (AuthException ex) {
               getLogger().log(Level.SEVERE,"Cannot instantiate auth service for database "+adminDB.getName(),ex);
               continue;
            }
         } else {
View Full Code Here

         atomDB = autodbList.get(host.getDatabaseName());
      }
      if (atomDB==null) {
         throw new RuntimeException("Database "+host.getDatabaseName()+" does not exist.");
      }
      AuthService auth = atomDB.getAuthService();
      if (auth==null) {
         throw new RuntimeException("The auth service for database "+host.getDatabaseName()+" does not exist.");
      }
     
      Storage storage = storageFactory.getStorage(atomDB.getDB());
View Full Code Here

      if (facet!=null) {
         getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
         return null;
      }
        
      AuthService auth = (AuthService)getRequest().getAttributes().get(App.AUTH_SERVICE_ATTR);

      User user = null;
      try {
         ChallengeResponse transCred = getRequest().getChallengeResponse();
         AuthCredentials cred = new AuthCredentials(transCred.getScheme().toString(),transCred.getIdentifier(),new String(transCred.getSecret()));
         user = auth.getUser(cred,alias);
         if (user==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return new StringRepresentation("User "+alias+" does not exist.");
         }
      } catch (AuthException ex) {
View Full Code Here

      if (facet!=null && !facet.equals(GROUPS_FACET)) {
         getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
         return new StringRepresentation("Unknown facet "+facet);
      }
     
      AuthService auth = (AuthService)getRequest().getAttributes().get(App.AUTH_SERVICE_ATTR);

      ChallengeResponse transCred = getRequest().getChallengeResponse();
      AuthCredentials cred = new AuthCredentials(transCred.getScheme().toString(),transCred.getIdentifier(),new String(transCred.getSecret()));
      if (facet==null) {

         if (!top.getName().equals(NM_USER)) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("Document element "+top.getName()+" not allowed on user.");
         }
        
         String password = top.getAttributeValue("password");
         if (password!=null) {
            password = password.trim();
         }

         Element nameE = top.getFirstElementNamed(NM_NAME);
         String name = null;
         if (nameE!=null) {
            name = nameE.getText();
         }
         Element emailE = top.getFirstElementNamed(NM_EMAIL);
         String email = null;
         if (emailE!=null) {
            email = emailE.getText();
         }
         try {

            User user = auth.getUser(cred,alias);
            if (user!=null) {
               try {
                  if (nameE!=null || emailE!=null) {
                     // The name starts the same and can only be changed.  It can't be deleted
                     String newName = user.getName();
                     // Set it to the new name only if it was specified
                     if (name!=null) {
                        newName = name;
                     }
                     String newEmail = user.getEmail();
                     // Set to new e-mail if it exists
                     if (email!=null) {
                        newEmail = email;
                     }
                     // If the e-mail was missing, remove it
                     if (emailE==null) {
                        newEmail = null;
                     }
                     auth.updateUser(cred,alias,newName,newEmail);
                  }
                  if (password!=null) {
                     if (!auth.setPassword(cred,alias,password)) {
                        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                        return null;
                     }
                  }
                  getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                  return null;
               } catch (AuthException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Cannot modify user "+alias+": "+ex.getMessage(),ex);
                  getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
                  return new StringRepresentation("Internal error, see logs.");
               }
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return new StringRepresentation("User "+alias+" does not exist.");
            }
         } catch (AuthException ex) {
            getContext().getLogger().log(Level.SEVERE,"Cannot check user "+alias+": "+ex.getMessage(),ex);
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            return new StringRepresentation("Internal error, see logs.");
         }
      } else if (facetAlias!=null) {
         getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
         return null;
      } else {
         if (!top.getName().equals(NM_GROUP)) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("Document element "+top.getName()+" not allowed to groups.");
         }
         String group = top.getAttributeValue("alias");
         if (group==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The 'alias' attribute is missing.");
         }
   
         try {
            if (auth.addUserToGroup(cred,alias,group)) {
               getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            }
            return null;
View Full Code Here

         }
      }
   }
  
   public Representation delete() {
      AuthService auth = (AuthService)getRequest().getAttributes().get(App.AUTH_SERVICE_ATTR);
      ChallengeResponse transCred = getRequest().getChallengeResponse();
      AuthCredentials cred = new AuthCredentials(transCred.getScheme().toString(),transCred.getIdentifier(),new String(transCred.getSecret()));
      if (facet!=null) {
         if (!facet.equals(GROUPS_FACET)) {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return new StringRepresentation("Unknown facet "+facet);
         } else if (facetAlias==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
            return null;
         } else {
            try {
               if (auth.removeUserFromGroup(cred,alias,facetAlias)) {
                  getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
               } else {
                  getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               }
               return null;
            } catch (AuthException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot remove user "+alias+" from group "+facetAlias+": "+ex.getMessage(),ex);
               getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
               return new StringRepresentation("Internal error, see logs.");
            }
         }
      } else {
         try {
            if (auth.deleteUser(cred,alias)) {
               getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            }
            return null;
View Full Code Here

TOP

Related Classes of org.atomojo.app.auth.AuthService

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.