use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class SurrogateAuthenticationRestHttpRequestCredentialFactoryTests method verifyBasicUsernamePasswordOperationWithoutSurrogatePrincipal.
@Test
public void verifyBasicUsernamePasswordOperationWithoutSurrogatePrincipal() {
val request = new MockHttpServletRequest();
val requestBody = new LinkedMultiValueMap<String, String>();
requestBody.add("username", "test");
requestBody.add("password", "password");
val service = new SimpleSurrogateAuthenticationService(Collections.emptyMap(), mock(ServicesManager.class));
val factory = new SurrogateAuthenticationRestHttpRequestCredentialFactory(service, casProperties.getAuthn().getSurrogate());
val results = factory.fromRequest(request, requestBody);
assertFalse(results.isEmpty());
assertFalse(results.get(0) instanceof SurrogateUsernamePasswordCredential);
assertTrue(results.get(0) instanceof UsernamePasswordCredential);
val credential = (UsernamePasswordCredential) results.get(0);
assertNotNull(credential);
assertEquals("test", credential.getUsername());
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class LoadSurrogatesListAction method loadSurrogates.
private boolean loadSurrogates(final RequestContext requestContext) {
val c = WebUtils.getCredential(requestContext);
if (c instanceof UsernamePasswordCredential) {
val username = c.getId();
LOGGER.debug("Loading eligible accounts for [{}] to proxy", username);
val surrogates = surrogateService.getEligibleAccountsForSurrogateToProxy(username).stream().sorted().distinct().collect(Collectors.toCollection(ArrayList::new));
LOGGER.debug("Surrogate accounts found are [{}]", surrogates);
if (!surrogates.isEmpty()) {
if (!surrogates.contains(username)) {
surrogates.add(0, username);
}
WebUtils.putSurrogateAuthenticationAccounts(requestContext, surrogates);
return true;
}
LOGGER.debug("No surrogate accounts could be located for [{}]", username);
} else {
LOGGER.debug("Current credential in the webflow is not one of [{}]", UsernamePasswordCredential.class.getName());
}
return false;
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class JcifsSpnegoAuthenticationHandlerTests method verifySupports.
@Test
public void verifySupports() {
val authenticationHandler = new JcifsSpnegoAuthenticationHandler(StringUtils.EMPTY, null, null, CollectionUtils.wrapList(new MockJcifsAuthentication()), true, true, null);
assertFalse(authenticationHandler.supports((SpnegoCredential) null));
assertTrue(authenticationHandler.supports(new SpnegoCredential(new byte[] { 0, 1, 2 })));
assertFalse(authenticationHandler.supports(new UsernamePasswordCredential()));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class CasSimpleMultifactorAuthenticationHandlerTests method verifyFailsPrincipal.
@Test
public void verifyFailsPrincipal() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
val factory = (CasSimpleMultifactorAuthenticationTicketFactory) defaultTicketFactory.get(CasSimpleMultifactorAuthenticationTicket.class);
val ticket = factory.create(RegisteredServiceTestUtils.getService(), Map.of());
ticketRegistry.addTicket(ticket);
val credential = new CasSimpleMultifactorTokenCredential(ticket.getId());
assertThrows(FailedLoginException.class, () -> casSimpleMultifactorAuthenticationHandler.authenticate(credential));
assertFalse(casSimpleMultifactorAuthenticationHandler.supports(new UsernamePasswordCredential()));
assertFalse(casSimpleMultifactorAuthenticationHandler.supports(UsernamePasswordCredential.class));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class BaseThrottledSubmissionHandlerInterceptorAdapterTests method badCredentials.
private static UsernamePasswordCredential badCredentials(final String username) {
val credentials = new UsernamePasswordCredential();
credentials.setUsername(username);
credentials.setPassword("badpassword");
return credentials;
}
Aggregations