Search in sources :

Example 1 with NoOpProtocolAttributeEncoder

use of org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder in project cas by apereo.

the class Cas20ResponseViewTests method verifyView.

@Test
public void verifyView() throws Exception {
    val modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl(RegisteredServiceTestUtils.getService("https://www.casinthecloud.com"));
    val req = new MockHttpServletRequest(new MockServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
    val resp = new MockHttpServletResponse();
    val delegatedView = new View() {

        @Override
        public String getContentType() {
            return MediaType.TEXT_HTML_VALUE;
        }

        @Override
        public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) {
            map.forEach(request::setAttribute);
        }
    };
    val view = new Cas20ResponseView(true, new NoOpProtocolAttributeEncoder(), null, delegatedView, new DefaultAuthenticationAttributeReleasePolicy("attribute"), new DefaultAuthenticationServiceSelectionPlan(), NoOpProtocolAttributesRenderer.INSTANCE);
    view.render(modelAndView.getModel(), req, resp);
    assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_CHAINED_AUTHENTICATIONS));
    assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRIMARY_AUTHENTICATION));
    assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL));
    assertNotNull(req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_PROXY_GRANTING_TICKET_IOU));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) View(org.springframework.web.servlet.View) MockServletContext(org.springframework.mock.web.MockServletContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultAuthenticationAttributeReleasePolicy(org.apereo.cas.authentication.DefaultAuthenticationAttributeReleasePolicy) NoOpProtocolAttributeEncoder(org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Map(java.util.Map) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with NoOpProtocolAttributeEncoder

use of org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder in project cas by apereo.

the class Cas10ResponseViewTests method verifyFailureView.

@Test
public void verifyFailureView() throws Exception {
    val response = new MockHttpServletResponse();
    val view = new Cas10ResponseView(false, new NoOpProtocolAttributeEncoder(), mock(ServicesManager.class), mock(AuthenticationAttributeReleasePolicy.class), new DefaultAuthenticationServiceSelectionPlan(), NoOpProtocolAttributesRenderer.INSTANCE);
    view.render(this.model, new MockHttpServletRequest(), response);
    assertEquals("no\n\n", response.getContentAsString());
}
Also used : lombok.val(lombok.val) AuthenticationAttributeReleasePolicy(org.apereo.cas.validation.AuthenticationAttributeReleasePolicy) ServicesManager(org.apereo.cas.services.ServicesManager) NoOpProtocolAttributeEncoder(org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 3 with NoOpProtocolAttributeEncoder

use of org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder in project cas by apereo.

the class Cas30JsonResponseViewTests method verifyFailureView.

@Test
public void verifyFailureView() throws Exception {
    val response = new MockHttpServletResponse();
    val view = getCasView(false, new NoOpProtocolAttributeEncoder(), getDelegatedView());
    val model = new HashMap<String, Object>();
    model.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_ERROR_CODE, "code");
    model.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_ERROR_DESCRIPTION, "description");
    val request = new MockHttpServletRequest();
    view.render(model, request, response);
    val casResponse = (CasJsonServiceResponse) request.getAttribute(Cas30JsonResponseView.ATTRIBUTE_NAME_MODEL_SERVICE_RESPONSE);
    assertNotNull(casResponse.getAuthenticationFailure().getCode());
    assertNotNull(casResponse.getAuthenticationFailure().getDescription());
}
Also used : lombok.val(lombok.val) CasJsonServiceResponse(org.apereo.cas.web.view.json.CasJsonServiceResponse) HashMap(java.util.HashMap) NoOpProtocolAttributeEncoder(org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 4 with NoOpProtocolAttributeEncoder

use of org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder in project cas by apereo.

the class Saml10SuccessResponseViewTests method initialize.

@BeforeEach
public void initialize() {
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val list = new ArrayList<RegisteredService>();
    list.add(RegisteredServiceTestUtils.getRegisteredService("https://.+"));
    val dao = new InMemoryServiceRegistry(appCtx, list, new ArrayList<>());
    val context = ServicesManagerConfigurationContext.builder().serviceRegistry(dao).applicationContext(appCtx).environments(new HashSet<>(0)).servicesCache(Caffeine.newBuilder().build()).registeredServiceLocators(List.of(new DefaultServicesManagerRegisteredServiceLocator())).build();
    val mgmr = new DefaultServicesManager(context);
    mgmr.load();
    val protocolAttributeEncoder = new DefaultCasProtocolAttributeEncoder(mgmr, CipherExecutor.noOpOfStringToString());
    val builder = new Saml10ObjectBuilder(configBean);
    val samlResponseBuilder = new SamlResponseBuilder(builder, "testIssuer", "whatever", 1000, "PT30S", new NoOpProtocolAttributeEncoder(), mgmr);
    this.response = new Saml10SuccessResponseView(protocolAttributeEncoder, mgmr, new DefaultArgumentExtractor(new SamlServiceFactory()), StandardCharsets.UTF_8.name(), new DefaultAuthenticationAttributeReleasePolicy("attribute"), new DefaultAuthenticationServiceSelectionPlan(), NoOpProtocolAttributesRenderer.INSTANCE, samlResponseBuilder);
}
Also used : lombok.val(lombok.val) DefaultServicesManagerRegisteredServiceLocator(org.apereo.cas.services.DefaultServicesManagerRegisteredServiceLocator) SamlServiceFactory(org.apereo.cas.support.saml.authentication.principal.SamlServiceFactory) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ArrayList(java.util.ArrayList) SamlResponseBuilder(org.apereo.cas.support.saml.authentication.SamlResponseBuilder) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) DefaultAuthenticationAttributeReleasePolicy(org.apereo.cas.authentication.DefaultAuthenticationAttributeReleasePolicy) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) NoOpProtocolAttributeEncoder(org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder) DefaultCasProtocolAttributeEncoder(org.apereo.cas.authentication.support.DefaultCasProtocolAttributeEncoder) DefaultServicesManager(org.apereo.cas.services.DefaultServicesManager) Saml10ObjectBuilder(org.apereo.cas.support.saml.util.Saml10ObjectBuilder) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with NoOpProtocolAttributeEncoder

