List of usage examples for javax.servlet.http HttpSession getAttributeNames
public Enumeration<String> getAttributeNames();
Enumeration
of String
objects containing the names of all the objects bound to this session. From source file:org.alfresco.web.site.servlet.SSOAuthenticationFilter.java
/** * Removes all attributes stored in session * // ww w . j ava 2s.com * @param session Session */ @SuppressWarnings("unchecked") private void clearSession(HttpSession session) { if (logger.isDebugEnabled()) logger.debug("Clearing the session."); Enumeration<String> names = (Enumeration<String>) session.getAttributeNames(); while (names.hasMoreElements()) { session.removeAttribute(names.nextElement()); } }
From source file:org.terasoluna.gfw.web.token.transaction.HttpSessionTransactionTokenStoreTest.java
/** * create a new Token key (stored token is as it is the same as sizePerTokenName) *///w w w .ja v a 2s .c om @Test public void testCreateAndReserveTokenKey_storedToken_is_as_same_as_sizePerTokenName() throws InterruptedException { // prepare store instance store = new HttpSessionTransactionTokenStore(4, 4); // setup parameters HttpSession session = new MockHttpSession(); request.setSession(session); TransactionToken tokenA = new TransactionToken("tokenName", "tokenKeyA", "tokenValueA"); store.store(tokenA); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenB = new TransactionToken("tokenName", "tokenKeyB", "tokenValueB"); store.store(tokenB); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenC = new TransactionToken("tokenName", "tokenKeyC", "tokenValueC"); store.store(tokenC); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenD = new TransactionToken("tokenName", "tokenKeyD", "tokenValueD"); store.store(tokenD); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token1 = new TransactionToken("tokenName1", "tokenKey1", "tokenValue1"); store.store(token1); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token2 = new TransactionToken("tokenName2", "tokenKey2", "tokenValue2"); store.store(token2); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token3 = new TransactionToken("tokenName3", "tokenKey3", "tokenValue3"); store.store(token3); // run String actual = store.createAndReserveTokenKey(tokenA.getTokenName()); Enumeration<String> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); } // String expected = ""; // assert assertNotNull(actual); assertThat(session.getAttribute(store.createSessionAttributeName(tokenA)), is(nullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(tokenB)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(tokenC)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(tokenD)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token1)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token2)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token3)), is(notNullValue())); }
From source file:org.apache.tapestry.request.RequestContext.java
/** * Writes the state of the context to the writer, typically for inclusion * in a HTML page returned to the user. This is useful * when debugging. The Inspector uses this as well. * **//*from w ww . j a va2s .c o m*/ public void write(IMarkupWriter writer) { // Create a box around all of this stuff ... writer.begin("table"); writer.attribute("class", "request-context-border"); writer.begin("tr"); writer.begin("td"); // Get the session, if it exists, and display it. HttpSession session = getSession(); if (session != null) { object(writer, "Session"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "id", session.getId()); datePair(writer, "creationTime", session.getCreationTime()); datePair(writer, "lastAccessedTime", session.getLastAccessedTime()); pair(writer, "maxInactiveInterval", session.getMaxInactiveInterval()); pair(writer, "new", session.isNew()); List names = getSorted(session.getAttributeNames()); int count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, session.getAttribute(name)); } writer.end(); // Session } object(writer, "Request"); writer.begin("table"); writer.attribute("class", "request-context-object"); // Parameters ... List parameters = getSorted(_request.getParameterNames()); int count = parameters.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Parameters"); header(writer, "Name", "Value(s)"); } String name = (String) parameters.get(i); String[] values = _request.getParameterValues(name); writer.begin("tr"); writer.attribute("class", getRowClass()); writer.begin("th"); writer.print(name); writer.end(); writer.begin("td"); if (values.length > 1) writer.begin("ul"); for (int j = 0; j < values.length; j++) { if (values.length > 1) writer.beginEmpty("li"); writer.print(values[j]); } writer.end("tr"); } section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "authType", _request.getAuthType()); pair(writer, "characterEncoding", _request.getCharacterEncoding()); pair(writer, "contentLength", _request.getContentLength()); pair(writer, "contentType", _request.getContentType()); pair(writer, "method", _request.getMethod()); pair(writer, "pathInfo", _request.getPathInfo()); pair(writer, "pathTranslated", _request.getPathTranslated()); pair(writer, "protocol", _request.getProtocol()); pair(writer, "queryString", _request.getQueryString()); pair(writer, "remoteAddr", _request.getRemoteAddr()); pair(writer, "remoteHost", _request.getRemoteHost()); pair(writer, "remoteUser", _request.getRemoteUser()); pair(writer, "requestedSessionId", _request.getRequestedSessionId()); pair(writer, "requestedSessionIdFromCookie", _request.isRequestedSessionIdFromCookie()); pair(writer, "requestedSessionIdFromURL", _request.isRequestedSessionIdFromURL()); pair(writer, "requestedSessionIdValid", _request.isRequestedSessionIdValid()); pair(writer, "requestURI", _request.getRequestURI()); pair(writer, "scheme", _request.getScheme()); pair(writer, "serverName", _request.getServerName()); pair(writer, "serverPort", _request.getServerPort()); pair(writer, "contextPath", _request.getContextPath()); pair(writer, "servletPath", _request.getServletPath()); // Now deal with any headers List headers = getSorted(_request.getHeaderNames()); count = headers.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Headers"); header(writer, "Name", "Value"); } String name = (String) headers.get(i); String value = _request.getHeader(name); pair(writer, name, value); } // Attributes List attributes = getSorted(_request.getAttributeNames()); count = attributes.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) attributes.get(i); pair(writer, name, _request.getAttribute(name)); } // Cookies ... Cookie[] cookies = _request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (i == 0) { section(writer, "Cookies"); header(writer, "Name", "Value"); } Cookie cookie = cookies[i]; pair(writer, cookie.getName(), cookie.getValue()); } // Cookies loop } writer.end(); // Request object(writer, "Servlet"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "servlet", _servlet); pair(writer, "name", _servlet.getServletName()); pair(writer, "servletInfo", _servlet.getServletInfo()); ServletConfig config = _servlet.getServletConfig(); List names = getSorted(config.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Init Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); ; pair(writer, name, config.getInitParameter(name)); } writer.end(); // Servlet ServletContext context = config.getServletContext(); object(writer, "Servlet Context"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "majorVersion", context.getMajorVersion()); pair(writer, "minorVersion", context.getMinorVersion()); pair(writer, "serverInfo", context.getServerInfo()); names = getSorted(context.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Initial Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getInitParameter(name)); } names = getSorted(context.getAttributeNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getAttribute(name)); } writer.end(); // Servlet Context writeSystemProperties(writer); writer.end("table"); // The enclosing border }
From source file:com.jsmartframework.web.manager.BeanHandler.java
void finalizeBeans(HttpSession session) { synchronized (session) { List<String> names = Collections.list(session.getAttributeNames()); for (String name : names) { Object bean = session.getAttribute(name); if (bean == null) { continue; }// w w w.j a v a 2 s . c o m if (bean.getClass().isAnnotationPresent(WebBean.class)) { finalizeWebBean(bean, session); } else if (bean.getClass().isAnnotationPresent(AuthBean.class)) { finalizeAuthBean(bean, session); } } } }
From source file:org.sakaiproject.portal.util.ErrorReporter.java
@SuppressWarnings("rawtypes") private String requestDisplay(HttpServletRequest request) { ResourceBundle rb = rbDefault; StringBuilder sb = new StringBuilder(); try {/* w w w . j ava 2 s . c o m*/ sb.append(rb.getString("bugreport.request")).append("\n"); sb.append(rb.getString("bugreport.request.authtype")).append(request.getAuthType()).append("\n"); sb.append(rb.getString("bugreport.request.charencoding")).append(request.getCharacterEncoding()) .append("\n"); sb.append(rb.getString("bugreport.request.contentlength")).append(request.getContentLength()) .append("\n"); sb.append(rb.getString("bugreport.request.contenttype")).append(request.getContentType()).append("\n"); sb.append(rb.getString("bugreport.request.contextpath")).append(request.getContextPath()).append("\n"); sb.append(rb.getString("bugreport.request.localaddr")).append(request.getLocalAddr()).append("\n"); sb.append(rb.getString("bugreport.request.localname")).append(request.getLocalName()).append("\n"); sb.append(rb.getString("bugreport.request.localport")).append(request.getLocalPort()).append("\n"); sb.append(rb.getString("bugreport.request.method")).append(request.getMethod()).append("\n"); sb.append(rb.getString("bugreport.request.pathinfo")).append(request.getPathInfo()).append("\n"); sb.append(rb.getString("bugreport.request.protocol")).append(request.getProtocol()).append("\n"); sb.append(rb.getString("bugreport.request.querystring")).append(request.getQueryString()).append("\n"); sb.append(rb.getString("bugreport.request.remoteaddr")).append(request.getRemoteAddr()).append("\n"); sb.append(rb.getString("bugreport.request.remotehost")).append(request.getRemoteHost()).append("\n"); sb.append(rb.getString("bugreport.request.remoteport")).append(request.getRemotePort()).append("\n"); sb.append(rb.getString("bugreport.request.requesturl")).append(request.getRequestURL()).append("\n"); sb.append(rb.getString("bugreport.request.scheme")).append(request.getScheme()).append("\n"); sb.append(rb.getString("bugreport.request.servername")).append(request.getServerName()).append("\n"); sb.append(rb.getString("bugreport.request.headers")).append("\n"); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String headerName = (String) e.nextElement(); boolean censor = (censoredHeaders.get(headerName) != null); for (Enumeration he = request.getHeaders(headerName); he.hasMoreElements();) { String headerValue = (String) he.nextElement(); sb.append(rb.getString("bugreport.request.header")).append(headerName).append(":") .append(censor ? "---censored---" : headerValue).append("\n"); } } sb.append(rb.getString("bugreport.request.parameters")).append("\n"); for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); boolean censor = (censoredParameters.get(parameterName) != null); String[] paramvalues = request.getParameterValues(parameterName); for (int i = 0; i < paramvalues.length; i++) { sb.append(rb.getString("bugreport.request.parameter")).append(parameterName).append(":") .append(i).append(":").append(censor ? "----censored----" : paramvalues[i]) .append("\n"); } } sb.append(rb.getString("bugreport.request.attributes")).append("\n"); for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) { String attributeName = (String) e.nextElement(); Object attribute = request.getAttribute(attributeName); boolean censor = (censoredAttributes.get(attributeName) != null); sb.append(rb.getString("bugreport.request.attribute")).append(attributeName).append(":") .append(censor ? "----censored----" : attribute).append("\n"); } HttpSession session = request.getSession(false); if (session != null) { DateFormat serverLocaleDateFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault()); sb.append(rb.getString("bugreport.session")).append("\n"); sb.append(rb.getString("bugreport.session.creation")).append(session.getCreationTime()) .append("\n"); sb.append(rb.getString("bugreport.session.lastaccess")).append(session.getLastAccessedTime()) .append("\n"); sb.append(rb.getString("bugreport.session.creationdatetime")) .append(serverLocaleDateFormat.format(session.getCreationTime())).append("\n"); sb.append(rb.getString("bugreport.session.lastaccessdatetime")) .append(serverLocaleDateFormat.format(session.getLastAccessedTime())).append("\n"); sb.append(rb.getString("bugreport.session.maxinactive")).append(session.getMaxInactiveInterval()) .append("\n"); sb.append(rb.getString("bugreport.session.attributes")).append("\n"); for (Enumeration e = session.getAttributeNames(); e.hasMoreElements();) { String attributeName = (String) e.nextElement(); Object attribute = session.getAttribute(attributeName); boolean censor = (censoredAttributes.get(attributeName) != null); sb.append(rb.getString("bugreport.session.attribute")).append(attributeName).append(":") .append(censor ? "----censored----" : attribute).append("\n"); } } } catch (Exception ex) { M_log.error("Failed to generate request display", ex); sb.append("Error " + ex.getMessage()); } return sb.toString(); }
From source file:org.terasoluna.gfw.web.token.transaction.HttpSessionTransactionTokenStoreTest.java
/** * create a new Token key (stored token is as it is the same as sizePerTokenName) *///from w ww. j a v a 2 s . co m @Test public void testCreateAndReserveTokenKey_storedToken_is_greater_than_sizePerTokenName() throws InterruptedException { // prepare store instance store = new HttpSessionTransactionTokenStore(4, 4); // setup parameters HttpSession session = new MockHttpSession(); request.setSession(session); TransactionToken tokenA = new TransactionToken("tokenName", "tokenKeyA", "tokenValueA"); store.store(tokenA); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenB = new TransactionToken("tokenName", "tokenKeyB", "tokenValueB"); store.store(tokenB); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenC = new TransactionToken("tokenName", "tokenKeyC", "tokenValueC"); store.store(tokenC); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenD = new TransactionToken("tokenName", "tokenKeyD", "tokenValueE"); store.store(tokenD); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenE = new TransactionToken("tokenName", "tokenKeyE", "tokenValueD"); store.store(tokenE); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token1 = new TransactionToken("tokenName1", "tokenKey1", "tokenValue1"); store.store(token1); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token2 = new TransactionToken("tokenName2", "tokenKey2", "tokenValue2"); store.store(token2); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token3 = new TransactionToken("tokenName3", "tokenKey3", "tokenValue3"); store.store(token3); // run String actual = store.createAndReserveTokenKey(tokenA.getTokenName()); Enumeration<String> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); } // String expected = ""; // assert assertNotNull(actual); assertThat(session.getAttribute(store.createSessionAttributeName(tokenA)), is(nullValue())); // check assertThat(session.getAttribute(store.createSessionAttributeName(tokenB)), is(nullValue())); // check assertThat(session.getAttribute(store.createSessionAttributeName(tokenC)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(tokenD)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(tokenE)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token1)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token2)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token3)), is(notNullValue())); }
From source file:ro.raisercostin.web.DebuggingFilter.java
public String debug(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, DebuggingPrinter debuggingPrinter, boolean debugAll, boolean debugRequest) { final JspFactory jspFactory = JspFactory.getDefaultFactory(); HttpSession session = request.getSession(); debuggingPrinter.addHeader();//from www . j a v a2 s . com debuggingPrinter.addSection("Request Parameters"); for (Iterator iterator = request.getParameterMap().entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> parameter = (Map.Entry<String, Object>) iterator.next(); addRow(debuggingPrinter, parameter.getKey(), StringUtils.arrayToCommaDelimitedString((Object[]) parameter.getValue())); } debuggingPrinter.endSection(); if (debugRequest) { debuggingPrinter.addSection("Request Header"); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(request.getHeader(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Attributes"); java.util.Enumeration en = request.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(request.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Session Attributes"); en = session.getAttributeNames(); while (en.hasMoreElements()) { String attrName = (String) en.nextElement(); try { addRow(debuggingPrinter, split(attrName, 50), toString2(session.getAttribute(attrName), 120)); } catch (Exception e) { addRow(debuggingPrinter, split(attrName, 50), toString(e, 120)); } } debuggingPrinter.endSection(); debuggingPrinter.addSection("Request Info"); addRow(debuggingPrinter, "AuthType", request.getAuthType()); addRow(debuggingPrinter, "ContextPath", request.getContextPath()); addRow(debuggingPrinter, "Method", request.getMethod()); addRow(debuggingPrinter, "PathInfo", request.getPathInfo()); addRow(debuggingPrinter, "PathTranslated", request.getPathTranslated()); addRow(debuggingPrinter, "Protocol", request.getProtocol()); addRow(debuggingPrinter, "QueryString", request.getQueryString()); addRow(debuggingPrinter, "RemoteAddr", request.getRemoteAddr()); addRow(debuggingPrinter, "RemoteUser", request.getRemoteUser()); addRow(debuggingPrinter, "RequestedSessionId", request.getRequestedSessionId()); addRow(debuggingPrinter, "RequestURI", request.getRequestURI()); addRow(debuggingPrinter, "RequestURL", request.getRequestURL().toString()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); addRow(debuggingPrinter, "Scheme", request.getScheme()); addRow(debuggingPrinter, "ServletPath", request.getServletPath()); } if (debugAll) { debuggingPrinter.addSection("Server"); addRow(debuggingPrinter, "Server Info", servletContext.getServerInfo()); addRow(debuggingPrinter, "Servlet Engine Version", servletContext.getMajorVersion() + "." + servletContext.getMinorVersion()); addRow(debuggingPrinter, "JSP Version", jspFactory.getEngineInfo().getSpecificationVersion()); debuggingPrinter.endSection(); debuggingPrinter.addSection("JVM Properties"); for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements();) { String parameterName = (String) e.nextElement(); addRow(debuggingPrinter, parameterName, debuggingPrinter.transform(System.getProperty(parameterName))); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Environment"); for (Map.Entry<String, String> property : System.getenv().entrySet()) { addRow(debuggingPrinter, property.getKey(), debuggingPrinter.transform(property.getValue())); } debuggingPrinter.endSection(); debuggingPrinter.addSection("Debugger Provided by"); addRow(debuggingPrinter, "provided by", "raisercostin"); debuggingPrinter.addRow("source", "<a target='_blank' href='http://code.google.com/p/raisercostin/wiki/DebuggingFilter'>http://code.google.com/p/raisercostin/wiki/DebuggingFilter</a>"); addRow(debuggingPrinter, "version", "1.0"); addRow(debuggingPrinter, "timestamp", "2008.June.14"); addRow(debuggingPrinter, "license", "<a target='_blank' href='http://www.apache.org/licenses/LICENSE-2.0.html'>Apache License 2.0</a>"); debuggingPrinter.endSection(); } debuggingPrinter.addFooter(); return debuggingPrinter.getString(); }
From source file:org.terasoluna.gfw.web.token.transaction.HttpSessionTransactionTokenStoreTest.java
/** * create a new Token key (stored token is as it is the same as sizePerTokenName) */// w w w .ja v a 2 s.com @Test public void testCreateAndReserveTokenKey_storedToken_is_greater_than_sizePerTokenName2() throws InterruptedException { // prepare store instance store = new HttpSessionTransactionTokenStore(4, 4); // setup parameters HttpSession session = new MockHttpSession(); request.setSession(session); TransactionToken tokenA = new TransactionToken("tokenName", "tokenKeyA", "tokenValueA"); store.store(tokenA); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenB = new TransactionToken("tokenName", "tokenKeyB", "tokenValueB"); store.store(tokenB); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenC = new TransactionToken("tokenName", "tokenKeyC", "tokenValueC"); store.store(tokenC); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenD = new TransactionToken("tokenName", "tokenKeyD", "tokenValueD"); store.store(tokenD); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenE = new TransactionToken("tokenName", "tokenKeyE", "tokenValueE"); store.store(tokenE); TimeUnit.MILLISECONDS.sleep(1); TransactionToken tokenF = new TransactionToken("tokenName", "tokenKeyF", "tokenValueF"); store.store(tokenF); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token1 = new TransactionToken("tokenName1", "tokenKey1", "tokenValue1"); store.store(token1); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token2 = new TransactionToken("tokenName2", "tokenKey2", "tokenValue2"); store.store(token2); TimeUnit.MILLISECONDS.sleep(1); TransactionToken token3 = new TransactionToken("tokenName3", "tokenKey3", "tokenValue3"); store.store(token3); // run String actual = store.createAndReserveTokenKey(tokenA.getTokenName()); Enumeration<String> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); } // String expected = ""; // assert assertNotNull(actual); assertThat(session.getAttribute(store.createSessionAttributeName(tokenA)), is(nullValue())); // check assertThat(session.getAttribute(store.createSessionAttributeName(tokenB)), is(nullValue())); // check assertThat(session.getAttribute(store.createSessionAttributeName(tokenC)), is(nullValue())); // check assertThat(session.getAttribute(store.createSessionAttributeName(tokenD)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(tokenE)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(tokenF)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token1)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token2)), is(notNullValue())); assertThat(session.getAttribute(store.createSessionAttributeName(token3)), is(notNullValue())); }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractAuthenticationController.java
@RequestMapping(value = { "/{userParam}/loggedout", "{userParam}/j_spring_security_logout" }) public String loggedout(@PathVariable String userParam, ModelMap map, HttpSession session, HttpServletResponse response, HttpServletRequest request) { logger.debug("###Entering in loggedout(response) method"); String showSuffixControl = "false"; String suffixControlType = "textbox"; List<String> suffixList = null; if (config.getValue(Names.com_citrix_cpbm_username_duplicate_allowed).equals("true")) { showSuffixControl = "true"; if (config.getValue(Names.com_citrix_cpbm_login_screen_tenant_suffix_dropdown_enabled).equals("true")) { suffixControlType = "dropdown"; suffixList = tenantService.getSuffixList(); }//from w w w. j a v a 2s.c om } map.addAttribute("showSuffixControl", showSuffixControl); map.addAttribute("suffixControlType", suffixControlType); map.addAttribute("suffixList", suffixList); if (config.getBooleanValue(Configuration.Names.com_citrix_cpbm_portal_directory_service_enabled) && config.getValue(Names.com_citrix_cpbm_directory_mode).equals("pull")) { map.addAttribute("directoryServiceAuthenticationEnabled", "true"); } if (config.getValue(Names.com_citrix_cpbm_public_catalog_display).equals("true") && channelService.getDefaultServiceProviderChannel() != null) { map.addAttribute("showAnonymousCatalogBrowsing", "true"); } map.addAttribute("showLanguageSelection", "true"); map.addAttribute("supportedLocaleList", this.getLocaleDisplayName(listSupportedLocales())); map.addAttribute("logout", true); String redirect = null; Enumeration<String> en = session.getAttributeNames(); while (en.hasMoreElements()) { String attr = en.nextElement(); session.removeAttribute(attr); } Cookie cookie = new Cookie("JforumSSO", ""); cookie.setMaxAge(0); cookie.setPath("/"); response.addCookie(cookie); if (request.getRequestedSessionId() != null && request.isRequestedSessionIdValid()) { // create logout notification begins User user = userService.get(userParam); String message = "logged.out"; String messageArgs = user.getUsername(); eventService.createEvent(new Date(), user, message, messageArgs, Source.PORTAL, Scope.USER, Category.ACCOUNT, Severity.INFORMATION, true); } session.invalidate(); if (config.getAuthenticationService().compareToIgnoreCase(CAS) == 0) { try { redirect = StringUtils.isEmpty(config.getCasLogoutUrl()) ? null : config.getCasLogoutUrl() + "?service=" + URLEncoder.encode(config.getCasServiceUrl(), "UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("Exception encoding: " + redirect, e); } if (redirect == null) { throw new InternalError("CAS authentication required, but login url not set"); } } SecurityContextHolder.getContext().setAuthentication(null); // ends logger.debug("###Exiting loggedout(response) method"); return redirect == null ? "redirect:/j_spring_security_logout" : "redirect:" + redirect; }
From source file:com.sammyun.controller.shop.LoginController.java
/** * ??// w w w .ja v a 2s .co m */ @RequestMapping(value = "/submit", method = RequestMethod.POST) public @ResponseBody Message submit(String captchaId, String captcha, String username, HttpServletRequest request, HttpServletResponse response, HttpSession session) { String password = rsaService.decryptParameter("enPassword", request); rsaService.removePrivateKey(request); if (!captchaService.isValid(CaptchaType.memberLogin, captchaId, captcha)) { return Message.error("shop.captcha.invalid"); } if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { return Message.error("shop.common.invalid"); } Member member; Setting setting = SettingUtils.get(); if (setting.getIsEmailLogin() && username.contains("@")) { List<Member> members = memberService.findListByEmail(username); if (members.isEmpty()) { member = null; } else if (members.size() == 1) { member = members.get(0); } else { return Message.error("shop.login.unsupportedAccount"); } } else { member = memberService.findByUsername(username); } if (member == null) { return Message.error("shop.login.unknownAccount"); } if (!member.getIsEnabled()) { return Message.error("shop.login.disabledAccount"); } checkLockedStatus(member, setting); if (!DigestUtils.md5Hex(password).equals(member.getPassword())) { int loginFailureCount = member.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { member.setIsLocked(true); member.setLockedDate(new Date()); } member.setLoginFailureCount(loginFailureCount); memberService.update(member); if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.member)) { return Message.error("shop.login.accountLockCount", setting.getAccountLockCount()); } else { return Message.error("shop.login.incorrectCredentials"); } } updateLoginStatus(request, member); Map<String, Object> attributes = new HashMap<String, Object>(); Enumeration<?> keys = session.getAttributeNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); attributes.put(key, session.getAttribute(key)); } session.invalidate(); session = request.getSession(); for (Entry<String, Object> entry : attributes.entrySet()) { session.setAttribute(entry.getKey(), entry.getValue()); } session.setAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME, new Principal(member.getId(), username)); WebUtils.addCookie(request, response, Member.USERNAME_COOKIE_NAME, member.getUsername()); return SUCCESS_MESSAGE; }