Search in sources :

Example 21 with UsernamePasswordCredential

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

the class X509CredentialFactoryTests method createDefaultCredential.

@Test
public void createDefaultCredential() {
    final MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
    requestBody.add("username", "name");
    requestBody.add("password", "passwd");
    final Credential cred = factory.fromRequestBody(requestBody);
    assertTrue(cred instanceof UsernamePasswordCredential);
}
Also used : X509CertificateCredential(org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 22 with UsernamePasswordCredential

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

the class PrincipalBearingCredentialsAuthenticationHandlerTests method verifySupports.

@Test
public void verifySupports() {
    final PrincipalBearingCredential credentials = new PrincipalBearingCredential(new DefaultPrincipalFactory().createPrincipal("scott"));
    assertTrue(this.handler.supports(credentials));
    assertFalse(this.handler.supports(new UsernamePasswordCredential()));
}
Also used : PrincipalBearingCredential(org.apereo.cas.adaptors.trusted.authentication.principal.PrincipalBearingCredential) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 23 with UsernamePasswordCredential

use of org.apereo.cas.authentication.UsernamePasswordCredential 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 24 with UsernamePasswordCredential

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

the class KryoTranscoderTests method verifyEncodeDecodeTGTWithSingleton.

@Test
public void verifyEncodeDecodeTGTWithSingleton() throws Exception {
    final Map<String, Object> newAttributes = new HashMap<>();
    newAttributes.put(NICKNAME_KEY, Collections.singleton(NICKNAME_VALUE));
    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Test(org.junit.Test)

Example 25 with UsernamePasswordCredential

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

the class KryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableSet.

@Test
public void verifyEncodeDecodeTGTWithUnmodifiableSet() throws Exception {
    final Map<String, Object> newAttributes = new HashMap<>();
    final Set<String> values = new HashSet<>();
    values.add(NICKNAME_VALUE);
    newAttributes.put(NICKNAME_KEY, Collections.unmodifiableSet(values));
    final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)61 Test (org.junit.Test)40 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)14 Credential (org.apereo.cas.authentication.Credential)10 HttpBasedServiceCredential (org.apereo.cas.authentication.HttpBasedServiceCredential)9 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)9 Authentication (org.apereo.cas.authentication.Authentication)7 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)7 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 HashMap (java.util.HashMap)5 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)5 Service (org.apereo.cas.authentication.principal.Service)5 Assertion (org.apereo.cas.validation.Assertion)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 LinkedHashMap (java.util.LinkedHashMap)4 FailedLoginException (javax.security.auth.login.FailedLoginException)4 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)4 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)4 AbstractWebApplicationService (org.apereo.cas.authentication.principal.AbstractWebApplicationService)4