use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class PersonDirectoryPrincipalResolverLdaptiveTests method verifyChainedResolver.
@Test
public void verifyChainedResolver() {
final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver(this.attributeRepository);
final ChainingPrincipalResolver chain = new ChainingPrincipalResolver();
chain.setChain(Arrays.asList(resolver, new EchoingPrincipalResolver()));
final Map<String, Object> attributes = new HashMap<>(2);
attributes.put("a1", "v1");
attributes.put("a2", "v2");
final Principal p = chain.resolve(new UsernamePasswordCredential("castest1", "castest1"), CoreAuthenticationTestUtils.getPrincipal("castest1", attributes), new SimpleTestUsernamePasswordAuthenticationHandler());
assertNotNull(p);
assertTrue(p.getAttributes().containsKey("givenName"));
assertTrue(p.getAttributes().containsKey("a1"));
assertTrue(p.getAttributes().containsKey("a2"));
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithSingleton.
@Test
public void verifyEncodeDecodeTGTWithSingleton() {
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);
final CachedData result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableList.
@Test
public void verifyEncodeDecodeTGTWithUnmodifiableList() {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final List<String> values = new ArrayList<>();
values.add(NICKNAME_VALUE);
final Map<String, Object> newAttributes = new HashMap<>();
newAttributes.put(NICKNAME_KEY, new ArrayList<>(values));
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
final CachedData result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTImpl.
@Test
public void verifyEncodeDecodeTGTImpl() {
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", new AccountNotFoundException());
bldr.addSuccess("authn", new DefaultAuthenticationHandlerExecutionResult(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);
ServiceTicket resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
resultStTicket = (ServiceTicket) transcoder.decode(result);
assertEquals(ticket, resultStTicket);
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithSingletonMap.
@Test
public void verifyEncodeDecodeTGTWithSingletonMap() {
final Map<String, Object> newAttributes = Collections.singletonMap(NICKNAME_KEY, 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);
final CachedData result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
Aggregations