Search in sources :

Example 41 with Assertion

use of org.jasig.cas.client.validation.Assertion in project uhgroupings by uhawaii-system-its-ti-iam.

the class UserDetailsServiceTest method testAdminUsers.

// Rebase. Test admin users for code coverage purposes.
// Related to ticket-500, used hardcoded values that were deleted.
@Ignore
@Test
public void testAdminUsers() {
    Map<String, Object> map = new HashMap<>();
    map.put("uid", "duckart");
    map.put("uhUuid", "89999999");
    AttributePrincipal principal = new AttributePrincipalImpl("duckart", map);
    Assertion assertion = new AssertionImpl(principal);
    CasUserDetailsServiceImplj userDetailsService = new CasUserDetailsServiceImplj(userBuilder);
    User user = (User) userDetailsService.loadUserDetails(assertion);
    // Basics.
    assertThat(user.getUsername(), is("duckart"));
    assertThat(user.getUid(), is("duckart"));
    assertThat(user.getUhUuid(), is("89999999"));
    // Granted Authorities.
    assertTrue(user.getAuthorities().size() > 0);
    assertTrue(user.hasRole(Role.ANONYMOUS));
    assertTrue(user.hasRole(Role.UH));
    assertTrue(user.hasRole(Role.EMPLOYEE));
    assertTrue(user.hasRole(Role.ADMIN));
    // Check a made-up junky role name.
    map = new HashMap<>();
    map.put("uid", "someuser");
    map.put("uhUuid", "10000001");
    principal = new AttributePrincipalImpl("someuser", map);
    assertion = new AssertionImpl(principal);
    user = (User) userDetailsService.loadUserDetails(assertion);
    assertThat(user.getUsername(), is("someuser"));
    assertThat(user.getUid(), is("someuser"));
    assertThat(user.getUhUuid(), is("10000001"));
    assertTrue(user.getAuthorities().size() > 0);
    assertTrue(user.hasRole(Role.ANONYMOUS));
    assertTrue(user.hasRole(Role.UH));
    assertTrue(user.hasRole(Role.EMPLOYEE));
    assertTrue(user.hasRole(Role.ADMIN));
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) HashMap(java.util.HashMap) Assertion(org.jasig.cas.client.validation.Assertion) AttributePrincipal(org.jasig.cas.client.authentication.AttributePrincipal) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Assertion (org.jasig.cas.client.validation.Assertion)41 AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)14 Test (org.junit.Test)13 AttributePrincipal (org.jasig.cas.client.authentication.AttributePrincipal)10 HashMap (java.util.HashMap)5 TicketValidationException (org.jasig.cas.client.validation.TicketValidationException)5 MessageContext (org.opensaml.messaging.context.MessageContext)5 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)5 ZonedDateTime (java.time.ZonedDateTime)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)3 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)3 LinkedHashMap (java.util.LinkedHashMap)2 HttpSession (javax.servlet.http.HttpSession)2 SneakyThrows (lombok.SneakyThrows)2 Authentication (org.apereo.cas.authentication.Authentication)2 AttributePrincipalImpl (org.jasig.cas.client.authentication.AttributePrincipalImpl)2 Cas30ServiceTicketValidator (org.jasig.cas.client.validation.Cas30ServiceTicketValidator)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2