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="));
}
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);
}
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());
}
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();
}
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));
}
Aggregations