Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sentinel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sentinel
Commits
a81874b8
Commit
a81874b8
authored
Nov 23, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xx
parent
9c3e3a80
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
7 deletions
+28
-7
TokenService.java
src/main/java/com/egolm/film/api/service/TokenService.java
+1
-1
AdminTokenServiceImpl.java
...om/egolm/film/api/service/impl/AdminTokenServiceImpl.java
+1
-1
MemberTokenServiceImpl.java
...m/egolm/film/api/service/impl/MemberTokenServiceImpl.java
+1
-1
UserTokenServiceImpl.java
...com/egolm/film/api/service/impl/UserTokenServiceImpl.java
+1
-1
WebMvcConfig.java
src/main/java/com/egolm/film/config/WebMvcConfig.java
+21
-0
AdminLoginInterceptor.java
.../egolm/film/config/interceptor/AdminLoginInterceptor.java
+1
-1
MemberLoginInterceptor.java
...egolm/film/config/interceptor/MemberLoginInterceptor.java
+1
-1
UserLoginInterceptor.java
...m/egolm/film/config/interceptor/UserLoginInterceptor.java
+1
-1
No files found.
src/main/java/com/egolm/film/api/service/TokenService.java
View file @
a81874b8
...
...
@@ -6,7 +6,7 @@ import com.egolm.film.model.LoginToken;
public
interface
TokenService
{
final
String
JSESSIONID
=
"JSESSIONID
"
;
final
String
LOGINID_COOKIE_NAME
=
"token
"
;
LoginToken
getToken
();
...
...
src/main/java/com/egolm/film/api/service/impl/AdminTokenServiceImpl.java
View file @
a81874b8
...
...
@@ -43,7 +43,7 @@ public class AdminTokenServiceImpl implements AdminTokenService {
Integer
adminid
=
admin
.
getAdminid
();
LoginToken
token
=
new
LoginToken
(
adminid
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
Cookie
cookie
=
WebMvcConfig
.
get
Cookie
(
JSESSIONID
);
Cookie
cookie
=
WebMvcConfig
.
get
OrCreateUUIDCookie
(
LOGINID_COOKIE_NAME
,
"/"
,
60
*
60
,
true
);
if
(
cookie
!=
null
)
{
String
sql
=
"update fc_admin set token = ? where adminid = ?"
;
jdbcTemplate
.
executeUpdate
(
sql
,
cookie
.
getValue
(),
adminid
);
...
...
src/main/java/com/egolm/film/api/service/impl/MemberTokenServiceImpl.java
View file @
a81874b8
...
...
@@ -51,7 +51,7 @@ public class MemberTokenServiceImpl implements MemberTokenService {
Integer
id
=
member
.
getId
();
LoginToken
token
=
new
LoginToken
(
id
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
Cookie
cookie
=
WebMvcConfig
.
getCookie
(
JSESSIONID
);
Cookie
cookie
=
WebMvcConfig
.
getCookie
(
LOGINID_COOKIE_NAME
);
if
(
cookie
!=
null
)
{
memberService
.
updateToken
(
id
,
cookie
.
getValue
());
}
...
...
src/main/java/com/egolm/film/api/service/impl/UserTokenServiceImpl.java
View file @
a81874b8
...
...
@@ -47,7 +47,7 @@ public class UserTokenServiceImpl implements UserTokenService {
Long
uid
=
user
.
getUid
();
LoginToken
token
=
new
LoginToken
(
uid
);
session
.
setAttribute
(
TOKEN_NAME
,
token
);
Cookie
cookie
=
WebMvcConfig
.
getCookie
(
JSESSIONID
);
Cookie
cookie
=
WebMvcConfig
.
getCookie
(
LOGINID_COOKIE_NAME
);
if
(
cookie
!=
null
)
{
jdbcTemplate
.
executeUpdate
(
"update fc_user set token = ? where uid = ?"
,
cookie
.
getValue
(),
uid
);
}
...
...
src/main/java/com/egolm/film/config/WebMvcConfig.java
View file @
a81874b8
...
...
@@ -18,6 +18,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import
org.springframework.web.servlet.config.annotation.PathMatchConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
com.egolm.common.StringUtil
;
import
com.egolm.film.config.interceptor.AdminLoginInterceptor
;
import
com.egolm.film.config.interceptor.LocaleInterceptor
;
import
com.egolm.film.config.interceptor.MemberLoginInterceptor
;
...
...
@@ -98,6 +99,26 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
return
null
;
}
public
static
Cookie
getOrCreateUUIDCookie
(
String
name
,
String
path
,
int
expiry
,
boolean
httpOnly
)
{
HttpServletRequest
request
=
WebMvcConfig
.
getRequest
();
if
(
request
!=
null
)
{
Cookie
[]
cookies
=
request
.
getCookies
();
if
(
cookies
!=
null
)
{
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
name
))
{
return
cookie
;
}
}
}
}
Cookie
cookie
=
new
Cookie
(
name
,
StringUtil
.
getUid
().
toLowerCase
());
cookie
.
setPath
(
path
);
cookie
.
setHttpOnly
(
httpOnly
);
cookie
.
setMaxAge
(
expiry
);
getResponse
().
addCookie
(
cookie
);
return
cookie
;
}
public
static
String
getRemoteIp
()
{
HttpServletRequest
request
=
WebMvcConfig
.
getRequest
();
String
ip
=
request
.
getHeader
(
"X-Real_IP"
);
...
...
src/main/java/com/egolm/film/config/interceptor/AdminLoginInterceptor.java
View file @
a81874b8
...
...
@@ -28,7 +28,7 @@ public class AdminLoginInterceptor extends HandlerInterceptorAdapter {
Cookie
[]
cookies
=
req
.
getCookies
();
if
(
cookies
!=
null
)
{
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
JSESSIONID
))
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
LOGINID_COOKIE_NAME
))
{
sessionid
=
cookie
.
getValue
();
}
}
...
...
src/main/java/com/egolm/film/config/interceptor/MemberLoginInterceptor.java
View file @
a81874b8
...
...
@@ -27,7 +27,7 @@ public class MemberLoginInterceptor extends HandlerInterceptorAdapter {
String
sessionid
=
null
;
Cookie
[]
cookies
=
req
.
getCookies
();
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
JSESSIONID
))
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
LOGINID_COOKIE_NAME
))
{
sessionid
=
cookie
.
getValue
();
}
}
...
...
src/main/java/com/egolm/film/config/interceptor/UserLoginInterceptor.java
View file @
a81874b8
...
...
@@ -27,7 +27,7 @@ public class UserLoginInterceptor extends HandlerInterceptorAdapter {
String
sessionid
=
null
;
Cookie
[]
cookies
=
req
.
getCookies
();
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
JSESSIONID
))
{
if
(
cookie
.
getName
().
equals
(
TokenService
.
LOGINID_COOKIE_NAME
))
{
sessionid
=
cookie
.
getValue
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment