use of org.apereo.cas.support.oauth.web.response.accesstoken.response.OAuth20JwtAccessTokenCipherExecutor in project cas by apereo.
the class OAuth20UserProfileEndpointControllerTests method verifyExpiredAccessToken.
@Test
public void verifyExpiredAccessToken() throws Exception {
val principal = CoreAuthenticationTestUtils.getPrincipal(ID, new HashMap<>());
val authentication = getAuthentication(principal);
val jwtBuilder = new JwtBuilder(new OAuth20JwtAccessTokenCipherExecutor(), servicesManager, new OAuth20RegisteredServiceJwtAccessTokenCipherExecutor());
val expiringAccessTokenFactory = new OAuth20DefaultAccessTokenFactory(alwaysExpiresExpirationPolicyBuilder(), jwtBuilder, servicesManager);
val code = addCode(principal, addRegisteredService());
val accessToken = expiringAccessTokenFactory.create(RegisteredServiceTestUtils.getService(), authentication, new MockTicketGrantingTicket("casuser"), new ArrayList<>(), code.getId(), code.getClientId(), new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
this.ticketRegistry.addTicket(accessToken);
val mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.PROFILE_URL);
mockRequest.setParameter(OAuth20Constants.ACCESS_TOKEN, accessToken.getId());
val mockResponse = new MockHttpServletResponse();
val entity = oAuth20ProfileController.handleGetRequest(mockRequest, mockResponse);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
assertEquals(MediaType.APPLICATION_JSON_VALUE, mockResponse.getContentType());
assertNotNull(entity.getBody());
assertTrue(entity.getBody().toString().contains(OAuth20Constants.EXPIRED_ACCESS_TOKEN));
}
Aggregations