Search in sources :

Example 21 with Model

use of org.springframework.ui.Model in project Asqatasun by Asqatasun.

the class LoginControllerTest method testDisplayLoginPage.

/**
     * Test of displayLoginPage method, of class LoginController.
     */
public void testDisplayLoginPage() {
    System.out.println("displayLoginPage");
    Model model = new ExtendedModelMap();
    setUpMockAuthenticationContext();
    LoginController instance = new LoginController();
    String expResult = TgolKeyStore.LOGIN_VIEW_NAME;
    String result = instance.displayLoginPage("", new HttpServletRequest() {

        @Override
        public String getAuthType() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Cookie[] getCookies() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public long getDateHeader(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getHeader(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getHeaders(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getHeaderNames() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getIntHeader(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getMethod() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getPathInfo() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getPathTranslated() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getContextPath() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getQueryString() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRemoteUser() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isUserInRole(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Principal getUserPrincipal() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRequestedSessionId() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRequestURI() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public StringBuffer getRequestURL() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getServletPath() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public HttpSession getSession(boolean bln) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public HttpSession getSession() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdValid() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdFromCookie() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdFromURL() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isRequestedSessionIdFromUrl() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Object getAttribute(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getAttributeNames() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getCharacterEncoding() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void setCharacterEncoding(String string) throws UnsupportedEncodingException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getContentLength() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getContentType() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ServletInputStream getInputStream() throws IOException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getParameter(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getParameterNames() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String[] getParameterValues(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Map getParameterMap() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getProtocol() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getScheme() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getServerName() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getServerPort() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public BufferedReader getReader() throws IOException {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRemoteAddr() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRemoteHost() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void setAttribute(String string, Object o) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public void removeAttribute(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Locale getLocale() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Enumeration getLocales() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public boolean isSecure() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public RequestDispatcher getRequestDispatcher(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getRealPath(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getRemotePort() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getLocalName() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public String getLocalAddr() {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public int getLocalPort() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }, model);
    assertEquals(expResult, result);
}
Also used : Locale(java.util.Locale) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Enumeration(java.util.Enumeration) HttpSession(javax.servlet.http.HttpSession) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) Model(org.springframework.ui.Model) BufferedReader(java.io.BufferedReader) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Principal(java.security.Principal)

Example 22 with Model

use of org.springframework.ui.Model in project Asqatasun by Asqatasun.

the class AuditSetUpControllerTest method testDisplayPageAuditUploadSetUp.

public void testDisplayPageAuditUploadSetUp() {
    System.out.println("testDisplayPageAuditUploadSetUp");
    // Set-up
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(1, "Contract1");
    setUpViewFunctionalityBindingMap();
    setUpAuditSetUpCommandFactory();
    Model model = new ExtendedModelMap();
    // test
    String returnedView = instance.displayUploadAuditSetUp("1", null, null, model);
    // assertions
    assertEquals(TgolKeyStore.AUDIT_UPLOAD_SET_UP_VIEW_NAME, returnedView);
    assertEquals("http://www.test1.com", model.asMap().get(TgolKeyStore.URL_KEY));
    assertEquals(false, model.asMap().get(TgolKeyStore.DEFAULT_PARAM_SET_KEY));
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model)

Example 23 with Model

use of org.springframework.ui.Model in project Asqatasun by Asqatasun.

the class AuditSetUpControllerTest method testDisplayPageAuditSiteSetUp.

public void testDisplayPageAuditSiteSetUp() {
    System.out.println("testDisplayPageAuditSiteSetUp");
    // Set-up
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(1, "Contract1");
    setUpViewFunctionalityBindingMap();
    setUpAuditSetUpCommandFactory();
    Model model = new ExtendedModelMap();
    String returnedView = instance.displaySiteAuditSetUp("1", null, null, model);
    // assertions
    assertEquals(TgolKeyStore.AUDIT_SITE_SET_UP_VIEW_NAME, returnedView);
    assertEquals("http://www.test1.com", model.asMap().get(TgolKeyStore.URL_KEY));
    assertEquals(true, model.asMap().get(TgolKeyStore.DEFAULT_PARAM_SET_KEY));
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model)

Example 24 with Model

use of org.springframework.ui.Model in project Asqatasun by Asqatasun.

the class AuditSetUpControllerTest method testDisplayPageAuditPageSetUp.

public void testDisplayPageAuditPageSetUp() {
    System.out.println("testDisplayPageAuditPageSetUp");
    // set-up
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(1, "Contract1");
    setUpViewFunctionalityBindingMap();
    setUpAuditSetUpCommandFactory();
    Model model = new ExtendedModelMap();
    // test
    String returnedView = instance.displayPageAuditSetUp("1", null, null, model);
    // assertions
    assertEquals(TgolKeyStore.AUDIT_PAGE_SET_UP_VIEW_NAME, returnedView);
    assertEquals("http://www.test1.com", model.asMap().get(TgolKeyStore.URL_KEY));
    assertEquals(false, model.asMap().get(TgolKeyStore.DEFAULT_PARAM_SET_KEY));
// TO DO : write test to control the integrity of data of the AuditSetUpCommand
// regarding the option/functionality rules
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model)

Example 25 with Model

use of org.springframework.ui.Model in project cas by apereo.

the class OidcJwksEndpointController method handleRequestInternal.

/**
     * Handle request for jwk set.
     *
     * @param request  the request
     * @param response the response
     * @param model    the model
     * @return the jwk set
     * @throws Exception the exception
     */
@GetMapping(value = '/' + OidcConstants.BASE_OIDC_URL + '/' + OidcConstants.JWKS_URL, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response, final Model model) throws Exception {
    Assert.notNull(this.jwksFile, "JWKS file cannot be undefined or null.");
    try {
        final String jsonJwks = IOUtils.toString(this.jwksFile.getInputStream(), StandardCharsets.UTF_8);
        final JsonWebKeySet jsonWebKeySet = new JsonWebKeySet(jsonJwks);
        getServicesManager().getAllServices().stream().filter(s -> s instanceof OidcRegisteredService && StringUtils.isNotBlank(((OidcRegisteredService) s).getJwks())).forEach(Unchecked.consumer(s -> {
            final OidcRegisteredService service = (OidcRegisteredService) s;
            final Resource resource = this.resourceLoader.getResource(service.getJwks());
            final JsonWebKeySet set = new JsonWebKeySet(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8));
            set.getJsonWebKeys().forEach(jsonWebKeySet::addJsonWebKey);
        }));
        final String body = jsonWebKeySet.toJson(JsonWebKey.OutputControlLevel.PUBLIC_ONLY);
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        return new ResponseEntity<>(body, HttpStatus.OK);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
    }
}
Also used : Assert(com.stormpath.sdk.lang.Assert) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) LoggerFactory(org.slf4j.LoggerFactory) OAuth20Validator(org.apereo.cas.support.oauth.validator.OAuth20Validator) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseOAuthWrapperController(org.apereo.cas.support.oauth.web.BaseOAuthWrapperController) StringUtils(org.apache.commons.lang3.StringUtils) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Model(org.springframework.ui.Model) HttpServletRequest(javax.servlet.http.HttpServletRequest) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) TicketRegistry(org.apereo.cas.ticket.registry.TicketRegistry) GetMapping(org.springframework.web.bind.annotation.GetMapping) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) ServicesManager(org.apereo.cas.services.ServicesManager) Resource(org.springframework.core.io.Resource) Unchecked(org.jooq.lambda.Unchecked) Logger(org.slf4j.Logger) ResourceLoader(org.springframework.core.io.ResourceLoader) OAuth20ProfileScopeToAttributesFilter(org.apereo.cas.support.oauth.profile.OAuth20ProfileScopeToAttributesFilter) OidcConstants(org.apereo.cas.oidc.OidcConstants) JsonWebKey(org.jose4j.jwk.JsonWebKey) MediaType(org.springframework.http.MediaType) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonWebKeySet(org.jose4j.jwk.JsonWebKeySet) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) AccessTokenFactory(org.apereo.cas.ticket.accesstoken.AccessTokenFactory) HttpStatus(org.springframework.http.HttpStatus) OidcRegisteredService(org.apereo.cas.services.OidcRegisteredService) ResponseEntity(org.springframework.http.ResponseEntity) ResponseEntity(org.springframework.http.ResponseEntity) OidcRegisteredService(org.apereo.cas.services.OidcRegisteredService) Resource(org.springframework.core.io.Resource) JsonWebKeySet(org.jose4j.jwk.JsonWebKeySet) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Model (org.springframework.ui.Model)38 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)15 BindingResult (org.springframework.validation.BindingResult)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 MediaType (org.springframework.http.MediaType)8 IOException (java.io.IOException)6 Map (java.util.Map)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 WebDataBinder (org.springframework.web.bind.WebDataBinder)6 GetRequest (com.mashape.unirest.request.GetRequest)5 FileNotFoundException (java.io.FileNotFoundException)5 DateFormat (java.text.DateFormat)5 SimpleDateFormat (java.text.SimpleDateFormat)5 java.util (java.util)5 Valid (javax.validation.Valid)5