use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateInitialAuthenticationAction method deconvertFromSurrogatePrincipal.
private static void deconvertFromSurrogatePrincipal(final RequestContext context) {
final Credential c = WebUtils.getCredential(context);
if (c instanceof SurrogateUsernamePasswordCredential) {
final SurrogateUsernamePasswordCredential sc = SurrogateUsernamePasswordCredential.class.cast(c);
final UsernamePasswordCredential up = new UsernamePasswordCredential();
up.setUsername(sc.getUsername());
up.setPassword(sc.getPassword());
WebUtils.putCredential(context, up);
}
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateAuthenticationRestHttpRequestCredentialFactoryTests method verifyOperationByCredentialSeparator.
@Test
public void verifyOperationByCredentialSeparator() {
val request = new MockHttpServletRequest();
val requestBody = new LinkedMultiValueMap<String, String>();
requestBody.add("username", "surrogate+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());
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());
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class LoadSurrogatesListAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
try {
if (WebUtils.hasSurrogateAuthenticationRequest(requestContext)) {
WebUtils.removeSurrogateAuthenticationRequest(requestContext);
LOGGER.trace("Attempting to load surrogates...");
if (loadSurrogates(requestContext)) {
return new Event(this, CasWebflowConstants.TRANSITION_ID_SURROGATE_VIEW);
}
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_SKIP_SURROGATE);
}
val currentCredential = WebUtils.getCredential(requestContext);
if (currentCredential instanceof SurrogateUsernamePasswordCredential) {
val authenticationResultBuilder = WebUtils.getAuthenticationResultBuilder(requestContext);
val credential = (SurrogateUsernamePasswordCredential) currentCredential;
val registeredService = WebUtils.getRegisteredService(requestContext);
val result = surrogatePrincipalBuilder.buildSurrogateAuthenticationResult(authenticationResultBuilder, currentCredential, credential.getSurrogateUsername(), registeredService);
result.ifPresent(builder -> WebUtils.putAuthenticationResultBuilder(builder, requestContext));
}
return success();
} catch (final Exception e) {
requestContext.getMessageContext().addMessage(new MessageBuilder().error().source("surrogate").code("screen.surrogates.account.selection.error").defaultText("Unable to accept or authorize selection").build());
LoggingUtils.error(LOGGER, e);
return error(e);
}
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class LoadSurrogatesListActionTests method verifySkipAuthenticate.
@Test
public void verifySkipAuthenticate() throws Exception {
val context = new MockRequestContext();
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
WebUtils.putSurrogateAuthenticationRequest(context, Boolean.TRUE);
val attributes = new LinkedHashMap<String, List<Object>>();
attributes.put(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_ENABLED, List.of(true));
attributes.putAll(CoreAuthenticationTestUtils.getAttributeRepository().getBackingMap());
val p = CoreAuthenticationTestUtils.getPrincipal("someuser", attributes);
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(p), context);
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
val creds = new SurrogateUsernamePasswordCredential();
creds.setPassword("Mellon");
creds.setUsername("someuser");
creds.setSurrogateUsername("others");
WebUtils.putCredential(context, creds);
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(CoreAuthenticationTestUtils.getAuthentication("casuser")));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SKIP_SURROGATE, loadSurrogatesListAction.execute(context).getId());
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class LoadSurrogatesListActionTests method verifyAuthenticate.
@Test
public void verifyAuthenticate() throws Exception {
val context = new MockRequestContext();
WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
val attributes = new LinkedHashMap<String, List<Object>>();
attributes.put(SurrogateAuthenticationService.AUTHENTICATION_ATTR_SURROGATE_ENABLED, List.of(true));
attributes.putAll(CoreAuthenticationTestUtils.getAttributeRepository().getBackingMap());
val p = CoreAuthenticationTestUtils.getPrincipal("casuser", attributes);
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(p), context);
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
val creds = new SurrogateUsernamePasswordCredential();
creds.setPassword("Mellon");
creds.setUsername("casuser");
creds.setSurrogateUsername("cassurrogate");
WebUtils.putCredential(context, creds);
val builder = mock(AuthenticationResultBuilder.class);
when(builder.getInitialAuthentication()).thenReturn(Optional.of(CoreAuthenticationTestUtils.getAuthentication("casuser")));
when(builder.collect(any(Authentication.class))).thenReturn(builder);
WebUtils.putAuthenticationResultBuilder(builder, context);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, loadSurrogatesListAction.execute(context).getId());
}
Aggregations