use of org.apereo.cas.authentication.BasicCredentialMetaData 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;
}
use of org.apereo.cas.authentication.BasicCredentialMetaData in project cas by apereo.
the class OpenIdCredentialsAuthenticationHandler method authenticate.
@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException {
final OpenIdCredential c = (OpenIdCredential) credential;
final TicketGrantingTicket t = this.ticketRegistry.getTicket(c.getTicketGrantingTicketId(), TicketGrantingTicket.class);
if (t == null || t.isExpired()) {
throw new FailedLoginException("TGT is null or expired.");
}
final Principal principal = t.getAuthentication().getPrincipal();
if (!principal.getId().equals(c.getUsername())) {
throw new FailedLoginException("Principal ID mismatch");
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(c), principal);
}
use of org.apereo.cas.authentication.BasicCredentialMetaData 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));
}
Aggregations