Esempio n. 1
0
  @Override
  public ResponseVO isUserAuthenticated(String authString, ResponseVO response) throws IOException {
    String decodedAuth = "";
    // Header is in the format "Basic 5tyc0uiDat4"
    // We need to extract data before decoding it back to original string
    // Decode the data back to original string
    byte[] bytes = null;
    new Base64();
    bytes = Base64.decode(authString);
    decodedAuth = new String(bytes);

    String[] decodedAuths = decodedAuth.split(":");

    User user = getUserDetail(decodedAuths[0], decodedAuths[1]);
    if (user == null) {
      response.setSuccess(false);
      response.setError(new Error(222, "Invalid credentials!!"));
    } else {
      String accessToken = ApplicationUtilities.generateAccessToken(user);
      CachedObject newCachedObject = new CachedObject(user.getUuid(), accessToken, 0);
      CacheManager.putCache(newCachedObject);
      response.setSuccess(true);
      // response.setData(new LoggedInUserVO(accessToken,user.getEmailAddress()));
    }
    return response;
  }
Esempio n. 2
0
 @Override
 public String findUserRoleNameByUserId(Long userId) {
   User user = findUserById(userId);
   if (user != null) {
     return user.getUserRole().getRole().getName();
   }
   return null;
 }
Esempio n. 3
0
 @Override
 public User updatePassword(ResetPasswordVo rpVo) {
   CachedObject cachedObject = (CachedObject) CacheManager.getCache(rpVo.getAccessToken());
   if (cachedObject != null) {
     User user = getUserByUUID((String) cachedObject.object.toString());
     user.setPassword(rpVo.getNewPassword());
     saveUser(user);
     return user;
   }
   return null;
 }
Esempio n. 4
0
 @Override
 public boolean isUserAuthenticated(User user, HttpSession session) {
   user = getUserDetail(user.getUsername(), user.getPassword());
   if (user != null) {
     log.info(user.getEmailAddress());
     if (session != null) {
       session.setAttribute("displayUser", user.getEmailAddress());
     }
     return true;
   }
   return false;
 }
Esempio n. 5
0
 @Override
 public String validateOTPAndGenerateAccessToken(String otp) {
   CachedObject cachedObject = (CachedObject) CacheManager.getCache(otp);
   if (cachedObject != null) {
     User user = getUserByUUID((String) cachedObject.object.toString());
     String accessToken = ApplicationUtilities.generateAccessToken(user);
     CachedObject newCachedObject = new CachedObject(user.getUuid(), accessToken, 10);
     CacheManager.putCache(newCachedObject);
     return accessToken;
   }
   return null;
 }
Esempio n. 6
0
 @Override
 public boolean generateOTP(String emailAddress, String mobileNumber) {
   User user = null;
   if (!StringUtils.isNullOrEmpty(emailAddress)) {
     user = getUserByEmailAddress(emailAddress);
   }
   if (!StringUtils.isNullOrEmpty(mobileNumber)) {
     user = getUserByMobileNumber(mobileNumber);
   }
   if (user != null) {
     String otp = Otp.generate(6);
     CachedObject cachedObject = new CachedObject(user.getUuid(), otp, 10);
     CacheManager.putCache(cachedObject);
     log.info("Generated otp is " + otp);
     CachedObject o = (CachedObject) CacheManager.getCache(otp);
     log.info("from cache " + (String) o.object.toString());
     // notificationService.sendEmail("*****@*****.**", "One time password",otp);
     return true;
   }
   return false;
 }
Esempio n. 7
0
 @Override
 public ResponseVO isUserAuthenticated(DoLoginVo doLoginVo, ResponseVO response) {
   User user = getUserDetail(doLoginVo.getAuthString());
   List<AssignedTest> assignedTests = null;
   if (user != null) {
     UserProfile profile = getUserProfileByUUID(user.getUuid());
     if (profile != null) {
       profile.setMobileNumber(user.getMobileNumber());
       profile.setEmailAddress(user.getEmailAddress());
       profile.setUsername(user.getUsername());
       assignedTests = schoolAssesmentService.findAllAssignedTestByuser(user);
     }
     String accessToken = ApplicationUtilities.generateAccessToken(user);
     user.setAccessToken(accessToken);
     saveUser(user);
     response.setData(new LoggedInUserVO(accessToken, profile, assignedTests));
   } else {
     response.setData("Invalid Student code!!");
   }
   response.setSuccess(true);
   return response;
 }
Esempio n. 8
0
 @Override
 public void removeAccessToken(String accessToken) {
   User user = getUserByAccessToken(accessToken);
   user.setAccessToken(null);
   saveUser(user);
 }