Search in sources :

Example 1 with SimpleUrlValidatorFactoryBean

use of org.apereo.cas.web.SimpleUrlValidatorFactoryBean in project cas by apereo.

the class DefaultLogoutManagerTests method setUp.

@Before
public void setUp() {
    when(client.isValidEndPoint(any(String.class))).thenReturn(true);
    when(client.isValidEndPoint(any(URL.class))).thenReturn(true);
    when(client.sendMessageToEndPoint(any(HttpMessage.class))).thenReturn(true);
    final UrlValidator validator = new SimpleUrlValidatorFactoryBean(true).getObject();
    singleLogoutServiceMessageHandler = new DefaultSingleLogoutServiceMessageHandler(client, new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(validator), true, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    final Map<String, Service> services = new HashMap<>();
    this.simpleWebApplicationServiceImpl = getService(URL);
    services.put(ID, this.simpleWebApplicationServiceImpl);
    when(this.tgt.getServices()).thenReturn(services);
    this.logoutManager = new DefaultLogoutManager(new SamlCompliantLogoutMessageCreator(), singleLogoutServiceMessageHandler, false, mock(LogoutExecutionPlan.class));
    this.registeredService = getRegisteredService(URL);
    when(servicesManager.findServiceBy(this.simpleWebApplicationServiceImpl)).thenReturn(this.registeredService);
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) HashMap(java.util.HashMap) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) AbstractWebApplicationService(org.apereo.cas.authentication.principal.AbstractWebApplicationService) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) URL(java.net.URL) SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) UrlValidator(org.apereo.cas.web.UrlValidator) HttpMessage(org.apereo.cas.util.http.HttpMessage) Before(org.junit.Before)

Example 2 with SimpleUrlValidatorFactoryBean

use of org.apereo.cas.web.SimpleUrlValidatorFactoryBean in project cas by apereo.

the class FrontChannelLogoutActionTests method onSetUp.

