use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class WSFederationValidateRequestControllerTests method verifyLoginRenewWithToken.
@Test
public void verifyLoginRenewWithToken() throws Exception {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val registeredService = getWsFederationRegisteredService();
request.addParameter(WSFederationConstants.WTREALM, registeredService.getRealm());
request.addParameter(WSFederationConstants.WREPLY, registeredService.getServiceId());
request.addParameter(WSFederationConstants.WREFRESH, "1");
request.addParameter(WSFederationConstants.WA, WSFederationConstants.WSIGNIN10);
val token = mock(SecurityToken.class);
when(token.isExpired()).thenReturn(Boolean.FALSE);
when(token.getCreated()).thenReturn(Instant.now(Clock.systemUTC()).minusSeconds(300));
val id = UUID.randomUUID().toString();
val sts = mock(SecurityTokenTicket.class);
when(sts.getPrefix()).thenReturn(SecurityTokenTicket.PREFIX);
when(sts.getId()).thenReturn(SecurityTokenTicket.PREFIX + '-' + id);
when(sts.isExpired()).thenReturn(Boolean.FALSE);
when(sts.getSecurityToken()).thenReturn(token);
ticketRegistry.addTicket(sts);
val tgt = new MockTicketGrantingTicket("casuser");
tgt.getDescendantTickets().add(sts.getId());
ticketRegistry.addTicket(tgt);
ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
request.setCookies(response.getCookies());
assertDoesNotThrow(() -> {
federationValidateRequestController.handleFederationRequest(response, request);
return null;
});
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, response.getStatus());
val builder = new URIBuilder(response.getHeader("Location"));
assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(CasProtocolConstants.PARAMETER_SERVICE)));
assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(CasProtocolConstants.PARAMETER_RENEW)));
assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(WSFederationConstants.WTREALM)));
assertTrue(builder.getQueryParams().stream().anyMatch(p -> p.getName().equals(WSFederationConstants.WREPLY)));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class GroovyAcceptableUsagePolicyRepositoryTests method verifyPolicyTermsFails.
@Test
public void verifyPolicyTermsFails() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
val credential = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword("casuser");
val tgt = new MockTicketGrantingTicket(credential.getId(), credential, Map.of());
ticketRegistry.addTicket(tgt);
assertFalse(acceptableUsagePolicyRepository.fetchPolicy(context).isPresent());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class AbstractOAuth20Tests method generateAccessTokenResponseAndGetModelAndView.
@SneakyThrows
protected ModelAndView generateAccessTokenResponseAndGetModelAndView(final OAuthRegisteredService registeredService, final Authentication authentication, final OAuth20GrantTypes grantType, final HttpServletRequest mockRequest) {
val mockResponse = new MockHttpServletResponse();
val service = RegisteredServiceTestUtils.getService(SERVICE_URL);
val holder = AccessTokenRequestContext.builder().clientId(registeredService.getClientId()).service(service).authentication(authentication).registeredService(registeredService).grantType(grantType).responseType(OAuth20ResponseTypes.CODE).ticketGrantingTicket(new MockTicketGrantingTicket("casuser")).claims(OAuth20Utils.parseRequestClaims(new JEEContext(mockRequest, mockResponse))).build();
val generatedToken = oauthTokenGenerator.generate(holder);
val builder = OAuth20AccessTokenResponseResult.builder();
val result = builder.registeredService(registeredService).responseType(OAuth20ResponseTypes.CODE).service(service).generatedToken(generatedToken).build();
return accessTokenResponseGenerator.generate(result);
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class AbstractOAuth20Tests method addRefreshToken.
protected OAuth20RefreshToken addRefreshToken(final Principal principal, final OAuthRegisteredService registeredService) throws Exception {
val authentication = getAuthentication(principal);
val factory = new WebApplicationServiceFactory();
val service = factory.createService(registeredService.getServiceId());
val refreshToken = oAuthRefreshTokenFactory.create(service, authentication, new MockTicketGrantingTicket("casuser"), new ArrayList<>(), registeredService.getClientId(), StringUtils.EMPTY, new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
this.ticketRegistry.addTicket(refreshToken);
return refreshToken;
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class AbstractOAuth20Tests method addAccessToken.
protected OAuth20AccessToken addAccessToken(final Principal principal, final OAuthRegisteredService registeredService) throws Exception {
val code = addCode(principal, registeredService);
val authentication = getAuthentication(principal);
val factory = new WebApplicationServiceFactory();
val service = factory.createService(registeredService.getServiceId());
val accessToken = defaultAccessTokenFactory.create(service, authentication, new MockTicketGrantingTicket("casuser"), new ArrayList<>(), code.getId(), registeredService.getClientId(), new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
this.ticketRegistry.addTicket(accessToken);
return accessToken;
}
Aggregations