use of org.apereo.cas.authentication.principal.DefaultPrincipalFactory in project cas by apereo.
the class RestAuthenticationHandlerTests method verifySuccess.
@Test
public void verifySuccess() throws Exception {
final Principal principalWritten = new DefaultPrincipalFactory().createPrincipal("casuser");
final ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
final StringWriter writer = new StringWriter();
mapper.writeValue(writer, principalWritten);
server.andRespond(withSuccess(writer.toString(), MediaType.APPLICATION_JSON));
final AuthenticationHandlerExecutionResult res = authenticationHandler.authenticate(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
assertEquals("casuser", res.getPrincipal().getId());
}
use of org.apereo.cas.authentication.principal.DefaultPrincipalFactory in project cas by apereo.
the class JcifsSpnegoAuthenticationHandlerTests method verifyGetSimpleCredentials.
@Test
public void verifyGetSimpleCredentials() {
final String myNtlmUser = "DOMAIN\\Username";
final String myNtlmUserWithNoDomain = USERNAME;
final String myKerberosUser = "Username@DOMAIN.COM";
final PrincipalFactory factory = new DefaultPrincipalFactory();
final JcifsSpnegoAuthenticationHandler authenticationHandler = new JcifsSpnegoAuthenticationHandler("", null, null, new MockJcifsAuthentication(), true, true);
assertEquals(factory.createPrincipal(myNtlmUser), authenticationHandler.getPrincipal(myNtlmUser, true));
assertEquals(factory.createPrincipal(myNtlmUserWithNoDomain), authenticationHandler.getPrincipal(myNtlmUserWithNoDomain, false));
assertEquals(factory.createPrincipal(myKerberosUser), authenticationHandler.getPrincipal(myKerberosUser, false));
final JcifsSpnegoAuthenticationHandler handlerNoDomain = new JcifsSpnegoAuthenticationHandler("", null, null, new MockJcifsAuthentication(), false, true);
assertEquals(factory.createPrincipal(USERNAME), handlerNoDomain.getPrincipal(myNtlmUser, true));
assertEquals(factory.createPrincipal(USERNAME), handlerNoDomain.getPrincipal(myNtlmUserWithNoDomain, true));
assertEquals(factory.createPrincipal(USERNAME), handlerNoDomain.getPrincipal(myKerberosUser, false));
}
use of org.apereo.cas.authentication.principal.DefaultPrincipalFactory in project cas by apereo.
the class Saml10SuccessResponseViewTests method verifyResponseWithoutAuthMethod.
@Test
public void verifyResponseWithoutAuthMethod() throws Exception {
final Map<String, Object> model = new HashMap<>();
final Map<String, Object> attributes = new HashMap<>();
attributes.put(TEST_ATTRIBUTE, TEST_VALUE);
final Principal principal = new DefaultPrincipalFactory().createPrincipal(PRINCIPAL_ID, attributes);
final Map<String, Object> authnAttributes = new HashMap<>();
authnAttributes.put("authnAttribute1", "authnAttrbuteV1");
authnAttributes.put("authnAttribute2", "authnAttrbuteV2");
authnAttributes.put(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, Boolean.TRUE);
final Authentication primary = CoreAuthenticationTestUtils.getAuthentication(principal, authnAttributes);
final Assertion assertion = new DefaultAssertionBuilder(primary).with(Collections.singletonList(primary)).with(CoreAuthenticationTestUtils.getService()).with(true).build();
model.put("assertion", assertion);
final MockHttpServletResponse servletResponse = new MockHttpServletResponse();
this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
final String written = servletResponse.getContentAsString();
assertTrue(written.contains(PRINCIPAL_ID));
assertTrue(written.contains(TEST_ATTRIBUTE));
assertTrue(written.contains(TEST_VALUE));
assertTrue(written.contains("authnAttribute1"));
assertTrue(written.contains("authnAttribute2"));
assertTrue(written.contains(CasProtocolConstants.VALIDATION_REMEMBER_ME_ATTRIBUTE_NAME));
assertTrue(written.contains("urn:oasis:names:tc:SAML:1.0:am:unspecified"));
}
Aggregations