@Before
public void onSetUp() throws Exception {
    final UrlValidator validator = new SimpleUrlValidatorFactoryBean(false).getObject();
    final DefaultSingleLogoutServiceMessageHandler handler = new DefaultSingleLogoutServiceMessageHandler(new SimpleHttpClientFactoryBean().getObject(), new SamlCompliantLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(validator), false, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    final DefaultLogoutManager logoutManager = new DefaultLogoutManager(new SamlCompliantLogoutMessageCreator(), handler, false, mock(LogoutExecutionPlan.class));
    this.frontChannelLogoutAction = new FrontChannelLogoutAction(logoutManager);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    this.requestContext = mock(RequestContext.class);
    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(this.requestContext.getExternalContext()).thenReturn(servletExternalContext);
    when(servletExternalContext.getNativeRequest()).thenReturn(request);
    when(servletExternalContext.getNativeResponse()).thenReturn(response);
    final LocalAttributeMap flowScope = new LocalAttributeMap();
    when(this.requestContext.getFlowScope()).thenReturn(flowScope);
    final MockFlowExecutionKey mockFlowExecutionKey = new MockFlowExecutionKey(FLOW_EXECUTION_KEY);
    final MockFlowExecutionContext mockFlowExecutionContext = new MockFlowExecutionContext();
    mockFlowExecutionContext.setKey(mockFlowExecutionKey);
    when(this.requestContext.getFlowExecutionContext()).thenReturn(mockFlowExecutionContext);
}
Also used : DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) MockFlowExecutionKey(org.springframework.webflow.test.MockFlowExecutionKey) DefaultSingleLogoutServiceMessageHandler(org.apereo.cas.logout.DefaultSingleLogoutServiceMessageHandler) DefaultLogoutManager(org.apereo.cas.logout.DefaultLogoutManager) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultSingleLogoutServiceLogoutUrlBuilder(org.apereo.cas.logout.DefaultSingleLogoutServiceLogoutUrlBuilder) FrontChannelLogoutAction(org.apereo.cas.web.flow.logout.FrontChannelLogoutAction) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) SimpleHttpClientFactoryBean(org.apereo.cas.util.http.SimpleHttpClientFactoryBean) LogoutExecutionPlan(org.apereo.cas.logout.LogoutExecutionPlan) SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) SamlCompliantLogoutMessageCreator(org.apereo.cas.logout.SamlCompliantLogoutMessageCreator) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) UrlValidator(org.apereo.cas.web.UrlValidator) RequestContext(org.springframework.webflow.execution.RequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 3 with SimpleUrlValidatorFactoryBean

use of org.apereo.cas.web.SimpleUrlValidatorFactoryBean in project cas by apereo.

the class DefaultLogoutManagerTests method initialize.

@BeforeEach
public void initialize() {
    tgt = new MockTicketGrantingTicket("casuser");
    when(client.isValidEndPoint(any(String.class))).thenReturn(true);
    when(client.isValidEndPoint(any(URL.class))).thenReturn(true);
    when(client.sendMessageToEndPoint(any(HttpMessage.class))).thenReturn(true);
    val validator = new SimpleUrlValidatorFactoryBean(true).getObject();
    singleLogoutServiceMessageHandler = new DefaultSingleLogoutServiceMessageHandler(client, new DefaultSingleLogoutMessageCreator(), servicesManager, new DefaultSingleLogoutServiceLogoutUrlBuilder(servicesManager, validator), true, new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy()));
    this.simpleWebApplicationServiceImpl = getService(URL);
    tgt.getServices().put(ID, this.simpleWebApplicationServiceImpl);
    val plan = new DefaultLogoutExecutionPlan();
    plan.registerSingleLogoutServiceMessageHandler(singleLogoutServiceMessageHandler);
    this.logoutManager = new DefaultLogoutManager(false, plan);
    this.registeredService = getRegisteredService(URL);
    when(servicesManager.findServiceBy(this.simpleWebApplicationServiceImpl)).thenReturn(this.registeredService);
    assertTrue(plan.getLogoutRedirectionStrategies().isEmpty());
}
Also used : lombok.val(lombok.val) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) DefaultSingleLogoutServiceMessageHandler(org.apereo.cas.logout.slo.DefaultSingleLogoutServiceMessageHandler) DefaultSingleLogoutServiceLogoutUrlBuilder(org.apereo.cas.logout.slo.DefaultSingleLogoutServiceLogoutUrlBuilder) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) URL(java.net.URL) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) HttpMessage(org.apereo.cas.util.http.HttpMessage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with SimpleUrlValidatorFactoryBean

use of org.apereo.cas.web.SimpleUrlValidatorFactoryBean in project cas by apereo.

the class OidcClientRegistrationUtils method getClientRegistrationResponse.

/**
 * Gets client registration response.
 *
 * @param registeredService the registered service
 * @param serverPrefix      the server prefix
 * @return the client registration response
 */
@SneakyThrows
public static OidcClientRegistrationResponse getClientRegistrationResponse(final OidcRegisteredService registeredService, final String serverPrefix) {
    val clientResponse = new OidcClientRegistrationResponse();
    clientResponse.setApplicationType(registeredService.getApplicationType());
    clientResponse.setClientId(registeredService.getClientId());
    clientResponse.setClientSecret(registeredService.getClientSecret());
    clientResponse.setSubjectType(registeredService.getSubjectType());
    clientResponse.setTokenEndpointAuthMethod(registeredService.getTokenEndpointAuthenticationMethod());
    clientResponse.setClientName(registeredService.getName());
    clientResponse.setRedirectUris(CollectionUtils.wrap(registeredService.getServiceId()));
    clientResponse.setUserInfoSignedReponseAlg(registeredService.getUserInfoSigningAlg());
    clientResponse.setUserInfoEncryptedReponseAlg(registeredService.getUserInfoEncryptedResponseAlg());
    clientResponse.setUserInfoEncryptedReponseEncoding(registeredService.getUserInfoEncryptedResponseEncoding());
    clientResponse.setContacts(registeredService.getContacts().stream().map(RegisteredServiceContact::getName).filter(StringUtils::isNotBlank).collect(Collectors.toList()));
    clientResponse.setGrantTypes(Arrays.stream(OAuth20GrantTypes.values()).map(type -> type.getType().toLowerCase()).collect(Collectors.toList()));
    clientResponse.setResponseTypes(Arrays.stream(OAuth20ResponseTypes.values()).map(type -> type.getType().toLowerCase()).collect(Collectors.toList()));
    val validator = new SimpleUrlValidatorFactoryBean(false).getObject();
    val keystore = SpringExpressionLanguageValueResolver.getInstance().resolve(registeredService.getJwks());
    if (Objects.requireNonNull(validator).isValid(keystore)) {
        clientResponse.setJwksUri(keystore);
    } else if (ResourceUtils.doesResourceExist(keystore)) {
        val res = ResourceUtils.getResourceFrom(keystore);
        val json = IOUtils.toString(res.getInputStream(), StandardCharsets.UTF_8);
        clientResponse.setJwks(new JsonWebKeySet(json).toJson());
    } else if (StringUtils.isNotBlank(keystore)) {
        val jwks = new JsonWebKeySet(keystore);
        clientResponse.setJwks(jwks.toJson());
    }
    clientResponse.setLogo(registeredService.getLogo());
    clientResponse.setPolicyUri(registeredService.getInformationUrl());
    clientResponse.setTermsOfUseUri(registeredService.getPrivacyUrl());
    clientResponse.setRedirectUris(CollectionUtils.wrapList(registeredService.getServiceId()));
    val clientConfigUri = getClientConfigurationUri(registeredService, serverPrefix);
    clientResponse.setRegistrationClientUri(clientConfigUri);
    return clientResponse;
}
Also used : lombok.val(lombok.val) SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) StringUtils(org.apache.commons.lang3.StringUtils) JsonWebKeySet(org.jose4j.jwk.JsonWebKeySet) OidcClientRegistrationResponse(org.apereo.cas.oidc.dynareg.OidcClientRegistrationResponse) SneakyThrows(lombok.SneakyThrows)

