Search in sources :

Example 1 with DefaultAccessTokenFactory

use of org.apereo.cas.ticket.accesstoken.DefaultAccessTokenFactory in project cas by apereo.

the class OAuth20ProfileControllerTests method verifyExpiredAccessToken.

@Test
public void verifyExpiredAccessToken() throws Exception {
    final Principal principal = CoreAuthenticationTestUtils.getPrincipal(ID, new HashMap<>());
    final Authentication authentication = getAuthentication(principal);
    final DefaultAccessTokenFactory expiringAccessTokenFactory = new DefaultAccessTokenFactory(new AlwaysExpiresExpirationPolicy());
    final AccessTokenImpl accessToken = (AccessTokenImpl) expiringAccessTokenFactory.create(CoreAuthenticationTestUtils.getService(), authentication);
    oAuth20ProfileController.getTicketRegistry().addTicket(accessToken);
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuthConstants.PROFILE_URL);
    mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getId());
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ResponseEntity<String> entity = oAuth20ProfileController.handleRequestInternal(mockRequest, mockResponse);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());
    assertTrue(entity.getBody().contains(OAuthConstants.EXPIRED_ACCESS_TOKEN));
}
Also used : Authentication(org.apereo.cas.authentication.Authentication) DefaultAccessTokenFactory(org.apereo.cas.ticket.accesstoken.DefaultAccessTokenFactory) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AccessTokenImpl(org.apereo.cas.ticket.accesstoken.AccessTokenImpl) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy) Principal(org.apereo.cas.authentication.principal.Principal) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Authentication (org.apereo.cas.authentication.Authentication)1 Principal (org.apereo.cas.authentication.principal.Principal)1 AccessTokenImpl (org.apereo.cas.ticket.accesstoken.AccessTokenImpl)1 DefaultAccessTokenFactory (org.apereo.cas.ticket.accesstoken.DefaultAccessTokenFactory)1 AlwaysExpiresExpirationPolicy (org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy)1 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1