use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class TicketGrantingTicketCheckActionTests method verifyInvalidTicket.
@Test
public void verifyInvalidTicket() throws Exception {
val ctx = new MockRequestContext();
val tgt = new MockTicketGrantingTicket("user");
WebUtils.putTicketGrantingTicketInScopes(ctx, tgt);
val action = new TicketGrantingTicketCheckAction(getCentralAuthenticationService());
val event = action.execute(ctx);
assertEquals(CasWebflowConstants.TRANSITION_ID_TICKET_GRANTING_TICKET_INVALID, event.getId());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class OidcPushedAuthorizationRequestUriResponseBuilderTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
assertEquals(0, oidcPushedAuthorizationRequestResponseBuilder.getOrder());
val registeredService = getOidcRegisteredService();
val profile = new CommonProfile();
profile.setId("casuser");
val holder = AccessTokenRequestContext.builder().clientId(registeredService.getClientId()).service(RegisteredServiceTestUtils.getService()).authentication(RegisteredServiceTestUtils.getAuthentication()).registeredService(registeredService).grantType(OAuth20GrantTypes.AUTHORIZATION_CODE).responseType(OAuth20ResponseTypes.CODE).userProfile(profile).build();
var authzRequest = OAuth20AuthorizationRequest.builder().clientId(registeredService.getClientId()).url(OidcConstants.PUSHED_AUTHORIZE_URL).grantType(OAuth20GrantTypes.AUTHORIZATION_CODE.getType()).responseType(OAuth20ResponseTypes.CODE.getType()).build();
assertTrue(oidcPushedAuthorizationRequestResponseBuilder.supports(authzRequest));
val mv = oidcPushedAuthorizationRequestResponseBuilder.build(holder);
assertTrue(mv.getModel().containsKey(OidcConstants.EXPIRES_IN));
val uri = mv.getModel().get(OidcConstants.REQUEST_URI).toString();
var ticket = ticketRegistry.getTicket(uri, OidcPushedAuthorizationRequest.class);
assertNotNull(ticket);
val request = new MockHttpServletRequest();
request.setRequestURI('/' + OidcConstants.PUSHED_AUTHORIZE_URL);
val response = new MockHttpServletResponse();
var context = new JEEContext(request, response);
authzRequest = oidcPushedAuthorizationRequestResponseBuilder.toAuthorizationRequest(context, holder.getAuthentication(), holder.getService(), holder.getRegisteredService()).get().build();
assertNotNull(authzRequest);
assertFalse(authzRequest.isSingleSignOnSessionRequired());
request.addParameter(OidcConstants.REQUEST_URI, uri);
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
val c = ticketGrantingTicketCookieGenerator.addCookie(request, response, tgt.getId());
request.setCookies(c);
context = new JEEContext(request, response);
authzRequest = oidcPushedAuthorizationRequestResponseBuilder.toAuthorizationRequest(context, holder.getAuthentication(), holder.getService(), holder.getRegisteredService()).get().build();
val accessTokenRequest = authzRequest.getAccessTokenRequest();
assertTrue(authzRequest.isSingleSignOnSessionRequired());
assertNotNull(accessTokenRequest.getAuthentication());
assertNotNull(accessTokenRequest.getRegisteredService());
assertNotNull(accessTokenRequest.getResponseType());
assertNotNull(accessTokenRequest.getGrantType());
assertNotNull(accessTokenRequest.getTicketGrantingTicket());
ticket = ticketRegistry.getTicket(uri, OidcPushedAuthorizationRequest.class);
assertNull(ticket);
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class AbstractOidcTests method addCode.
protected OAuth20Code addCode(final Principal principal, final OAuthRegisteredService registeredService) throws Exception {
val tgt = new MockTicketGrantingTicket("casuser");
val authentication = RegisteredServiceTestUtils.getAuthentication(principal);
val factory = new WebApplicationServiceFactory();
val service = factory.createService(registeredService.getClientId());
val code = defaultOAuthCodeFactory.create(service, authentication, tgt, new ArrayList<>(), null, null, "clientid", new HashMap<>(), OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
this.ticketRegistry.addTicket(code);
return code;
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class OidcProfileScopeToAttributesFilterTests method verifyOperationFilterWithOpenId.
@Test
public void verifyOperationFilterWithOpenId() {
val service = getOidcRegisteredService();
val accessToken = mock(OAuth20AccessToken.class);
when(accessToken.getTicketGrantingTicket()).thenReturn(new MockTicketGrantingTicket("casuser"));
when(accessToken.getScopes()).thenReturn(CollectionUtils.wrapSet(OidcConstants.StandardScopes.OPENID.getScope(), OidcConstants.StandardScopes.PHONE.getScope(), OidcConstants.StandardScopes.PROFILE.getScope(), OidcConstants.StandardScopes.ADDRESS.getScope(), OidcConstants.StandardScopes.EMAIL.getScope()));
service.getScopes().add(OidcConstants.StandardScopes.EMAIL.getScope());
service.getScopes().add(OidcConstants.StandardScopes.ADDRESS.getScope());
service.getScopes().add(OidcConstants.StandardScopes.PHONE.getScope());
service.getScopes().add(OidcConstants.StandardScopes.PROFILE.getScope());
val original = CoreAuthenticationTestUtils.getPrincipal(CollectionUtils.wrap("email", "casuser@example.org", "address", "1234 Main Street", "phone", "123445677", "name", "CAS", "gender", "male"));
val principal = profileScopeToAttributesFilter.filter(CoreAuthenticationTestUtils.getService(), original, service, accessToken);
assertTrue(principal.getAttributes().containsKey("name"));
assertTrue(principal.getAttributes().containsKey("address"));
assertTrue(principal.getAttributes().containsKey("gender"));
assertTrue(principal.getAttributes().containsKey("email"));
assertEquals(4, principal.getAttributes().size());
}
use of org.apereo.cas.mock.MockTicketGrantingTicket in project cas by apereo.
the class DelegatedClientAuthenticationActionTests method verifySsoAuthenticationWithInvalidTicketFails.
@Test
public void verifySsoAuthenticationWithInvalidTicketFails() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter("error_message", "Auth+failed");
val response = new MockHttpServletResponse();
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());
request.setParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");
val service = CoreAuthenticationTestUtils.getService("https://delegated2.example.org");
servicesManager.save(RegisteredServiceTestUtils.getRegisteredService(service.getId(), Map.of()));
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
setRequestContext(context);
setExternalContext(context.getExternalContext());
val tgt = new MockTicketGrantingTicket("casuser");
centralAuthenticationService.addTicket(tgt);
WebUtils.putTicketGrantingTicketInScopes(context, new MockTicketGrantingTicket("otheruser"));
assertEquals(CasWebflowConstants.TRANSITION_ID_STOP, delegatedAuthenticationAction.execute(context).getId());
}
Aggregations