Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
2f194111
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2f194111
编写于
1月 08, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
spring-boot session
上级
916692c1
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
109 addition
and
185 deletion
+109
-185
pom.xml
pom.xml
+8
-1
whatsmars-spring-boot-samples/pom.xml
whatsmars-spring-boot-samples/pom.xml
+4
-4
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/pom.xml
...spring-boot-samples/whatsmars-boot-sample-session/pom.xml
+5
-81
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/HelloRestController.java
...xi/whatsmars/boot/sample/session/HelloRestController.java
+15
-1
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplication.java
...atsmars/boot/sample/session/SampleSessionApplication.java
+4
-2
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/User.java
...n/java/org/hongxi/whatsmars/boot/sample/session/User.java
+57
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/application.yml
...rs-boot-sample-session/src/main/resources/application.yml
+16
-9
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/hazelcast.xml
...mars-boot-sample-session/src/main/resources/hazelcast.xml
+0
-20
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/test/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplicationTests.java
...rs/boot/sample/session/SampleSessionApplicationTests.java
+0
-67
未找到文件。
pom.xml
浏览文件 @
2f194111
...
...
@@ -42,6 +42,8 @@
<commons-collections.version>
3.2.2
</commons-collections.version>
<commons-codec.version>
1.11
</commons-codec.version>
<commons-fileupload.version>
1.3.3
</commons-fileupload.version>
<commons-lang3.version>
3.7
</commons-lang3.version>
<commons-beanutils.version>
1.9.3
</commons-beanutils.version>
<log4j.version>
1.2.17
</log4j.version>
<servlet.version>
3.1.0
</servlet.version>
<velocity.version>
1.7
</velocity.version>
...
...
@@ -51,7 +53,6 @@
<slf4j.version>
1.7.25
</slf4j.version>
<logback.version>
1.2.3
</logback.version>
<jackson.version>
2.9.3
</jackson.version>
<commons-beanutils.version>
1.9.3
</commons-beanutils.version>
<fastjson.version>
1.2.44
</fastjson.version>
<aspectj.version>
1.8.13
</aspectj.version>
<httpcomponents.version>
4.5.3
</httpcomponents.version>
...
...
@@ -186,6 +187,12 @@
<artifactId>
commons-beanutils
</artifactId>
<version>
${commons-beanutils.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
${commons-lang3.version}
</version>
</dependency>
<!-- logging -->
<dependency>
...
...
whatsmars-spring-boot-samples/pom.xml
浏览文件 @
2f194111
...
...
@@ -18,9 +18,9 @@
<module>
whatsmars-boot-sample-session
</module>
</modules>
<properties>
<
!--<
properties>
<spring-boot.version>2.0.0.M7</spring-boot.version>
</properties>
</properties>
-->
<dependencyManagement>
<dependencies>
...
...
@@ -43,7 +43,7 @@
</plugins>
</build>
<repositories>
<
!--<
repositories>
<repository>
<id>spring-repo</id>
<name>Spring Repo</name>
...
...
@@ -68,7 +68,7 @@
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>
-->
</project>
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/pom.xml
浏览文件 @
2f194111
...
...
@@ -13,98 +13,22 @@
<name>
${project.artifactId}
</name>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.
boot
</groupId>
<artifactId>
spring-
boot-starter-security
</artifactId>
<groupId>
org.springframework.
session
</groupId>
<artifactId>
spring-
session-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-
actuator
</artifactId>
<artifactId>
spring-boot-starter-
data-redis
</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>
redis
</id>
<!--<activation>-->
<!--<activeByDefault>true</activeByDefault>-->
<!--</activation>-->
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>
jdbc
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>
hazelcast
</id>
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-hazelcast
</artifactId>
</dependency>
<dependency>
<groupId>
com.hazelcast
</groupId>
<artifactId>
hazelcast
</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>
mongodb
</id>
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-data-mongodb
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-mongodb
</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/HelloRestController.java
浏览文件 @
2f194111
package
org.hongxi.whatsmars.boot.sample.session
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
import
com.alibaba.fastjson.JSON
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
public
class
HelloRestController
{
private
static
final
String
SESSION_KEY
=
"user"
;
@GetMapping
(
"/"
)
String
uid
(
HttpSession
session
)
{
return
session
.
getId
();
if
(
session
.
getAttribute
(
SESSION_KEY
)
==
null
)
return
"not logged in"
;
User
user
=
(
User
)
session
.
getAttribute
(
SESSION_KEY
);
return
session
.
getId
()
+
","
+
JSON
.
toJSONString
(
user
);
}
@GetMapping
(
"/login"
)
HttpStatus
login
(
HttpServletRequest
request
)
{
User
user
=
new
User
(
"qwert54321"
,
"hongxi"
,
1
,
28
);
request
.
getSession
(
true
).
setAttribute
(
SESSION_KEY
,
user
);
return
HttpStatus
.
OK
;
}
}
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplication.java
浏览文件 @
2f194111
...
...
@@ -2,12 +2,14 @@ package org.hongxi.whatsmars.boot.sample.session;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession
;
@EnableRedisHttpSession
(
redisNamespace
=
"sample"
)
@SpringBootApplication
public
class
SampleSessionApplication
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleSessionApplication
.
class
);
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SampleSessionApplication
.
class
,
args
);
}
}
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/User.java
0 → 100644
浏览文件 @
2f194111
package
org.hongxi.whatsmars.boot.sample.session
;
import
java.io.Serializable
;
/**
* Created by shenhongxi on 2018/1/8.
*/
public
class
User
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6332350121099606299L
;
private
String
id
;
private
String
name
;
private
int
gender
;
private
int
age
;
public
User
(
String
id
,
String
name
,
int
gender
,
int
age
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
gender
=
gender
;
this
.
age
=
age
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
int
getGender
()
{
return
gender
;
}
public
void
setGender
(
int
gender
)
{
this
.
gender
=
gender
;
}
public
int
getAge
()
{
return
age
;
}
public
void
setAge
(
int
age
)
{
this
.
age
=
age
;
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/application.yml
浏览文件 @
2f194111
---
spring
:
security
:
user
:
password
:
password
name
:
user
management
:
endpoints
:
web
:
expose
:
*
redis
:
host
:
127.0.0.1
port
:
6379
password
:
timeout
:
0
pool
:
max-idle
:
8
min-idle
:
1
max-active
:
8
max-wait
:
-1
session
:
store-type
:
redis
server
:
session
:
timeout
:
1800
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/hazelcast.xml
已删除
100644 → 0
浏览文件 @
916692c1
<hazelcast
xsi:schemaLocation=
"http://www.hazelcast.com/schema/config hazelcast-config-3.9.xsd"
xmlns=
"http://www.hazelcast.com/schema/config"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<map
name=
"spring:session:sessions"
>
<attributes>
<attribute
extractor=
"org.springframework.session.hazelcast.PrincipalNameExtractor"
>
principalName
</attribute>
</attributes>
<indexes>
<index>
principalName
</index>
</indexes>
</map>
<network>
<join>
<multicast
enabled=
"false"
/>
</join>
</network>
</hazelcast>
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/test/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplicationTests.java
已删除
100644 → 0
浏览文件 @
916692c1
package
org.hongxi.whatsmars.boot.sample.session
;
import
java.net.URI
;
import
java.util.Base64
;
import
org.junit.Test
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.RequestEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleSessionApplication}.
*
* @author Andy Wilkinson
* @author Vedran Pavic
*/
public
class
SampleSessionApplicationTests
{
@Test
public
void
sessionExpiry
()
throws
Exception
{
ConfigurableApplicationContext
context
=
createContext
();
String
port
=
context
.
getEnvironment
().
getProperty
(
"local.server.port"
);
URI
uri
=
URI
.
create
(
"http://localhost:"
+
port
+
"/"
);
RestTemplate
restTemplate
=
new
RestTemplate
();
ResponseEntity
<
String
>
firstResponse
=
firstRequest
(
restTemplate
,
uri
);
String
sessionId1
=
firstResponse
.
getBody
();
String
cookie
=
firstResponse
.
getHeaders
().
getFirst
(
"Set-Cookie"
);
String
sessionId2
=
nextRequest
(
restTemplate
,
uri
,
cookie
).
getBody
();
assertThat
(
sessionId1
).
isEqualTo
(
sessionId2
);
Thread
.
sleep
(
1000
);
String
loginPage
=
nextRequest
(
restTemplate
,
uri
,
cookie
).
getBody
();
assertThat
(
loginPage
).
containsIgnoringCase
(
"login"
);
}
private
ConfigurableApplicationContext
createContext
()
{
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
()
.
sources
(
SampleSessionApplication
.
class
)
.
properties
(
"server.port:0"
,
"server.session.timeout:1"
)
.
initializers
(
new
ServerPortInfoApplicationContextInitializer
()).
run
();
return
context
;
}
private
ResponseEntity
<
String
>
firstRequest
(
RestTemplate
restTemplate
,
URI
uri
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"Authorization"
,
"Basic "
+
Base64
.
getEncoder
().
encodeToString
(
"user:password"
.
getBytes
()));
RequestEntity
<
Object
>
request
=
new
RequestEntity
<>(
headers
,
HttpMethod
.
GET
,
uri
);
return
restTemplate
.
exchange
(
request
,
String
.
class
);
}
private
ResponseEntity
<
String
>
nextRequest
(
RestTemplate
restTemplate
,
URI
uri
,
String
cookie
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"Cookie"
,
cookie
);
RequestEntity
<
Object
>
request
=
new
RequestEntity
<>(
headers
,
HttpMethod
.
GET
,
uri
);
return
restTemplate
.
exchange
(
request
,
String
.
class
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录