List of usage examples for javax.servlet.http HttpServletRequest isSecure
public boolean isSecure();
From source file:ru.org.linux.topic.TopicModificationController.java
@RequestMapping(value = "/uncommit.jsp", method = RequestMethod.GET) public ModelAndView uncommitForm(HttpServletRequest request, @RequestParam int msgid) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isModeratorSession()) { throw new AccessViolationException("Not authorized"); }//w w w . j a v a 2s .c om Topic message = messageDao.getById(msgid); checkUncommitable(message); ModelAndView mv = new ModelAndView("uncommit"); mv.getModel().put("message", message); mv.getModel().put("preparedMessage", prepareService.prepareTopic(message, request.isSecure(), tmpl.getCurrentUser())); return mv; }
From source file:org.codice.ddf.security.idp.server.IdpEndpointTest.java
@Test public void testShowGetLoginWithValidCookie() throws CertificateEncodingException, WSSecurityException { String samlRequest = authNRequestGet; HttpServletRequest request = mock(HttpServletRequest.class); Cookie cookie = mock(Cookie.class); when(request.isSecure()).thenReturn(true); when(request.getRequestURL()).thenReturn(requestURL); when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*"); when(request.getCookies()).thenReturn(new Cookie[] { cookie }); when(cookie.getName()).thenReturn(IdpEndpoint.COOKIE); when(cookie.getValue()).thenReturn("1"); Response response = idpEndpoint.showGetLogin(samlRequest, relayState, signatureAlgorithm, signature, request);//from w w w. ja v a 2s .c o m assertThat(response.getEntity().toString(), containsString(ssoSAMLResponse)); assertThat(response.getEntity().toString(), containsString("RelayState=")); }
From source file:com.qlkh.client.server.proxy.ProxyServlet.java
private String getProxyURL(HttpServletRequest httpServletRequest) { // Set the protocol to HTTP String protocol = (httpServletRequest.isSecure()) ? "https://" : "http://"; String stringProxyURL = protocol + this.getProxyHostAndPort(); // simply use whatever servlet path that was part of the request as opposed to getting a preset/configurable proxy path if (!removePrefix) { stringProxyURL += httpServletRequest.getServletPath(); }/* w w w . j av a 2 s.co m*/ stringProxyURL += "/"; // Handle the path given to the servlet String pathInfo = httpServletRequest.getPathInfo(); if (pathInfo != null && pathInfo.startsWith("/")) { if (stringProxyURL != null && stringProxyURL.endsWith("/")) { // avoid double '/' stringProxyURL += pathInfo.substring(1); } } else { stringProxyURL += httpServletRequest.getPathInfo(); } // Handle the query string if (httpServletRequest.getQueryString() != null) { stringProxyURL += "?" + httpServletRequest.getQueryString(); } return stringProxyURL; }
From source file:ru.org.linux.user.WhoisController.java
@RequestMapping(value = "/people/{nick}/profile", method = { RequestMethod.GET, RequestMethod.HEAD }) public ModelAndView getInfoNew(@PathVariable String nick, HttpServletRequest request, HttpServletResponse response) throws Exception { Template tmpl = Template.getTemplate(request); User user = userDao.getUser(nick);/*from ww w.j a v a 2 s . c om*/ if (user.isBlocked() && !tmpl.isSessionAuthorized()) { throw new UserBanedException(user, userDao.getBanInfoClass(user)); } ModelAndView mv = new ModelAndView("whois"); mv.getModel().put("user", user); mv.getModel().put("userInfo", userDao.getUserInfoClass(user)); mv.getModel().put("userpic", userService.getUserpic(user, request.isSecure(), tmpl.getProf().getAvatarMode())); if (user.isBlocked()) { mv.getModel().put("banInfo", userDao.getBanInfoClass(user)); } boolean currentUser = tmpl.isSessionAuthorized() && tmpl.getNick().equals(nick); if (!user.isAnonymous()) { UserStatistics userStat = userDao.getUserStatisticsClass(user, currentUser || tmpl.isModeratorSession()); mv.getModel().put("userStat", userStat); mv.getModel().put("sectionStat", prepareSectionStats(userStat)); } mv.getModel().put("moderatorOrCurrentUser", currentUser || tmpl.isModeratorSession()); mv.getModel().put("currentUser", currentUser); if (tmpl.isSessionAuthorized() && !currentUser) { Set<Integer> ignoreList = ignoreListDao.get(tmpl.getCurrentUser()); mv.getModel().put("ignored", ignoreList.contains(user.getId())); mv.getModel().put("remark", userDao.getRemark(tmpl.getCurrentUser(), user)); } if (tmpl.isSessionAuthorized() && currentUser) { mv.getModel().put("hasRemarks", (userDao.getRemarkCount(tmpl.getCurrentUser()) > 0)); } String userinfo = userDao.getUserInfo(user); if (!Strings.isNullOrEmpty(userinfo)) { mv.getModel().put("userInfoText", lorCodeService.parseComment(userinfo, request.isSecure(), !topicPermissionService.followAuthorLinks(user))); } mv.addObject("favoriteTags", userTagService.favoritesGet(user)); if (currentUser || tmpl.isModeratorSession()) { mv.addObject("ignoreTags", userTagService.ignoresGet(user)); } response.setDateHeader("Expires", System.currentTimeMillis() + 120000); return mv; }
From source file:com.redhat.rhn.frontend.servlets.EnvironmentFilter.java
/** * {@inheritDoc}/* w ww .j a va2 s . com*/ */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hreq = new RhnHttpServletRequest((HttpServletRequest) request); HttpServletResponse hres = new RhnHttpServletResponse((HttpServletResponse) response, hreq); boolean sslAvail = ConfigDefaults.get().isSSLAvailable(); // There are a list of pages that don't require SSL, that list should // be called out here. String path = hreq.getRequestURI(); // Have to make this decision here, because once we pass the request // off to the next filter, that filter can do work that sends data to // the client, meaning that we can't redirect. if (RhnHelper.pathNeedsSecurity(nosslurls, path) && !hreq.isSecure() && sslAvail) { if (log.isDebugEnabled()) { log.debug("redirecting to secure: " + path); } redirectToSecure(hreq, hres); return; } // Set request attributes we may need later HttpServletRequest req = (HttpServletRequest) request; request.setAttribute(RequestContext.REQUESTED_URI, req.getRequestURI()); if (log.isDebugEnabled()) { log.debug("set REQUESTED_URI: " + req.getRequestURI()); } // add messages that were put on the request path. addParameterizedMessages(req); // Done, go up chain chain.doFilter(hreq, hres); }
From source file:org.codice.ddf.security.idp.server.IdpEndpointTest.java
@Test public void testProcessLoginPki() throws CertificateEncodingException, WSSecurityException { String samlRequest = authNRequestGet; HttpServletRequest request = mock(HttpServletRequest.class); X509Certificate x509Certificate = mock(X509Certificate.class); when(request.isSecure()).thenReturn(true); when(request.getRequestURL()).thenReturn(requestURL); when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*"); //dummy cert//from w w w. j av a2 s.co m when((X509Certificate[]) request.getAttribute(requestCertificateAttributeName)) .thenReturn(new X509Certificate[] { x509Certificate }); when(x509Certificate.getEncoded()).thenReturn(new byte[48]); Response response = idpEndpoint.processLogin(samlRequest, relayState, Idp.PKI, signatureAlgorithm, signature, SamlProtocol.REDIRECT_BINDING, request); assertThat(response.getEntity().toString(), containsString(ssoSAMLResponse)); assertThat(response.getEntity().toString(), containsString("RelayState=")); }
From source file:org.codice.ddf.security.idp.server.IdpEndpointTest.java
@Test public void testProcessLoginPkiPost() throws CertificateEncodingException { idpEndpoint.setStrictSignature(false); String samlRequest = authNRequestPkiPost; HttpServletRequest request = mock(HttpServletRequest.class); X509Certificate x509Certificate = mock(X509Certificate.class); when(request.isSecure()).thenReturn(true); when(request.getRequestURL()).thenReturn(requestURL); when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*"); //dummy cert// ww w. ja v a 2 s . c o m when((X509Certificate[]) request.getAttribute(requestCertificateAttributeName)) .thenReturn(new X509Certificate[] { x509Certificate }); when(x509Certificate.getEncoded()).thenReturn(new byte[48]); Response response = idpEndpoint.processLogin(samlRequest, relayState, Idp.PKI, null, null, SamlProtocol.POST_BINDING, request); assertThat(response.getEntity().toString(), containsString("Form Submit")); assertThat(response.getEntity().toString(), containsString("SAMLResponse")); assertThat(response.getEntity().toString(), containsString("RelayState")); }
From source file:ru.org.linux.comment.CommentService.java
public void prepareReplyto(CommentRequest add, Map<String, Object> formParams, HttpServletRequest request) throws UserNotFoundException { if (add.getReplyto() != null) { formParams.put("onComment", commentPrepareService.prepareCommentForReplayto(add.getReplyto(), request.isSecure())); }/* w ww . j a v a 2 s .com*/ }
From source file:org.icefaces.samples.showcase.util.SourceCodeLoaderConnection.java
@PostConstruct private void initialize() { // If no logger exists for this class, create and add a new one if ((logger = LogManager.getLogManager().getLogger(this.getClass().getName())) == null) { logger = Logger.getLogger(this.getClass().getName()); LogManager.getLogManager().addLogger(logger); }/*from w w w . j av a 2 s. c om*/ // Pull the maximum cache size from web.xml using FacesUtils // We'll default this value if it isn't found MAX_CACHE_SIZE = Integer.parseInt( FacesUtils.getFacesParameter("org.icefaces.samples.showcase.MAX_SOURCE_CACHE_SIZE", "20971520")); // Next we'll try to build a URL to load the source from // This is basically http://localhost:8080/showcase/, but the port and address could change // We'll try to dynamically get this from the ExternalContext request, otherwise we'll check it from the web.xml // and finally just default it Object request = FacesContext.getCurrentInstance().getExternalContext().getRequest(); if ((request != null) && (request instanceof HttpServletRequest)) { HttpServletRequest httpRequest = (HttpServletRequest) request; String hostName = "localhost"; try { //construct a url (SOURCE_SERVLET_URL) from getLocalName is not reliable //should use host from requestURL. URL requestUrl = new URL(httpRequest.getRequestURL().toString()); hostName = requestUrl.getHost(); } catch (MalformedURLException mfException) { } IS_SECURE = httpRequest.isSecure(); String protocol = IS_SECURE ? "https://" : "http://"; SOURCE_SERVLET_URL = protocol + hostName + ":" + httpRequest.getLocalPort() + httpRequest.getContextPath() + "/"; } else { String fromFile = FacesUtils.getFacesParameter("org.icefaces.samples.showcase.SOURCE_SERVLET_URL"); if (fromFile != null) { SOURCE_SERVLET_URL = fromFile; } else { SOURCE_SERVLET_URL = "http://localhost:8080/comp-suite/"; } } SOURCE_SERVLET_URL += "sourcecodeStream.html?path="; //logger.info("Reading source code from url [" + SOURCE_SERVLET_URL + "]."); }
From source file:org.codice.ddf.security.idp.server.IdpEndpointTest.java
@Test public void testPassiveLoginPki() throws SecurityServiceException, WSSecurityException, CertificateEncodingException { String samlRequest = authNRequestPassivePkiGet; HttpServletRequest request = mock(HttpServletRequest.class); X509Certificate x509Certificate = mock(X509Certificate.class); idpEndpoint.setStrictSignature(false); when(request.isSecure()).thenReturn(true); when(request.getRequestURL()).thenReturn(requestURL); when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*"); //dummy cert/* ww w. j a v a 2 s . c om*/ when((X509Certificate[]) request.getAttribute(requestCertificateAttributeName)) .thenReturn(new X509Certificate[] { x509Certificate }); when(x509Certificate.getEncoded()).thenReturn(new byte[48]); Response response = idpEndpoint.showGetLogin(samlRequest, relayState, signatureAlgorithm, signature, request); assertThat(response.getEntity().toString(), containsString(ssoSAMLResponse)); assertThat(response.getEntity().toString(), containsString("RelayState=")); }