Search in sources :

Example 16 with DefaultPrincipalFactory

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());
}
Also used : StringWriter(java.io.StringWriter) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) AuthenticationHandlerExecutionResult(org.apereo.cas.authentication.AuthenticationHandlerExecutionResult) Principal(org.apereo.cas.authentication.principal.Principal) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 17 with DefaultPrincipalFactory

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));
}
Also used : DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) MockJcifsAuthentication(org.apereo.cas.support.spnego.MockJcifsAuthentication) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) Test(org.junit.Test)

Example 18 with DefaultPrincipalFactory

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"));
}
Also used : DefaultAssertionBuilder(org.apereo.cas.validation.DefaultAssertionBuilder) HashMap(java.util.HashMap) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Assertion(org.apereo.cas.validation.Assertion) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) Principal(org.apereo.cas.authentication.principal.Principal) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)18 Test (org.junit.Test)14 Principal (org.apereo.cas.authentication.principal.Principal)8 HashMap (java.util.HashMap)7 Authentication (org.apereo.cas.authentication.Authentication)4 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)4 DefaultAuthenticationHandlerExecutionResult (org.apereo.cas.authentication.DefaultAuthenticationHandlerExecutionResult)4 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)4 FailedLoginException (javax.security.auth.login.FailedLoginException)3 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 CachedData (net.spy.memcached.CachedData)2 PrincipalBearingCredential (org.apereo.cas.adaptors.trusted.authentication.principal.PrincipalBearingCredential)2 AcceptUsersAuthenticationHandler (org.apereo.cas.authentication.AcceptUsersAuthenticationHandler)2 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)2 AuthenticationHandlerExecutionResult (org.apereo.cas.authentication.AuthenticationHandlerExecutionResult)2 Credential (org.apereo.cas.authentication.Credential)2 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)2