Search in sources :

Example 91 with UsernamePasswordCredential

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

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableList.

@Test
public void verifyEncodeDecodeTGTWithUnmodifiableList() {
    val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    val values = new ArrayList<String>();
    values.add(NICKNAME_VALUE);
    val newAttributes = new HashMap<String, List<Object>>();
    newAttributes.put(NICKNAME_KEY, new ArrayList<>(values));
    val expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    val result = transcoder.encode(expectedTGT);
    assertEquals(expectedTGT, transcoder.decode(result));
    assertEquals(expectedTGT, transcoder.decode(result));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 92 with UsernamePasswordCredential

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

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTImpl.

@Test
public void verifyEncodeDecodeTGTImpl() {
    val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    val bldr = new DefaultAuthenticationBuilder(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("user", new HashMap<>(this.principalAttributes)));
    bldr.setAttributes(new HashMap<>(this.principalAttributes));
    bldr.setAuthenticationDate(ZonedDateTime.now(ZoneId.systemDefault()));
    bldr.addCredential(new BasicCredentialMetaData(userPassCredential));
    bldr.addFailure("error", new AccountNotFoundException());
    bldr.addSuccess("authn", new DefaultAuthenticationHandlerExecutionResult(new AcceptUsersAuthenticationHandler(StringUtils.EMPTY), new BasicCredentialMetaData(userPassCredential)));
    val authentication = bldr.build();
    val expectedTGT = new TicketGrantingTicketImpl(TGT_ID, RegisteredServiceTestUtils.getService(), null, authentication, NeverExpiresExpirationPolicy.INSTANCE);
    val serviceTicket = (ProxyGrantingTicketIssuerTicket) expectedTGT.grantServiceTicket(ST_ID, RegisteredServiceTestUtils.getService(), NeverExpiresExpirationPolicy.INSTANCE, false, true);
    var encoded = transcoder.encode(expectedTGT);
    var decoded = transcoder.decode(encoded);
    assertEquals(expectedTGT, decoded);
    encoded = transcoder.encode(serviceTicket);
    decoded = transcoder.decode(encoded);
    assertEquals(serviceTicket, decoded);
    decoded = transcoder.decode(encoded);
    assertEquals(serviceTicket, decoded);
    val pgt = serviceTicket.grantProxyGrantingTicket(PGT_ID, authentication, new HardTimeoutExpirationPolicy(100));
    encoded = transcoder.encode(pgt);
    decoded = transcoder.decode(encoded);
    assertEquals(pgt, decoded);
    val pt = pgt.grantProxyTicket(PT_ID, RegisteredServiceTestUtils.getService(), new HardTimeoutExpirationPolicy(100), true);
    encoded = transcoder.encode(pt);
    decoded = transcoder.decode(encoded);
    assertEquals(pt, decoded);
}
Also used : lombok.val(lombok.val) DefaultAuthenticationBuilder(org.apereo.cas.authentication.DefaultAuthenticationBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HardTimeoutExpirationPolicy(org.apereo.cas.ticket.expiration.HardTimeoutExpirationPolicy) DefaultAuthenticationHandlerExecutionResult(org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult) ProxyGrantingTicketIssuerTicket(org.apereo.cas.ticket.ProxyGrantingTicketIssuerTicket) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) AcceptUsersAuthenticationHandler(org.apereo.cas.authentication.AcceptUsersAuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) BasicCredentialMetaData(org.apereo.cas.authentication.metadata.BasicCredentialMetaData) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 93 with UsernamePasswordCredential

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

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithSingleton.

@Test
public void verifyEncodeDecodeTGTWithSingleton() {
    val newAttributes = new HashMap<String, List<Object>>();
    newAttributes.put(NICKNAME_KEY, List.of(NICKNAME_VALUE));
    val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    val expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    val result = transcoder.encode(expectedTGT);
    assertEquals(expectedTGT, transcoder.decode(result));
    assertEquals(expectedTGT, transcoder.decode(result));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 94 with UsernamePasswordCredential

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

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithSingletonMap.

@Test
public void verifyEncodeDecodeTGTWithSingletonMap() {
    val newAttributes = Collections.<String, List<Object>>singletonMap(NICKNAME_KEY, List.of(NICKNAME_VALUE));
    val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    val expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    val result = transcoder.encode(expectedTGT);
    assertEquals(expectedTGT, transcoder.decode(result));
    assertEquals(expectedTGT, transcoder.decode(result));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) List(java.util.List) ArrayList(java.util.ArrayList) ToString(lombok.ToString) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 95 with UsernamePasswordCredential

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

the class ActiveDirectoryLdapAuthenticationHandlerPasswordPolicyTests method verifyAuthenticateWarnings.

@Test
public void verifyAuthenticateWarnings() {
    assertNotEquals(ldapAuthenticationHandlers.size(), 0);
    ldapAuthenticationHandlers.toList().forEach(Unchecked.consumer(h -> {
        val credential = new UsernamePasswordCredential(getUsername(), getSuccessPassword());
        val result = h.authenticate(credential);
        assertTrue(result.getWarnings() != null && !result.getWarnings().isEmpty());
        assertTrue(result.getWarnings().stream().anyMatch(messageDescriptor -> messageDescriptor.getCode().equals("password.expiration.warning")));
        assertNotNull(result.getPrincipal());
        assertEquals(credential.getUsername(), result.getPrincipal().getId());
        val attributes = result.getPrincipal().getAttributes();
        Arrays.stream(getPrincipalAttributes()).forEach(s -> assertTrue(attributes.containsKey(s)));
    }));
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Unchecked(org.jooq.lambda.Unchecked) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) EnabledIfPortOpen(org.apereo.cas.util.junit.EnabledIfPortOpen) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) lombok.val(lombok.val) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) TestPropertySource(org.springframework.test.context.TestPropertySource) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)111 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)111 Test (org.junit.jupiter.api.Test)74 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)12 HashMap (java.util.HashMap)8 Map (java.util.Map)8 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)8 LinkedHashMap (java.util.LinkedHashMap)7 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 Executable (org.junit.jupiter.api.function.Executable)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)6 MockRequestContext (org.springframework.webflow.test.MockRequestContext)6 ArrayList (java.util.ArrayList)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 MockServletContext (org.springframework.mock.web.MockServletContext)5 FailedLoginException (javax.security.auth.login.FailedLoginException)4 SurrogateUsernamePasswordCredential (org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)4