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