@Test public void shouldAssembleExpectedResultForRefreshToken() throws ParseException { OAuth2RefreshTokenEntity refreshToken = refreshToken(new Date(123 * 1000L), authentication("name", request("clientId", scopes("foo", "bar")))); UserInfo userInfo = userInfo("sub"); Map<String, Object> result = assembler.assembleFrom(refreshToken, userInfo); Map<String, Object> expected = new ImmutableMap.Builder<String, Object>() .put("sub", "sub") .put("exp", 123L) .put("expires_at", dateFormat.valueToString(new Date(123 * 1000L))) .put("scope", "bar foo") .put("active", Boolean.TRUE) .put("user_id", "name") .put("client_id", "clientId") .build(); assertThat(result, is(equalTo(expected))); }
@Override public Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo) { Map<String, Object> result = newLinkedHashMap(); OAuth2Authentication authentication = accessToken.getAuthenticationHolder().getAuthentication(); result.put("active", true); result.put("scope", Joiner.on(" ").join(accessToken.getScope())); if (accessToken.getExpiration() != null) { try { result.put("expires_at", dateFormat.valueToString(accessToken.getExpiration())); result.put("exp", accessToken.getExpiration().getTime() / 1000L); } catch (ParseException e) { log.error("Parse exception in token introspection", e); } } if (userInfo != null) { result.put("sub", userInfo.getSub()); } else { result.put("sub", authentication.getName()); } result.put("user_id", authentication.getName()); result.put("client_id", authentication.getOAuth2Request().getClientId()); result.put("token_type", accessToken.getTokenType()); return result; }
DefaultIntrospectionResultAssembler implements IntrospectionResultAssembler { @Override public Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo) { Map<String, Object> result = newLinkedHashMap(); OAuth2Authentication authentication = accessToken.getAuthenticationHolder().getAuthentication(); result.put("active", true); result.put("scope", Joiner.on(" ").join(accessToken.getScope())); if (accessToken.getExpiration() != null) { try { result.put("expires_at", dateFormat.valueToString(accessToken.getExpiration())); result.put("exp", accessToken.getExpiration().getTime() / 1000L); } catch (ParseException e) { log.error("Parse exception in token introspection", e); } } if (userInfo != null) { result.put("sub", userInfo.getSub()); } else { result.put("sub", authentication.getName()); } result.put("user_id", authentication.getName()); result.put("client_id", authentication.getOAuth2Request().getClientId()); result.put("token_type", accessToken.getTokenType()); return result; } }
DefaultIntrospectionResultAssembler implements IntrospectionResultAssembler { @Override public Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo) { Map<String, Object> result = newLinkedHashMap(); OAuth2Authentication authentication = accessToken.getAuthenticationHolder().getAuthentication(); result.put("active", true); result.put("scope", Joiner.on(" ").join(accessToken.getScope())); if (accessToken.getExpiration() != null) { try { result.put("expires_at", dateFormat.valueToString(accessToken.getExpiration())); result.put("exp", accessToken.getExpiration().getTime() / 1000L); } catch (ParseException e) { log.error("Parse exception in token introspection", e); } } if (userInfo != null) { result.put("sub", userInfo.getSub()); } else { result.put("sub", authentication.getName()); } result.put("user_id", authentication.getName()); result.put("client_id", authentication.getOAuth2Request().getClientId()); result.put("token_type", accessToken.getTokenType()); return result; }  }
DefaultIntrospectionResultAssembler implements IntrospectionResultAssembler { @Override public Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo) { Map<String, Object> result = newLinkedHashMap(); OAuth2Authentication authentication = accessToken.getAuthenticationHolder().getAuthentication(); result.put("active", true); result.put("scope", Joiner.on(" ").join(accessToken.getScope())); if (accessToken.getExpiration() != null) { try { result.put("expires_at", dateFormat.valueToString(accessToken.getExpiration())); result.put("exp", accessToken.getExpiration().getTime() / 1000L); } catch (ParseException e) { log.error("Parse exception in token introspection", e); } } if (userInfo != null) { result.put("sub", userInfo.getSub()); } else { result.put("sub", authentication.getName()); } result.put("user_id", authentication.getName()); result.put("client_id", authentication.getOAuth2Request().getClientId()); result.put("token_type", accessToken.getTokenType()); return result; }  @Override Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo); @Override Map<String, Object> assembleFrom(OAuth2RefreshTokenEntity refreshToken, UserInfo userInfo); }
DefaultIntrospectionResultAssembler implements IntrospectionResultAssembler { @Override public Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo) { Map<String, Object> result = newLinkedHashMap(); OAuth2Authentication authentication = accessToken.getAuthenticationHolder().getAuthentication(); result.put("active", true); result.put("scope", Joiner.on(" ").join(accessToken.getScope())); if (accessToken.getExpiration() != null) { try { result.put("expires_at", dateFormat.valueToString(accessToken.getExpiration())); result.put("exp", accessToken.getExpiration().getTime() / 1000L); } catch (ParseException e) { log.error("Parse exception in token introspection", e); } } if (userInfo != null) { result.put("sub", userInfo.getSub()); } else { result.put("sub", authentication.getName()); } result.put("user_id", authentication.getName()); result.put("client_id", authentication.getOAuth2Request().getClientId()); result.put("token_type", accessToken.getTokenType()); return result; }  @Override Map<String, Object> assembleFrom(OAuth2AccessTokenEntity accessToken, UserInfo userInfo); @Override Map<String, Object> assembleFrom(OAuth2RefreshTokenEntity refreshToken, UserInfo userInfo);  }