Search in sources :

Example 1 with ServiceProperties

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

the class CasAuthenticationEntryPointTests method testDetectsMissingLoginFormUrl.

// ~ Methods
// ========================================================================================================
@Test
public void testDetectsMissingLoginFormUrl() throws Exception {
    CasAuthenticationEntryPoint ep = new CasAuthenticationEntryPoint();
    ep.setServiceProperties(new ServiceProperties());
    try {
        ep.afterPropertiesSet();
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage()).isEqualTo("loginUrl must be specified");
    }
}
Also used : ServiceProperties(org.springframework.security.cas.ServiceProperties) Test(org.junit.Test)

Example 2 with ServiceProperties

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

the class CasAuthenticationFilterTests method testGettersSetters.

@Test
public void testGettersSetters() {
    CasAuthenticationFilter filter = new CasAuthenticationFilter();
    filter.setProxyGrantingTicketStorage(mock(ProxyGrantingTicketStorage.class));
    filter.setProxyReceptorUrl("/someurl");
    filter.setServiceProperties(new ServiceProperties());
}
Also used : ProxyGrantingTicketStorage(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage) ServiceProperties(org.springframework.security.cas.ServiceProperties) Test(org.junit.Test)

Example 3 with ServiceProperties

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

the class CasAuthenticationProviderTests method authenticateAllAuthenticationIsSuccessful.

@Test
public void authenticateAllAuthenticationIsSuccessful() 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);
    verify(validator).validate(ticket, serviceProperties.getService());
    serviceProperties.setAuthenticateAllArtifacts(true);
    result = cap.authenticate(token);
    verify(validator, times(2)).validate(ticket, serviceProperties.getService());
    token.setDetails(details);
    result = cap.authenticate(token);
    verify(validator).validate(ticket, serviceUrl);
    serviceProperties.setAuthenticateAllArtifacts(false);
    serviceProperties.setService(null);
    cap.setServiceProperties(serviceProperties);
    cap.afterPropertiesSet();
    result = cap.authenticate(token);
    verify(validator, times(2)).validate(ticket, serviceUrl);
    token.setDetails(new WebAuthenticationDetails(new MockHttpServletRequest()));
    try {
        cap.authenticate(token);
        fail("Expected Exception");
    } catch (IllegalStateException success) {
    }
    cap.setServiceProperties(null);
    cap.afterPropertiesSet();
    try {
        cap.authenticate(token);
        fail("Expected Exception");
    } catch (IllegalStateException success) {
    }
}
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) WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Example 4 with ServiceProperties

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

the class ServicePropertiesTests method detectsMissingService.

// ~ Methods
// ========================================================================================================
@Test(expected = IllegalArgumentException.class)
public void detectsMissingService() throws Exception {
    ServiceProperties sp = new ServiceProperties();
    sp.afterPropertiesSet();
}
Also used : ServiceProperties(org.springframework.security.cas.ServiceProperties) SamlServiceProperties(org.springframework.security.cas.SamlServiceProperties) Test(org.junit.Test)

Example 5 with ServiceProperties

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

the class ServicePropertiesTests method testGettersSetters.

@Test
public void testGettersSetters() throws Exception {
    ServiceProperties[] sps = { new ServiceProperties(), new SamlServiceProperties() };
    for (ServiceProperties sp : sps) {
        sp.setSendRenew(false);
        assertThat(sp.isSendRenew()).isFalse();
        sp.setSendRenew(true);
        assertThat(sp.isSendRenew()).isTrue();
        sp.setArtifactParameter("notticket");
        assertThat(sp.getArtifactParameter()).isEqualTo("notticket");
        sp.setServiceParameter("notservice");
        assertThat(sp.getServiceParameter()).isEqualTo("notservice");
        sp.setService("https://mycompany.com/service");
        assertThat(sp.getService()).isEqualTo("https://mycompany.com/service");
        sp.afterPropertiesSet();
    }
}
Also used : SamlServiceProperties(org.springframework.security.cas.SamlServiceProperties) ServiceProperties(org.springframework.security.cas.ServiceProperties) SamlServiceProperties(org.springframework.security.cas.SamlServiceProperties) Test(org.junit.Test)

Aggregations

ServiceProperties (org.springframework.security.cas.ServiceProperties)16 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 Bean (org.springframework.context.annotation.Bean)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