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));
}
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);
}
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));
}
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));
}
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)));
}));
}
Aggregations