Example 5 with SimpleUrlValidatorFactoryBean

use of org.apereo.cas.web.SimpleUrlValidatorFactoryBean in project cas by apereo.

the class CasCoreWebConfiguration method urlValidator.

@Bean
public FactoryBean<UrlValidator> urlValidator() {
    final HttpClientProperties httpClient = this.casProperties.getHttpClient();
    final boolean allowLocalLogoutUrls = httpClient.isAllowLocalLogoutUrls();
    final String authorityValidationRegEx = httpClient.getAuthorityValidationRegEx();
    final boolean authorityValidationRegExCaseSensitive = httpClient.isAuthorityValidationRegExCaseSensitive();
    return new SimpleUrlValidatorFactoryBean(allowLocalLogoutUrls, authorityValidationRegEx, authorityValidationRegExCaseSensitive);
}
Also used : SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) HttpClientProperties(org.apereo.cas.configuration.model.core.authentication.HttpClientProperties) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) FactoryBean(org.springframework.beans.factory.FactoryBean) SimpleUrlValidatorFactoryBean(org.apereo.cas.web.SimpleUrlValidatorFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

SimpleUrlValidatorFactoryBean (org.apereo.cas.web.SimpleUrlValidatorFactoryBean)5 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)3 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)3 URL (java.net.URL)2 lombok.val (lombok.val)2 HttpMessage (org.apereo.cas.util.http.HttpMessage)2 UrlValidator (org.apereo.cas.web.UrlValidator)2 Before (org.junit.Before)2 HashMap (java.util.HashMap)1 SneakyThrows (lombok.SneakyThrows)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)1 Service (org.apereo.cas.authentication.principal.Service)1 HttpClientProperties (org.apereo.cas.configuration.model.core.authentication.HttpClientProperties)1 DefaultLogoutManager (org.apereo.cas.logout.DefaultLogoutManager)1 DefaultSingleLogoutServiceLogoutUrlBuilder (org.apereo.cas.logout.DefaultSingleLogoutServiceLogoutUrlBuilder)1 DefaultSingleLogoutServiceMessageHandler (org.apereo.cas.logout.DefaultSingleLogoutServiceMessageHandler)1 LogoutExecutionPlan (org.apereo.cas.logout.LogoutExecutionPlan)1 SamlCompliantLogoutMessageCreator (org.apereo.cas.logout.SamlCompliantLogoutMessageCreator)1 DefaultSingleLogoutServiceLogoutUrlBuilder (org.apereo.cas.logout.slo.DefaultSingleLogoutServiceLogoutUrlBuilder)1