Search in sources :

Example 6 with ServiceProperties

use of org.springframework.security.cas.ServiceProperties in project spring-security by spring-projects.

the class CasAuthenticationProviderTests method makeServiceProperties.

private ServiceProperties makeServiceProperties() {
    final ServiceProperties serviceProperties = new ServiceProperties();
    serviceProperties.setSendRenew(false);
    serviceProperties.setService("http://test.com");
    return serviceProperties;
}
Also used : ServiceProperties(org.springframework.security.cas.ServiceProperties)

Example 7 with ServiceProperties

use of org.springframework.security.cas.ServiceProperties in project spring-security by spring-projects.

the class CasAuthenticationProviderTests method authenticateAllNullService.

@Test
public void authenticateAllNullService() throws Exception {
    String serviceUrl = "https://service/context";
    ServiceAuthenticationDetails details = mock(ServiceAuthenticationDetails.class);
    when(details.getServiceUrl()).thenReturn(serviceUrl);
    TicketValidator validator = mock(TicketValidator.class);
    when(validator.validate(any(String.class), any(String.class))).thenReturn(new AssertionImpl("rod"));
    ServiceProperties serviceProperties = makeServiceProperties();
    serviceProperties.setAuthenticateAllArtifacts(true);
    CasAuthenticationProvider cap = new CasAuthenticationProvider();
    cap.setAuthenticationUserDetailsService(new MockAuthoritiesPopulator());
    cap.setKey("qwerty");
    cap.setTicketValidator(validator);
    cap.setServiceProperties(serviceProperties);
    cap.afterPropertiesSet();
    String ticket = "ST-456";
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER, ticket);
    Authentication result = cap.authenticate(token);
}
Also used : ServiceAuthenticationDetails(org.springframework.security.cas.web.authentication.ServiceAuthenticationDetails) AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) ServiceProperties(org.springframework.security.cas.ServiceProperties) TicketValidator(org.jasig.cas.client.validation.TicketValidator) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 8 with ServiceProperties

use of org.springframework.security.cas.ServiceProperties in project spring-security by spring-projects.

the class ServicePropertiesTests method nullServiceWhenAuthenticateAllTokens.

@Test
public void nullServiceWhenAuthenticateAllTokens() throws Exception {
    ServiceProperties sp = new ServiceProperties();
    sp.setAuthenticateAllArtifacts(true);
    try {
        sp.afterPropertiesSet();
        fail("Expected Exception");
    } catch (IllegalArgumentException success) {
    }
    sp.setAuthenticateAllArtifacts(false);
    try {
        sp.afterPropertiesSet();
        fail("Expected Exception");
    } catch (IllegalArgumentException success) {
    }
}
Also used : ServiceProperties(org.springframework.security.cas.ServiceProperties) SamlServiceProperties(org.springframework.security.cas.SamlServiceProperties) Test(org.junit.Test)

Example 9 with ServiceProperties

use of org.springframework.security.cas.ServiceProperties in project spring-security by spring-projects.

the class CasAuthenticationEntryPointTests method testNormalOperationWithRenewFalse.

@Test
public void testNormalOperationWithRenewFalse() throws Exception {
    ServiceProperties sp = new ServiceProperties();
    sp.setSendRenew(false);
    sp.setService("https://mycompany.com/bigWebApp/login/cas");
    CasAuthenticationEntryPoint ep = new CasAuthenticationEntryPoint();
    ep.setLoginUrl("https://cas/login");
    ep.setServiceProperties(sp);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("/some_path");
    MockHttpServletResponse response = new MockHttpServletResponse();
    ep.afterPropertiesSet();
    ep.commence(request, response, null);
    assertThat("https://cas/login?service=" + URLEncoder.encode("https://mycompany.com/bigWebApp/login/cas", "UTF-8")).isEqualTo(response.getRedirectedUrl());
}
Also used : ServiceProperties(org.springframework.security.cas.ServiceProperties) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 10 with ServiceProperties

use of org.springframework.security.cas.ServiceProperties in project spring-security by spring-projects.

the class CasAuthenticationEntryPointTests method testGettersSetters.

@Test
public void testGettersSetters() {
    CasAuthenticationEntryPoint ep = new CasAuthenticationEntryPoint();
    ep.setLoginUrl("https://cas/login");
    assertThat(ep.getLoginUrl()).isEqualTo("https://cas/login");
    ep.setServiceProperties(new ServiceProperties());
    assertThat(ep.getServiceProperties() != null).isTrue();
}
Also used : ServiceProperties(org.springframework.security.cas.ServiceProperties) Test(org.junit.Test)

Aggregations

ServiceProperties (org.springframework.security.cas.ServiceProperties)13 Test (org.junit.Test)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 SamlServiceProperties (org.springframework.security.cas.SamlServiceProperties)3 Authentication (org.springframework.security.core.Authentication)3 ProxyGrantingTicketStorage (org.jasig.cas.client.proxy.ProxyGrantingTicketStorage)2 AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)2 TicketValidator (org.jasig.cas.client.validation.TicketValidator)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 ServiceAuthenticationDetails (org.springframework.security.cas.web.authentication.ServiceAuthenticationDetails)2 FilterChain (javax.servlet.FilterChain)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)1 AuthenticationSuccessHandler (org.springframework.security.web.authentication.AuthenticationSuccessHandler)1 WebAuthenticationDetails (org.springframework.security.web.authentication.WebAuthenticationDetails)1