Search in sources :

Example 1 with AttributePrincipalImpl

use of org.jasig.cas.client.authentication.AttributePrincipalImpl in project spring-security by spring-projects.

the class CasAuthenticationTokenMixinTests method createCasAuthenticationToken.

private CasAuthenticationToken createCasAuthenticationToken() {
    User principal = new User("admin", "1234", Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER")));
    Collection<? extends GrantedAuthority> authorities = Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"));
    Assertion assertion = new AssertionImpl(new AttributePrincipalImpl("assertName"), START_DATE, END_DATE, START_DATE, Collections.<String, Object>emptyMap());
    return new CasAuthenticationToken(KEY, principal, principal.getPassword(), authorities, new User("admin", "1234", authorities), assertion);
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) CasAuthenticationToken(org.springframework.security.cas.authentication.CasAuthenticationToken) Assertion(org.jasig.cas.client.validation.Assertion) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl)

Example 2 with AttributePrincipalImpl

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

the class AbstractSamlProfileHandlerController method buildCasAssertion.

/**
 * Build  cas assertion.
 *
 * @param authentication      the authentication
 * @param service             the service
 * @param registeredService   the registered service
 * @param attributesToCombine the attributes to combine
 * @return the assertion
 */
protected Assertion buildCasAssertion(final Authentication authentication, final Service service, final RegisteredService registeredService, final Map<String, Object> attributesToCombine) {
    final Map attributes = registeredService.getAttributeReleasePolicy().getAttributes(authentication.getPrincipal(), service, registeredService);
    final AttributePrincipal principal = new AttributePrincipalImpl(authentication.getPrincipal().getId(), attributes);
    final Map authnAttrs = new LinkedHashMap(authentication.getAttributes());
    authnAttrs.putAll(attributesToCombine);
    return new AssertionImpl(principal, DateTimeUtils.dateOf(authentication.getAuthenticationDate()), null, DateTimeUtils.dateOf(authentication.getAuthenticationDate()), authnAttrs);
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) AttributePrincipal(org.jasig.cas.client.authentication.AttributePrincipal) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl) LinkedHashMap(java.util.LinkedHashMap)

Example 3 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 4 with AttributePrincipalImpl

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

the class DefaultRelyingPartyTokenProducerTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    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("CAS");
    registeredService.setWsdlLocation("classpath:wsdl/ws-trust-1.4-service.wsdl");
    servicesManager.save(registeredService);
    val attributes = CoreAuthenticationTestUtils.getAttributes();
    attributes.put(WSFederationClaims.COMMON_NAME.name(), List.of("common-name-wsfed"));
    attributes.put(WSFederationClaims.GIVEN_NAME.getUri(), List.of("common-name-wsfed"));
    attributes.put("my-custom-claim", List.of("custom-claim-value"));
    val principal = new AttributePrincipalImpl("casuser", attributes);
    val assertion = mock(Assertion.class);
    when(assertion.getPrincipal()).thenReturn(principal);
    val securityToken = mock(SecurityToken.class);
    val result = wsFederationRelyingPartyTokenProducer.produce(securityToken, registeredService, WSFederationRequest.of(request), request, assertion);
    assertEquals("<SecurityToken id=\"abcdefgh123456\"/>", result);
}
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 5 with AttributePrincipalImpl

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

the class CasAuthenticationFilterIntegrationTest method testAuthorizeAssertionFailed.

@Test
public void testAuthorizeAssertionFailed() 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, Date.from(ZonedDateTime.now().plusDays(1).toInstant()), null, null, new HashMap<>());
    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);
    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) AttributePrincipalImpl(org.jasig.cas.client.authentication.AttributePrincipalImpl) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

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