use of org.apereo.cas.util.MockServletContext 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.util.MockServletContext in project cas by apereo.
the class DelegatedClientAuthenticationActionTests method verifyLogoutRequestWithOkAction.
@Test
public void verifyLogoutRequestWithOkAction() throws Exception {
val request = new MockHttpServletRequest();
request.setParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "MockClientNoCredentials");
request.addParameter(Pac4jConstants.LOGOUT_ENDPOINT_PARAMETER, "true");
val service = RegisteredServiceTestUtils.getService(UUID.randomUUID().toString());
servicesManager.save(RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of()));
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
val context = new MockRequestContext();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
setRequestContext(context);
setExternalContext(context.getExternalContext());
val event = delegatedAuthenticationAction.execute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, event.getId());
}
use of org.apereo.cas.util.MockServletContext 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.util.MockServletContext in project cas by apereo.
the class DelegatedAuthenticationClientLogoutActionTests method verifyOperationWithNoProfile.
@Test
public void verifyOperationWithNoProfile() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val result = delegatedAuthenticationClientLogoutAction.execute(context);
assertNull(result);
assertNotEquals(HttpStatus.SC_MOVED_TEMPORARILY, response.getStatus());
}
use of org.apereo.cas.util.MockServletContext in project cas by apereo.
the class WSFederationMetadataUIActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val registeredService = new WSFederationRegisteredService();
registeredService.setRealm("CAS");
registeredService.setServiceId("http://app.example5.org/wsfed-idp");
registeredService.setName("WSFED App");
registeredService.setId(100);
registeredService.setAppliesTo("CAS");
registeredService.setWsdlLocation("classpath:wsdl/ws-trust-1.4-service.wsdl");
servicesManager.save(registeredService);
val service = RegisteredServiceTestUtils.getService("http://app.example5.org/wsfed-idp");
service.getAttributes().put(WSFederationConstants.WREPLY, List.of(registeredService.getServiceId()));
WebUtils.putServiceIntoFlowScope(context, service);
val event = wsFederationMetadataUIAction.execute(context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, event.getId());
}
Aggregations