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);
}
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);
}
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));
}
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);
}
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);
}
Aggregations