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