Exemple #1
0
 public void send(String message, String username)
     throws PushNotInitializedException, UserNotFoundException, SqlInjectionException,
         InvalidRequestException, IOException, UnknownHostException {
   if (Logger.isDebugEnabled())
     Logger.debug("Try to send a message (" + message + ") to " + username);
   UserDao udao = UserDao.getInstance();
   ODocument user = udao.getByUserName(username);
   if (user == null) {
     if (Logger.isDebugEnabled()) Logger.debug("User " + username + " does not exist");
     throw new UserNotFoundException("User " + username + " does not exist");
   }
   ODocument userSystemProperties = user.field(UserDao.ATTRIBUTES_SYSTEM);
   if (Logger.isDebugEnabled()) Logger.debug("userSystemProperties: " + userSystemProperties);
   List<ODocument> loginInfos = userSystemProperties.field(UserDao.USER_LOGIN_INFO);
   if (Logger.isDebugEnabled()) Logger.debug("Sending to " + loginInfos.size() + " devices");
   for (ODocument loginInfo : loginInfos) {
     String pushToken = loginInfo.field(UserDao.USER_PUSH_TOKEN);
     String vendor = loginInfo.field(UserDao.USER_DEVICE_OS);
     if (Logger.isDebugEnabled()) Logger.debug("push token: " + pushToken);
     if (Logger.isDebugEnabled()) Logger.debug("vendor: " + vendor);
     if (!StringUtils.isEmpty(vendor) && !StringUtils.isEmpty(pushToken)) {
       VendorOS vos = VendorOS.getVendorOs(vendor);
       if (Logger.isDebugEnabled()) Logger.debug("vos: " + vos);
       if (vos != null) {
         IPushServer pushServer = Factory.getIstance(vos);
         pushServer.setConfiguration(getPushParameters());
         pushServer.send(message, pushToken);
       } // vos!=null
     } // (!StringUtils.isEmpty(vendor) && !StringUtils.isEmpty(deviceId)
   } // for (ODocument loginInfo : loginInfos)
 } // send
Exemple #2
0
 public static void changePassword(String username, String newPassword)
     throws SqlInjectionException, UserNotFoundException {
   ODatabaseRecordTx db = DbHelper.getConnection();
   db = DbHelper.reconnectAsAdmin();
   UserDao udao = UserDao.getInstance();
   ODocument user = udao.getByUserName(username);
   if (user == null) {
     if (Logger.isDebugEnabled()) Logger.debug("User " + username + " does not exist");
     throw new UserNotFoundException("User " + username + " does not exist");
   }
   db.getMetadata().getSecurity().getUser(username).setPassword(newPassword).save();
 }
Exemple #3
0
  public static ODocument updateProfile(
      String username,
      String role,
      JsonNode nonAppUserAttributes,
      JsonNode privateAttributes,
      JsonNode friendsAttributes,
      JsonNode appUsersAttributes)
      throws Exception {
    try {
      ORole newORole = RoleDao.getRole(role);
      if (newORole == null) throw new InvalidParameterException(role + " is not a role");
      if (!RoleService.isAssignable(newORole))
        throw new RoleIsNotAssignableException("Role " + role + " is not assignable");
      ORID newRole = newORole.getDocument().getIdentity();
      UserDao udao = UserDao.getInstance();
      ODocument profile = udao.getByUserName(username);
      if (profile == null) throw new InvalidParameterException(username + " is not a user");
      profile =
          updateProfile(
              profile,
              nonAppUserAttributes,
              privateAttributes,
              friendsAttributes,
              appUsersAttributes);

      Set<OIdentifiable> roles =
          (Set<OIdentifiable>) ((ODocument) profile.field("user")).field("roles");
      // extracts the role skipping the friends ones
      String oldRole = null;
      for (OIdentifiable r : roles) {
        oldRole = ((String) ((ODocument) r.getRecord()).field("name"));
        if (!oldRole.startsWith(RoleDao.FRIENDS_OF_ROLE)) {
          break;
        }
      }
      ORole oldORole = RoleDao.getRole(oldRole);
      // TODO: update role
      OUser ouser = DbHelper.getConnection().getMetadata().getSecurity().getUser(username);
      ouser.getRoles().remove(oldORole);
      ouser.addRole(newORole);
      ouser.save();
      profile.save();
      profile.reload();

      return profile;
    } catch (Exception e) {
      throw e;
    }
  } // updateProfile with role
Exemple #4
0
 public static ODocument getUserProfilebyUsername(String username) throws SqlInjectionException {
   UserDao dao = UserDao.getInstance();
   ODocument userDetails = null;
   userDetails = dao.getByUserName(username);
   return userDetails;
 }