use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class WebUtilsTests method verifyOperation.
@Test
public void verifyOperation() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val flow = new Flow("mockFlow");
val flowSession = new MockFlowSession(flow);
flowSession.setParent(new MockFlowSession(flow));
val mockExecutionContext = new MockFlowExecutionContext(flowSession);
context.setFlowExecutionContext(mockExecutionContext);
WebUtils.putLogoutRedirectUrl(context, URL);
assertNotNull(WebUtils.getLogoutRedirectUrl(context, String.class));
WebUtils.removeLogoutRedirectUrl(context);
assertNull(WebUtils.getLogoutRedirectUrl(context, String.class));
assertNull(WebUtils.getHttpServletRequestUserAgentFromRequestContext(context));
assertNull(WebUtils.getHttpServletRequestUserAgentFromRequestContext(request));
assertNull(WebUtils.getAuthenticationResult(context));
assertNull(WebUtils.getHttpServletRequestGeoLocationFromRequestContext());
assertNull(WebUtils.getAcceptableUsagePolicyTermsFromFlowScope(context, Object.class));
assertFalse(WebUtils.hasSurrogateAuthenticationRequest(context));
assertNotNull(WebUtils.produceUnauthorizedErrorView(new RuntimeException()));
assertNotNull(WebUtils.produceErrorView(new IllegalArgumentException()));
assertNotNull(WebUtils.produceErrorView("error-view", new IllegalArgumentException()));
assertNotNull(WebUtils.getHttpRequestFullUrl(context));
request.setQueryString("param=value");
assertNotNull(WebUtils.getHttpRequestFullUrl(request));
assertFalse(WebUtils.isGraphicalUserAuthenticationEnabled(context));
assertTrue(WebUtils.getDelegatedAuthenticationProviderConfigurations(context).isEmpty());
assertNull(WebUtils.getAvailableAuthenticationHandleNames(context));
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
WebUtils.putYubiKeyMultipleDeviceRegistrationEnabled(context, true);
WebUtils.putInitialHttpRequestPostParameters(context);
WebUtils.putExistingSingleSignOnSessionAvailable(context, true);
WebUtils.putExistingSingleSignOnSessionPrincipal(context, CoreAuthenticationTestUtils.getPrincipal());
WebUtils.putAvailableAuthenticationHandleNames(context, List.of());
WebUtils.putPasswordManagementEnabled(context, true);
WebUtils.putRecaptchaPropertiesFlowScope(context, new GoogleRecaptchaProperties().setEnabled(true));
WebUtils.putLogoutUrls(context, Map.of());
val ac = OneTimeTokenAccount.builder().validationCode(123456).username("casuser").name("Example").build();
WebUtils.putOneTimeTokenAccount(context, ac);
assertNotNull(WebUtils.getOneTimeTokenAccount(context, OneTimeTokenAccount.class));
WebUtils.putOneTimeTokenAccounts(context, List.of(ac));
WebUtils.putWarnCookieIfRequestParameterPresent(null, context);
WebUtils.putTicketGrantingTicketInScopes(context, "ticket-id");
}
});
WebUtils.putCredential(context, new UsernamePasswordCredential("casuser", "password"));
assertThrows(ClassCastException.class, () -> WebUtils.getCredential(context, OneTimeTokenCredential.class));
WebUtils.putTicketGrantingTicketInScopes(context, StringUtils.EMPTY);
WebUtils.putTicketGrantingTicketInScopes(context, (TicketGrantingTicket) null);
WebUtils.putTicketGrantingTicketInScopes(context, (String) null);
assertNull(WebUtils.getTicketGrantingTicket(context));
assertThrows(IllegalArgumentException.class, () -> WebUtils.getPrincipalFromRequestContext(context, null));
request.addParameter(WebUtils.PUBLIC_WORKSTATION_ATTRIBUTE, "true");
WebUtils.putPublicWorkstationToFlowIfRequestParameterPresent(context);
assertTrue(WebUtils.isAuthenticatingAtPublicWorkstation(context));
val ticketRegistrySupport = mock(TicketRegistrySupport.class);
WebUtils.putTicketGrantingTicketInScopes(context, "TGT-XYZ123");
assertNull(WebUtils.getPrincipalFromRequestContext(context, ticketRegistrySupport));
WebUtils.putLogoutPostUrl(context, URL);
assertEquals(URL, WebUtils.getLogoutPostUrl(context));
val data = new HashMap<String, Object>();
data.put("SAMLResponse", "xxx");
WebUtils.putLogoutPostData(context, data);
assertEquals(data, WebUtils.getLogoutPostData(context));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class BasicAuthenticationAction method constructCredentialsFromRequest.
@Override
protected Credential constructCredentialsFromRequest(final RequestContext requestContext) {
try {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val extractor = new BasicAuthExtractor();
val webContext = new JEEContext(request, response);
val credentialsResult = extractor.extract(webContext, JEESessionStore.INSTANCE);
if (credentialsResult.isPresent()) {
val credentials = (UsernamePasswordCredentials) credentialsResult.get();
LOGGER.debug("Received basic authentication request from credentials [{}]", credentials);
return new UsernamePasswordCredential(credentials.getUsername(), credentials.getPassword());
}
} catch (final Exception e) {
LoggingUtils.warn(LOGGER, e);
}
return null;
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithLinkedHashMap.
@Test
public void verifyEncodeDecodeTGTWithLinkedHashMap() {
val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
val expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, new LinkedHashMap<>(this.principalAttributes));
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
val result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableMap.
@Test
public void verifyEncodeDecodeTGTWithUnmodifiableMap() {
val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
val expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, new HashMap<>(this.principalAttributes));
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
val result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithListOrderedMap.
@Test
public void verifyEncodeDecodeTGTWithListOrderedMap() {
val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
val expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, this.principalAttributes);
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
val result = transcoder.encode(expectedTGT);
assertEquals(expectedTGT, transcoder.decode(result));
assertEquals(expectedTGT, transcoder.decode(result));
}
Aggregations