Search in sources :

Example 6 with CredentialMetaData

use of org.apereo.cas.authentication.CredentialMetaData in project cas by apereo.

the class PrincipalBearingCredentialsTests method verifySerializeAPrincipalBearingCredentialToJson.

@Test
public void verifySerializeAPrincipalBearingCredentialToJson() throws IOException {
    MAPPER.writeValue(JSON_FILE, principalBearingCredentials);
    final CredentialMetaData credentialRead = MAPPER.readValue(JSON_FILE, PrincipalBearingCredential.class);
    assertEquals(principalBearingCredentials, credentialRead);
}
Also used : CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) Test(org.junit.Test)

Example 7 with CredentialMetaData

use of org.apereo.cas.authentication.CredentialMetaData in project cas by apereo.

the class OAuth20AccessTokenControllerTests method getAuthentication.

private static Authentication getAuthentication(final Principal principal) {
    final CredentialMetaData metadata = new BasicCredentialMetaData(new BasicIdentifiableCredential(principal.getId()));
    final HandlerResult handlerResult = new DefaultHandlerResult(principal.getClass().getCanonicalName(), metadata, principal, new ArrayList<>());
    return DefaultAuthenticationBuilder.newInstance().setPrincipal(principal).setAuthenticationDate(ZonedDateTime.now()).addCredential(metadata).addSuccess(principal.getClass().getCanonicalName(), handlerResult).build();
}
Also used : BasicIdentifiableCredential(org.apereo.cas.authentication.BasicIdentifiableCredential) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) HandlerResult(org.apereo.cas.authentication.HandlerResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 8 with CredentialMetaData

use of org.apereo.cas.authentication.CredentialMetaData in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method newBuilder.

private AuthenticationBuilder newBuilder(final Credential credential) {
    final CredentialMetaData meta = new BasicCredentialMetaData(new UsernamePasswordCredential());
    final AuthenticationHandler handler = new SimpleTestUsernamePasswordAuthenticationHandler();
    final AuthenticationBuilder builder = new DefaultAuthenticationBuilder(CoreAuthenticationTestUtils.getPrincipal()).addCredential(meta).addSuccess("test", new DefaultHandlerResult(handler, meta));
    if (this.p.supports(credential)) {
        this.p.populateAttributes(builder, credential);
    }
    return builder;
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) SimpleTestUsernamePasswordAuthenticationHandler(org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.RememberMeUsernamePasswordCredential) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 9 with CredentialMetaData

use of org.apereo.cas.authentication.CredentialMetaData in project cas by apereo.

the class DigestCredentialTests method verifySerializeADigestCredentialToJson.

@Test
public void verifySerializeADigestCredentialToJson() throws IOException {
    final DigestCredential credentialMetaDataWritten = new DigestCredential("uid", "realm", "hash");
    MAPPER.writeValue(JSON_FILE, credentialMetaDataWritten);
    final CredentialMetaData credentialMetaDataRead = MAPPER.readValue(JSON_FILE, DigestCredential.class);
    assertEquals(credentialMetaDataWritten, credentialMetaDataRead);
}
Also used : CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) Test(org.junit.Test)

Example 10 with CredentialMetaData

use of org.apereo.cas.authentication.CredentialMetaData in project cas by apereo.

the class CentralAuthenticationServiceImplWithMockitoTests method prepareNewCAS.

