Example usage for org.apache.commons.jcs.access.exception CacheException getMessage

List of usage examples for org.apache.commons.jcs.access.exception CacheException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.jcs.access.exception CacheException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.slu.action.ObjectAction.java

private boolean verifyAccess(String access_token) throws IOException, ServletException, Exception {
    System.out.println("verify a JWT access token");
    System.out.println(access_token);
    boolean verified = false;
    JSONObject userInfo;/*  w ww.  j  a  v a 2 s. com*/
    try {
        DecodedJWT receivedToken = JWT.decode(access_token);
        System.out.println("initialize cache...");
        cache = JCS.getInstance("jwksCache");
        String KID = receivedToken.getKeyId();
        // Could cache this so we don't have to keep grabbing it since it has to happen on every call. 
        // http://commons.apache.org/proper/commons-jcs/getting_started/intro.html
        // https://commons.apache.org/proper/commons-jcs/
        Jwk jwk;
        JwkProvider provider;
        System.out.println("check cache for key...");
        RSAPublicKey pubKey = cache.get("pubKey");
        //Cache the key so we don't have to keep requesting auth0 for it.  Expires in cache every 10 hours.  
        if (null == pubKey) {
            System.out.println("key not in cache, ask auth0...");
            provider = new UrlJwkProvider("https://cubap.auth0.com/.well-known/jwks.json");
            jwk = provider.get(KID);
            pubKey = (RSAPublicKey) jwk.getPublicKey();
            cache.put("pubKey", pubKey);
            System.out.println("key in cache...");
        }
        Algorithm algorithm = Algorithm.RSA256(pubKey, null);
        JWTVerifier verifier = JWT.require(algorithm).build(); //Reusable verifier instance
        //.withIssuer("auth0")
        generatorID = receivedToken.getClaim(Constant.RERUM_AGENT_ClAIM).asString();
        //System.out.println("Was I able to pull the agent claim from the token directly without userinfo without verifying?  Value below");
        //System.out.println("Value: "+generatorID);
        if (botCheck(generatorID)) {
            System.out.println(
                    "It passed the bot check, no need to verify the access token.  I have the generator ID.  ");
            verified = true;
        } else {
            DecodedJWT d_jwt = verifier.verify(access_token);
            System.out.println("We were able to verify the access token. ");
            verified = true;
        }
    } catch (CacheException e) {
        System.out.println("Problem initializing cache: " + e.getMessage());
    } catch (JwkException | JWTVerificationException | IllegalArgumentException exception) {
        //Invalid signature/claims/token.  Try to authenticate the old way
        System.out.println(
                "Verification failed.  We were given a bad token.  IP fallback.  Exception below, but caught.");
        Logger.getLogger(ObjectAction.class.getName()).log(Level.SEVERE, null, exception);
        String requestIP = request.getRemoteAddr();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        //check if the domain name and ip is in database
        BasicDBObject query = new BasicDBObject();
        query.append("ip", requestIP);
        DBObject result = mongoDBService.findOneByExample(Constant.COLLECTION_ACCEPTEDSERVER, query);
        if (null != result) {
            System.out.println("[Modifying Data Request]: ip ========== " + requestIP + "@"
                    + sdf.format(new Date()) + " +++++ App registered in legacy system");
            if (null != result.get("agent") && !"".equals(result.get("agent"))) {
                //The user registered their IP with the new system
                System.out.println(
                        "The registered server had an agent ID with it, so it must be from the new system.");
                userInfo = JSONObject.fromObject(result);
            } else {
                //This is a legacy user.
                //Create agent and write back to server collection
                //_id is messed up so adding the agent in doesn't always work.
                System.out.println(
                        "The registered server did not have an agent ID.  It must be from the old system.");
                System.out.println("We will generate a new agent to store with the registered server.");
                userInfo = generateAgentForLegacyUser(JSONObject.fromObject(result));
            }
            //System.out.println("Grab agent id from");
            //System.out.println(userInfo);
            generatorID = userInfo.getString("agent");
            verified = true;
        } else {
            System.out.println("[Modifying Data Request]: ip ========== " + requestIP + "@"
                    + sdf.format(new Date()) + " +++++ The app needs to register with RERUM");
            verified = false;
        }
    }
    System.out.println("I need a generator out of all this.  Did I get it: " + generatorID);
    return verified;
}

From source file:org.ebayopensource.scc.cache.JCSCache.java

@Override
public void put(String key, CacheResponse resp) {
    if (m_isInitialized && resp != null) {
        try {//from ww w . ja v  a2s . c o m
            synchronized (s_cacheAccess) {
                s_cacheAccess.put(key, resp);
            }
        } catch (CacheException e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
}