Search in sources :

Example 11 with AssertionImpl

use of org.jasig.cas.client.validation.AssertionImpl in project spring-security by spring-projects.

the class CasAuthenticationTokenTests method testConstructorRejectsNulls.

@Test
public void testConstructorRejectsNulls() {
    final Assertion assertion = new AssertionImpl("test");
    try {
        new CasAuthenticationToken(null, makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        new CasAuthenticationToken("key", null, "Password", ROLES, makeUserDetails(), assertion);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        new CasAuthenticationToken("key", makeUserDetails(), null, ROLES, makeUserDetails(), assertion);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), null);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, null, assertion);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        new CasAuthenticationToken("key", makeUserDetails(), "Password", AuthorityUtils.createAuthorityList("ROLE_1", null), makeUserDetails(), assertion);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Assertion(org.jasig.cas.client.validation.Assertion) Test(org.junit.Test)

Example 12 with AssertionImpl

use of org.jasig.cas.client.validation.AssertionImpl in project spring-security by spring-projects.

the class CasAuthenticationTokenTests method testToString.

@Test
public void testToString() {
    final Assertion assertion = new AssertionImpl("test");
    CasAuthenticationToken token = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    String result = token.toString();
    assertThat(result.lastIndexOf("Credentials (Service/Proxy Ticket):") != -1).isTrue();
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Assertion(org.jasig.cas.client.validation.Assertion) Test(org.junit.Test)

Example 13 with AssertionImpl

use of org.jasig.cas.client.validation.AssertionImpl in project spring-security by spring-projects.

the class CasAuthenticationTokenTests method testGetters.

@Test
public void testGetters() {
    // Build the proxy list returned in the ticket from CAS
    final Assertion assertion = new AssertionImpl("test");
    CasAuthenticationToken token = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    assertThat(token.getKeyHash()).isEqualTo("key".hashCode());
    assertThat(token.getPrincipal()).isEqualTo(makeUserDetails());
    assertThat(token.getCredentials()).isEqualTo("Password");
    assertThat(token.getAuthorities()).contains(new SimpleGrantedAuthority("ROLE_ONE"));
    assertThat(token.getAuthorities()).contains(new SimpleGrantedAuthority("ROLE_TWO"));
    assertThat(token.getAssertion()).isEqualTo(assertion);
    assertThat(token.getUserDetails().getUsername()).isEqualTo(makeUserDetails().getUsername());
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Assertion(org.jasig.cas.client.validation.Assertion) Test(org.junit.Test)

Example 14 with AssertionImpl

use of org.jasig.cas.client.validation.AssertionImpl in project spring-security by spring-projects.

the class CasAuthenticationTokenTests method testEqualsWhenEqual.

@Test
public void testEqualsWhenEqual() {
    final Assertion assertion = new AssertionImpl("test");
    CasAuthenticationToken token1 = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    CasAuthenticationToken token2 = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    assertThat(token2).isEqualTo(token1);
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Assertion(org.jasig.cas.client.validation.Assertion) Test(org.junit.Test)

Example 15 with AssertionImpl

use of org.jasig.cas.client.validation.AssertionImpl in project spring-security by spring-projects.

the class CasAuthenticationTokenTests method testNotEqualsDueToAbstractParentEqualsCheck.

@Test
public void testNotEqualsDueToAbstractParentEqualsCheck() {
    final Assertion assertion = new AssertionImpl("test");
    CasAuthenticationToken token1 = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES, makeUserDetails(), assertion);
    CasAuthenticationToken token2 = new CasAuthenticationToken("key", makeUserDetails("OTHER_NAME"), "Password", ROLES, makeUserDetails(), assertion);
    assertThat(!token1.equals(token2)).isTrue();
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Assertion(org.jasig.cas.client.validation.Assertion) Test(org.junit.Test)

Aggregations

AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)15 Assertion (org.jasig.cas.client.validation.Assertion)12 Test (org.junit.Test)9 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 AttributePrincipalImpl (org.jasig.cas.client.authentication.AttributePrincipalImpl)2 TicketValidator (org.jasig.cas.client.validation.TicketValidator)2 ServiceProperties (org.springframework.security.cas.ServiceProperties)2 CasAuthenticationToken (org.springframework.security.cas.authentication.CasAuthenticationToken)2 ServiceAuthenticationDetails (org.springframework.security.cas.web.authentication.ServiceAuthenticationDetails)2 Authentication (org.springframework.security.core.Authentication)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 User (org.springframework.security.core.userdetails.User)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AttributePrincipal (org.jasig.cas.client.authentication.AttributePrincipal)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 WebAuthenticationDetails (org.springframework.security.web.authentication.WebAuthenticationDetails)1