Search in sources :

Example 11 with AttributePrincipalImpl

use of org.jasig.cas.client.authentication.AttributePrincipalImpl in project cas by apereo.

the class InternalTicketValidator method validate.

@Override
@SuppressWarnings("unchecked")
public Assertion validate(final String ticketId, final String serviceId) {
    val service = webApplicationServiceFactory.createService(serviceId);
    val assertion = centralAuthenticationService.validateServiceTicket(ticketId, service);
    val authentication = assertion.getPrimaryAuthentication();
    val principal = authentication.getPrincipal();
    val attrPrincipal = new AttributePrincipalImpl(principal.getId(), (Map) principal.getAttributes());
    val registeredService = servicesManager.findServiceBy(service);
    val authenticationAttributes = authenticationAttributeReleasePolicy.getAuthenticationAttributesForRelease(authentication, assertion, new HashMap<>(0), registeredService);
    return new AssertionImpl(attrPrincipal, (Map) authenticationAttributes);
}
Also used : lombok.val(lombok.val) AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl)

Example 12 with AttributePrincipalImpl

use of org.jasig.cas.client.authentication.AttributePrincipalImpl in project CzechIdMng by bcvsolutions.

the class CasAuthenticationFilterIntegrationTest method testAuthorizeFailedDisabledIdentity.

@Test()
public void testAuthorizeFailedDisabledIdentity() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    AttributePrincipalImpl attributePrincipal = new AttributePrincipalImpl(CAS_USER);
    AssertionImpl assertion = new AssertionImpl(attributePrincipal);
    Mockito.when(casConfiguration.getUrl()).thenReturn(CAS_URL);
    Mockito.when(casConfiguration.getService(request, true)).thenReturn(IDM_URL);
    Mockito.when(casValidationService.validate(TEST_TOKEN, IDM_URL, CAS_URL)).thenReturn(assertion);
    IdmIdentityDto idmIdentityDto = new IdmIdentityDto(CAS_USER);
    idmIdentityDto.setState(IdentityState.DISABLED);
    Mockito.when(identityService.getByUsername(CAS_USER)).thenReturn(idmIdentityDto);
    boolean authorizeResult = casAuthenticationFilter.authorize(TEST_TOKEN, request, response);
    Assert.assertFalse(authorizeResult);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) HttpServletResponse(javax.servlet.http.HttpServletResponse) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 13 with AttributePrincipalImpl

use of org.jasig.cas.client.authentication.AttributePrincipalImpl in project CzechIdMng by bcvsolutions.

the class CasAuthenticationFilterIntegrationTest method testAuthorizeSuccess.

@Test
public void testAuthorizeSuccess() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    IdmIdentityDto idmIdentityDto = new IdmIdentityDto(CAS_USER);
    LoginDto loginDto = new LoginDto(idmIdentityDto);
    AttributePrincipalImpl attributePrincipal = new AttributePrincipalImpl(CAS_USER);
    AssertionImpl assertion = new AssertionImpl(attributePrincipal);
    Mockito.when(casConfiguration.getUrl()).thenReturn(CAS_URL);
    Mockito.when(casConfiguration.getService(request, true)).thenReturn(IDM_URL);
    Mockito.when(casValidationService.validate(TEST_TOKEN, IDM_URL, CAS_URL)).thenReturn(assertion);
    Mockito.when(identityService.getByUsername(CAS_USER)).thenReturn(idmIdentityDto);
    Mockito.when(jwtAuthenticationService.createJwtAuthenticationAndAuthenticate(Mockito.any(LoginDto.class), Mockito.eq(idmIdentityDto), Mockito.eq(CoreModuleDescriptor.MODULE_ID))).thenReturn(loginDto);
    boolean authorizeResult = casAuthenticationFilter.authorize(TEST_TOKEN, request, response);
    Assert.assertTrue(authorizeResult);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) HttpServletResponse(javax.servlet.http.HttpServletResponse) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 14 with AttributePrincipalImpl

use of org.jasig.cas.client.authentication.AttributePrincipalImpl 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

AttributePrincipalImpl (org.jasig.cas.client.authentication.AttributePrincipalImpl)14 AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)11 Test (org.junit.Test)7 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 lombok.val (lombok.val)4 AttributePrincipal (org.jasig.cas.client.authentication.AttributePrincipal)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 Assertion (org.jasig.cas.client.validation.Assertion)3 Test (org.junit.jupiter.api.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Ignore (org.junit.Ignore)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 CasAuthenticationToken (org.springframework.security.cas.authentication.CasAuthenticationToken)1