Search in sources :

Example 6 with AttributePrincipalImpl

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

the class CasAuthenticationFilterIntegrationTest method testTwoFactorAuthenticationRequiredException.

@Test(expected = TwoFactorAuthenticationRequiredException.class)
public void testTwoFactorAuthenticationRequiredException() throws TicketValidationException {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    IdmIdentityDto idmIdentityDto = new IdmIdentityDto(CAS_USER);
    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))).thenThrow(TwoFactorAuthenticationRequiredException.class);
    casAuthenticationFilter.authorize(TEST_TOKEN, request, response);
}
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 7 with AttributePrincipalImpl

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

the class UserDetailsServiceTest method testEmployees.

// Delete this. Do not need to test for Employees.
// Related to ticket-500, used hardcoded values that were deleted.
@Ignore
@Test
public void testEmployees() {
    Map<String, Object> map = new HashMap<>();
    map.put("uid", "jjcale");
    map.put("uhUuid", "10000004");
    AttributePrincipal principal = new AttributePrincipalImpl("jjcale", map);
    Assertion assertion = new AssertionImpl(principal);
    CasUserDetailsServiceImplj userDetailsService = new CasUserDetailsServiceImplj(userBuilder);
    User user = (User) userDetailsService.loadUserDetails(assertion);
    // Basics.
    assertThat(user.getUsername(), is("jjcale"));
    assertThat(user.getUid(), is("jjcale"));
    assertThat(user.getUhUuid(), is("10000004"));
    // Granted Authorities.
    assertThat(user.getAuthorities().size(), is(3));
    assertTrue(user.hasRole(Role.ANONYMOUS));
    assertTrue(user.hasRole(Role.UH));
    assertTrue(user.hasRole(Role.EMPLOYEE));
    assertFalse(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)

Example 8 with AttributePrincipalImpl

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

the class ECPProfileHandlerController method buildEcpCasAssertion.

/**
     * Build ecp cas assertion assertion.
     *
     * @param authentication    the authentication
     * @param registeredService the registered service
     * @return the assertion
     */
protected Assertion buildEcpCasAssertion(final Authentication authentication, final RegisteredService registeredService) {
    final Map attributes = registeredService.getAttributeReleasePolicy().getAttributes(authentication.getPrincipal(), registeredService);
    final AttributePrincipal principal = new AttributePrincipalImpl(authentication.getPrincipal().getId(), attributes);
    return new AssertionImpl(principal, DateTimeUtils.dateOf(authentication.getAuthenticationDate()), null, DateTimeUtils.dateOf(authentication.getAuthenticationDate()), authentication.getAttributes());
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Map(java.util.Map) AttributePrincipal(org.jasig.cas.client.authentication.AttributePrincipal) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl)

Example 9 with AttributePrincipalImpl

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

the class DefaultRelyingPartyTokenProducerTests method verifyRequestFailsOperation.

@Test
public void verifyRequestFailsOperation() {
    val request = new MockHttpServletRequest();
    val registeredService = new WSFederationRegisteredService();
    registeredService.setRealm("CAS");
    registeredService.setServiceId("http://app.example.org/wsfed-idp");
    registeredService.setName("WSFED App");
    registeredService.setId(100);
    registeredService.setAppliesTo("RequestFailed");
    registeredService.setWsdlLocation("classpath:wsdl/ws-trust-1.4-service.wsdl");
    servicesManager.save(registeredService);
    val principal = new AttributePrincipalImpl("casuser", CoreAuthenticationTestUtils.getAttributes());
    val assertion = mock(Assertion.class);
    when(assertion.getPrincipal()).thenReturn(principal);
    val securityToken = mock(SecurityToken.class);
    assertThrows(IllegalArgumentException.class, () -> wsFederationRelyingPartyTokenProducer.produce(securityToken, registeredService, WSFederationRequest.of(request), request, assertion));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl) Test(org.junit.jupiter.api.Test)

Example 10 with AttributePrincipalImpl

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

the class DefaultRelyingPartyTokenProducerTests method verifyFailsOperation.

@Test
public void verifyFailsOperation() {
    val request = new MockHttpServletRequest();
    val registeredService = new WSFederationRegisteredService();
    registeredService.setRealm("CAS");
    registeredService.setServiceId("http://app.example.org/wsfed-idp");
    registeredService.setName("WSFED App");
    registeredService.setId(100);
    registeredService.setAppliesTo("FatalError");
    registeredService.setWsdlLocation("classpath:wsdl/ws-trust-1.4-service.wsdl");
    servicesManager.save(registeredService);
    val principal = new AttributePrincipalImpl("casuser", CoreAuthenticationTestUtils.getAttributes());
    val assertion = mock(Assertion.class);
    when(assertion.getPrincipal()).thenReturn(principal);
    val securityToken = mock(SecurityToken.class);
    assertThrows(SoapFault.class, () -> wsFederationRelyingPartyTokenProducer.produce(securityToken, registeredService, WSFederationRequest.of(request), request, assertion));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl) Test(org.junit.jupiter.api.Test)

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