Search in sources :

Example 1 with NullPrincipal

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;
}
Also used : NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) UnresolvedPrincipalException(org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) Principal(org.apereo.cas.authentication.principal.Principal) Audit(org.apereo.inspektr.audit.annotation.Audit) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with NullPrincipal

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);
}
Also used : NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) ServicesManager(org.apereo.cas.services.ServicesManager) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) NullPrincipal(org.apereo.cas.authentication.principal.NullPrincipal) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test)

Aggregations

NullPrincipal (org.apereo.cas.authentication.principal.NullPrincipal)2 Principal (org.apereo.cas.authentication.principal.Principal)2 Counted (com.codahale.metrics.annotation.Counted)1 Metered (com.codahale.metrics.annotation.Metered)1 Timed (com.codahale.metrics.annotation.Timed)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 UnresolvedPrincipalException (org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException)1 ServiceFactory (org.apereo.cas.authentication.principal.ServiceFactory)1 ServicesManager (org.apereo.cas.services.ServicesManager)1 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)1 Audit (org.apereo.inspektr.audit.annotation.Audit)1 Test (org.junit.Test)1