Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nouiWithSpringMVC
Overview
Overview
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
gechengyang
nouiWithSpringMVC
Commits
97637c72
Commit
97637c72
authored
Sep 03, 2020
by
cjh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件下载需求
parent
930c0f16
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
178 additions
and
36 deletions
+178
-36
NoUiParam.java
...ava/org/sss/presentation/noui/api/response/NoUiParam.java
+11
-1
AbstractCommonController.java
...resentation/noui/controller/AbstractCommonController.java
+4
-4
FileBrowserController.java
...s/presentation/noui/controller/FileBrowserController.java
+76
-0
LoginController.java
...org/sss/presentation/noui/controller/LoginController.java
+6
-6
UkeyLoginController.java
...sss/presentation/noui/controller/UkeyLoginController.java
+4
-4
FileTypeInterceptor.java
...org/sss/presentation/noui/filter/FileTypeInterceptor.java
+3
-3
OpenTransInterceptor.java
...a/org/sss/presentation/noui/jwt/OpenTransInterceptor.java
+4
-4
TokenInterceptor.java
.../java/org/sss/presentation/noui/jwt/TokenInterceptor.java
+12
-9
NoUiUtils.java
src/main/java/org/sss/presentation/noui/util/NoUiUtils.java
+22
-4
StringUtil.java
src/main/java/org/sss/presentation/noui/util/StringUtil.java
+33
-0
spring-mvc.xml
src/main/resources/spring-mvc.xml
+3
-1
No files found.
src/main/java/org/sss/presentation/noui/api/response/NoUi
Version
.java
→
src/main/java/org/sss/presentation/noui/api/response/NoUi
Param
.java
View file @
97637c72
package
org
.
sss
.
presentation
.
noui
.
api
.
response
;
package
org
.
sss
.
presentation
.
noui
.
api
.
response
;
public
class
NoUi
Version
{
public
class
NoUi
Param
{
private
String
version
=
"1.0.0"
;
private
String
version
=
"1.0.0"
;
private
String
rootFilePath
;
public
String
getRootFilePath
()
{
return
rootFilePath
;
}
public
void
setRootFilePath
(
String
rootFilePath
)
{
this
.
rootFilePath
=
rootFilePath
;
}
public
String
getVersion
()
{
public
String
getVersion
()
{
return
version
;
return
version
;
}
}
...
...
src/main/java/org/sss/presentation/noui/controller/AbstractCommonController.java
View file @
97637c72
...
@@ -23,7 +23,7 @@ import org.sss.presentation.noui.api.exception.NoUiException;
...
@@ -23,7 +23,7 @@ import org.sss.presentation.noui.api.exception.NoUiException;
import
org.sss.presentation.noui.api.model.Alias
;
import
org.sss.presentation.noui.api.model.Alias
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUi
Version
;
import
org.sss.presentation.noui.api.response.NoUi
Param
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.common.Constants
;
...
@@ -48,7 +48,7 @@ public abstract class AbstractCommonController {
...
@@ -48,7 +48,7 @@ public abstract class AbstractCommonController {
protected
static
String
ON_STREAM_DOWNLOAD
=
"ON_STREAM_DOWNLOAD"
;
protected
static
String
ON_STREAM_DOWNLOAD
=
"ON_STREAM_DOWNLOAD"
;
@Autowired
@Autowired
private
NoUi
Version
noUiVersion
;
private
NoUi
Param
noUiParam
;
public
String
getMainPanel
(){
public
String
getMainPanel
(){
return
""
;
return
""
;
...
@@ -139,10 +139,10 @@ public abstract class AbstractCommonController {
...
@@ -139,10 +139,10 @@ public abstract class AbstractCommonController {
Map
<
String
,
Object
>
afterReturnData
=
handleReturnData
(
eventType
,
context
,
noUiRequest
,
alias
);
Map
<
String
,
Object
>
afterReturnData
=
handleReturnData
(
eventType
,
context
,
noUiRequest
,
alias
);
ret
=
ResultUtil
.
result
(
NoUiPresentationUtil
.
retCode
(
context
),
NoUiPresentationUtil
.
retMsg
(
context
),
afterReturnData
,
ret
=
ResultUtil
.
result
(
NoUiPresentationUtil
.
retCode
(
context
),
NoUiPresentationUtil
.
retMsg
(
context
),
afterReturnData
,
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
),
noUi
Version
.
getVersion
());
NoUiPresentationUtil
.
handleErrorReturnData
(
context
,
alias
),
NoUiPresentationUtil
.
handleCodeTableReturnData
(
context
,
alias
),
noUi
Param
.
getVersion
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"OnClick command error"
,
e
);
log
.
error
(
"OnClick command error"
,
e
);
ret
=
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"hander error"
,
e
.
getMessage
(),
noUi
Version
.
getVersion
());
ret
=
ResultUtil
.
result
(
ErrorCodes
.
ERROR
,
"hander error"
,
e
.
getMessage
(),
noUi
Param
.
getVersion
());
}
finally
{
}
finally
{
if
(
context
!=
null
)
if
(
context
!=
null
)
{
{
...
...
src/main/java/org/sss/presentation/noui/controller/FileBrowserController.java
0 → 100644
View file @
97637c72
package
org
.
sss
.
presentation
.
noui
.
controller
;
import
log.Log
;
import
log.LogFactory
;
import
org.apache.commons.io.FileUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
org.sss.presentation.noui.api.response.NoUiParam
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.jwt.RedisLoginInfo
;
import
org.sss.presentation.noui.util.RedisUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
import
java.io.File
;
import
java.util.Set
;
@Controller
public
class
FileBrowserController
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
FileBrowserController
.
class
);
@Autowired
private
NoUiParam
noUiParam
;
@RequestMapping
(
value
=
"/fileBrowser/{docpath}/{usrName}/{fileName}/{fileExt}/{safeCode}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
download
(
@PathVariable
String
docpath
,
@PathVariable
String
usrName
,
@PathVariable
String
fileName
,
@PathVariable
String
fileExt
,
@PathVariable
String
safeCode
)
{
try
{
String
file
=
fileName
+
"."
+
fileExt
;
if
(
checkFileName
(
fileName
)
&&
authVerify
(
usrName
,
file
,
safeCode
))
{
byte
[]
bytes
=
FileUtils
.
readFileToByteArray
(
new
File
(
noUiParam
.
getRootFilePath
()+
docpath
+
"/"
+
file
));
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"Content-Disposition"
,
"attachment;filename="
+
file
);
ResponseEntity
entity
=
new
ResponseEntity
<>(
bytes
,
headers
,
HttpStatus
.
OK
);
return
entity
;
}
else
{
ResponseEntity
entity
=
new
ResponseEntity
<>(
HttpStatus
.
FORBIDDEN
);
return
entity
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"下载出错:"
,
e
);
return
null
;
}
}
public
static
boolean
authVerify
(
String
usrName
,
String
file
,
String
safeCode
)
throws
Exception
{
String
token
;
//redis获取token
Set
<
String
>
keys
=
RedisUtil
.
keys
(
Constants
.
SESSION
+
"."
+
usrName
);
if
(!
keys
.
isEmpty
())
{
token
=
((
RedisLoginInfo
)
keys
.
toArray
()[
0
]).
getToken
();
}
else
return
false
;
StringBuilder
sb
=
new
StringBuilder
(
usrName
);
StringBuilder
result
=
new
StringBuilder
();
result
.
append
(
sb
.
reverse
());
result
.
append
(
file
);
result
.
append
(
token
);
result
.
append
(
"1415926@;RHxC"
);
if
(
StringUtil
.
encryptMD5
(
result
.
toString
()).
equalsIgnoreCase
(
safeCode
))
{
return
true
;
}
else
return
false
;
}
public
static
boolean
checkFileName
(
String
fileName
){
if
(
fileName
.
contains
(
"../"
)
||
fileName
.
contains
(
"./"
)
||
fileName
.
contains
(
"..\\"
)
||
fileName
.
contains
(
".\\"
))
return
false
;
else
return
true
;
}
}
src/main/java/org/sss/presentation/noui/controller/LoginController.java
View file @
97637c72
...
@@ -14,7 +14,7 @@ import org.sss.presentation.noui.api.model.Menu;
...
@@ -14,7 +14,7 @@ import org.sss.presentation.noui.api.model.Menu;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCode
;
import
org.sss.presentation.noui.api.response.ErrorCode
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUi
Version
;
import
org.sss.presentation.noui.api.response.NoUi
Param
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiContext
;
...
@@ -37,7 +37,7 @@ public class LoginController {
...
@@ -37,7 +37,7 @@ public class LoginController {
public
static
final
String
ERROR
=
"error"
;
public
static
final
String
ERROR
=
"error"
;
@Autowired
@Autowired
private
NoUi
Version
noUiVersion
;
private
NoUi
Param
noUiParam
;
@ResponseBody
@ResponseBody
@RequestMapping
(
value
=
"/login"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/login"
,
method
=
RequestMethod
.
POST
)
...
@@ -86,22 +86,22 @@ public class LoginController {
...
@@ -86,22 +86,22 @@ public class LoginController {
//解决初次登陆,超期限登陆
//解决初次登陆,超期限登陆
final
Object
o
=
map
.
get
(
ERROR
);
final
Object
o
=
map
.
get
(
ERROR
);
if
(
Objects
.
isNull
(
o
))
{
if
(
Objects
.
isNull
(
o
))
{
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
,
noUi
Version
.
getVersion
());
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
,
noUi
Param
.
getVersion
());
}
else
{
}
else
{
ErrorCode
errorCode
=
(
ErrorCode
)
o
;
ErrorCode
errorCode
=
(
ErrorCode
)
o
;
log
.
error
(
errorCode
);
log
.
error
(
errorCode
);
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
retDatamap
,
noUi
Version
.
getVersion
());
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
retDatamap
,
noUi
Param
.
getVersion
());
}
}
}
else
{
}
else
{
final
ErrorCode
errorCode
=
(
ErrorCode
)
map
.
get
(
ERROR
);
final
ErrorCode
errorCode
=
(
ErrorCode
)
map
.
get
(
ERROR
);
log
.
error
(
errorCode
);
log
.
error
(
errorCode
);
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
null
,
noUi
Version
.
getVersion
());
return
ResultUtil
.
result
(
errorCode
.
getCode
(),
errorCode
.
getMessage
(),
null
,
noUi
Param
.
getVersion
());
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"Login command error"
,
e
);
log
.
error
(
"Login command error"
,
e
);
//throw new NoUiException("Login command error", e);
//throw new NoUiException("Login command error", e);
// return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null);
// return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null);
return
ResultUtil
.
result
(
ErrorCode
.
SYSTEM_ERROR
.
getCode
(),
ErrorCode
.
SYSTEM_ERROR
.
getMessage
(),
null
,
noUi
Version
.
getVersion
());
return
ResultUtil
.
result
(
ErrorCode
.
SYSTEM_ERROR
.
getCode
(),
ErrorCode
.
SYSTEM_ERROR
.
getMessage
(),
null
,
noUi
Param
.
getVersion
());
}
}
finally
{
finally
{
if
(
context
!=
null
)
if
(
context
!=
null
)
...
...
src/main/java/org/sss/presentation/noui/controller/UkeyLoginController.java
View file @
97637c72
...
@@ -13,7 +13,7 @@ import org.sss.common.model.Argument;
...
@@ -13,7 +13,7 @@ import org.sss.common.model.Argument;
import
org.sss.common.model.IResult
;
import
org.sss.common.model.IResult
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUi
Version
;
import
org.sss.presentation.noui.api.response.NoUi
Param
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.api.response.ResultUtil
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
...
@@ -28,7 +28,7 @@ import java.util.Map;
...
@@ -28,7 +28,7 @@ import java.util.Map;
public
class
UkeyLoginController
{
public
class
UkeyLoginController
{
@Autowired
@Autowired
private
NoUi
Version
noUiVersion
;
private
NoUi
Param
noUiParam
;
private
static
final
Log
log
=
LogFactory
.
getLog
(
UkeyLoginController
.
class
);
private
static
final
Log
log
=
LogFactory
.
getLog
(
UkeyLoginController
.
class
);
@ResponseBody
@ResponseBody
...
@@ -47,12 +47,12 @@ public class UkeyLoginController {
...
@@ -47,12 +47,12 @@ public class UkeyLoginController {
{
{
retDatamap
.
put
(
"msgCode"
,
"0000"
);
retDatamap
.
put
(
"msgCode"
,
"0000"
);
retDatamap
.
put
(
"loginid"
,
loginid
);
retDatamap
.
put
(
"loginid"
,
loginid
);
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
,
noUi
Version
.
getVersion
());
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
,
noUi
Param
.
getVersion
());
}
}
}
}
retDatamap
.
put
(
"msgCode"
,
"9999"
);
retDatamap
.
put
(
"msgCode"
,
"9999"
);
retDatamap
.
put
(
"loginid"
,
""
);
retDatamap
.
put
(
"loginid"
,
""
);
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
,
noUi
Version
.
getVersion
());
return
ResultUtil
.
result
(
ErrorCodes
.
SUCCESS
,
ErrorCodes
.
SUCCESS_INFO
,
retDatamap
,
noUi
Param
.
getVersion
());
}
}
private
Map
<
String
,
Object
>
getLoginidByDN
(
String
certdn
,
NoUiRequest
noUiRequest
)
{
private
Map
<
String
,
Object
>
getLoginidByDN
(
String
certdn
,
NoUiRequest
noUiRequest
)
{
...
...
src/main/java/org/sss/presentation/noui/filter/FileTypeInterceptor.java
View file @
97637c72
...
@@ -7,7 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -7,7 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUi
Version
;
import
org.sss.presentation.noui.api.response.NoUi
Param
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.api.response.Result
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -22,7 +22,7 @@ import java.util.Map;
...
@@ -22,7 +22,7 @@ import java.util.Map;
public
class
FileTypeInterceptor
extends
HandlerInterceptorAdapter
{
public
class
FileTypeInterceptor
extends
HandlerInterceptorAdapter
{
@Autowired
@Autowired
private
NoUi
Version
noUiVersion
;
private
NoUi
Param
noUiParam
;
private
String
type_list
;
private
String
type_list
;
...
@@ -44,7 +44,7 @@ public class FileTypeInterceptor extends HandlerInterceptorAdapter {
...
@@ -44,7 +44,7 @@ public class FileTypeInterceptor extends HandlerInterceptorAdapter {
//限制文件类型,请求转发到原始请求页面,并携带错误提示信息
//限制文件类型,请求转发到原始请求页面,并携带错误提示信息
flag
=
false
;
flag
=
false
;
response
.
setContentType
(
"application/json; charset=utf-8"
);
response
.
setContentType
(
"application/json; charset=utf-8"
);
Result
result
=
new
Result
(
ErrorCodes
.
ERROR
,
"不支持的文件类型!"
,
null
,
noUi
Version
.
getVersion
());
Result
result
=
new
Result
(
ErrorCodes
.
ERROR
,
"不支持的文件类型!"
,
null
,
noUi
Param
.
getVersion
());
PrintWriter
out
=
response
.
getWriter
();
PrintWriter
out
=
response
.
getWriter
();
String
json
=
new
Gson
().
toJson
(
result
);
String
json
=
new
Gson
().
toJson
(
result
);
out
.
print
(
json
);
out
.
print
(
json
);
...
...
src/main/java/org/sss/presentation/noui/jwt/OpenTransInterceptor.java
View file @
97637c72
...
@@ -11,7 +11,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
...
@@ -11,7 +11,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUi
Version
;
import
org.sss.presentation.noui.api.response.NoUi
Param
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
import
org.sss.presentation.noui.context.NoUiContextManager
;
...
@@ -30,7 +30,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
...
@@ -30,7 +30,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
protected
static
final
Log
log
=
LogFactory
.
getLog
(
OpenTransInterceptor
.
class
);
protected
static
final
Log
log
=
LogFactory
.
getLog
(
OpenTransInterceptor
.
class
);
@Autowired
@Autowired
private
NoUi
Version
noUiVersion
;
private
NoUi
Param
noUiParam
;
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
arg3
)
throws
Exception
{
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
arg3
)
throws
Exception
{
...
@@ -67,7 +67,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
...
@@ -67,7 +67,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
trnnam
=
url
.
substring
(
begpos
,
idx2
);
trnnam
=
url
.
substring
(
begpos
,
idx2
);
if
(
trnnam
==
null
)
if
(
trnnam
==
null
)
{
{
Result
rt
=
new
Result
(
ErrorCodes
.
UNKNOEW_TRANS
,
"未知的交易"
,
null
,
noUi
Version
.
getVersion
());
Result
rt
=
new
Result
(
ErrorCodes
.
UNKNOEW_TRANS
,
"未知的交易"
,
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
...
@@ -75,7 +75,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
...
@@ -75,7 +75,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
log
.
debug
(
"开放访问交易名:"
+
trnnam
);
log
.
debug
(
"开放访问交易名:"
+
trnnam
);
if
(!
NoUiContextManager
.
openTransactions
.
contains
(
trnnam
))
if
(!
NoUiContextManager
.
openTransactions
.
contains
(
trnnam
))
{
{
Result
rt
=
new
Result
(
ErrorCodes
.
FORBIDDEN_TRANS
,
"非法访问"
,
null
,
noUi
Version
.
getVersion
());
Result
rt
=
new
Result
(
ErrorCodes
.
FORBIDDEN_TRANS
,
"非法访问"
,
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
...
...
src/main/java/org/sss/presentation/noui/jwt/TokenInterceptor.java
View file @
97637c72
...
@@ -10,9 +10,10 @@ import org.springframework.web.servlet.HandlerInterceptor;
...
@@ -10,9 +10,10 @@ import org.springframework.web.servlet.HandlerInterceptor;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.ErrorCodes
;
import
org.sss.presentation.noui.api.response.NoUi
Version
;
import
org.sss.presentation.noui.api.response.NoUi
Param
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.api.response.Result
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.util.NoUiUtils
;
import
org.sss.presentation.noui.util.NumericUtil
;
import
org.sss.presentation.noui.util.NumericUtil
;
import
org.sss.presentation.noui.util.RedisUtil
;
import
org.sss.presentation.noui.util.RedisUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
import
org.sss.presentation.noui.util.StringUtil
;
...
@@ -22,10 +23,10 @@ import com.google.gson.Gson;
...
@@ -22,10 +23,10 @@ import com.google.gson.Gson;
public
class
TokenInterceptor
implements
HandlerInterceptor
{
public
class
TokenInterceptor
implements
HandlerInterceptor
{
@Autowired
@Autowired
private
NoUi
Version
noUiVersion
;
private
NoUi
Param
noUiParam
;
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
arg3
)
throws
Exception
{
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
arg3
)
throws
Exception
{
NoUiUtils
.
clearLoginInfo
();
}
}
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
ModelAndView
model
)
throws
Exception
{
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
ModelAndView
model
)
throws
Exception
{
...
@@ -40,14 +41,14 @@ public class TokenInterceptor implements HandlerInterceptor {
...
@@ -40,14 +41,14 @@ public class TokenInterceptor implements HandlerInterceptor {
String
terminalType
=
noUiRequest
.
getTerminalType
();
// APP WEB
String
terminalType
=
noUiRequest
.
getTerminalType
();
// APP WEB
// token不存在
// token不存在
if
(
StringUtil
.
isEmpty
(
token
))
{
if
(
StringUtil
.
isEmpty
(
token
))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_ISNULL
,
"登录token不能为空"
,
null
,
noUi
Version
.
getVersion
());
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_ISNULL
,
"登录token不能为空"
,
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
// userId不存在
// userId不存在
if
(
StringUtil
.
isEmpty
(
userId
))
{
if
(
StringUtil
.
isEmpty
(
userId
))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ID_ISNULL
,
"用户id不能为空"
,
null
,
noUi
Version
.
getVersion
());
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ID_ISNULL
,
"用户id不能为空"
,
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
...
@@ -60,20 +61,20 @@ public class TokenInterceptor implements HandlerInterceptor {
...
@@ -60,20 +61,20 @@ public class TokenInterceptor implements HandlerInterceptor {
JwtLogin
login
=
JWT
.
unsign
(
token
,
JwtLogin
.
class
);
JwtLogin
login
=
JWT
.
unsign
(
token
,
JwtLogin
.
class
);
if
(
login
==
null
||
(!
userId
.
equals
((
login
.
getUserId
()))))
{
if
(
login
==
null
||
(!
userId
.
equals
((
login
.
getUserId
()))))
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"用户token或ID验证不通过"
,
null
,
noUi
Version
.
getVersion
());
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"用户token或ID验证不通过"
,
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
RedisLoginInfo
redisLoginInfo
=
(
RedisLoginInfo
)
RedisUtil
.
get
(
StringUtil
.
userUniqueId
(
noUiRequest
));
RedisLoginInfo
redisLoginInfo
=
(
RedisLoginInfo
)
RedisUtil
.
get
(
StringUtil
.
userUniqueId
(
noUiRequest
));
if
(
redisLoginInfo
==
null
)
{
if
(
redisLoginInfo
==
null
)
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ERROR
,
"登陆异常"
,
null
,
noUi
Version
.
getVersion
());
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_ERROR
,
"登陆异常"
,
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
//验证token是否一致
//验证token是否一致
if
(!
token
.
equals
(
redisLoginInfo
.
getToken
())){
if
(!
token
.
equals
(
redisLoginInfo
.
getToken
())){
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"token失效,该用户被强迫下线"
,
null
,
noUi
Version
.
getVersion
());
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TOKEN_CHECKERROR
,
"token失效,该用户被强迫下线"
,
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
...
@@ -81,7 +82,7 @@ public class TokenInterceptor implements HandlerInterceptor {
...
@@ -81,7 +82,7 @@ public class TokenInterceptor implements HandlerInterceptor {
if
(
System
.
currentTimeMillis
()
>
redisLoginInfo
.
getExpiredTime
())
{
if
(
System
.
currentTimeMillis
()
>
redisLoginInfo
.
getExpiredTime
())
{
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TIMEOUT
,
"会话超时,请重新登录。超时时间戳:"
+
redisLoginInfo
.
getExpiredTime
()+
Result
rt
=
new
Result
(
ErrorCodes
.
LOGIN_TIMEOUT
,
"会话超时,请重新登录。超时时间戳:"
+
redisLoginInfo
.
getExpiredTime
()+
",当前时间戳:"
+
System
.
currentTimeMillis
(),
null
,
noUi
Version
.
getVersion
());
",当前时间戳:"
+
System
.
currentTimeMillis
(),
null
,
noUi
Param
.
getVersion
());
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
responseMessage
(
response
,
response
.
getWriter
(),
rt
);
return
false
;
return
false
;
}
}
...
@@ -89,6 +90,8 @@ public class TokenInterceptor implements HandlerInterceptor {
...
@@ -89,6 +90,8 @@ public class TokenInterceptor implements HandlerInterceptor {
// 重新刷入登陆时间
// 重新刷入登陆时间
RedisLoginInfo
nweRedisLoginInfo
=
new
RedisLoginInfo
(
userId
,
token
,
NumericUtil
.
sessionTimeOut
(),
redisLoginInfo
.
getSysmod
(),
noUiRequest
.
getTerminalType
());
RedisLoginInfo
nweRedisLoginInfo
=
new
RedisLoginInfo
(
userId
,
token
,
NumericUtil
.
sessionTimeOut
(),
redisLoginInfo
.
getSysmod
(),
noUiRequest
.
getTerminalType
());
RedisUtil
.
set
(
Constants
.
SESSION
+
"."
+
userId
+
"."
+
terminalType
,
nweRedisLoginInfo
);
RedisUtil
.
set
(
Constants
.
SESSION
+
"."
+
userId
+
"."
+
terminalType
,
nweRedisLoginInfo
);
NoUiUtils
.
setLoginInfo
(
nweRedisLoginInfo
);
return
true
;
return
true
;
}
}
...
...
src/main/java/org/sss/presentation/noui/util/NoUiUtils.java
View file @
97637c72
...
@@ -9,6 +9,7 @@ import org.sss.presentation.noui.api.request.NoUiRequest;
...
@@ -9,6 +9,7 @@ import org.sss.presentation.noui.api.request.NoUiRequest;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiContext
;
import
org.sss.presentation.noui.context.NoUiPresentation
;
import
org.sss.presentation.noui.context.NoUiPresentation
;
import
org.sss.presentation.noui.jwt.RedisLoginInfo
;
import
org.sss.util.ContainerUtils
;
import
org.sss.util.ContainerUtils
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -107,9 +108,6 @@ public class NoUiUtils {
...
@@ -107,9 +108,6 @@ public class NoUiUtils {
//模糊匹配删除所有终端登陆key
//模糊匹配删除所有终端登陆key
public
static
void
logout
(
String
userId
,
String
type
){
public
static
void
logout
(
String
userId
,
String
type
){
// NoUiRequest noUiRequest = new NoUiRequest();
// noUiRequest.setUserId(userId);
// noUiRequest.setTerminalType(type);
try
{
try
{
if
(
"*"
.
equals
(
type
))
{
if
(
"*"
.
equals
(
type
))
{
Set
<
String
>
keys
=
RedisUtil
.
keys
(
Constants
.
SESSION
+
"."
+
userId
);
Set
<
String
>
keys
=
RedisUtil
.
keys
(
Constants
.
SESSION
+
"."
+
userId
);
...
@@ -120,6 +118,26 @@ public class NoUiUtils {
...
@@ -120,6 +118,26 @@ public class NoUiUtils {
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
log
.
error
(
"logout error:"
,
e
);
log
.
error
(
"logout error:"
,
e
);
}
}
// return RedisUtil.delete(StringUtil.userUniqueId(noUiRequest));
}
public
static
ThreadLocal
<
RedisLoginInfo
>
tl
=
new
ThreadLocal
<
RedisLoginInfo
>();
public
static
void
setLoginInfo
(
RedisLoginInfo
redisLoginInfo
){
tl
.
set
(
redisLoginInfo
);
}
public
static
void
clearLoginInfo
(){
tl
.
remove
();
}
public
static
String
getToken
()
{
return
tl
.
get
().
getToken
();
}
public
static
String
getTerminalType
()
{
return
tl
.
get
().
getTerminalType
();
}
}
}
}
src/main/java/org/sss/presentation/noui/util/StringUtil.java
View file @
97637c72
...
@@ -3,6 +3,8 @@ package org.sss.presentation.noui.util;
...
@@ -3,6 +3,8 @@ package org.sss.presentation.noui.util;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.api.request.NoUiRequest
;
import
org.sss.presentation.noui.common.Constants
;
import
org.sss.presentation.noui.common.Constants
;
import
java.security.MessageDigest
;
public
class
StringUtil
{
public
class
StringUtil
{
public
static
boolean
isEmpty
(
String
str
)
{
public
static
boolean
isEmpty
(
String
str
)
{
...
@@ -15,4 +17,35 @@ public class StringUtil {
...
@@ -15,4 +17,35 @@ public class StringUtil {
return
Constants
.
SESSION
+
"."
+
request
.
getUserId
()
+
"."
+
request
.
getTerminalType
();
return
Constants
.
SESSION
+
"."
+
request
.
getUserId
()
+
"."
+
request
.
getTerminalType
();
}
}
/**
* MD5加密字符串
* @param inStr
* @return
* @throws Exception
*/
public
static
String
encryptMD5
(
String
inStr
)
throws
Exception
{
MessageDigest
md5
=
null
;
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
char
[]
charArray
=
inStr
.
toCharArray
();
byte
[]
byteArray
=
new
byte
[
charArray
.
length
];
for
(
int
i
=
0
;
i
<
charArray
.
length
;
i
++)
byteArray
[
i
]
=
(
byte
)
charArray
[
i
];
byte
[]
md5Bytes
=
md5
.
digest
(
byteArray
);
StringBuffer
hexValue
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
md5Bytes
.
length
;
i
++)
{
int
val
=
((
int
)
md5Bytes
[
i
])
&
0xff
;
if
(
val
<
16
)
hexValue
.
append
(
"0"
);
hexValue
.
append
(
Integer
.
toHexString
(
val
));
}
return
hexValue
.
toString
();
}
}
}
src/main/resources/spring-mvc.xml
View file @
97637c72
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
<mvc:mapping
path=
"/**"
/>
<mvc:mapping
path=
"/**"
/>
<!--login 不需要拦截 -->
<!--login 不需要拦截 -->
<mvc:exclude-mapping
path=
"/login"
/>
<mvc:exclude-mapping
path=
"/login"
/>
<mvc:exclude-mapping
path=
"/fileBrowser/**"
/>
<bean
class=
"org.sss.presentation.noui.jwt.TokenInterceptor"
></bean>
<bean
class=
"org.sss.presentation.noui.jwt.TokenInterceptor"
></bean>
</mvc:interceptor>
</mvc:interceptor>
...
@@ -42,8 +43,9 @@
...
@@ -42,8 +43,9 @@
<property
name=
"maxInMemorySize"
value=
"200000"
/>
<property
name=
"maxInMemorySize"
value=
"200000"
/>
</bean>
</bean>
<bean
id=
"noui
Version"
class=
"org.sss.presentation.noui.api.response.NoUiVersion
"
>
<bean
id=
"noui
Param"
class=
"org.sss.presentation.noui.api.response.NoUiParam
"
>
<property
name=
"version"
value=
"V1.0.0"
/>
<property
name=
"version"
value=
"V1.0.0"
/>
<property
name=
"rootFilePath"
value=
"f:/"
/>
</bean>
</bean>
<!-- 配置自动扫描的包 -->
<!-- 配置自动扫描的包 -->
...
...
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