use of org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder in project cas by apereo.

the class Saml10FailureResponseViewTests method initialize.

@BeforeEach
public void initialize() {
    val builder = new Saml10ObjectBuilder(this.configBean);
    val samlResponseBuilder = new SamlResponseBuilder(builder, null, null, 0, "PT30S", new NoOpProtocolAttributeEncoder(), null);
    view = new Saml10FailureResponseView(new NoOpProtocolAttributeEncoder(), null, new DefaultArgumentExtractor(new SamlServiceFactory()), StandardCharsets.UTF_8.name(), null, new DefaultAuthenticationServiceSelectionPlan(), NoOpProtocolAttributesRenderer.INSTANCE, samlResponseBuilder);
}
Also used : lombok.val(lombok.val) DefaultArgumentExtractor(org.apereo.cas.web.support.DefaultArgumentExtractor) SamlServiceFactory(org.apereo.cas.support.saml.authentication.principal.SamlServiceFactory) NoOpProtocolAttributeEncoder(org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder) SamlResponseBuilder(org.apereo.cas.support.saml.authentication.SamlResponseBuilder) DefaultAuthenticationServiceSelectionPlan(org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan) Saml10ObjectBuilder(org.apereo.cas.support.saml.util.Saml10ObjectBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

lombok.val (lombok.val)6 NoOpProtocolAttributeEncoder (org.apereo.cas.authentication.support.NoOpProtocolAttributeEncoder)6 DefaultAuthenticationServiceSelectionPlan (org.apereo.cas.authentication.DefaultAuthenticationServiceSelectionPlan)5 Test (org.junit.jupiter.api.Test)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 DefaultAuthenticationAttributeReleasePolicy (org.apereo.cas.authentication.DefaultAuthenticationAttributeReleasePolicy)2 ServicesManager (org.apereo.cas.services.ServicesManager)2 SamlResponseBuilder (org.apereo.cas.support.saml.authentication.SamlResponseBuilder)2 SamlServiceFactory (org.apereo.cas.support.saml.authentication.principal.SamlServiceFactory)2 Saml10ObjectBuilder (org.apereo.cas.support.saml.util.Saml10ObjectBuilder)2 AuthenticationAttributeReleasePolicy (org.apereo.cas.validation.AuthenticationAttributeReleasePolicy)2 DefaultArgumentExtractor (org.apereo.cas.web.support.DefaultArgumentExtractor)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1