Examples of AuthenticationPojo


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

import com.mongodb.BasicDBObject;

public class AuthUtils {
  public static boolean isAdmin(ObjectId userId) {
    try {
      AuthenticationPojo authQuery = new AuthenticationPojo();
      authQuery.setProfileId(userId);
      BasicDBObject dbo = (BasicDBObject) DbManager.getSocial().getAuthentication().findOne(authQuery.toDb());
      if (null != dbo) {
        AuthenticationPojo ap = AuthenticationPojo.fromDb(dbo, AuthenticationPojo.class);
        if (null != ap.getAccountType()) {
          if (ap.getAccountType().equalsIgnoreCase("admin")) {
            return true;
          }
          else if (ap.getAccountType().equalsIgnoreCase("admin-enabled")) {
            return true; // (these are offline so always allow this also)
          }
        }//TESTED
      }
      return false;
View Full Code Here

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

import com.mongodb.BasicDBObject;

public class AuthUtils {
  public static boolean isAdmin(ObjectId userId) {
    try {
      AuthenticationPojo authQuery = new AuthenticationPojo();
      authQuery.setProfileId(userId);
      BasicDBObject dbo = (BasicDBObject) DbManager.getSocial().getAuthentication().findOne(authQuery.toDb());
      if (null != dbo) {
        AuthenticationPojo ap = AuthenticationPojo.fromDb(dbo, AuthenticationPojo.class);
        if (null != ap.getAccountType()) {
          if (ap.getAccountType().equalsIgnoreCase("admin")) {
            return true;
          }
          else if (ap.getAccountType().equalsIgnoreCase("admin-enabled")) {
            return true; // (these are offline so always allow this also)
          }
        }//TESTED
      }
      return false;
View Full Code Here

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

      if (null != wpu.getSubscriptionTypeID()) {
        pp.setSubscriptionTypeID(wpu.getSubscriptionTypeID());
      }
      // (can't change WPUserId obv)
     
      AuthenticationPojo authQuery = new AuthenticationPojo();
      if (null != pp.get_id()) {
        authQuery.setProfileId(pp.get_id());
      }
      else {
        rp.setResponse(new ResponseObject("WP Update User",false,"Internal authentication error 1"));
        return rp;       
      }
      DBObject dboauth = DbManager.getSocial().getAuthentication().findOne(authQuery.toDb());
      if (null == dboauth) {
        rp.setResponse(new ResponseObject("WP Update User",false,"Internal authentication error 2"));
        return rp;       
      }     
      AuthenticationPojo ap = AuthenticationPojo.fromDb(dboauth, AuthenticationPojo.class);
     
      if ((null != wpu.getEmail()) && !wpu.getEmail().isEmpty()) {
        ap.setUsername(wpu.getEmail().get(0)); // (ap.username == email address, make life easy when resetting password)
      }
      if (null != wpa.getPassword()) {
        if (44 != wpa.getPassword().length()) { // hash if in the clear
          wpa.setPassword(PasswordEncryption.encrypt(wpa.getPassword()));
        }
        ap.setPassword(wpa.getPassword());
      }
      if (null != wpa.getAccountType()) {
        if (null == personIdStr) { // (this means you're admin and hence can upgrade users to admins)
          ap.setAccountType(wpa.getAccountType());
        }
      }
      // (can't change WPUserId obv)
     
      //Handle dates (just update modified times)
      pp.setModified(new Date());
      ap.setModified(new Date());
     
      if ((null != wpa.getApiKey()) && (0 == wpa.getApiKey().length()) && (null != ap.getApiKey()))     
      {
        // Delete existing API key
        // (We'll allow a user to update their own API key - just not create it, see below)
        CookiePojo removeMe = new CookiePojo();
        removeMe.setApiKey(ap.getApiKey());
        ap.setApiKey(null);       
        DbManager.getSocial().getCookies().remove(removeMe.toDb());
      }
      else if (null != wpa.getApiKey()) {
        // Change or create API key
        // Only admins can do this:
        if (null != personIdStr) { // (this is != null iff user isn't admin)
          // Check security settings
          PropertiesManager pm = new PropertiesManager();
          if (pm.getHarvestSecurity()) {
            rp.setResponse(new ResponseObject("WP Update User",false,"You must be admin in secure mode to set an API key"));
            return rp;
          }
        }//TESTED (admin, admin-enabled, non-admin - harvest.secure on and off)
       
        ap.setApiKey(wpa.getApiKey());
        CookiePojo cp = new CookiePojo();
        cp.set_id(ap.getProfileId());
        cp.setCookieId(cp.get_id());
        cp.setApiKey(wpa.getApiKey());
        cp.setStartDate(ap.getCreated());
        cp.setProfileId(ap.getProfileId());
        DbManager.getSocial().getCookies().save(cp.toDb());               
      }//TESTED
      //else if api key is null then leave alone, assume hasn't changed
     
      //update old entries
      DbManager.getSocial().getPerson().update(new BasicDBObject("_id", pp.get_id()), pp.toDb());
      DbManager.getSocial().getAuthentication().update(authQuery.toDb(), ap.toDb());     
      rp.setResponse(new ResponseObject("WP Update User",true,"User Updated Successfully"));
      rp.setData(ap, new AuthenticationPojoApiMap());
     
      //update communities if necessary
      if (bNeedToUpdateCommunities)
View Full Code Here

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

    PersonPojo personQuery = new PersonPojo();
    personQuery.set_id(pp.get_id());
    DbManager.getSocial().getPerson().remove(personQuery.toDb());
    //TESTED
   
    AuthenticationPojo authQuery = new AuthenticationPojo();
    if (null != authQuery.getWPUserID()) { // (Some older records have this and of course it deletes the entire auth DB...)
      authQuery.setWPUserID(pp.getWPUserID());
      DbManager.getSocial().getAuthentication().remove(authQuery.toDb());
    }
    else if (null != pp.getEmail()) {
      authQuery.setUsername(pp.getEmail());
      DbManager.getSocial().getAuthentication().remove(authQuery.toDb());
    }
    // (else we'll just have to leave that object in there unfortunately)
    //TESTED
   
    // Delete any cookies the user might have
View Full Code Here

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

          }
          if ((null == sKeyCmp) || !sKeyCmp.equals(sKey)) {
            // User/password also allowed, TBD this will require SSL
            String user = queryOptions.get("user");
            String password = queryOptions.get("password");
            AuthenticationPojo authuser = null;
            if ((null != user) && (null != password)) {
              authuser = PasswordEncryption.validateUser(user,password, false);
            }
            if ( authuser == null )
            {
              // Don't have either authentication or key, bomb out...
              rp = new ResponsePojo();
              rp.setResponse(new ResponseObject("Cookie Lookup", false, "Cookie session expired or never existed, please login first or use valid key or user/pass"));
              data = rp.toApi();   
              mediaType = MediaType.APPLICATION_JSON;
              return new StringRepresentation(data, mediaType);
            }
            userId = authuser.getProfileId();
            cookieLookup = userId.toString();
           
          }
          //no other auth was used, try using the commid
          if ( null == cookieLookup )
View Full Code Here

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

    pp.setTags(null);
    pp.setTitle(null);
    //end set of fields i didn't use
       
    //Step 4 Create the new auth object so user can login
    AuthenticationPojo ap = new AuthenticationPojo();
    ap.setId(profileId);
    ap.setProfileId(profileId);
    ap.setUsername(pp.getEmail());
    ap.setAccountStatus(AccountStatus.ACTIVE);
    if (null == wpa.getPassword()) { // Obligatory
      rp.setResponse(new ResponseObject("WP Register User",false,"Need to specify password"));
      return rp;
    }
    try
    {
      if (44 != wpa.getPassword().length()) { // hash if in the clear
        wpa.setPassword(PasswordEncryption.encrypt(wpa.getPassword()));
      }
      ap.setPassword(wpa.getPassword());
      if (null == wpa.getAccountType()) { // (optional, defaults to "user"
        wpa.setAccountType("user");
      }
      ap.setAccountType(wpa.getAccountType());
        // to create an account you must be admin, so this is fine....
     
      ap.setWPUserID(wpa.getWPUserID());   
       
      DateFormat df = new SimpleDateFormat("MMM dd, yyyy kk:mm:ss aa");
      //Handle copying dates from wordpress objects
      // (These are all optional, just use now if not specified)
      if (null == wpu.getCreated()) {
        pp.setCreated(new Date());       
      }
      else {
        pp.setCreated(df.parse(wpu.getCreated()));       
      }
      if (null == wpu.getModified()) {
        pp.setModified(new Date());       
      }
      else {
        pp.setModified(df.parse(wpu.getModified()));       
      }
      if (null == wpa.getCreated()) {
        ap.setCreated(new Date());       
      }
      else {
        ap.setCreated(df.parse(wpa.getCreated()));       
      }
      if (null == wpa.getModified()) {
        ap.setModified(new Date());       
      }
      else {
        ap.setModified(df.parse(wpa.getModified()));       
      }
      ap.setApiKey(wpa.getApiKey());
     
      //Step 5 Save all of these objects to the DB
      DbManager.getSocial().getPerson().insert(pp.toDb());
      DbManager.getSocial().getAuthentication().insert(ap.toDb());
     
      CommunityHandler cc = new CommunityHandler();
      cc.createSelfCommunity(pp); //add user to own community
     
      //try to get system
      BasicDBObject commQueryDbo = new BasicDBObject("isSystemCommunity", true);
        // (annoyingly can't use community pojo for queries because it has default fields)
      DBObject dbo = DbManager.getSocial().getCommunity().findOne(commQueryDbo);
      if (null != dbo) {
        CommunityPojo systemGroup = CommunityPojo.fromDb(dbo, CommunityPojo.class);
       
        //Add user to system community also
        cc.addCommunityMember(cookieLookup, systemGroup.getId().toString(), "Infinit.e System", pp.get_id().toString(),
            pp.getEmail(), pp.getDisplayName(), "member", "active", true);
      }               
      rp.setResponse(new ResponseObject("WP Register User",true,"User Registered Successfully"));
      rp.setData(ap, new AuthenticationPojoApiMap());
     
      // OK we're all good, finally for API key users create a persistent cookie:
      if (null != ap.getApiKey()) {
        // (if we're here then we're already admin so can always do this - unlike the update)
        CookiePojo cp = new CookiePojo();
        cp.set_id(profileId);
        cp.setCookieId(cp.get_id());
        cp.setApiKey(wpa.getApiKey());
        cp.setStartDate(ap.getCreated());
        cp.setProfileId(profileId);
        DbManager.getSocial().getCookies().save(cp.toDb());
      }//TOTEST
    }
    catch (Exception ex )
View Full Code Here

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

            module.setCommunityIds(newSet);
          }
        }//TESTED
       
        // Get username from profile id:
        AuthenticationPojo userQuery = new AuthenticationPojo();
        userQuery.setProfileId(new ObjectId(userIdStr));
        BasicDBObject userDbo = (BasicDBObject) DbManager.getSocial().getAuthentication().findOne(userQuery.toDb());
        String userName = userIdStr;
        if (null != userDbo) {
          AuthenticationPojo user =  AuthenticationPojo.fromDb(userDbo, AuthenticationPojo.class);
          userName = user.getUsername();
        }//TESTED
        if (!bAdmin || (null == module.getAuthor())) {
          module.setAuthor(userName);
            // (if module name set and I'm admin then allow it)
        }
View Full Code Here

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

        return rp;
      }//TESTED
      UIModulePojo oldModule = UIModulePojo.fromDb(oldModuleDbo, UIModulePojo.class);
     
      // Get username from profile id:
      AuthenticationPojo userQuery = new AuthenticationPojo();
      userQuery.setProfileId(new ObjectId(userIdStr));
      BasicDBObject userDbo = (BasicDBObject) DbManager.getSocial().getAuthentication().findOne(userQuery.toDb());       
      String userName = userIdStr;
      if (null != userDbo) {
        AuthenticationPojo user =  AuthenticationPojo.fromDb(userDbo, AuthenticationPojo.class);
        userName = user.getUsername();
      }//TOTEST
     
      String moduleOwner = oldModule.getAuthor();
      if ((null == moduleOwner) || (moduleOwner.equals(userName)) || RESTTools.adminLookup(userIdStr)) {
        DbManager.getSocial().getUIModules().remove(moduleQuery.toDb());
View Full Code Here

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

        override = parameters.getOverride();
      }

      //Verify login
      if (!user.equals("ping")) { // (this is a reserved username for LB pinging)
        AuthenticationPojo authuser = PasswordEncryption.validateUser(user,pass);

        if ( authuser != null )
        {
          // Since logging-in isn't time critical, we'll ensure that api users have their api cookie at this point...
          if (null != authuser.getApiKey()) {
            CookiePojo cp = new CookiePojo();
            cp.set_id(authuser.getProfileId());
            cp.setCookieId(cp.get_id());
            cp.setApiKey(authuser.getApiKey());
            cp.setStartDate(authuser.getCreated());
            cp.setProfileId(authuser.getProfileId());
            DbManager.getSocial().getCookies().save(cp.toDb());            
          }//TESTED

          if ((authuser.getAccountType() == null) ||
              !(authuser.getAccountType().equalsIgnoreCase("admin") || authuser.getAccountType().equalsIgnoreCase("admin-enabled")))
          {
            multi = false; // (not allowed except for admin)
          }

          CookieSetting cookieId = createSessionCookie(authuser.getProfileId(), true, response.getServerInfo().getPort());
          if (null != cookieId) {

            Series<CookieSetting> cooks = response.getCookieSettings();        
            cooks.add(cookieId);
            response.setCookieSettings(cooks);
            isLogin = true;
            cookieLookup = cookieId.getValue();
            boolean bAdmin = false;

            //If this request is checking admin status, check that
            if (urlStr.contains("/admin/"))
            {
              isLogin = false;
              if (authuser.getAccountType().equalsIgnoreCase("admin")) {
                bAdmin = true;
                isLogin = true;
              }
              else if (authuser.getAccountType().equalsIgnoreCase("admin-enabled")) {
                isLogin = true;
                if (!multi) {
                  authuser.setLastSudo(new Date());
                  MongoDbManager.getSocial().getAuthentication().save(authuser.toDb());
                  bAdmin = true;
                }
              }
            }//TESTED

            logMsg.setLength(0);
            logMsg.append("auth/login");
            logMsg.append(" user=").append(user);
            logMsg.append(" userid=").append(authuser.getProfileId().toString());
            if (bAdmin) logMsg.append(" admin=true");
            logMsg.append(" success=").append(isLogin);
            logger.info(logMsg.toString());
          }
        }
View Full Code Here

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

  {
    if ( null == personIdStr)
      return false;
    try
    {
      AuthenticationPojo authQuery = new AuthenticationPojo();
      authQuery.setProfileId(new ObjectId(personIdStr));
      BasicDBObject dbo = (BasicDBObject) DbManager.getSocial().getAuthentication().findOne(authQuery.toDb());
      if (null != dbo) {
        AuthenticationPojo ap = AuthenticationPojo.fromDb(dbo, AuthenticationPojo.class);     
        return adminCheck(ap, mustBeEnabled);
      }
      return false;
    }
    catch (Exception e )
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.