Examples of AuthService


Examples of org.atomojo.app.auth.AuthService

      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

Examples of org.atomojo.app.auth.AuthService

         }
      }
   }
  
   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

Examples of org.jmanage.core.services.AuthService

        /* User must have username and password specified */
        assert user.getUsername() != null;
        assert user.getPassword() != null;

        /* authenticate with the server */
        AuthService authService = ServiceFactory.getAuthService();
        try {
            authService.login(context, user.getUsername(), user._getPlaintextPassword());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of org.jmanage.core.services.AuthService

        return null;
    }

    // logs-in the user if the username and password are valid
    private boolean login(WebContext context, String username, String password){
        AuthService authService = ServiceFactory.getAuthService();
        try {
            authService.login(context.getServiceContext(),
                    username,
                    password);
            return true;
        } catch (ServiceException e) {
            return false;
View Full Code Here

Examples of org.jmanage.core.services.AuthService

                /* get the password */
                password = new String(PasswordField.getPassword("Password:"));
            }

            /* authenticate with the server */
            AuthService authService = ServiceFactory.getAuthService();
            try {
                authService.login(new ServiceContextImpl(), username, password);
                break;
            } catch (ServiceException e){
                Out.println(e.getMessage());
                username = null;
                password = null;
View Full Code Here

Examples of org.jmanage.core.services.AuthService

                                 ActionForm actionForm,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
            throws Exception {
        LoginForm loginForm = (LoginForm) actionForm;
        AuthService authService = ServiceFactory.getAuthService();
        authService.login(Utils.getServiceContext(context),
                loginForm.getUsername(),
                loginForm.getPassword());
        return mapping.findForward(Forwards.SUCCESS);
    }
View Full Code Here

Examples of org.jmanage.core.services.AuthService

                                 ActionMapping mapping,
                                 ActionForm actionForm,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
            throws Exception {
        AuthService authService = ServiceFactory.getAuthService();
        authService.logout(Utils.getServiceContext(context), context.getUser());
        context.removeUser();
        return mapping.findForward(Forwards.SUCCESS);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.