Search in sources :

Example 6 with DefaultAssertionBuilder

use of org.apereo.cas.validation.DefaultAssertionBuilder 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

Authentication (org.apereo.cas.authentication.Authentication)6 DefaultAssertionBuilder (org.apereo.cas.validation.DefaultAssertionBuilder)6 Principal (org.apereo.cas.authentication.principal.Principal)5 Assertion (org.apereo.cas.validation.Assertion)5 HashMap (java.util.HashMap)4 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)3 Test (org.junit.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 AuthenticationBuilder (org.apereo.cas.authentication.AuthenticationBuilder)2 DefaultAuthenticationBuilder (org.apereo.cas.authentication.DefaultAuthenticationBuilder)2 Service (org.apereo.cas.authentication.principal.Service)2 RegisteredService (org.apereo.cas.services.RegisteredService)2 Counted (com.codahale.metrics.annotation.Counted)1 Metered (com.codahale.metrics.annotation.Metered)1 Timed (com.codahale.metrics.annotation.Timed)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 AuditableContext (org.apereo.cas.audit.AuditableContext)1 AuditableExecutionResult (org.apereo.cas.audit.AuditableExecutionResult)1