use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateInitialAuthenticationAction method convertToUsernamePasswordCredential.
private static void convertToUsernamePasswordCredential(final RequestContext context, final UsernamePasswordCredential up) throws Exception {
if (up instanceof SurrogateUsernamePasswordCredential) {
val sc = new UsernamePasswordCredential();
BeanUtils.copyProperties(sc, up);
WebUtils.putCredential(context, sc);
}
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateInitialAuthenticationAction method convertToSurrogateCredential.
private void convertToSurrogateCredential(final RequestContext context, final UsernamePasswordCredential up) {
val tUsername = up.getUsername();
val surrogateUsername = tUsername.substring(0, tUsername.indexOf(this.separator));
val realUsername = tUsername.substring(tUsername.indexOf(this.separator) + this.separator.length());
LOGGER.debug("Converting to surrogate credential for username [{}], surrogate username [{}]", realUsername, surrogateUsername);
if (StringUtils.isBlank(surrogateUsername)) {
up.setUsername(realUsername);
WebUtils.putSurrogateAuthenticationRequest(context, Boolean.TRUE);
WebUtils.putCredential(context, up);
LOGGER.debug("No surrogate username is defined; Signal webflow to request for surrogate credentials");
return;
}
val sc = new SurrogateUsernamePasswordCredential();
sc.setUsername(realUsername);
sc.setSurrogateUsername(surrogateUsername);
sc.setPassword(up.getPassword());
if (up instanceof RememberMeCredential) {
sc.setRememberMe(((RememberMeCredential) up).isRememberMe());
}
WebUtils.putSurrogateAuthenticationRequest(context, Boolean.FALSE);
LOGGER.debug("Converted credential to surrogate for username [{}] and assigned it to webflow", realUsername);
WebUtils.putCredential(context, sc);
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateAuthenticationRestHttpRequestCredentialFactory method extractCredential.
/**
* Extract credential surrogate username password.
*
* @param request the request
* @param credentials the credentials
* @return the surrogate username password credential
* @throws Exception the exception
*/
protected SurrogateUsernamePasswordCredential extractCredential(final HttpServletRequest request, final List<Credential> credentials) throws Exception {
val sc = new SurrogateUsernamePasswordCredential();
val credential = UsernamePasswordCredential.class.cast(credentials.get(0));
BeanUtils.copyProperties(sc, credential);
val surrogatePrincipal = request.getHeader(REQUEST_HEADER_SURROGATE_PRINCIPAL);
if (StringUtils.isNotBlank(surrogatePrincipal)) {
LOGGER.debug("Request surrogate principal [{}]", surrogatePrincipal);
sc.setSurrogateUsername(surrogatePrincipal);
return sc;
}
val username = credential.getUsername();
if (username.contains(properties.getSeparator())) {
val surrogateUsername = username.substring(0, username.indexOf(properties.getSeparator()));
val realUsername = username.substring(username.indexOf(properties.getSeparator()) + properties.getSeparator().length());
sc.setUsername(realUsername);
sc.setSurrogateUsername(surrogateUsername);
sc.setPassword(credential.getPassword());
return sc;
}
return null;
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential 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.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateAuthenticationRestHttpRequestCredentialFactoryTests method verifyOperationByHeader.
@Test
public void verifyOperationByHeader() {
val request = new MockHttpServletRequest();
val requestBody = new LinkedMultiValueMap<String, String>();
request.addHeader(SurrogateAuthenticationRestHttpRequestCredentialFactory.REQUEST_HEADER_SURROGATE_PRINCIPAL, "surrogate");
requestBody.add("username", "test");
requestBody.add("password", "password");
val service = new SimpleSurrogateAuthenticationService(Map.of("test", List.of("surrogate")), mock(ServicesManager.class));
val factory = new SurrogateAuthenticationRestHttpRequestCredentialFactory(service, casProperties.getAuthn().getSurrogate());
assertTrue(factory.getOrder() > 0);
val results = factory.fromRequest(request, requestBody);
assertFalse(results.isEmpty());
val credential = (SurrogateUsernamePasswordCredential) results.get(0);
assertNotNull(credential);
assertEquals("surrogate", credential.getSurrogateUsername());
assertEquals("test", credential.getUsername());
}
Aggregations