use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class LoadSurrogatesListActionTests method verifyAuthenticateNotAuthorized.
@Test
public void verifyAuthenticateNotAuthorized() 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("unknown-user");
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_ERROR, loadSurrogatesListAction.execute(context).getId());
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateInitialAuthenticationActionTests method verifySurrogateCredentialsFound.
@Test
public void verifySurrogateCredentialsFound() {
try {
val context = new MockRequestContext();
val c = new SurrogateUsernamePasswordCredential();
c.setUsername("casuser");
c.setPassword("Mellon");
c.setSurrogateUsername("cassurrogate");
WebUtils.putCredential(context, c);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, authenticationViaFormAction.execute(context).getId());
} catch (final Exception e) {
throw new AssertionError(e);
}
}
use of org.apereo.cas.authentication.SurrogateUsernamePasswordCredential in project cas by apereo.
the class SurrogateInitialAuthenticationActionTests method verifyUsernamePasswordCredentialsBadPasswordAndCancelled.
@Test
public void verifyUsernamePasswordCredentialsBadPasswordAndCancelled() {
try {
val context = new MockRequestContext();
var credential = new UsernamePasswordCredential();
credential.setUsername("cassurrogate+casuser");
credential.setPassword("badpassword");
WebUtils.putCredential(context, credential);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse()));
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, authenticationViaFormAction.execute(context).getId());
assertTrue(WebUtils.getCredential(context) instanceof SurrogateUsernamePasswordCredential);
val sc = WebUtils.getCredential(context, SurrogateUsernamePasswordCredential.class);
sc.setUsername("casuser");
sc.setPassword("Mellon");
WebUtils.putCredential(context, sc);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, authenticationViaFormAction.execute(context).getId());
assertTrue(WebUtils.getCredential(context) instanceof UsernamePasswordCredential);
} catch (final Exception e) {
throw new AssertionError(e);
}
}
Aggregations