Package com.ikanow.infinit.e.data_model.store.social.authentication

Examples of com.ikanow.infinit.e.data_model.store.social.authentication.AuthenticationPojo


         if (44 != admpass.length()) { // hash if in the clear
           admpass = PasswordEncryption.encrypt(admpass);
         }
         query.put("password", admpass);
        
         AuthenticationPojo ap = AuthenticationPojo.fromDb(DbManager.getSocial().getAuthentication().findOne(query), AuthenticationPojo.class);
         if (null != ap) {
           allowedToRegisterUpdate = adminCheck(ap, true);
         }//TESTED (admin, admin-enabled, non-admin)
       }
       catch (Exception e) {
View Full Code Here


    {
      if (null != cookie) {
        cookieLookup = RESTTools.cookieLookup(cookie);
      }
      if (null != cookieLookup) {
        AuthenticationPojo query = new AuthenticationPojo();
        query.setProfileId(new ObjectId(cookieLookup));
        AuthenticationPojo authUser = AuthenticationPojo.fromDb(DbManager.getSocial().getAuthentication().findOne(query.toDb()), AuthenticationPojo.class);
        if ((authUser.getAccountType() != null) && authUser.getAccountType().equalsIgnoreCase("admin")) {
          rp = new LoginHandler().keepAlive(cookieLookup, true);         
        }
        else if ((authUser.getAccountType() != null) && authUser.getAccountType().equalsIgnoreCase("admin-enabled")) { // keepalive - only updates auth pojo if needed
          boolean bUpdateCookie = false;
          if (null == authUser.getLastSudo()) {
            bUpdateCookie = true;
          }
          else if ((authUser.getLastSudo().getTime() + 10*60*1000) < new Date().getTime()) {
            // (ie admin rights last 10 minutes)
            bUpdateCookie = true;
          }
          if (bUpdateCookie && override) {
            authUser.setLastSudo(new Date());
            MongoDbManager.getSocial().getAuthentication().save(authUser.toDb());
          }
          rp = new LoginHandler().keepAlive(cookieLookup, override || !bUpdateCookie);
          // (ie if we're overriding we must be ... also if we're not override but are within the last sudo range then we are)
        }
        else {         
          rp.setResponse(new ResponseObject("Keepalive", false, "Logged in but not admin."));
        }
      }//TESTED
      else {
        rp.setResponse(new ResponseObject("Keepalive", false, "Not logged in."));
      }
    }
    else if ( action.equals("keepalive"))
    {
      if (null != cookie) {
        cookieLookup = RESTTools.cookieLookup(cookie);
      }
      if (null != cookieLookup) {
        rp = new LoginHandler().keepAlive(cookieLookup);
      }
      else {
        rp.setResponse(new ResponseObject("Keepalive", false, "Not logged in."));
      }
    }
    else if ( action.equals("admin-logout"))
    {
      cookieLookup = RESTTools.cookieLookup(cookie);
      if (null != cookieLookup) {
        AuthenticationPojo query = new AuthenticationPojo();
        query.setProfileId(new ObjectId(cookieLookup));
        AuthenticationPojo authUser = AuthenticationPojo.fromDb(DbManager.getSocial().getAuthentication().findOne(query.toDb()), AuthenticationPojo.class);     
        if ((null != authUser) && (null != authUser.getLastSudo())) {
          authUser.setLastSudo(null);
          MongoDbManager.getSocial().getAuthentication().save(authUser.toDb());
        }
      }
      rp.setResponse(new ResponseObject("Logout", true, "No longer admin."));
    }
    else if ( action.equals("logout"))
    {
      cookieLookup = RESTTools.cookieLookup(cookie);
      if (null != cookieLookup) {
        rp = new LoginHandler().removeCookies(cookieLookup);
      }
      else {
        rp.setResponse(new ResponseObject("Logout", false, "Not logged in."));
      }
    }
    else if (this.mustComeFromAuthority)
    {      
      boolean bCanProceed = RESTTools.mustComeFromAuthority(new PropertiesManager(), ipAddress, cookie, admuser, admpass);

      if (bCanProceed)
      {      
        if (action.equals("forgot"))
        {  
          rp = new LoginHandler().resetPassword(user, true);
        }
        else if (action.equals("deactivate"))
        {
          rp = new LoginHandler().deactivateAccount(user);
        }
      }
      else if (action.equals("forgot"))
      {
        // This has come from the user, part of 2 stage process
        // No password specified
        if (null == pass)
        {
          rp = new LoginHandler().resetPassword(user, false);
        }
        else { // Validate password, allow reset if valid
          AuthenticationPojo authuser = PasswordEncryption.validateUser(user,pass);
          if (null != authuser) {
            rp = new LoginHandler().resetPassword(user, true);
          }
        }
      }
View Full Code Here

      query.put("username", username);
      DBObject dbo = DbManager.getSocial().getAuthentication().findOne(query);
      if (dbo != null )
      {     
        //  check if pwords match
        AuthenticationPojo ap = AuthenticationPojo.fromDb(dbo, AuthenticationPojo.class);
        //only active accts can login (not pending or disabled)
        if ( (ap.getAccountStatus() == null) || ( ap.getAccountStatus() == AccountStatus.ACTIVE ) )
        {
          //(legacy users have accountStatus==null)
         
          if ( ap.getPassword().equals(userPword))
          {
            return ap;
          }
          else if (!bPasswdEncrypted)
          {
            if ( ap.getPassword().equals(encrypt(userPword)))
            {
              return ap;
            }
          }
        }
View Full Code Here

      DBObject dbo = DbManager.getSocial().getAuthentication().findOne(query);
      if (null == dbo) {
        rp.setResponse(new ResponseObject("Reset Password",true,"Email has been sent containing link to reset password."));
        return rp; // (lies but won't leak out usernames)
      }
      AuthenticationPojo ap = AuthenticationPojo.fromDb(dbo,AuthenticationPojo.class);     
     
      Date now = new Date();
      if (bLoggedIn)
      {       
        //change pword
        String newpassword = createNewRandomPassword();
        //Take new password and encrypt it
        ap.setPassword(PasswordEncryption.encrypt(newpassword));
        ap.setModified(now);
        DbManager.getSocial().getAuthentication().save(ap.toDb());
       
        //email new password
        // Subject Line
        String subject = "Request to reset password";
 
        // Message Body
        String body = "<p>Your new password is: " + newpassword + "</p>";
 
        // Send
        new SendMail(new PropertiesManager().getAdminEmailAddress(), ap.getUsername(), subject, body).send("text/html")
 
        // (Remove new password from end of this message once mailing works, Currently attached just so can use)
        rp.setResponse(new ResponseObject("Reset Password",true,"Password reset successfully, new password has been emailed to user."));
      }//TESTED
      else
      { // Two stage process ... first "forgotten password" just sends email containing link to click on
       
        // To avoid people just hitting this button 1000 times, ensure only sent once per 5 minutes
        if ((now.getTime() - ap.getModified().getTime()) < 300000L) { // ie 300s ie 5mins
          rp.setResponse(new ResponseObject("Reset Password",true,"Password reset request ignored, try later."));
          return rp;
        }//TESTED
       
        // Update auth to ensure this isn't abused
        ap.setModified(now);
        DbManager.getSocial().getAuthentication().save(ap.toDb());
       
        //email new password
        // Subject Line
        String subject = "Request to reset password";
 
        PropertiesManager props = new PropertiesManager();
       
        // Message Body
        StringBuffer newLink = new StringBuffer(props.getUrlRoot()).append("auth/forgotpassword").
                              append("?username=").append(URLEncoder.encode(username, "UTF-8")).
                              append("&password=").append(URLEncoder.encode(ap.getPassword(), "UTF-8"));
        String body = "<p>Click on this link to reset password: " + newLink.toString() + "</p>";
 
        // Send
        new SendMail(props.getAdminEmailAddress(), ap.getUsername(), subject, body).send("text/html")
 
        // (Remove new password from end of this message once mailing works, Currently attached just so can use)
        rp.setResponse(new ResponseObject("Reset Password",true,"Email has been sent containing link to reset password."));
      }//TESTED
    }
View Full Code Here

    ResponsePojo rp = new  ResponsePojo();
    try
    {
      //Get user
      DBObject dbo = DbManager.getSocial().getAuthentication().findOne(new BasicDBObject("username",username));
      AuthenticationPojo ap = AuthenticationPojo.fromDb(dbo,AuthenticationPojo.class);     
      //change status to deactivate
      ap.setAccountStatus(InfiniteEnums.AccountStatus.DISABLED);
      DbManager.getSocial().getAuthentication().update(dbo, ap.toDb());
      //remove any cookie this user has
      removeCookies(ap.getProfileId().toString());     
      rp.setResponse(new ResponseObject("Deactivate Account",true,"Account deactivated successfully"));
    }
    catch (Exception e)
    {
      // If an exception occurs log the error
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.store.social.authentication.AuthenticationPojo

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.