List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:net.maritimecloud.identityregistry.controllers.OrganizationController.java
/** * Updates info about the organization identified by the given ID * //from w w w . jav a 2 s . c o m * @return a http reply * @throws McBasicRestException */ @RequestMapping(value = "/api/org/{orgMrn}", method = RequestMethod.PUT) @PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)") public ResponseEntity<?> updateOrganization(HttpServletRequest request, @PathVariable String orgMrn, @Valid @RequestBody Organization input, BindingResult bindingResult) throws McBasicRestException { ValidateUtil.hasErrors(bindingResult, request); Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { if (!orgMrn.equals(input.getMrn())) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.URL_DATA_MISMATCH, request.getServletPath()); } // If a well-known url and client id and secret was supplied, and it is different from the current data we create a new IDP, or update it. if ("own-idp".equals(input.getFederationType()) && input.getIdentityProviderAttributes() != null && !input.getIdentityProviderAttributes().isEmpty()) { keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE); // If the IDP setup is different we delete the old IDP in keycloak if (org.getIdentityProviderAttributes() != null && !org.getIdentityProviderAttributes().isEmpty() && !IdentityProviderAttribute.listsEquals(org.getIdentityProviderAttributes(), input.getIdentityProviderAttributes())) { keycloakAU.deleteIdentityProvider(input.getMrn()); } try { keycloakAU.createIdentityProvider(input.getMrn().toLowerCase(), input.getIdentityProviderAttributes()); } catch (InternalServerErrorException e) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.INVALID_IDP_URL, request.getServletPath()); } catch (IOException e) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.COULD_NOT_GET_DATA_FROM_IDP, request.getServletPath()); } org.setFederationType("own-idp"); } else if (org.getIdentityProviderAttributes() != null && !org.getIdentityProviderAttributes().isEmpty()) { // Remove old IDP if new input doesn't contain IDP info keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE); keycloakAU.deleteIdentityProvider(input.getMrn()); // TODO: Determine if setting to "external-idp" could be done as well. org.setFederationType("test-idp"); } input.selectiveCopyTo(org); this.organizationService.save(org); return new ResponseEntity<>(HttpStatus.OK); } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }
From source file:net.cloudfree.apps.shop.internal.app.ListingServlet.java
private StringBuilder getBaseUrl(final HttpServletRequest req) { final StringBuilder builder = new StringBuilder(50); builder.append(req.getScheme());/*from w w w . j a va2 s. co m*/ builder.append("://"); builder.append(req.getServerName()); if ((req.getScheme().equals("http") && (req.getServerPort() != 80)) || (req.getScheme().equals("https") && (req.getServerPort() != 443))) { builder.append(":"); builder.append(req.getServerPort()); } builder.append(req.getContextPath()); builder.append(req.getServletPath()); builder.append("/"); return builder; }
From source file:ch.entwine.weblounge.kernel.http.WelcomeFileFilterServlet.java
/** * {@inheritDoc}//from ww w .ja va2 s . c o m * * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { if (req.getPathInfo() != null && "/".equals(req.getPathInfo())) { if (!welcomeFileList.isEmpty()) { // use the first one for now: for (String welcomeFile : welcomeFileList) { String file = welcomeFile; if (welcomeFile.startsWith("/")) file = welcomeFile.substring(1); RequestDispatcher dispatcher = req.getRequestDispatcher(file); // TODO: check if resource exists before forwarding dispatcher.forward(req, res); return; } } else { req.getRequestDispatcher(req.getServletPath() + "/resources/index.html").forward(req, res); // Tomcat also defaults to index.jsp return; } } else { // no welcome file, trying to forward to remapped resource: // /resources"+req.getPathInfo() req.getRequestDispatcher(req.getServletPath() + "/resources" + req.getPathInfo()).forward(req, res); } }
From source file:edu.cornell.mannlib.vitro.webapp.web.widgets.LoginWidget.java
@Override protected WidgetTemplateValues process(Environment env, Map params, HttpServletRequest request, ServletContext context) {/*from w w w . j a va 2 s.c om*/ WidgetTemplateValues values = null; try { State state = getCurrentLoginState(request); log.debug("State on exit: " + state); TemplateHashModel dataModel = env.getDataModel(); switch (state) { case LOGGED_IN: // On the login page itself, show a message that the user is already logged in. // Otherwise, when redirecting to login page from a page that the logged-in user // doesn't have access to, we would just show a blank page. if (request.getServletPath().equals(Route.LOGIN.path())) { values = showMessageToLoggedInUser(request); break; } else { return null; } case FORCED_PASSWORD_CHANGE: values = showPasswordChangeScreen(request); break; default: values = showLoginScreen(request, dataModel.get("siteName").toString()); } values.put("urls", dataModel.get("urls")); values.put("currentServlet", dataModel.get("currentServlet")); @SuppressWarnings("unchecked") Map<String, Object> dm = (Map<String, Object>) DeepUnwrap.permissiveUnwrap(dataModel); User user = (User) dm.get("user"); values.put("user", user); } catch (Exception e) { log.error(e, e); // This widget should display an error message rather than throwing the exception // up to the doMarkup() method, which would result in no display. values = showError(e); } return values; }
From source file:net.maritimecloud.identityregistry.controllers.EntityController.java
/** * Revokes certificate for the entity identified by the given ID * * @return a reply.../*from w w w . j av a2 s . co m*/ * @throws McBasicRestException */ protected ResponseEntity<?> revokeEntityCert(HttpServletRequest request, String orgMrn, String entityMrn, Long certId, CertificateRevocation input) throws McBasicRestException { Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { // Check that the entity being queried belongs to the organization if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn) .equals(MrnUtil.getOrgShortNameFromEntityMrn(entityMrn))) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } T entity = this.entityService.getByMrn(entityMrn); if (entity == null) { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND, request.getServletPath()); } if (entity.getIdOrganization().compareTo(org.getId()) == 0) { Certificate cert = this.certificateService.getCertificateById(certId); T certEntity = getCertEntity(cert); if (certEntity != null && certEntity.getId().compareTo(entity.getId()) == 0) { this.revokeCertificate(cert.getId(), input, request); return new ResponseEntity<>(HttpStatus.OK); } } throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }
From source file:com.alfaariss.oa.profile.saml2.SAML2Profile.java
private ISAML2Profile resolveSAMLProfile(HttpServletRequest servletRequest) { ISAML2Profile samlProfile = null;//from w ww .j a v a 2 s. c o m String sRequestURI = servletRequest.getRequestURI(); //remove a trailing '/' from the URL if it is available if (sRequestURI.endsWith("/")) sRequestURI = sRequestURI.substring(0, sRequestURI.length() - 1); String sContextPath = servletRequest.getContextPath(); String sServletPath = servletRequest.getServletPath(); int iBaseURILength = sContextPath.length() + sServletPath.length() + "/".length() + _sID.length() + "/".length(); if (sRequestURI.length() <= iBaseURILength) {//URL is smaller than or equal to the saml2 profile root URL, so no specific SAML profile is requested. return null; } String sSubURI = sRequestURI.substring(iBaseURILength); if (sSubURI.length() > 1) { for (String samlProfileID : _processors.keySet()) { if (sSubURI.startsWith(samlProfileID)) { samlProfile = _processors.get(samlProfileID); break; } } } return samlProfile; }
From source file:net.maritimecloud.identityregistry.controllers.ServiceController.java
/** * Updates a Service/* w ww .jav a2 s. com*/ * * @return a reply... * @throws McBasicRestException */ @RequestMapping(value = "/api/org/{orgMrn}/service/{serviceMrn}", method = RequestMethod.PUT) @ResponseBody @PreAuthorize("hasRole('SERVICE_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)") public ResponseEntity<?> updateService(HttpServletRequest request, @PathVariable String orgMrn, @PathVariable String serviceMrn, @Valid @RequestBody Service input, BindingResult bindingResult) throws McBasicRestException { ValidateUtil.hasErrors(bindingResult, request); if (!serviceMrn.equals(input.getMrn())) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.URL_DATA_MISMATCH, request.getServletPath()); } Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { // Check that the entity being updated belongs to the organization if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn) .equals(MrnUtil.getOrgShortNameFromEntityMrn(input.getMrn()))) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } Service service = this.entityService.getByMrn(serviceMrn); if (service == null) { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND, request.getServletPath()); } if (service.getIdOrganization().compareTo(org.getId()) == 0) { // Update the keycloak client for the service if needed if (input.getOidcAccessType() != null && !input.getOidcAccessType().trim().isEmpty()) { // Check if the redirect uri is set if access type is "bearer-only" if (!"bearer-only".equals(input.getOidcAccessType()) && (input.getOidcRedirectUri() == null || input.getOidcRedirectUri().trim().isEmpty())) { throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.OIDC_MISSING_REDIRECT_URL, request.getServletPath()); } keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE); String clientSecret; try { if (service.getOidcClientId() != null && !service.getOidcClientId().isEmpty()) { clientSecret = keycloakAU.updateClient(service.getMrn(), service.getOidcAccessType(), service.getOidcRedirectUri()); } else { service.setOidcClientId(service.getMrn()); clientSecret = keycloakAU.createClient(service.getMrn(), service.getOidcAccessType(), service.getOidcRedirectUri()); } } catch (IOException e) { log.error("Error while updating/creation client in keycloak.", e); throw new McBasicRestException(HttpStatus.INTERNAL_SERVER_ERROR, MCIdRegConstants.ERROR_CREATING_KC_CLIENT, request.getServletPath()); } catch (DuplicatedKeycloakEntry dke) { throw new McBasicRestException(HttpStatus.CONFLICT, dke.getErrorMessage(), request.getServletPath()); } if ("confidential".equals(service.getOidcAccessType())) { service.setOidcClientSecret(clientSecret); } else { service.setOidcClientSecret(null); } } input.selectiveCopyTo(service); try { this.entityService.save(service); return new ResponseEntity<>(HttpStatus.OK); } catch (DataIntegrityViolationException e) { throw new McBasicRestException(HttpStatus.CONFLICT, e.getRootCause().getMessage(), request.getServletPath()); } } throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS, request.getServletPath()); } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }
From source file:org.xine.marketplace.frontend.views.security.JsfLoginUrlAuthenticationEntryPoint.java
/** * Builds a URL to redirect the supplied request to HTTPS. Used to redirect the current request * to HTTPS, before doing a forward to the login page. */// w w w .j a va2 s . co m protected String buildHttpsRedirectUrlForRequest(final HttpServletRequest request) throws IOException, ServletException { final int serverPort = this.portResolver.getServerPort(request); final Integer httpsPort = this.portMapper.lookupHttpsPort(Integer.valueOf(serverPort)); if (httpsPort != null) { final RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme("https"); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(httpsPort.intValue()); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setServletPath(request.getServletPath()); urlBuilder.setPathInfo(request.getPathInfo()); urlBuilder.setQuery(request.getQueryString()); return urlBuilder.getUrl(); } // Fall through to server-side forward with warning message logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); return null; }
From source file:org.imsglobal.lti2.LTI2Servlet.java
public String getServiceURL(HttpServletRequest request) { String scheme = request.getScheme(); // http String serverName = request.getServerName(); // localhost int serverPort = request.getServerPort(); // 80 String contextPath = request.getContextPath(); // /imsblis String servletPath = request.getServletPath(); // /ltitest String url = scheme + "://" + serverName + ":" + serverPort + contextPath + servletPath + "/"; return url;// www . j ava2 s. c o m }
From source file:net.maritimecloud.identityregistry.controllers.LogoController.java
/** * Returns info about the logo identified by the given ID * * @return a reply...//from w ww. j a va 2 s .co m * @throws McBasicRestException */ @RequestMapping(value = "/api/org/{orgMrn}/logo", method = RequestMethod.GET) @ResponseBody public ResponseEntity<?> getLogo(HttpServletRequest request, @PathVariable String orgMrn) throws McBasicRestException { Organization org = this.organizationService.getOrganizationByMrn(orgMrn); if (org != null) { if (org.getLogo() != null) { byte[] image = org.getLogo().getImage(); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentLength(image.length); responseHeaders.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<>(image, responseHeaders, HttpStatus.OK); } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.LOGO_NOT_FOUND, request.getServletPath()); } } else { throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND, request.getServletPath()); } }