use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class DelegatedClientAuthenticationActionTests method verifySsoAuthenticationUnauthz.
@Test
public void verifySsoAuthenticationUnauthz() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
request.setParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");
val service = CoreAuthenticationTestUtils.getService("https://delegated3.example.org");
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
val client = builtClients.findClient("FacebookClient").get();
val webContext = new JEEContext(request, new MockHttpServletResponse());
val ticket = delegatedClientAuthenticationWebflowManager.store(webContext, client);
request.addParameter(DefaultDelegatedClientAuthenticationWebflowManager.PARAMETER_CLIENT_ID, ticket.getId());
val accessStrategy = new DefaultRegisteredServiceAccessStrategy();
accessStrategy.setEnabled(false);
val registeredService = RegisteredServiceTestUtils.getRegisteredService(service.getId());
registeredService.setAccessStrategy(accessStrategy);
servicesManager.save(registeredService);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
setRequestContext(context);
setExternalContext(context.getExternalContext());
val tgt = new MockTicketGrantingTicket("casuser", Map.of(), Map.of(ClientCredential.AUTHENTICATION_ATTRIBUTE_CLIENT_NAME, List.of("FacebookClient")));
centralAuthenticationService.addTicket(tgt);
WebUtils.putTicketGrantingTicketInScopes(context, tgt);
assertThrows(UnauthorizedServiceException.class, () -> delegatedAuthenticationAction.execute(context).getId());
assertThrows(InvalidTicketException.class, () -> centralAuthenticationService.getTicket(tgt.getId()));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class DelegatedAuthenticationClientLogoutActionTests method verifyOperationWithProfile.
@Test
public void verifyOperationWithProfile() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
val profile = new CommonProfile();
profile.setId("casuser");
profile.setClientName("CasClient");
request.setAttribute(Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
val result = delegatedAuthenticationClientLogoutAction.execute(context);
assertNull(result);
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, response.getStatus());
val tgt = new MockTicketGrantingTicket("casuser");
logoutManager.performLogout(SingleLogoutExecutionRequest.builder().httpServletRequest(Optional.of(request)).httpServletResponse(Optional.of(response)).ticketGrantingTicket(tgt).build());
assertNull(request.getSession(false));
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class DefaultSamlArtifactTicketFactoryTests method verifyOperation.
@Test
public void verifyOperation() {
val tgt = new MockTicketGrantingTicket("casuser");
val ticketId = samlArtifactTicketFactory.create(UUID.randomUUID().toString(), tgt.getAuthentication(), tgt, casProperties.getAuthn().getSamlIdp().getCore().getEntityId(), "https://www.example.org", getAuthnRequestFor("helloworld"));
assertNotNull(ticketId);
assertNotNull(ticketId.getPrefix());
assertNotNull(ticketId.getTicketGrantingTicket());
assertNotNull(ticketId.getObject());
assertNotNull(ticketId.getRelyingPartyId());
assertNotNull(ticketId.getExpirationPolicy());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class SSOSamlIdPPostProfileHandlerControllerTests method verifyPostRequestWithSso.
@Test
@Order(5)
public void verifyPostRequestWithSso() throws Exception {
val response = new MockHttpServletResponse();
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
val request = new MockHttpServletRequest();
request.setCookies(response.getCookies());
request.setMethod("POST");
val authnRequest = getAuthnRequest();
val xml = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest).toString();
request.addParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
samlIdPDistributedSessionStore.set(new JEEContext(request, response), SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "relay-state");
val mv = controller.handleSaml2ProfileSsoPostRequest(response, request);
assertNull(mv);
assertEquals(HttpStatus.OK.value(), response.getStatus());
assertNotNull(response.getContentAsString());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class SSOSamlIdPPostProfileHandlerControllerTests method verifyPostRequestWithUnknownCookie.
@Test
@Order(7)
public void verifyPostRequestWithUnknownCookie() throws Exception {
val response = new MockHttpServletResponse();
val tgt = new MockTicketGrantingTicket("casuser");
ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
val request = new MockHttpServletRequest();
request.setCookies(response.getCookies());
request.setMethod("POST");
val authnRequest = getAuthnRequest();
val xml = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest).toString();
request.addParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
samlIdPDistributedSessionStore.set(new JEEContext(request, response), SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "relay-state");
val mv = controller.handleSaml2ProfileSsoPostRequest(response, request);
assertEquals(HttpStatus.FOUND, mv.getStatus());
}
Aggregations