Search in sources :

Example 1 with CacheWritingException

use of org.ehcache.spi.loaderwriter.CacheWritingException in project Insights by CognizantOneDevOps.

the class TokenProviderUtility method createToken.

/**
 * used to create token and add it in customize cache,This will use custom expiration time
 *
 * @param userName
 * @return
 */
public String createToken(String userName, int tokenTime, Map<String, Object> claimparam) {
    String strJWTToken = "";
    log.debug("Inside Create token with tokenTime {} === ", tokenTime);
    try {
        String username = ValidationUtils.cleanXSS(userName);
        String id = UUID.randomUUID().toString().replace("-", "");
        Date now = new Date();
        Date expDate = new Date(System.currentTimeMillis() + (tokenTime * 60 * 1000));
        strJWTToken = createAndStoreToken(username, id, now, expDate, claimparam);
    } catch (CacheWritingException e) {
        log.error(e);
        log.error("CacheWritingException While writing token in cache  ==== {} ", e.getMessage());
    } catch (Exception e) {
        log.error(e);
        log.error("Error While creating JWT token ==== {} ", e.getMessage());
    }
    return strJWTToken;
}
Also used : CacheWritingException(org.ehcache.spi.loaderwriter.CacheWritingException) Date(java.util.Date) JOSEException(com.nimbusds.jose.JOSEException) AuthorizationServiceException(org.springframework.security.access.AuthorizationServiceException) CacheWritingException(org.ehcache.spi.loaderwriter.CacheWritingException) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) AccountExpiredException(org.springframework.security.authentication.AccountExpiredException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 2 with CacheWritingException

use of org.ehcache.spi.loaderwriter.CacheWritingException in project Insights by CognizantOneDevOps.

the class TokenProviderUtility method createToken.

/**
 * used to create token and add it in customize cache,This will use custom expiration time
 *
 * @param userName
 * @return
 */
public String createToken(String userName, int tokenTime) {
    String strJWTToken = "";
    log.debug("Inside Create token with tokenTime {} === ", tokenTime);
    try {
        String username = ValidationUtils.cleanXSS(userName);
        String id = UUID.randomUUID().toString().replace("-", "");
        Date now = new Date();
        Date expDate = new Date(System.currentTimeMillis() + (tokenTime * 60 * 1000));
        strJWTToken = createAndStoreToken(username, id, now, expDate, new HashMap<String, Object>(0));
    } catch (CacheWritingException e) {
        log.error(e);
        log.error("CacheWritingException While writing token in cache  ==== {} ", e.getMessage());
    } catch (Exception e) {
        log.error(e);
        log.error("Error While creating JWT token ==== {} ", e.getMessage());
    }
    return strJWTToken;
}
Also used : CacheWritingException(org.ehcache.spi.loaderwriter.CacheWritingException) HashMap(java.util.HashMap) Date(java.util.Date) JOSEException(com.nimbusds.jose.JOSEException) AuthorizationServiceException(org.springframework.security.access.AuthorizationServiceException) CacheWritingException(org.ehcache.spi.loaderwriter.CacheWritingException) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) AccountExpiredException(org.springframework.security.authentication.AccountExpiredException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Aggregations

InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)2 JOSEException (com.nimbusds.jose.JOSEException)2 Date (java.util.Date)2 CacheWritingException (org.ehcache.spi.loaderwriter.CacheWritingException)2 AuthorizationServiceException (org.springframework.security.access.AuthorizationServiceException)2 AccountExpiredException (org.springframework.security.authentication.AccountExpiredException)2 AuthenticationCredentialsNotFoundException (org.springframework.security.authentication.AuthenticationCredentialsNotFoundException)2 HashMap (java.util.HashMap)1