protected CachedAuthentication getCachedAuthentication(Token at) { return cache.get(at.getToken()); }
log.debug("Access token '{}' was expired", at.getToken()); removeCachedAuthentication(at, cached); return null; removeCachedAuthentication(at, cached); }else{ log.debug("Returns the cached authentication of access token : {}", at.getToken()); return cached.authentication; if(!Strings.isEmpty(at.getType())) { TokenVerifier verifier = typedAccessTokenVerifiers.get(at.getType()); if(null == verifier) { throw new AppConfigException("Cannot handle access token type '" + at.getType() + "'"); tokenInfo = tokenInfoLookup.lookupByAccessToken(at.getToken()); log.info("Access token '{}' not found", at.getToken()); return null; log.info("Access token '{}' was expired", at.getToken()); return null; user = userInfoLookup.lookupUserInfo(at.getToken(), userId); if(null == user) { log.warn("User info not exists in oauth2 server, user id -> {}, access token -> {}", userId, at.getToken()); return null;
public String getAccessToken() { return null == authc ? null : authc.getCredentials().getToken(); }
protected void removeCachedAuthentication(Token at, CachedAuthentication cached) { cache.remove(at.getToken()); }
protected void cacheAuthentication(Token at, TokenInfo tokenDetails, OAuth2Authentication authc) { int cachedMs=cacheExpiresInMs; if(tokenDetails instanceof TimeExpirableSeconds){ cachedMs=((TimeExpirableSeconds)tokenDetails).getExpiresInFormNow()*1000; } cache.put(at.getToken(), new CachedAuthentication(tokenDetails, authc, cachedMs)); }
public AccessToken getAccessToken(Request request){ AccessToken at= TokenContext.getAccessToken(); if(at!=null){ return at; } Token token= tokenExtractor.extractTokenFromRequest(request); if(token==null){ return null; } String clientAt=token.getToken(); at=mapToSelfToken(clientAt); return at; }
protected TokenInfo doVerifyToken(Token token) { try { Map<String, Object> claims = server.verifyToken(token.getToken()); String clientId = (String)claims.get(JWT.CLAIM_AUDIENCE); OAuth2Client client = server.getClient(clientId); SimpleTokenInfo tokenInfo = new SimpleTokenInfo(); tokenInfo.setClientId(clientId); tokenInfo.setCreated(System.currentTimeMillis()); tokenInfo.setScope(client.getScope()); Object exp = claims.get(JWT.CLAIM_EXPIRATION_TIME); if (null != exp && exp instanceof Number) { long expirationTimeSecond = ((Number) exp).longValue(); long nowTimeInSecond = System.currentTimeMillis()/1000L; tokenInfo.setExpiresIn((int)(expirationTimeSecond-nowTimeInSecond)); } return tokenInfo; }catch (TokenVerifyException e) { if(isInternalOnly()) { throw e; } return null; } }
@Override public TokenInfo verifyToken(Token token) throws TokenVerifyException { if(null == verifier) { if(Strings.isEmpty(config.getPublicKeyUrl())) { throw new AppConfigException("publicKeyUrl must be configured"); } refreshJwtVerifier(); } return verify(verifier, token.getToken()); }
OAuth2Authentication authc = authenticator.authenticate(token); if(null == authc) { log.warn("Invalid access token '{}'", token.getToken()); return State.CONTINUE;