Package ca.carleton.gcrc.couch.user.token

Examples of ca.carleton.gcrc.couch.user.token.CreationToken


  public JSONObject initUserCreation(String emailAddr) throws Exception {
    JSONObject result = new JSONObject();
    result.put("message", "User creation email was sent to the given address");

    // Create token
    CreationToken creationToken = new CreationToken();
    {
      creationToken.setEmailAddress(emailAddr);
      Date now = new Date();
      long thirtyDaysMs = now.getTime() + (30 * 24 * 60 * 60 * 1000);
      creationToken.setExpiry( new Date(thirtyDaysMs) );
    }
   
    // Encrypt token
    if( null == serverKey ){
      throw new Exception("Server key was not installed. Configuration must be adjusted.");
View Full Code Here


  public JSONObject initUserCreation(String emailAddr) throws Exception {
    JSONObject result = new JSONObject();
    result.put("message", "User creation email was sent to the given address");

    // Create token
    CreationToken creationToken = new CreationToken();
    {
      creationToken.setEmailAddress(emailAddr);
      long now = (new Date()).getTime();
      long thirtyDaysMs = 30L * 24L * 60L * 60L * 1000L;
      long thirtyDaysFromNowMs = now + thirtyDaysMs;
      creationToken.setExpiry( new Date(thirtyDaysFromNowMs) );
    }
   
    // Encrypt token
    if( null == serverKey ){
      throw new Exception("Server key was not installed. Configuration must be adjusted.");
View Full Code Here

  public JSONObject validateUserCreation(String b64Token) throws Exception {
    byte[] encryptedToken = Base64.decodeBase64(b64Token);
    Token token = TokenEncryptor.decryptToken(serverKey, encryptedToken);
    if( token instanceof CreationToken ){
      CreationToken creationToken = (CreationToken)token;
     
      Date expiry = creationToken.getExpiry();
      if( null != expiry ){
        Date now = new Date();
        if( now.getTime() > expiry.getTime() ){
          throw new TokenExpiredException("Token is expired");
        }
      }
     
      // Check if user already exists
      String emailAddress = creationToken.getEmailAddress();
      if( null == emailAddress ) {
        throw new Exception("Token does not specify e-mail address");
      }
      JSONObject user = null;
      try {
        user = userRepository.getUserFromEmailAddress(emailAddress);
      } catch(Exception e) {
        // OK
      }
      if( null != user ) {
        throw new Exception("User with e-mail "+emailAddress+
            " already exists. Attempt password recovery.");
      }
     
      JSONObject result = new JSONObject();
      result.put("valid", true);
      result.put("emailAddress", creationToken.getEmailAddress());
      return result;
    } else {
      throw new Exception("Unexpected token class: "+token.getClass().getName());
    }
  }
View Full Code Here

  public JSONObject initUserCreation(String emailAddr) throws Exception {
    JSONObject result = new JSONObject();
    result.put("message", "User creation email was sent to the given address");

    // Create token
    CreationToken creationToken = new CreationToken();
    {
      creationToken.setEmailAddress(emailAddr);
      long now = (new Date()).getTime();
      long thirtyDaysMs = 30L * 24L * 60L * 60L * 1000L;
      long thirtyDaysFromNowMs = now + thirtyDaysMs;
      creationToken.setExpiry( new Date(thirtyDaysFromNowMs) );
    }
   
    // Encrypt token
    if( null == serverKey ){
      throw new Exception("Server key was not installed. Configuration must be adjusted.");
View Full Code Here

  public JSONObject validateUserCreation(String b64Token) throws Exception {
    byte[] encryptedToken = Base64.decodeBase64(b64Token);
    Token token = TokenEncryptor.decryptToken(serverKey, encryptedToken);
    if( token instanceof CreationToken ){
      CreationToken creationToken = (CreationToken)token;
     
      Date expiry = creationToken.getExpiry();
      if( null != expiry ){
        Date now = new Date();
        if( now.getTime() > expiry.getTime() ){
          throw new TokenExpiredException("Token is expired");
        }
      }
     
      // Check if user already exists
      String emailAddress = creationToken.getEmailAddress();
      if( null == emailAddress ) {
        throw new Exception("Token does not specify e-mail address");
      }
      JSONObject user = null;
      try {
        user = userRepository.getUserFromEmailAddress(emailAddress);
      } catch(Exception e) {
        // OK
      }
      if( null != user ) {
        throw new Exception("User with e-mail "+emailAddress+
            " already exists. Attempt password recovery.");
      }
     
      JSONObject result = new JSONObject();
      result.put("valid", true);
      result.put("emailAddress", creationToken.getEmailAddress());
      return result;
    } else {
      throw new Exception("Unexpected token class: "+token.getClass().getName());
    }
  }
View Full Code Here

TOP

Related Classes of ca.carleton.gcrc.couch.user.token.CreationToken

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.