List of usage examples for javax.servlet.http HttpSession invalidate
public void invalidate();
From source file:com.idega.core.accesscontrol.business.LoginBusinessBean.java
protected void logOut(HttpServletRequest request, String userName) throws Exception { if (IWMainApplication.getDefaultIWMainApplication().getSettings().getBoolean("test_logout_stack", false) && !"root".equals(userName)) { try {// ww w .j a va2s .c o m throw new RuntimeException( "Logging out user '" + userName + "'. Rquest URI: " + request.getRequestURI()); } catch (Exception e) { String message = "Testing logout stack"; getLogger().log(Level.WARNING, message, e); CoreUtil.sendExceptionNotification(message, e); } } HttpSession session = request.getSession(); if (LoginBusinessBean.getLoginSessionBean() != null) { LoggedOnInfo info = getLoggedOnInfo(session); if (info != null) { Map<Object, Object> lm = getLoggedOnInfoMap(session); lm.remove(info.getLogin()); } UserProperties properties = getUserProperties(session); if (properties != null) { properties.store(); } removeLoginSession(session); } session.invalidate(); }
From source file:com.paperfood.controller.Authenticate.java
/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */// w w w . j a v a 2 s .c om protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); HttpSession session = request.getSession(true); JSONObject resp = new JSONObject(); MD5Hash md5; String status = ""; try { md5 = new MD5Hash(); String req_type = request.getParameter("type"); if (req_type.equalsIgnoreCase("login")) //Request of Login { String loginEmail = request.getParameter("loginEmail"); String loginPass = md5.getStringHash(request.getParameter("loginPass")); boolean loginRemember = request.getParameter("loginRemember").equalsIgnoreCase("true"); DatabaseManager dm = new DatabaseManager(); dm.open(); PaperFoodUser user = new PaperFoodUser(); user = (PaperFoodUser) dm.getLoggedUser(loginEmail, loginPass); dm.close(); if (user != null) //Credentials are valid, create session. { session.setAttribute("paperfooduseremail", user.getEmail()); if (loginRemember) { int time = 60 * 60 * 24 * 30; Cookie c = new Cookie("paperfood", user.getEmail()); c.setMaxAge(time); response.addCookie(c); } status = "success"; } else status = "invalid"; } else if (req_type.equalsIgnoreCase("cookielogin")) //Request for Cookie-based Login. { String loginEmail = request.getParameter("loginEmail"); session.setAttribute("paperfooduseremail", loginEmail); status = "success"; } else if (req_type.equalsIgnoreCase("sessionlogin")) //Request for Session-based Login. { String useremail = (String) session.getAttribute("paperfooduseremail"); if (useremail != null) status = "success"; } else if (req_type.equalsIgnoreCase("logout")) //Request for Logout. { session.invalidate(); Cookie[] c = request.getCookies(); if (c != null) { for (int i = 0; i < c.length; i++) { Cookie curr = c[i]; String cnm = curr.getName(); if (cnm.equalsIgnoreCase("paperfood")) { curr.setMaxAge(0); response.addCookie(curr); } } } status = "success"; } } catch (CommunicationsException e) { status = "unavailable"; } catch (Exception e) { status = "fail"; e.printStackTrace(); } try { resp.put("status", status); } catch (JSONException e) { e.printStackTrace(); } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); out.println(resp); }
From source file:com.sundevils.web.controller.TopController.java
@RequestMapping(value = "**/logoutusers", method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView logoutUser(HttpServletRequest request, HttpSession session) { ModelAndView model = new ModelAndView(); LoginHandler handler;//from ww w.java2 s . c o m String userName = ""; handler = new LoginHandler(); userName = (String) session.getAttribute("USERNAME"); handler.updateLoggedInFlag(userName, 0); session.invalidate(); model.setViewName("logout"); return model; }
From source file:com.sundevils.web.controller.TopController.java
@RequestMapping(value = "/forgotusername", method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView forgotUserName(HttpServletRequest request, HttpSession session) { ModelAndView model = new ModelAndView(); LoginHandler handler = new LoginHandler(); String userName = (String) session.getAttribute("USERNAME"); if (userName != null) { handler.updateLoggedInFlag(userName, 0); session.invalidate(); model.setViewName("index"); return model; }// w w w .jav a 2 s .co m model.setViewName("forgotusername"); return model; }
From source file:com.sundevils.web.controller.TopController.java
@RequestMapping(value = "/forgotpassword", method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView forgotPassword(HttpServletRequest request, HttpSession session) { ModelAndView model = new ModelAndView(); LoginHandler handler = new LoginHandler(); String userName = (String) session.getAttribute("USERNAME"); if (userName != null) { handler.updateLoggedInFlag(userName, 0); session.invalidate(); model.setViewName("index"); return model; }//from ww w . jav a 2 s . c om model.setViewName("forgotpassword"); return model; }
From source file:com.haulmont.cuba.web.security.idp.BaseIdpSessionFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // send static files without authentication HttpServletRequest httpRequest = (HttpServletRequest) request; if (StringUtils.startsWith(httpRequest.getRequestURI(), httpRequest.getContextPath() + "/VAADIN/")) { chain.doFilter(request, response); return;/*from w w w . java 2 s. co m*/ } HttpServletResponse httpResponse = (HttpServletResponse) response; String idpBaseURL = webIdpConfig.getIdpBaseURL(); if (Strings.isNullOrEmpty(idpBaseURL)) { log.error("Application property cuba.web.idp.url is not set"); httpResponse.setStatus(500); return; } if (!idpBaseURL.endsWith("/")) { idpBaseURL += "/"; } String requestUrl = httpRequest.getRequestURL().toString(); if (StringUtils.startsWith(requestUrl, idpBaseURL)) { chain.doFilter(httpRequest, response); return; } HttpSession session = httpRequest.getSession(true); Lock sessionLock = (Lock) session.getAttribute(IDP_SESSION_LOCK_ATTRIBUTE); if (sessionLock == null) { sessionCheckLock.lock(); try { sessionLock = (Lock) session.getAttribute(IDP_SESSION_LOCK_ATTRIBUTE); if (sessionLock == null) { sessionLock = new ReentrantLock(); session.setAttribute(IDP_SESSION_LOCK_ATTRIBUTE, sessionLock); } } finally { sessionCheckLock.unlock(); } } IdpSession boundIdpSession; sessionLock.lock(); try { session.getAttribute(IDP_SESSION_LOCK_ATTRIBUTE); } catch (IllegalStateException e) { // Someone might have invalidated the session between fetching the lock and acquiring it. sessionLock.unlock(); log.debug("Invalidated session {}", session.getId()); httpResponse.sendRedirect(httpRequest.getRequestURL().toString()); return; } try { if ("GET".equals(httpRequest.getMethod()) && httpRequest.getParameter(IDP_TICKET_REQUEST_PARAM) != null) { String idpTicket = httpRequest.getParameter(IDP_TICKET_REQUEST_PARAM); IdpSession idpSession; try { idpSession = getIdpSession(idpTicket); } catch (IdpActivationException e) { log.error("Unable to obtain IDP session by ticket", e); httpResponse.setStatus(500); return; } if (idpSession == null) { log.warn("Used old IDP ticket {}, send redirect", idpTicket); // used old ticket, send redirect httpResponse.sendRedirect(getIdpRedirectUrl()); return; } session.invalidate(); session = httpRequest.getSession(true); session.setAttribute(IDP_SESSION_LOCK_ATTRIBUTE, sessionLock); session.setAttribute(IDP_SESSION_ATTRIBUTE, idpSession); log.debug("IDP session {} obtained, redirect to application", idpSession); // redirect to application without parameters httpResponse.sendRedirect(httpRequest.getRequestURL().toString()); return; } if (session.getAttribute(IDP_SESSION_ATTRIBUTE) == null) { if ("GET".equals(httpRequest.getMethod()) && !StringUtils.startsWith(httpRequest.getRequestURI(), httpRequest.getContextPath() + "/PUSH")) { httpResponse.sendRedirect(getIdpRedirectUrl()); } return; } boundIdpSession = (IdpSession) session.getAttribute(IDP_SESSION_ATTRIBUTE); } finally { sessionLock.unlock(); } HttpServletRequest authenticatedRequest = new IdpServletRequestWrapper(httpRequest, new IdpSessionPrincipalImpl(boundIdpSession)); chain.doFilter(authenticatedRequest, response); }
From source file:org.josso.wls10.agent.WLSSessionEnforcementServletFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest hreq = (HttpServletRequest) request; HttpServletResponse hres = (HttpServletResponse) response; HttpSession session = hreq.getSession(true); if (log.isDebugEnabled()) log.debug("Processing : " + hreq.getContextPath()); String contextPath = hreq.getContextPath(); String vhost = hreq.getServerName(); SSOPartnerAppConfig cfg = _agent.getPartnerAppConfig(vhost, contextPath); // ------------------------------------------------------------------ // Check for the single sign on cookie // ------------------------------------------------------------------ if (log.isDebugEnabled()) log.debug("Checking for SSO cookie"); Cookie cookie = null;//from ww w .ja v a2 s . c o m Cookie cookies[] = hreq.getCookies(); if (cookies == null) cookies = new Cookie[0]; for (int i = 0; i < cookies.length; i++) { if (org.josso.gateway.Constants.JOSSO_SINGLE_SIGN_ON_COOKIE.equals(cookies[i].getName())) { cookie = cookies[i]; break; } } if (cookie != null && !cookie.getValue().equals("-")) { String jossoSessionId = cookie.getValue(); if (log.isDebugEnabled()) log.debug("asserting SSO session for : " + jossoSessionId); SSOAgentRequest sessionAssertionRequest; sessionAssertionRequest = doMakeSSOAgentRequest(cfg.getId(), SSOAgentRequest.ACTION_ASSERT_SESSION, jossoSessionId, null, null, hreq, hres); // TODO: Agents should be able to pass back responses corresponding to the submitted request. try { _agent.processRequest(sessionAssertionRequest); if (log.isDebugEnabled()) log.debug("asserted successfully SSO session for : " + jossoSessionId); } catch (FatalSSOSessionException e) { if (log.isDebugEnabled()) log.debug("error asserting SSO session : " + jossoSessionId); String requestedResourceUrl; // Clear previous COOKIE ... Cookie ssoCookie = _agent.newJossoCookie(hreq.getContextPath(), "-", hreq.isSecure()); hres.addCookie(ssoCookie); session.invalidate(); requestedResourceUrl = _agent.buildBackToURL(hreq, ""); hres.sendRedirect(hres.encodeRedirectURL(requestedResourceUrl)); return; } } filterChain.doFilter(hreq, hres); }
From source file:org.josso.wls92.agent.WLSSessionEnforcementServletFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest hreq = (HttpServletRequest) request; HttpServletResponse hres = (HttpServletResponse) response; HttpSession session = hreq.getSession(true); if (log.isDebugEnabled()) log.debug("Processing : " + hreq.getContextPath()); String contextPath = hreq.getContextPath(); String vhost = hreq.getServerName(); SSOPartnerAppConfig cfg = _agent.getPartnerAppConfig(vhost, contextPath); // ------------------------------------------------------------------ // Check for the single sign on cookie // ------------------------------------------------------------------ if (log.isDebugEnabled()) log.debug("Checking for SSO cookie"); Cookie cookie = null;/* w w w. j a v a 2 s . c o m*/ Cookie cookies[] = hreq.getCookies(); if (cookies == null) cookies = new Cookie[0]; for (int i = 0; i < cookies.length; i++) { if (org.josso.gateway.Constants.JOSSO_SINGLE_SIGN_ON_COOKIE.equals(cookies[i].getName())) { cookie = cookies[i]; break; } } if (cookie != null && !cookie.getValue().equals("-")) { String jossoSessionId = cookie.getValue(); if (log.isDebugEnabled()) log.debug("asserting SSO session for : " + jossoSessionId); SSOAgentRequest sessionAssertionRequest; sessionAssertionRequest = doMakeSSOAgentRequest(cfg.getId(), SSOAgentRequest.ACTION_ASSERT_SESSION, jossoSessionId, null, null, hreq, hres); // TODO: Agents should be able to pass back responses corresponding to the submitted request. try { _agent.processRequest(sessionAssertionRequest); if (log.isDebugEnabled()) log.debug("asserted successfully SSO session for : " + jossoSessionId); } catch (FatalSSOSessionException e) { if (log.isDebugEnabled()) log.debug("error asserting SSO session : " + jossoSessionId); String requestedResourceUrl; // Clear previous COOKIE ... Cookie ssoCookie = _agent.newJossoCookie(hreq.getContextPath(), "-", hreq.isSecure()); hres.addCookie(ssoCookie); session.invalidate(); requestedResourceUrl = _agent.buildBackToURL(hreq, ""); hres.sendRedirect(hres.encodeRedirectURL(requestedResourceUrl)); return; } } filterChain.doFilter(hreq, hres); }
From source file:authorize.java
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Logger logger = LogManager.getLogger(authorize.class); logger.trace("START"); PrintWriter out = response.getWriter(); Connection conn = null;/*from www. ja v a2s. c o m*/ Statement stmt = null; ResultSet rs = null; HttpSession session = request.getSession(false); String response_type = request.getParameter("response_type"); String username = request.getParameter("username"); String password = request.getParameter("password"); String prompt = request.getParameter("prompt"); String login_hint = request.getParameter("login_hint"); String max_age = request.getParameter("max_age"); String client_id = request.getParameter("client_id"); String redirect_uri = request.getParameter("redirect_uri"); String scope = request.getParameter("scope"); String state = request.getParameter("state"); String nonce = request.getParameter("nonce"); String consent = request.getParameter("consent"); String client_scope = null; String access_token = null; String id_token = null; String passwd = null; String db_redirect_uri = null; String path = null; String sql = null; String uri = null; String issuer = null; String keyname = null; String kit = "public.key"; boolean redirect_uri_check = true; int access_token_time = 60; if (scope == null) { scope = "openid"; } else if (scope.equals("consent")) { scope = null; if (null != request.getParameter("openid")) { scope = "openid"; if (null != request.getParameter("profile")) scope += " profile"; if (null != request.getParameter("email")) scope += " email"; if (null != request.getParameter("phone")) scope += " phone"; if (null != request.getParameter("address")) scope += " address"; } } logger.trace(scope); if (prompt != null && prompt.contains("login") && consent == null && session != null) session.invalidate(); try { ServletContext context = this.getServletContext(); path = context.getRealPath("/WEB-INF/oauth2"); Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); conn = DriverManager.getConnection("jdbc:derby:" + path); stmt = conn.createStatement(); logger.trace("connect()"); sql = "SELECT scope,redirect_uri FROM client WHERE client_id='" + client_id + "'"; rs = stmt.executeQuery(sql); while (rs.next()) { client_scope = rs.getString("scope"); db_redirect_uri = rs.getString("redirect_uri"); } logger.trace(sql); if (redirect_uri == null) redirect_uri = db_redirect_uri; sql = "SELECT passwd FROM profile WHERE uid='" + username + "'"; rs = stmt.executeQuery(sql); while (rs.next()) { passwd = rs.getString("passwd"); } logger.trace(sql); path = context.getRealPath("/WEB-INF/config.json"); InputStream input = new FileInputStream(path); JsonParser parser = Json.createParser(input); while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch (event) { case KEY_NAME: keyname = parser.getString(); break; case VALUE_NUMBER: access_token_time = parser.getInt(); break; case VALUE_TRUE: redirect_uri_check = true; break; case VALUE_FALSE: redirect_uri_check = false; break; case VALUE_STRING: if (keyname.equals("issuer")) issuer = parser.getString(); if (keyname.equals("kit")) kit = parser.getString(); break; default: break; } } java.util.Date dt = new java.util.Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTime = sdf.format(dt); if (client_scope != null && passwd != null) { byte[] cipher_byte; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(password.getBytes()); cipher_byte = md.digest(); String sha256_password = Base64.getEncoder().withoutPadding().encodeToString(cipher_byte); StringTokenizer strToken = new StringTokenizer(scope, " "); while (strToken.hasMoreTokens()) { String token = strToken.nextToken().toString(); logger.trace(token); if (!client_scope.contains(token)) throw new Exception("out of scope"); } if (passwd.contains(sha256_password) && (!redirect_uri_check || db_redirect_uri.equals(redirect_uri))) { if (prompt != null && prompt.contains("consent") && !consent.equals("false")) { username = "null"; password = "null"; consent = "true"; throw new Exception("consent is true"); } access_token = RandomStringUtils.randomAlphanumeric(32); logger.trace(access_token); sql = "insert into session(uid,access_token,issued_in,scope,client_id) values ('" + username + "','" + access_token + "','" + currentTime + "','" + scope + "','" + client_id + "')"; stmt.executeUpdate(sql); md.update(access_token.getBytes()); cipher_byte = md.digest(); byte[] half_cipher_byte = Arrays.copyOf(cipher_byte, (cipher_byte.length / 2)); String at_hash = Base64.getEncoder().withoutPadding().encodeToString(half_cipher_byte); path = context.getRealPath("/WEB-INF/private.der"); File filePrivateKey = new File(path); FileInputStream fis = new FileInputStream(path); byte[] encodedPrivateKey = new byte[(int) filePrivateKey.length()]; fis.read(encodedPrivateKey); fis.close(); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedPrivateKey); PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec); Calendar exp = Calendar.getInstance(); exp.add(Calendar.SECOND, access_token_time); if (nonce == null || nonce.equals("null")) { if (response_type.contains("id_token")) { uri = redirect_uri; uri += "#error=invalid_request&error_description=nonce%20is%20not%20valid."; response.sendRedirect(uri); logger.info(uri); return; } } else { id_token = Jwts.builder().setHeaderParam("alg", "RS256").setHeaderParam("typ", "JWT") .setHeaderParam("kid", kit).setIssuer(issuer).claim("at_hash", at_hash) .setSubject(username).setAudience(client_id).claim("nonce", nonce) .setSubject(username).setExpiration(exp.getTime()) .setIssuedAt(Calendar.getInstance().getTime()) .claim("auth_time", String.valueOf(Calendar.getInstance().getTime().getTime()).substring(0, 10)) .signWith(SignatureAlgorithm.RS256, privateKey).compact(); logger.trace(id_token); } uri = redirect_uri; if (response_type.equals("token")) uri += "#access_token=" + access_token + "&token_type=bearer&expires_in=" + access_token_time; if (response_type.equals("id_token")) uri += "#id_token=" + id_token; if (response_type.equals("token id_token") || response_type.equals("id_token token")) uri += "#access_token=" + access_token + "&token_type=bearer&expires_in=" + access_token_time + "&id_token=" + id_token; if (state != null && !state.equals("null")) uri += "&state=" + state; response.sendRedirect(uri); logger.info(uri); return; } } } catch (Exception e) { logger.trace(e.getMessage()); } finally { try { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (conn != null) conn.close(); logger.trace("close()"); } catch (SQLException e) { logger.trace(e.getMessage()); } } if (redirect_uri != null || redirect_uri.equals("null")) uri = redirect_uri; else uri = "/myop/error"; if (username != null && !username.equals("null") && password != null && !password.equals("null")) { uri += "#error=access_denied&error_description=User%20authentication%20failed."; session = request.getSession(false); if (session != null) session.invalidate(); } else if (scope == null) { uri += "#error=invalid_scope&error_description=The%20scope%20value%20is%20not%20supported."; } else if (client_scope == null || client_scope.equals("null")) { uri += "#error=unauthorized_clienti&error_description=Client%20authentication%20failed."; } else if (response_type == null || response_type.equals("null") || !(response_type.equals("token") || response_type.equals("id_token") || response_type.equals("token id_token") || response_type.equals("id_token token"))) { uri += "#error=unsupported_response_type&error_description==The%20response_type%20value%20%22" + response_type + "%22%20is%20not%20supported."; } else if (redirect_uri_check && !db_redirect_uri.equals(redirect_uri)) { uri += "#error=invalid_request&error_description=redirect_uri%20is%20not%20valid."; } else { uri = "/myop/login?response_type=" + URLEncoder.encode(response_type, "UTF-8") + "&client_id=" + client_id + "&redirect_uri=" + URLEncoder.encode(redirect_uri, "UTF-8") + "&scope=" + URLEncoder.encode(scope, "UTF-8"); if (nonce != null && !nonce.equals("null")) uri += "&nonce=" + nonce; if (prompt != null && !prompt.equals("null")) uri += "&prompt=" + prompt; if (login_hint != null && !login_hint.equals("null")) uri += "&login_hint=" + login_hint; if (max_age != null && !max_age.equals("null")) uri += "&max_age=" + max_age; if (consent != null && consent.equals("true")) uri += "&consent=" + consent; } if (state != null && !state.equals("null")) uri += "&state=" + state; response.sendRedirect(uri); logger.info(uri); logger.trace("END"); }
From source file:org.kuali.continuity.security.KualiAuthenticationProcessingFilterEntryPoint.java
protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { String loginForm;/*w w w. j av a 2 s . c om*/ HttpSession session = request.getSession(false); if (session.getAttribute(SecurityEnum.DIRECT_LOGIN_CUSTOM_URL.toString()) != null) { loginForm = this.getLoginFormUrl() + session.getAttribute(SecurityEnum.DIRECT_LOGIN_CUSTOM_URL.toString()); } else if ((session.getAttribute(SecurityEnum.SHIBBOLETH_LOGIN_IDP_ID.toString()) != null && session.getAttribute(SecurityEnum.SHIBBOLETH_LOGIN_CUSTOM_URL.toString()) != null) && (!"".equals(session.getAttribute(SecurityEnum.SHIBBOLETH_LOGIN_IDP_ID.toString())) && !"".equals(session.getAttribute(SecurityEnum.SHIBBOLETH_LOGIN_CUSTOM_URL.toString())))) { return this.inCommonMetadataService.getLoginUrl( (String) session.getAttribute(SecurityEnum.SHIBBOLETH_LOGIN_IDP_ID.toString()), (String) session.getAttribute(SecurityEnum.SHIBBOLETH_LOGIN_CUSTOM_URL.toString())); } else { //Direct login String customUrl = SecurityUtil.getCookieValue(request.getCookies(), SecurityEnum.KUALI_DIRECTLOGIN_COOKIE_KEY.toString()); String shibbolethIdp = SecurityUtil.getCookieValue(request.getCookies(), SecurityEnum.SHIBBOLETH_LOGIN_IDP_ID.toString()); String shibbolethCustomUrl = SecurityUtil.getCookieValue(request.getCookies(), SecurityEnum.SHIBBOLETH_LOGIN_CUSTOM_URL.toString()); //System.out.println(" Session timed out. customUrl is: " + customUrl + " shibbolethIdp is: " + shibbolethIdp); if (customUrl == null && (shibbolethIdp == null || shibbolethCustomUrl == null)) { //Client cleared all cookies loginForm = this.getLogoutUrl() + "?error=" + "3"; } else if (customUrl != null && (shibbolethIdp == null || shibbolethCustomUrl == null)) { //Direct Login loginForm = this.getLoginFormUrl() + customUrl; } else if (customUrl == null && (shibbolethIdp != null && shibbolethCustomUrl != null)) { //Shibboleth Login //Invalidate the session //TODO: Session problem. Have to test this..!!!!! if (session != null) { session.invalidate(); } return this.inCommonMetadataService.getLoginUrl(shibbolethIdp, shibbolethCustomUrl); } else { loginForm = this.getLoginFormUrl(); } } int serverPort = portResolver.getServerPort(request); String scheme = request.getScheme(); RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme(scheme); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(serverPort); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setPathInfo(loginForm); if (forceHttps && "http".equals(scheme)) { Integer httpsPort = portMapper.lookupHttpsPort(new Integer(serverPort)); if (httpsPort != null) { // Overwrite scheme and port in the redirect URL urlBuilder.setScheme("https"); urlBuilder.setPort(httpsPort.intValue()); } else { logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); } } return urlBuilder.getUrl(); }