use of org.pac4j.cas.profile.CasProfile in project cas by apereo.
the class OAuth20AuthorizeEndpointControllerTests method verifyServiceAccessDenied.
@Test
public void verifyServiceAccessDenied() throws Exception {
clearAllServices();
val mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.AUTHORIZE_URL);
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.name().toLowerCase());
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
mockRequest.setContextPath(StringUtils.EMPTY);
val mockResponse = new MockHttpServletResponse();
val service = getRegisteredService(REDIRECT_URI, SERVICE_NAME);
service.setBypassApprovalPrompt(true);
service.setAccessStrategy(new DefaultRegisteredServiceAccessStrategy(Map.of("required", Set.of("value1"))));
oAuth20AuthorizeEndpointController.getConfigurationContext().getServicesManager().save(service);
val profile = new CasProfile();
profile.setId(ID);
val session = new MockHttpSession();
mockRequest.setSession(session);
val sessionStore = oAuth20AuthorizeEndpointController.getConfigurationContext().getSessionStore();
val context = new JEEContext(mockRequest, mockResponse);
val ticket = new MockTicketGrantingTicket("casuser");
oAuth20AuthorizeEndpointController.getConfigurationContext().getTicketRegistry().addTicket(ticket);
sessionStore.set(context, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, ticket.getId());
sessionStore.set(context, Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
val modelAndView = oAuth20AuthorizeEndpointController.handleRequest(mockRequest, mockResponse);
assertEquals(CasWebflowConstants.VIEW_ID_SERVICE_ERROR, modelAndView.getViewName());
}
use of org.pac4j.cas.profile.CasProfile in project cas by apereo.
the class OAuth20AuthorizeEndpointControllerTests method verifyCodeRedirectToClient.
@Test
public void verifyCodeRedirectToClient() throws Exception {
clearAllServices();
val mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.AUTHORIZE_URL);
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.CODE.name().toLowerCase());
mockRequest.setServerName(CAS_SERVER);
mockRequest.setServerPort(CAS_PORT);
mockRequest.setScheme(CAS_SCHEME);
mockRequest.setContextPath(StringUtils.EMPTY);
val mockResponse = new MockHttpServletResponse();
val casProperties = oAuth20AuthorizeEndpointController.getConfigurationContext().getCasProperties();
casProperties.getSessionReplication().getCookie().setAutoConfigureCookiePath(true);
casProperties.getAuthn().getOauth().setReplicateSessions(true);
oAuth20AuthorizeEndpointController.getConfigurationContext().getOauthDistributedSessionCookieGenerator().setCookiePath(StringUtils.EMPTY);
val service = getRegisteredService(REDIRECT_URI, SERVICE_NAME);
service.setBypassApprovalPrompt(true);
oAuth20AuthorizeEndpointController.getConfigurationContext().getServicesManager().save(service);
val profile = new CasProfile();
profile.setId(ID);
val attributes = new HashMap<String, Object>();
attributes.put(FIRST_NAME_ATTRIBUTE, FIRST_NAME);
attributes.put(LAST_NAME_ATTRIBUTE, LAST_NAME);
profile.addAttributes(attributes);
val session = new MockHttpSession();
mockRequest.setSession(session);
val sessionStore = oAuth20AuthorizeEndpointController.getConfigurationContext().getSessionStore();
val context = new JEEContext(mockRequest, mockResponse);
val ticket = new MockTicketGrantingTicket("casuser");
oAuth20AuthorizeEndpointController.getConfigurationContext().getTicketRegistry().addTicket(ticket);
sessionStore.set(context, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, ticket.getId());
sessionStore.set(context, Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
val modelAndView = oAuth20AuthorizeEndpointController.handleRequest(mockRequest, mockResponse);
val view = modelAndView.getView();
assertTrue(view instanceof RedirectView);
val redirectView = (RedirectView) view;
val redirectUrl = redirectView.getUrl();
assertNotNull(redirectUrl);
assertEquals(redirectUrl, REDIRECT_URI);
assertEquals("/", oAuth20AuthorizeEndpointController.getConfigurationContext().getOauthDistributedSessionCookieGenerator().getCookiePath());
val code = modelAndView.getModelMap().get("code");
val oAuthCode = (OAuth20Code) this.ticketRegistry.getTicket(String.valueOf(code));
assertNotNull(oAuthCode);
val principal = oAuthCode.getAuthentication().getPrincipal();
assertEquals(ID, principal.getId());
val principalAttributes = principal.getAttributes();
assertEquals(attributes.size(), principalAttributes.size());
assertEquals(FIRST_NAME, principalAttributes.get(FIRST_NAME_ATTRIBUTE).get(0));
}
use of org.pac4j.cas.profile.CasProfile in project cas by apereo.
the class OAuth20DefaultCasAuthenticationBuilderTests method verifyOperationToBuild.
@Test
public void verifyOperationToBuild() {
val profile = new CasProfile();
profile.setId("casuser");
profile.addAuthenticationAttribute("clazz", "high");
profile.addAttribute("cn", "casuser");
val request = new MockHttpServletRequest();
request.addParameter(OAuth20Constants.STATE, UUID.randomUUID().toString());
request.addParameter(OAuth20Constants.NONCE, UUID.randomUUID().toString());
request.addParameter(OAuth20Constants.ACR_VALUES, "mfa-dummy");
request.addHeader("X-".concat(CasProtocolConstants.PARAMETER_SERVICE), service.getServiceId());
val ctx = new JEEContext(request, new MockHttpServletResponse());
val result = authenticationBuilder.build(profile, service, ctx, RegisteredServiceTestUtils.getService());
assertNotNull(result);
assertTrue(result.getPrincipal().getAttributes().containsKey("cn"));
assertTrue(result.getAttributes().containsKey("clazz"));
}
use of org.pac4j.cas.profile.CasProfile in project cas by apereo.
the class OidcPushedAuthorizeEndpointControllerTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val id = UUID.randomUUID().toString();
val mockRequest = getHttpRequestForEndpoint(OidcConstants.PUSHED_AUTHORIZE_URL);
mockRequest.setMethod(HttpMethod.GET.name());
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, id);
mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, "https://oauth.example.org/");
mockRequest.setParameter(OAuth20Constants.RESPONSE_TYPE, OAuth20ResponseTypes.TOKEN.name().toLowerCase());
mockRequest.setContextPath(StringUtils.EMPTY);
val mockResponse = new MockHttpServletResponse();
val oauthContext = oidcPushedAuthorizeController.getConfigurationContext();
oauthContext.getCasProperties().getSessionReplication().getCookie().setAutoConfigureCookiePath(false);
oauthContext.getOauthDistributedSessionCookieGenerator().setCookiePath(StringUtils.EMPTY);
val service = getOidcRegisteredService(id);
service.setBypassApprovalPrompt(true);
servicesManager.save(service);
val profile = new CasProfile();
profile.setId("casuser");
val sessionStore = oidcPushedAuthorizeController.getConfigurationContext().getSessionStore();
val context = new JEEContext(mockRequest, mockResponse);
val ticket = new MockTicketGrantingTicket("casuser");
oidcPushedAuthorizeController.getConfigurationContext().getTicketRegistry().addTicket(ticket);
sessionStore.set(context, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, ticket.getId());
sessionStore.set(context, Pac4jConstants.USER_PROFILES, CollectionUtils.wrapLinkedHashMap(profile.getClientName(), profile));
val modelAndView = oidcPushedAuthorizeController.handleRequestPost(mockRequest, mockResponse);
assertNotNull(modelAndView);
}
Aggregations