use of org.apereo.cas.authentication.principal.NullPrincipal in project cas by apereo.
the class AbstractAuthenticationManager method authenticate.
@Override
@Audit(action = "AUTHENTICATION", actionResolverName = "AUTHENTICATION_RESOLVER", resourceResolverName = "AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name = "AUTHENTICATE_TIMER")
@Metered(name = "AUTHENTICATE_METER")
@Counted(name = "AUTHENTICATE_COUNT", monotonic = true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
AuthenticationCredentialsLocalBinder.bindCurrent(transaction.getCredentials());
final AuthenticationBuilder builder = authenticateInternal(transaction);
authenticationEventExecutionPlan.getAuthenticationPostProcessors().forEach(p -> {
LOGGER.info("Invoking authentication post processor [{}]", p);
p.process(transaction, builder);
});
final Authentication authentication = builder.build();
final Principal principal = authentication.getPrincipal();
if (principal instanceof NullPrincipal) {
throw new UnresolvedPrincipalException(authentication);
}
addAuthenticationMethodAttribute(builder, authentication);
LOGGER.info("Authenticated principal [{}] with attributes [{}] via credentials [{}].", principal.getId(), principal.getAttributes(), transaction.getCredentials());
populateAuthenticationMetadataAttributes(builder, transaction.getCredentials());
final Authentication a = builder.build();
AuthenticationCredentialsLocalBinder.bindCurrent(a);
return a;
}
use of org.apereo.cas.authentication.principal.NullPrincipal in project cas by apereo.
the class GenericSuccessViewActionTests method verifyPrincipalCanNotBeDetermined.
@Test
public void verifyPrincipalCanNotBeDetermined() throws InvalidTicketException {
final CentralAuthenticationService cas = mock(CentralAuthenticationService.class);
final ServicesManager mgr = mock(ServicesManager.class);
final ServiceFactory factory = mock(ServiceFactory.class);
when(cas.getTicket(any(String.class), any(Ticket.class.getClass()))).thenThrow(new InvalidTicketException("TGT-1"));
final GenericSuccessViewAction action = new GenericSuccessViewAction(cas, mgr, factory, "");
final Principal p = action.getAuthenticationPrincipal("TGT-1");
assertNotNull(p);
assertTrue(p instanceof NullPrincipal);
}
Aggregations