Search in sources :

Example 1 with AcceptUsersAuthenticationHandler

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

the class CasCoreAuthenticationHandlersConfiguration method acceptUsersAuthenticationHandler.

@RefreshScope
@Bean
public AuthenticationHandler acceptUsersAuthenticationHandler() {
    final AcceptAuthenticationProperties acceptAuthenticationProperties = casProperties.getAuthn().getAccept();
    final HashMap<String, String> users = new HashMap<>();
    final AcceptUsersAuthenticationHandler h = new AcceptUsersAuthenticationHandler(acceptAuthenticationProperties.getName(), servicesManager, acceptUsersPrincipalFactory(), null, users);
    h.setUsers(getParsedUsers());
    h.setPasswordEncoder(Beans.newPasswordEncoder(acceptAuthenticationProperties.getPasswordEncoder()));
    if (acceptPasswordPolicyConfiguration != null) {
        h.setPasswordPolicyConfiguration(acceptPasswordPolicyConfiguration);
    }
    h.setPrincipalNameTransformer(Beans.newPrincipalNameTransformer(acceptAuthenticationProperties.getPrincipalTransformation()));
    return h;
}
Also used : HashMap(java.util.HashMap) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) AcceptAuthenticationProperties(org.apereo.cas.configuration.model.support.generic.AcceptAuthenticationProperties) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with AcceptUsersAuthenticationHandler

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

the class KryoTranscoderTests method verifyEncodeDecodeTGTImpl.

@Test
public void verifyEncodeDecodeTGTImpl() throws Exception {
    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    final AuthenticationBuilder bldr = new DefaultAuthenticationBuilder(new DefaultPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
    bldr.setAttributes(new HashMap<>(this.principalAttributes));
    bldr.setAuthenticationDate(ZonedDateTime.now());
    bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
    bldr.addFailure("error", AccountNotFoundException.class);
    bldr.addSuccess("authn", new DefaultHandlerResult(new AcceptUsersAuthenticationHandler(""), new BasicCredentialMetaData(userPassCredential)));
    final TicketGrantingTicket expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, bldr.build(), new NeverExpiresExpirationPolicy());
    final ServiceTicket ticket = expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
    CachedData result = transcoder.encode(expectedTGT);
    final TicketGrantingTicket resultTicket = (TicketGrantingTicket) transcoder.decode(result);
    assertEquals(expectedTGT, resultTicket);
    result = transcoder.encode(ticket);
    final ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
    assertEquals(ticket, resultStTicket);
}
Also used : DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) AuthenticationBuilder(org.apereo.cas.authentication.AuthenticationBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) CachedData(net.spy.memcached.CachedData) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData) Test(org.junit.Test)

Example 3 with AcceptUsersAuthenticationHandler

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

the class RegisteredServiceAuthenticationHandlerResolverTests method setUp.

@Before
public void setUp() throws Exception {
    final InMemoryServiceRegistry dao = new InMemoryServiceRegistry();
    final List<RegisteredService> list = new ArrayList<>();
    AbstractRegisteredService svc = RegisteredServiceTestUtils.getRegisteredService("serviceid1");
    svc.setRequiredHandlers(Stream.of("handler1", "handler3").collect(Collectors.toSet()));
    list.add(svc);
    svc = RegisteredServiceTestUtils.getRegisteredService("serviceid2");
    svc.setRequiredHandlers(Collections.emptySet());
    list.add(svc);
    dao.setRegisteredServices(list);
    this.defaultServicesManager = new DefaultServicesManager(dao);
    this.defaultServicesManager.load();
    final AcceptUsersAuthenticationHandler handler1 = new AcceptUsersAuthenticationHandler("handler1");
    final AcceptUsersAuthenticationHandler handler2 = new AcceptUsersAuthenticationHandler("handler2");
    final AcceptUsersAuthenticationHandler handler3 = new AcceptUsersAuthenticationHandler("handler3");
    this.handlers = Stream.of(handler1, handler2, handler3).collect(Collectors.toSet());
}
Also used : ArrayList(java.util.ArrayList) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) Before(org.junit.Before)

Example 4 with AcceptUsersAuthenticationHandler

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

the class CasMultifactorTestAuthenticationEventExecutionPlanConfiguration method configureAuthenticationExecutionPlan.

@Override
public void configureAuthenticationExecutionPlan(final AuthenticationEventExecutionPlan plan) {
    final HashMap<String, String> users = new HashMap<>();
    users.put("alice", "alice");
    users.put("bob", "bob");
    users.put("mallory", "mallory");
    final HashMap<String, String> credentials = new HashMap<>();
    credentials.put("alice", "31415");
    credentials.put("bob", "62831");
    credentials.put("mallory", "14142");
    plan.registerAuthenticationHandler(new AcceptUsersAuthenticationHandler("", null, null, null, users));
    plan.registerAuthenticationHandler(new TestOneTimePasswordAuthenticationHandler(credentials));
}
Also used : HashMap(java.util.HashMap) TestOneTimePasswordAuthenticationHandler(org.apereo.cas.TestOneTimePasswordAuthenticationHandler) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)

Aggregations

AcceptUsersAuthenticationHandler (org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 CachedData (net.spy.memcached.CachedData)1 TestOneTimePasswordAuthenticationHandler (org.apereo.cas.TestOneTimePasswordAuthenticationHandler)1 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)1 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)1 Credential (org.apereo.cas.authentication.Credential)1 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)1 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)1 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)1 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 AcceptAuthenticationProperties (org.apereo.cas.configuration.model.support.generic.AcceptAuthenticationProperties)1 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)1 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)1 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)1