Search in sources :

Example 6 with DefaultPrincipalFactory

use of org.apereo.cas.authentication.principal.DefaultPrincipalFactory in project cas by apereo.

the class Saml10SuccessResponseViewTests method verifyResponseWithNoAttributes.

@Test
public void verifyResponseWithNoAttributes() throws Exception {
    final Map<String, Object> model = new HashMap<>();
    final Principal principal = new DefaultPrincipalFactory().createPrincipal(PRINCIPAL_ID);
    final Map<String, Object> authAttributes = new HashMap<>();
    authAttributes.put(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD, SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT);
    authAttributes.put("testSamlAttribute", "value");
    final Authentication primary = CoreAuthenticationTestUtils.getAuthentication(principal, authAttributes);
    final Assertion assertion = new ImmutableAssertion(primary, Collections.singletonList(primary), CoreAuthenticationTestUtils.getService(), true);
    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(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT));
    assertTrue(written.contains("AuthenticationMethod="));
}
Also used : HashMap(java.util.HashMap) ImmutableAssertion(org.apereo.cas.validation.ImmutableAssertion) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Assertion(org.apereo.cas.validation.Assertion) ImmutableAssertion(org.apereo.cas.validation.ImmutableAssertion) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) Principal(org.apereo.cas.authentication.principal.Principal) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 7 with DefaultPrincipalFactory

use of org.apereo.cas.authentication.principal.DefaultPrincipalFactory in project cas by apereo.

the class SpnegoCredentialsTests method verifyPrincipalAffectsHash.

/**
     * Make sure that when the Principal becomes populated / changes we return a new hash
     */
@Test
public void verifyPrincipalAffectsHash() {
    final SpnegoCredential credential = new SpnegoCredential(new byte[] {});
    final int hash1 = credential.hashCode();
    final Principal principal = new DefaultPrincipalFactory().createPrincipal("test");
    credential.setPrincipal(principal);
    final int hash2 = credential.hashCode();
    assertNotEquals(hash1, hash2);
}
Also used : DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test)

Example 8 with DefaultPrincipalFactory

use of org.apereo.cas.authentication.principal.DefaultPrincipalFactory in project cas by apereo.

the class SpnegoCredentialsTests method verifyToStringWithPrincipal.

@Test
public void verifyToStringWithPrincipal() {
    final SpnegoCredential credentials = new SpnegoCredential(new byte[] {});
    final Principal principal = new DefaultPrincipalFactory().createPrincipal("test");
    credentials.setPrincipal(principal);
    assertEquals("test", credentials.toString());
}
Also used : DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test)

Example 9 with DefaultPrincipalFactory

use of org.apereo.cas.authentication.principal.DefaultPrincipalFactory in project cas by apereo.

the class TestOneTimePasswordAuthenticationHandler method authenticate.

@Override
public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException, PreventedException {
    final OneTimePasswordCredential otp = (OneTimePasswordCredential) credential;
    final String valueOnRecord = credentialMap.get(otp.getId());
    if (otp.getPassword().equals(valueOnRecord)) {
        return new DefaultHandlerResult(this, new BasicCredentialMetaData(otp), new DefaultPrincipalFactory().createPrincipal(otp.getId()));
    }
    throw new FailedLoginException();
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) OneTimePasswordCredential(org.apereo.cas.authentication.OneTimePasswordCredential) DefaultHandlerResult(org.apereo.cas.authentication.DefaultHandlerResult) BasicCredentialMetaData(org.apereo.cas.authentication.BasicCredentialMetaData)

Example 10 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, 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(true), 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)

Aggregations

DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)16 Test (org.junit.Test)12 Principal (org.apereo.cas.authentication.principal.Principal)8 HashMap (java.util.HashMap)6 Authentication (org.apereo.cas.authentication.Authentication)4 DefaultHandlerResult (org.apereo.cas.authentication.DefaultHandlerResult)4 FailedLoginException (javax.security.auth.login.FailedLoginException)3 BasicCredentialMetaData (org.apereo.cas.authentication.BasicCredentialMetaData)3 UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)3 Assertion (org.apereo.cas.validation.Assertion)3 ImmutableAssertion (org.apereo.cas.validation.ImmutableAssertion)3 ArrayList (java.util.ArrayList)2 PrincipalBearingCredential (org.apereo.cas.adaptors.trusted.authentication.principal.PrincipalBearingCredential)2 HandlerResult (org.apereo.cas.authentication.HandlerResult)2 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)2 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1