Spaces to tabs and license cleanup
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample
|
||||
|
||||
import geb.spock.*
|
||||
@@ -13,112 +28,112 @@ import pages.*
|
||||
*/
|
||||
@Stepwise
|
||||
class UserTests extends GebReportingSpec {
|
||||
def 'first visit not authenticated'() {
|
||||
when:
|
||||
to HomePage
|
||||
then:
|
||||
form
|
||||
!username
|
||||
}
|
||||
def 'first visit not authenticated'() {
|
||||
when:
|
||||
to HomePage
|
||||
then:
|
||||
form
|
||||
!username
|
||||
}
|
||||
|
||||
def 'invalid login'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
login(user, user+'invalid')
|
||||
then:
|
||||
!username
|
||||
error == 'Invalid username / password. Please ensure the username is the same as the password.'
|
||||
}
|
||||
def 'invalid login'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
login(user, user+'invalid')
|
||||
then:
|
||||
!username
|
||||
error == 'Invalid username / password. Please ensure the username is the same as the password.'
|
||||
}
|
||||
|
||||
def 'empty username'() {
|
||||
setup:
|
||||
def user = ''
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
!username
|
||||
error == 'Invalid username / password. Please ensure the username is the same as the password.'
|
||||
}
|
||||
def 'empty username'() {
|
||||
setup:
|
||||
def user = ''
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
!username
|
||||
error == 'Invalid username / password. Please ensure the username is the same as the password.'
|
||||
}
|
||||
|
||||
def 'login single user'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
def 'login single user'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'add account'() {
|
||||
when:
|
||||
addAccount.click(HomePage)
|
||||
then:
|
||||
form
|
||||
!username
|
||||
}
|
||||
def 'add account'() {
|
||||
when:
|
||||
addAccount.click(HomePage)
|
||||
then:
|
||||
form
|
||||
!username
|
||||
}
|
||||
|
||||
def 'log in second user'() {
|
||||
setup:
|
||||
def user = 'luke'
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
def 'log in second user'() {
|
||||
setup:
|
||||
def user = 'luke'
|
||||
when:
|
||||
login(user, user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'following links keeps new session'() {
|
||||
when:
|
||||
navLink.click(LinkPage)
|
||||
then:
|
||||
username == 'luke'
|
||||
}
|
||||
def 'following links keeps new session'() {
|
||||
when:
|
||||
navLink.click(LinkPage)
|
||||
then:
|
||||
username == 'luke'
|
||||
}
|
||||
|
||||
def 'switch account rob'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
def 'switch account rob'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'following links keeps original session'() {
|
||||
when:
|
||||
navLink.click(LinkPage)
|
||||
then:
|
||||
username == 'rob'
|
||||
}
|
||||
def 'following links keeps original session'() {
|
||||
when:
|
||||
navLink.click(LinkPage)
|
||||
then:
|
||||
username == 'rob'
|
||||
}
|
||||
|
||||
def 'switch account luke'() {
|
||||
setup:
|
||||
def user = 'luke'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
def 'switch account luke'() {
|
||||
setup:
|
||||
def user = 'luke'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'logout luke'() {
|
||||
when:
|
||||
logout.click(HomePage)
|
||||
then:
|
||||
!username
|
||||
}
|
||||
def 'logout luke'() {
|
||||
when:
|
||||
logout.click(HomePage)
|
||||
then:
|
||||
!username
|
||||
}
|
||||
|
||||
def 'switch back rob'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
def 'switch back rob'() {
|
||||
setup:
|
||||
def user = 'rob'
|
||||
when:
|
||||
switchAccount(user)
|
||||
then:
|
||||
username == user
|
||||
}
|
||||
|
||||
def 'logout rob'() {
|
||||
when:
|
||||
logout.click(HomePage)
|
||||
then:
|
||||
!username
|
||||
}
|
||||
def 'logout rob'() {
|
||||
when:
|
||||
logout.click(HomePage)
|
||||
then:
|
||||
!username
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.pages
|
||||
|
||||
import geb.*
|
||||
@@ -8,24 +23,24 @@ import geb.*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
class HomePage extends Page {
|
||||
static url = ''
|
||||
static at = { assert driver.title == 'Demonstrates Multi User Log In'; true}
|
||||
static content = {
|
||||
navLink { $('#navLink') }
|
||||
error { $('#error').text() }
|
||||
form { $('form') }
|
||||
username(required:false) { $('#un').text() }
|
||||
logout(required:false) { $('#logout') }
|
||||
addAccount(required:false) { $('#addAccount') }
|
||||
submit { $('input[type=submit]') }
|
||||
login(required:false) { user, pass ->
|
||||
form.username = user
|
||||
form.password = pass
|
||||
submit.click(HomePage)
|
||||
}
|
||||
switchAccount{ un ->
|
||||
$("#switchAccount${un}").click(HomePage)
|
||||
}
|
||||
attributes { moduleList AttributeRow, $("table tr").tail() }
|
||||
}
|
||||
static url = ''
|
||||
static at = { assert driver.title == 'Demonstrates Multi User Log In'; true}
|
||||
static content = {
|
||||
navLink { $('#navLink') }
|
||||
error { $('#error').text() }
|
||||
form { $('form') }
|
||||
username(required:false) { $('#un').text() }
|
||||
logout(required:false) { $('#logout') }
|
||||
addAccount(required:false) { $('#addAccount') }
|
||||
submit { $('input[type=submit]') }
|
||||
login(required:false) { user, pass ->
|
||||
form.username = user
|
||||
form.password = pass
|
||||
submit.click(HomePage)
|
||||
}
|
||||
switchAccount{ un ->
|
||||
$("#switchAccount${un}").click(HomePage)
|
||||
}
|
||||
attributes { moduleList AttributeRow, $("table tr").tail() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package sample.pages
|
||||
|
||||
import geb.*
|
||||
@@ -8,13 +23,13 @@ import geb.*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
class LinkPage extends Page {
|
||||
static url = ''
|
||||
static at = { assert driver.title == 'Linked Page'; true}
|
||||
static content = {
|
||||
form { $('#navLinks') }
|
||||
username(required:false) { $('#un').text() }
|
||||
switchAccount{ un ->
|
||||
$("#switchAccount${un}").click(HomePage)
|
||||
}
|
||||
}
|
||||
static url = ''
|
||||
static at = { assert driver.title == 'Linked Page'; true}
|
||||
static content = {
|
||||
form { $('#navLinks') }
|
||||
username(required:false) { $('#un').text() }
|
||||
switchAccount{ un ->
|
||||
$("#switchAccount${un}").click(HomePage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,29 +16,29 @@
|
||||
package sample;
|
||||
|
||||
public class Account {
|
||||
private String username;
|
||||
private String username;
|
||||
|
||||
private String logoutUrl;
|
||||
private String logoutUrl;
|
||||
|
||||
private String switchAccountUrl;
|
||||
private String switchAccountUrl;
|
||||
|
||||
public Account(String username, String logoutUrl, String switchAccountUrl) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.logoutUrl = logoutUrl;
|
||||
this.switchAccountUrl = switchAccountUrl;
|
||||
}
|
||||
public Account(String username, String logoutUrl, String switchAccountUrl) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.logoutUrl = logoutUrl;
|
||||
this.switchAccountUrl = switchAccountUrl;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getLogoutUrl() {
|
||||
return logoutUrl;
|
||||
}
|
||||
public String getLogoutUrl() {
|
||||
return logoutUrl;
|
||||
}
|
||||
|
||||
public String getSwitchAccountUrl() {
|
||||
return switchAccountUrl;
|
||||
}
|
||||
public String getSwitchAccountUrl() {
|
||||
return switchAccountUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package sample;
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
@@ -14,6 +13,7 @@ package sample;
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package sample;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -24,13 +24,15 @@ import org.springframework.session.data.redis.config.annotation.web.http.EnableR
|
||||
/**
|
||||
* @author Rob Winch
|
||||
*/
|
||||
// tag::class[]
|
||||
@Import(EmbeddedRedisConfiguration.class)
|
||||
@Configuration
|
||||
@EnableRedisHttpSession
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
public JedisConnectionFactory connectionFactory() {
|
||||
return new JedisConnectionFactory();
|
||||
}
|
||||
@Bean
|
||||
public JedisConnectionFactory connectionFactory() {
|
||||
return new JedisConnectionFactory();
|
||||
}
|
||||
}
|
||||
// end::class[]
|
||||
@@ -1,6 +1,5 @@
|
||||
package sample;
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
@@ -14,6 +13,8 @@ package sample;
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package sample;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -36,36 +37,34 @@ import redis.embedded.RedisServer;
|
||||
@Configuration
|
||||
public class EmbeddedRedisConfiguration {
|
||||
|
||||
@Bean
|
||||
public RedisServerBean redisServer() {
|
||||
return new RedisServerBean();
|
||||
}
|
||||
@Bean
|
||||
public RedisServerBean redisServer() {
|
||||
return new RedisServerBean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements BeanDefinitionRegistryPostProcessor to ensure this Bean
|
||||
* is initialized before any other Beans. Specifically, we want to ensure
|
||||
* that the Redis Server is started before RedisHttpSessionConfiguration
|
||||
* attempts to enable Keyspace notifications.
|
||||
*/
|
||||
class RedisServerBean implements InitializingBean, DisposableBean, BeanDefinitionRegistryPostProcessor {
|
||||
private RedisServer redisServer;
|
||||
/**
|
||||
* Implements BeanDefinitionRegistryPostProcessor to ensure this Bean
|
||||
* is initialized before any other Beans. Specifically, we want to ensure
|
||||
* that the Redis Server is started before RedisHttpSessionConfiguration
|
||||
* attempts to enable Keyspace notifications.
|
||||
*/
|
||||
class RedisServerBean implements InitializingBean, DisposableBean, BeanDefinitionRegistryPostProcessor {
|
||||
private RedisServer redisServer;
|
||||
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
redisServer = new RedisServer(Protocol.DEFAULT_PORT);
|
||||
redisServer.start();
|
||||
}
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
redisServer = new RedisServer(Protocol.DEFAULT_PORT);
|
||||
redisServer.start();
|
||||
}
|
||||
|
||||
public void destroy() throws Exception {
|
||||
if(redisServer != null) {
|
||||
redisServer.stop();
|
||||
}
|
||||
}
|
||||
public void destroy() throws Exception {
|
||||
if(redisServer != null) {
|
||||
redisServer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {}
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {}
|
||||
}
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package sample;
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
@@ -14,7 +13,7 @@ package sample;
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package sample;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
@@ -25,12 +24,12 @@ import org.springframework.session.web.context.AbstractHttpSessionApplicationIni
|
||||
*/
|
||||
public class Initializer extends AbstractHttpSessionApplicationInitializer {
|
||||
|
||||
public Initializer() {
|
||||
super(Config.class);
|
||||
}
|
||||
public Initializer() {
|
||||
super(Config.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterSessionRepositoryFilter(ServletContext servletContext) {
|
||||
appendFilters(servletContext, new UserAccountsFilter());
|
||||
}
|
||||
@Override
|
||||
protected void afterSessionRepositoryFilter(ServletContext servletContext) {
|
||||
appendFilters(servletContext, new UserAccountsFilter());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,21 +26,21 @@ import javax.servlet.http.HttpServletResponse;
|
||||
@WebServlet("/login")
|
||||
public class LoginServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
String username = req.getParameter("username");
|
||||
String password = req.getParameter("password");
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
String username = req.getParameter("username");
|
||||
String password = req.getParameter("password");
|
||||
|
||||
if(username != null && !"".equals(username) && username.equals(password)) {
|
||||
req.getSession().setAttribute("username", username);
|
||||
String url = resp.encodeRedirectURL(req.getContextPath() + "/");
|
||||
resp.sendRedirect(url);
|
||||
} else {
|
||||
String url = resp.encodeRedirectURL(req.getContextPath() + "/?error");
|
||||
resp.sendRedirect(url);
|
||||
}
|
||||
}
|
||||
if(username != null && !"".equals(username) && username.equals(password)) {
|
||||
req.getSession().setAttribute("username", username);
|
||||
String url = resp.encodeRedirectURL(req.getContextPath() + "/");
|
||||
resp.sendRedirect(url);
|
||||
} else {
|
||||
String url = resp.encodeRedirectURL(req.getContextPath() + "/?error");
|
||||
resp.sendRedirect(url);
|
||||
}
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -8157634860354132501L;
|
||||
private static final long serialVersionUID = -8157634860354132501L;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,16 +27,16 @@ import javax.servlet.http.HttpSession;
|
||||
@WebServlet("/logout")
|
||||
public class LogoutServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
HttpSession session = req.getSession(false);
|
||||
if(session != null) {
|
||||
session.invalidate();
|
||||
}
|
||||
String url = resp.encodeRedirectURL(req.getContextPath() + "/");
|
||||
resp.sendRedirect(url);
|
||||
}
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
HttpSession session = req.getSession(false);
|
||||
if(session != null) {
|
||||
session.invalidate();
|
||||
}
|
||||
String url = resp.encodeRedirectURL(req.getContextPath() + "/");
|
||||
resp.sendRedirect(url);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 4061762524521437433L;
|
||||
private static final long serialVersionUID = 4061762524521437433L;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,68 +34,68 @@ import org.springframework.session.web.http.HttpSessionManager;
|
||||
|
||||
public class UserAccountsFilter implements Filter {
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
|
||||
// tag::HttpSessionManager[]
|
||||
HttpSessionManager sessionManager =
|
||||
(HttpSessionManager) httpRequest.getAttribute(HttpSessionManager.class.getName());
|
||||
// end::HttpSessionManager[]
|
||||
SessionRepository<Session> repo =
|
||||
(SessionRepository<Session>) httpRequest.getAttribute(SessionRepository.class.getName());
|
||||
// tag::HttpSessionManager[]
|
||||
HttpSessionManager sessionManager =
|
||||
(HttpSessionManager) httpRequest.getAttribute(HttpSessionManager.class.getName());
|
||||
// end::HttpSessionManager[]
|
||||
SessionRepository<Session> repo =
|
||||
(SessionRepository<Session>) httpRequest.getAttribute(SessionRepository.class.getName());
|
||||
|
||||
String currentSessionAlias = sessionManager.getCurrentSessionAlias(httpRequest);
|
||||
Map<String, String> sessionIds = sessionManager.getSessionIds(httpRequest);
|
||||
String unauthenticatedAlias = null;
|
||||
String currentSessionAlias = sessionManager.getCurrentSessionAlias(httpRequest);
|
||||
Map<String, String> sessionIds = sessionManager.getSessionIds(httpRequest);
|
||||
String unauthenticatedAlias = null;
|
||||
|
||||
String contextPath = httpRequest.getContextPath();
|
||||
List<Account> accounts = new ArrayList<Account>();
|
||||
Account currentAccount = null;
|
||||
for(Map.Entry<String, String> entry : sessionIds.entrySet()) {
|
||||
String alias = entry.getKey();
|
||||
String sessionId = entry.getValue();
|
||||
String contextPath = httpRequest.getContextPath();
|
||||
List<Account> accounts = new ArrayList<Account>();
|
||||
Account currentAccount = null;
|
||||
for(Map.Entry<String, String> entry : sessionIds.entrySet()) {
|
||||
String alias = entry.getKey();
|
||||
String sessionId = entry.getValue();
|
||||
|
||||
Session session = repo.getSession(sessionId);
|
||||
if(session == null) {
|
||||
continue;
|
||||
}
|
||||
Session session = repo.getSession(sessionId);
|
||||
if(session == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String username = session.getAttribute("username");
|
||||
if(username == null) {
|
||||
unauthenticatedAlias = alias;
|
||||
continue;
|
||||
}
|
||||
String username = session.getAttribute("username");
|
||||
if(username == null) {
|
||||
unauthenticatedAlias = alias;
|
||||
continue;
|
||||
}
|
||||
|
||||
String logoutUrl = sessionManager.encodeURL("./logout", alias);
|
||||
String switchAccountUrl = sessionManager.encodeURL("./", alias);
|
||||
Account account = new Account(username, logoutUrl, switchAccountUrl);
|
||||
if(currentSessionAlias.equals(alias)) {
|
||||
currentAccount = account;
|
||||
} else {
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
String logoutUrl = sessionManager.encodeURL("./logout", alias);
|
||||
String switchAccountUrl = sessionManager.encodeURL("./", alias);
|
||||
Account account = new Account(username, logoutUrl, switchAccountUrl);
|
||||
if(currentSessionAlias.equals(alias)) {
|
||||
currentAccount = account;
|
||||
} else {
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
|
||||
// tag::addAccountUrl[]
|
||||
String addAlias = unauthenticatedAlias == null ? // <1>
|
||||
sessionManager.getNewSessionAlias(httpRequest) : // <2>
|
||||
unauthenticatedAlias; // <3>
|
||||
String addAccountUrl = sessionManager.encodeURL(contextPath, addAlias); // <4>
|
||||
// end::addAccountUrl[]
|
||||
// tag::addAccountUrl[]
|
||||
String addAlias = unauthenticatedAlias == null ? // <1>
|
||||
sessionManager.getNewSessionAlias(httpRequest) : // <2>
|
||||
unauthenticatedAlias; // <3>
|
||||
String addAccountUrl = sessionManager.encodeURL(contextPath, addAlias); // <4>
|
||||
// end::addAccountUrl[]
|
||||
|
||||
httpRequest.setAttribute("currentAccount", currentAccount);
|
||||
httpRequest.setAttribute("addAccountUrl", addAccountUrl);
|
||||
httpRequest.setAttribute("accounts", accounts);
|
||||
httpRequest.setAttribute("currentAccount", currentAccount);
|
||||
httpRequest.setAttribute("addAccountUrl", addAccountUrl);
|
||||
httpRequest.setAttribute("accounts", accounts);
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user