@Before
public void prepareNewCAS() throws Exception {
    this.authentication = mock(Authentication.class);
    when(this.authentication.getAuthenticationDate()).thenReturn(ZonedDateTime.now(ZoneOffset.UTC));
    final CredentialMetaData metadata = new BasicCredentialMetaData(RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("principal"));
    final Map<String, HandlerResult> successes = new HashMap<>();
    successes.put("handler1", new DefaultHandlerResult(mock(AuthenticationHandler.class), metadata));
    when(this.authentication.getCredentials()).thenReturn(Arrays.asList(metadata));
    when(this.authentication.getSuccesses()).thenReturn(successes);
    when(this.authentication.getPrincipal()).thenReturn(new DefaultPrincipalFactory().createPrincipal(PRINCIPAL));
    final Service service1 = getService(SVC1_ID);
    final ServiceTicket stMock = createMockServiceTicket(ST_ID, service1);
    final TicketGrantingTicket tgtRootMock = createRootTicketGrantingTicket();
    final TicketGrantingTicket tgtMock = createMockTicketGrantingTicket(TGT_ID, stMock, false, tgtRootMock, new ArrayList<>());
    when(tgtMock.getProxiedBy()).thenReturn(getService("proxiedBy"));
    final List<Authentication> authnListMock = mock(List.class);
    //Size is required to be 2, so that we can simulate proxying capabilities
    when(authnListMock.size()).thenReturn(2);
    when(authnListMock.get(anyInt())).thenReturn(this.authentication);
    when(tgtMock.getChainedAuthentications()).thenReturn(authnListMock);
    when(stMock.getGrantingTicket()).thenReturn(tgtMock);
    final Service service2 = getService(SVC2_ID);
    final ServiceTicket stMock2 = createMockServiceTicket(ST2_ID, service2);
    final TicketGrantingTicket tgtMock2 = createMockTicketGrantingTicket(TGT2_ID, stMock2, false, tgtRootMock, authnListMock);
    //Mock TicketRegistry
    mockTicketRegistry(stMock, tgtMock, stMock2, tgtMock2);
    //Mock ServicesManager
    final ServicesManager smMock = getServicesManager(service1, service2);
    final DefaultTicketFactory factory = new DefaultTicketFactory(new DefaultProxyGrantingTicketFactory(null, null, null), new DefaultTicketGrantingTicketFactory(null, null, null), new DefaultServiceTicketFactory(null, Collections.emptyMap(), false, null), new DefaultProxyTicketFactory(null, Collections.emptyMap(), null, true));
    final AuthenticationServiceSelectionPlan authenticationRequestServiceSelectionStrategies = new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy());
    this.cas = new DefaultCentralAuthenticationService(ticketRegMock, factory, smMock, mock(LogoutManager.class), authenticationRequestServiceSelectionStrategies, new AcceptAnyAuthenticationPolicyFactory(), new DefaultPrincipalFactory(), null);
    this.cas.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));
}
Also used : HashMap(java.util.HashMap) DefaultProxyTicketFactory(org.apereo.cas.ticket.factory.DefaultProxyTicketFactory) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) DefaultProxyGrantingTicketFactory(org.apereo.cas.ticket.factory.DefaultProxyGrantingTicketFactory) AcceptAnyAuthenticationPolicyFactory(org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory) DefaultAuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy) DefaultServiceTicketFactory(org.apereo.cas.ticket.factory.DefaultServiceTicketFactory) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) DefaultTicketGrantingTicketFactory(org.apereo.cas.ticket.factory.DefaultTicketGrantingTicketFactory) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) HandlerResult(org.apereo.cas.authentication.HandlerResult) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) DefaultTicketFactory(org.apereo.cas.ticket.factory.DefaultTicketFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Authentication(org.apereo.cas.authentication.Authentication) CredentialMetaData(org.apereo.cas.authentication.CredentialMetaData) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Before(org.junit.Before)

Aggregations

CredentialMetaData (org.apereo.cas.authentication.CredentialMetaData)10 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)6 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)6 HandlerResult (org.apereo.cas.authentication.HandlerResult)4 Test (org.junit.Test)4 BasicIdentifiableCredential (org.apereo.cas.authentication.BasicIdentifiableCredential)3 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)3 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)2 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)2 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)2 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)2 X509Certificate (java.security.cert.X509Certificate)1 HashMap (java.util.HashMap)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)1 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)1 DefaultAuthenticationServiceSelectionStrategy (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionStrategy)1 RememberMeUsernamePasswordCredential (org.apereo.cas.authentication.RememberMeUsernamePasswordCredential)1 AcceptAnyAuthenticationPolicyFactory (org.apereo.cas.authentication.policy.AcceptAnyAuthenticationPolicyFactory)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1