Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loginservice
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
lanmw
loginservice
Commits
8fb67f02
Commit
8fb67f02
authored
Mar 28, 2021
by
huangkp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
单点登录
parent
52cdc784
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
679 additions
and
369 deletions
+679
-369
pom.xml
pom.xml
+15
-0
Constants.java
src/main/java/com/keymobile/proxy/api/Constants.java
+2
-1
RESTAuthenticationSuccessHandler.java
...eymobile/proxy/conf/RESTAuthenticationSuccessHandler.java
+13
-9
RedisClusterConfig.java
...ain/java/com/keymobile/proxy/conf/RedisClusterConfig.java
+0
-152
RedisConfig.java
src/main/java/com/keymobile/proxy/conf/RedisConfig.java
+15
-0
SecurityConfig.java
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
+26
-46
WebServiceConfig.java
src/main/java/com/keymobile/proxy/conf/WebServiceConfig.java
+1
-1
ModelPathEnum.java
src/main/java/com/keymobile/proxy/enums/ModelPathEnum.java
+31
-0
Author.java
src/main/java/com/keymobile/proxy/model/Author.java
+0
-26
Domain.java
src/main/java/com/keymobile/proxy/model/Domain.java
+0
-31
Role.java
src/main/java/com/keymobile/proxy/model/Role.java
+0
-35
User.java
src/main/java/com/keymobile/proxy/model/User.java
+172
-30
AuthService.java
src/main/java/com/keymobile/proxy/service/AuthService.java
+0
-34
PortalService.java
src/main/java/com/keymobile/proxy/service/PortalService.java
+9
-0
IpUtil.java
src/main/java/com/keymobile/proxy/util/IpUtil.java
+50
-0
LogManager.java
src/main/java/com/keymobile/proxy/util/LogManager.java
+175
-0
SystemUserUtil.java
src/main/java/com/keymobile/proxy/util/SystemUserUtil.java
+87
-0
WebServerService.java
src/main/java/com/keymobile/proxy/wss/WebServerService.java
+1
-1
WebServerServiceImpl.java
...va/com/keymobile/proxy/wss/impl/WebServerServiceImpl.java
+3
-3
application-local.yml
src/main/resources/application-local.yml
+52
-0
logback-custom.xml
src/main/resources/logback-custom.xml
+27
-0
No files found.
pom.xml
View file @
8fb67f02
...
...
@@ -66,6 +66,16 @@
<artifactId>
jedis
</artifactId>
<version>
2.9.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-pool2
</artifactId>
<version>
2.5.0
</version>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
8.0.11
</version>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
...
...
@@ -85,6 +95,11 @@
<artifactId>
spring-cloud-starter-feign
</artifactId>
<version>
1.4.5.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-pool2
</artifactId>
<version>
2.0
</version>
</dependency>
<!-- CXF webservice -->
...
...
src/main/java/com/keymobile/proxy/api/Constants.java
View file @
8fb67f02
...
...
@@ -9,5 +9,6 @@ public class Constants {
public
static
final
String
Session_Lang
=
"lang"
;
public
static
final
String
ROLE_PREFIX
=
"ROLE_"
;
public
static
final
String
SEP
=
"/"
;
public
static
final
String
LOG_AUTH_LOGIN_API
=
"auth.login"
;
}
src/main/java/com/keymobile/proxy/conf/RESTAuthenticationSuccessHandler.java
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
conf
;
import
com.keymobile.proxy.api.Constants
;
import
com.keymobile.proxy.util.LogManager
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler
;
import
org.springframework.stereotype.Component
;
import
com.keymobile.proxy.api.Constants
;
import
javax.servlet.ServletException
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.HashMap
;
import
java.util.Map
;
@Component
public
class
RESTAuthenticationSuccessHandler
extends
SimpleUrlAuthenticationSuccessHandler
{
Logger
logger
=
LoggerFactory
.
getLogger
(
RESTAuthenticationSuccessHandler
.
class
);
@Value
(
"${security.allowRootLogin:true}"
)
private
boolean
rootAllowLogin
=
true
;
...
...
@@ -31,16 +32,16 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
String
data
=
(
String
)
request
.
getSession
().
getAttribute
(
"ssoLogin"
);
System
.
out
.
println
(
"come onAuthenticationSuccess here"
);
if
(
null
==
data
){
System
.
out
.
println
(
"getAttribute('ssoLogin') is null"
);
logger
.
info
(
"getAttribute('ssoLogin') is null"
);
data
=
"ok"
;
}
String
returnStatus
=
data
;
//check if allow root login
if
(
null
==
request
.
getSession
()){
System
.
out
.
println
(
"RESTAuthenticationSuccessHandler--SessionID-->null"
);
logger
.
info
(
"RESTAuthenticationSuccessHandler--SessionID-->null"
);
}
else
{
System
.
out
.
println
(
"RESTAuthenticationSuccessHandler--SessionID-->"
+
request
.
getSession
().
getId
());
logger
.
info
(
"RESTAuthenticationSuccessHandler--SessionID-->"
+
request
.
getSession
().
getId
());
}
UserDetails
userDetails
=
(
UserDetails
)
authentication
.
getPrincipal
();
...
...
@@ -49,6 +50,9 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
&&
!
rootAllowLogin
)
returnStatus
=
"root not allow login"
;
if
(
StringUtils
.
equals
(
returnStatus
,
"ok"
))
{
LogManager
.
logInfo
(
Constants
.
LOG_AUTH_LOGIN_API
,
"登录"
,
null
);
}
response
.
sendRedirect
(
"/go"
);
PrintWriter
writer
=
response
.
getWriter
();
...
...
src/main/java/com/keymobile/proxy/conf/RedisClusterConfig.java
deleted
100644 → 0
View file @
52cdc784
package
com
.
keymobile
.
proxy
.
conf
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisClusterConfiguration
;
import
org.springframework.data.redis.connection.RedisNode
;
import
org.springframework.data.redis.connection.RedisPassword
;
import
org.springframework.data.redis.connection.jedis.JedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.JdkSerializationRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.session.data.redis.config.ConfigureRedisAction
;
import
org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession
;
import
redis.clients.jedis.JedisPoolConfig
;
import
java.util.HashSet
;
import
java.util.Set
;
/**
* Created by Administrator on 2019/2/28.
*/
@EnableRedisHttpSession
@Configuration
public
class
RedisClusterConfig
{
@Value
(
"${spring.redis.cluster.nodes}"
)
private
String
clusterNodes
;
@Value
(
"${spring.redis.cluster.max-redirects}"
)
private
int
maxRedirects
;
@Value
(
"${spring.redis.password}"
)
private
String
password
;
@Value
(
"${spring.redis.timeout}"
)
private
int
timeout
;
@Value
(
"${spring.redis.maxIdle}"
)
private
int
maxIdle
;
@Value
(
"${spring.redis.maxTotal}"
)
private
int
maxTotal
;
@Value
(
"${spring.redis.maxWaitMillis}"
)
private
int
maxWaitMillis
;
@Value
(
"${spring.redis.minEvictableIdleTimeMillis}"
)
private
int
minEvictableIdleTimeMillis
;
@Value
(
"${spring.redis.numTestsPerEvictionRun}"
)
private
int
numTestsPerEvictionRun
;
@Value
(
"${spring.redis.timeBetweenEvictionRunsMillis}"
)
private
int
timeBetweenEvictionRunsMillis
;
@Value
(
"${spring.redis.testOnBorrow}"
)
private
boolean
testOnBorrow
;
@Value
(
"${spring.redis.testWhileIdle}"
)
private
boolean
testWhileIdle
;
@Bean
public
JedisPoolConfig
getJedisPoolConfig
()
{
JedisPoolConfig
jedisPoolConfig
=
new
JedisPoolConfig
();
// 最大空闲数
jedisPoolConfig
.
setMaxIdle
(
maxIdle
);
// 连接池的最大数据库连接数
jedisPoolConfig
.
setMaxTotal
(
maxTotal
);
// 最大建立连接等待时间
jedisPoolConfig
.
setMaxWaitMillis
(
maxWaitMillis
);
// 逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
jedisPoolConfig
.
setMinEvictableIdleTimeMillis
(
minEvictableIdleTimeMillis
);
// 每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3
jedisPoolConfig
.
setNumTestsPerEvictionRun
(
numTestsPerEvictionRun
);
// 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
jedisPoolConfig
.
setTimeBetweenEvictionRunsMillis
(
timeBetweenEvictionRunsMillis
);
// 是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
jedisPoolConfig
.
setTestOnBorrow
(
testOnBorrow
);
// 在空闲时检查有效性, 默认false
jedisPoolConfig
.
setTestWhileIdle
(
testWhileIdle
);
return
jedisPoolConfig
;
}
/**
* Redis集群的配置
* @return RedisClusterConfiguration
* @throws
*/
@Bean
public
RedisClusterConfiguration
redisClusterConfiguration
(){
RedisClusterConfiguration
redisClusterConfiguration
=
new
RedisClusterConfiguration
();
//Set<RedisNode> clusterNodes
String
[]
serverArray
=
clusterNodes
.
split
(
","
);
Set
<
RedisNode
>
nodes
=
new
HashSet
<
RedisNode
>();
for
(
String
ipPort:
serverArray
){
String
[]
ipAndPort
=
ipPort
.
split
(
":"
);
nodes
.
add
(
new
RedisNode
(
ipAndPort
[
0
].
trim
(),
Integer
.
valueOf
(
ipAndPort
[
1
])));
}
redisClusterConfiguration
.
setClusterNodes
(
nodes
);
redisClusterConfiguration
.
setMaxRedirects
(
maxRedirects
);
redisClusterConfiguration
.
setPassword
(
RedisPassword
.
of
(
password
));
return
redisClusterConfiguration
;
}
/**
* @param
* @return
* @Description:redis连接工厂类
* @date 2018/10/25 19:45
*/
@Bean
public
JedisConnectionFactory
jedisConnectionFactory
()
{
if
(
clusterNodes
.
split
(
","
).
length
==
1
)
{
//非多节点集群
JedisConnectionFactory
factory
=
new
JedisConnectionFactory
();
factory
.
setHostName
(
clusterNodes
.
split
(
":"
)[
0
]);
factory
.
setPort
(
Integer
.
valueOf
(
clusterNodes
.
split
(
":"
)[
1
]));
factory
.
setPassword
(
password
);
factory
.
setTimeout
(
timeout
);
return
factory
;
}
else
{
//集群模式
JedisConnectionFactory
factory
=
new
JedisConnectionFactory
(
redisClusterConfiguration
(),
getJedisPoolConfig
());
factory
.
setDatabase
(
0
);
factory
.
setTimeout
(
timeout
);
factory
.
setUsePool
(
true
);
return
factory
;
}
}
/**
* 实例化 RedisTemplate 对象
*
* @return
*/
@Bean
public
RedisTemplate
<
String
,
Object
>
redisTemplate
()
{
RedisTemplate
<
String
,
Object
>
redisTemplate
=
new
RedisTemplate
<>();
initDomainRedisTemplate
(
redisTemplate
);
return
redisTemplate
;
}
/**
* 设置数据存入 redis 的序列化方式,并开启事务
* 使用默认的序列化会导致key乱码
*
*/
private
void
initDomainRedisTemplate
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
//如果不配置Serializer,那么存储的时候缺省使用String,如果用User类型存储,那么会提示错误User can't cast to String!
redisTemplate
.
setKeySerializer
(
new
StringRedisSerializer
());
//这个地方有一个问题,这种序列化器会将value序列化成对象存储进redis中,如果
//你想取出value,然后进行自增的话,这种序列化器是不可以的,因为对象不能自增;
//需要改成StringRedisSerializer序列化器。
redisTemplate
.
setValueSerializer
(
new
JdkSerializationRedisSerializer
());
redisTemplate
.
setEnableTransactionSupport
(
false
);
redisTemplate
.
setConnectionFactory
(
jedisConnectionFactory
());
}
@Bean
public
static
ConfigureRedisAction
configureRedisAction
(){
return
ConfigureRedisAction
.
NO_OP
;
}
}
src/main/java/com/keymobile/proxy/conf/RedisConfig.java
0 → 100644
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
conf
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.session.data.redis.config.ConfigureRedisAction
;
@Configuration
public
class
RedisConfig
{
@Bean
public
ConfigureRedisAction
configureRedisAction
()
{
return
ConfigureRedisAction
.
NO_OP
;
}
}
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
conf
;
import
com.keymobile.proxy.api.Constants
;
import
com.keymobile.proxy.model.Author
;
import
com.keymobile.proxy.model.Domain
;
import
com.keymobile.proxy.model.Role
;
import
com.keymobile.proxy.service.AuthService
;
import
com.keymobile.proxy.service.PortalService
;
import
com.keymobile.proxy.util.Des
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -22,6 +19,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.crypto.password.NoOpPasswordEncoder
;
import
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
;
import
org.springframework.util.CollectionUtils
;
import
javax.naming.Context
;
import
javax.naming.NamingException
;
...
...
@@ -41,20 +39,19 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SecurityConfig
.
class
);
private
static
final
String
usersQuery
=
"select concat(user_name, ':', user_id, ':', user_dname), password, true \n"
+
"from auth_user where user_name = ?"
;
private
static
final
String
rolesQuery
=
"select t1.user_name, concat(concat('ROLE_', t1.author_name), ':', GROUP_CONCAT(COALESCE(t2.domain_id, '*'))) as role_name \n"
+
"from \n"
+
" (select a.user_name, d.author_name\n"
+
" from auth_user a, auth_user_roles b, auth_role_authors c, auth_author d\n"
+
" where a.user_id = b.user_id and b.role_id = c.role_id and c.author_id = d.author_id\n"
+
" and a.user_name = substring_index(?, ':', 1)) t1\n"
+
private
static
final
String
usersQuery
=
"select concat(user_id, ':', id, ':', disname, ':', org_no), `password`, true from p_user where user_id = ? and `status` = '1'"
;
private
static
final
String
rolesQuery
=
"select t1.user_id, concat(concat(\"ROLE_\", t1.author_no), ':', GROUP_CONCAT(COALESCE(t2.domain_id, '*'))) as role_name\n"
+
" from \n"
+
" (select user.user_id, author.author_no\n"
+
" from p_user AS user, p_user_role AS ur, p_author_role AS ar, p_author AS author\n"
+
" where user.user_id = ur.user_id AND ur.role_id = ar.role_id AND ar.author_id = author.author_id\n"
+
" and user.user_id = substring_index(?, \":\", 1)) t1\n"
+
" left join\n"
+
"
(select a.user_name, c
.domain_id\n"
+
"
from auth_user a, auth_user_domains b, auth_domain c
\n"
+
"
where a.user_id = b.user_id and b.domain_id = c
.domain_id) t2\n"
+
"
on t1.user_name = t2.user_name
\n"
+
"
group by t1.author_name
"
;
"
(select user.user_id, domain
.domain_id\n"
+
"
from p_user user, p_user_domain ud, p_domain domain
\n"
+
"
where user.user_id = ud.user_id and ud.domain_id = domain
.domain_id) t2\n"
+
"
on t1.user_id = t2.user_id
\n"
+
"
group by t1.author_no
"
;
@Autowired
private
DataSource
dataSource
;
...
...
@@ -68,7 +65,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private
RESTLogoutSuccessHandler
logoutSuccessHandler
;
@Autowired
private
AuthService
auth
Service
;
private
PortalService
portal
Service
;
@Autowired
public
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
...
...
@@ -113,39 +110,22 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return
null
;
}
httpServletRequest
.
getSession
().
setAttribute
(
"ssoLogin"
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_succeed'}}});"
);
com
.
keymobile
.
proxy
.
model
.
User
u
=
authService
.
getUserByName
(
username
);
if
(
u
==
null
)
{
u
=
new
com
.
keymobile
.
proxy
.
model
.
User
();
u
.
setName
(
username
);
u
.
setPassword
(
"37fa265330ad83eaa879efb1e2db6380896cf639"
);
//pwd
u
.
setDName
(
username
);
u
=
authService
.
addUser
(
new
Long
[]
{
(
long
)
4
},
new
Long
[]
{},
u
);
this
.
logger
.
info
(
"单点登录新增用户:"
+
authService
);
com
.
keymobile
.
proxy
.
model
.
User
user
=
portalService
.
getUserByUserId
(
username
);
if
(
user
==
null
)
{
logger
.
error
(
username
+
" is not exit"
);
httpServletResponse
.
sendError
(
500
,
CallBack
+
"({'query':{'results':{'postresult':'portal_ssologin_fali'}}});"
);
return
null
;
}
List
<
GrantedAuthority
>
authorities
=
new
ArrayList
<>();
String
userName
=
u
.
getName
()
+
":"
+
u
.
getId
()
+
":"
+
u
.
getDName
();
String
userDomainFilterStr
=
"*"
;
List
<
String
>
userDomainList
=
new
ArrayList
<>();
List
<
Domain
>
domainsOfUser
=
authService
.
getDomainsOfUser
(
u
.
getId
());
domainsOfUser
.
forEach
(
d
->
userDomainList
.
add
(
d
.
getDomainId
().
toString
()));
if
(
userDomainList
.
size
()
>
0
)
{
userDomainFilterStr
=
String
.
join
(
","
,
userDomainList
);
}
List
<
Role
>
rolesOfUser
=
authService
.
getRolesOfUser
(
u
.
getId
());
for
(
Role
role
:
rolesOfUser
)
{
List
<
Author
>
authors
=
authService
.
getAuthorsOfRole
(
role
.
getRoleId
());
for
(
Author
author:
authors
)
{
GrantedAuthority
authorityInfo
=
new
SimpleGrantedAuthority
(
Constants
.
ROLE_PREFIX
+
author
.
getAuthorName
()
+
":"
+
userDomainFilterStr
);
String
userName
=
user
.
getUserId
()
+
":"
+
user
.
getId
()
+
":"
+
user
.
getDisname
()
+
":"
+
user
.
getOrgNo
();
List
<
String
>
authors
=
portalService
.
getByUserId
(
username
);
if
(!
CollectionUtils
.
isEmpty
(
authors
))
{
for
(
String
author
:
authors
)
{
GrantedAuthority
authorityInfo
=
new
SimpleGrantedAuthority
(
Constants
.
ROLE_PREFIX
+
author
);
authorities
.
add
(
authorityInfo
);
}
}
Authentication
auth
=
new
UsernamePasswordAuthenticationToken
(
new
User
(
userName
,
"whatever"
,
authorities
),
null
,
authorities
);
return
auth
;
return
new
UsernamePasswordAuthenticationToken
(
new
User
(
userName
,
"whatever"
,
authorities
),
null
,
authorities
);
}
};
authenticationFilter
.
setAuthenticationManager
(
authenticationManager
());
...
...
src/main/java/com/keymobile/proxy/conf/WebServiceConfig.java
View file @
8fb67f02
...
...
@@ -51,7 +51,7 @@ public class WebServiceConfig {
@Bean
public
Endpoint
endpoint
()
{
EndpointImpl
endpoint
=
new
EndpointImpl
(
springBus
(),
serverService
);
endpoint
.
publish
(
"/wss/GetPermission"
);
endpoint
.
publish
(
"/wss/GetP
ortalP
ermission"
);
return
endpoint
;
}
}
src/main/java/com/keymobile/proxy/enums/ModelPathEnum.java
0 → 100644
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
enums
;
public
enum
ModelPathEnum
{
LOG_PORTAL_REPORT_API
(
"auth.login"
,
"系统登录/系统登录"
),
;
private
String
modelName
;
private
String
modelPath
;
private
ModelPathEnum
(
String
modelName
,
String
modelPath
)
{
this
.
modelName
=
modelName
;
this
.
modelPath
=
modelPath
;
}
public
static
String
getModelPath
(
String
modelName
)
{
for
(
ModelPathEnum
path
:
ModelPathEnum
.
values
())
{
if
(
modelName
.
equals
(
path
.
getModelName
()))
{
return
path
.
getModelPath
();
}
}
return
null
;
}
public
String
getModelName
()
{
return
modelName
;
}
public
String
getModelPath
()
{
return
modelPath
;
}
}
src/main/java/com/keymobile/proxy/model/Author.java
deleted
100644 → 0
View file @
52cdc784
package
com
.
keymobile
.
proxy
.
model
;
public
class
Author
{
private
Long
id
;
private
String
name
;
public
Author
()
{}
public
Long
getAuthorId
()
{
return
id
;
}
public
void
setAuthorId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getAuthorName
()
{
return
name
;
}
public
void
setAuthorName
(
String
name
)
{
this
.
name
=
name
;
}
}
src/main/java/com/keymobile/proxy/model/Domain.java
deleted
100644 → 0
View file @
52cdc784
package
com
.
keymobile
.
proxy
.
model
;
public
class
Domain
{
private
Long
id
;
private
String
name
;
public
Domain
()
{}
public
Domain
(
String
name
)
{
this
.
name
=
name
;
}
public
Long
getDomainId
()
{
return
id
;
}
public
void
setDomainId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getDomainName
()
{
return
name
;
}
public
void
setDomainName
(
String
name
)
{
this
.
name
=
name
;
}
}
src/main/java/com/keymobile/proxy/model/Role.java
deleted
100644 → 0
View file @
52cdc784
package
com
.
keymobile
.
proxy
.
model
;
public
class
Role
{
private
Long
id
;
private
String
name
;
private
String
dname
;
public
Role
()
{}
public
Long
getRoleId
()
{
return
id
;
}
public
void
setRoleId
(
Long
id
)
{
this
.
id
=
id
;
}
public
String
getRoleName
()
{
return
name
;
}
public
void
setRoleName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getRoleDName
()
{
return
dname
;
}
public
void
setRoleDName
(
String
dname
)
{
this
.
dname
=
dname
;
}
}
src/main/java/com/keymobile/proxy/model/User.java
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
model
;
import
java.util.List
;
public
class
User
{
private
Long
id
;
private
String
name
;
private
String
dname
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @author fyj:
* @version 创建时间:2016年9月19日 下午1:51:55
*/
@Entity
@Table
(
name
=
"p_user"
)
public
class
User
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
2968201685546858938L
;
@Id
@GeneratedValue
private
Integer
id
;
/**
* 账号
*/
@Column
(
length
=
50
)
private
String
userId
;
/**
* 用户名
*/
@Column
(
length
=
50
)
private
String
username
;
/**
* 姓名
*/
@Column
(
length
=
50
)
private
String
disname
;
/**
* 邮件
*/
@Column
(
length
=
50
)
private
String
email
;
/**
* 手机号
*/
@Column
(
length
=
50
)
private
String
mobile
;
/**
* 密码
*/
@Column
(
length
=
50
)
private
String
password
;
private
List
<
Role
>
roles
;
private
List
<
Domain
>
domains
;
public
User
()
{}
/**
* 备注
*/
@Column
(
length
=
500
)
private
String
remarks
;
/**
* 状态:0失效 1:生效
*/
private
Integer
status
;
/**
* 机构编号
*/
@Column
(
length
=
50
)
private
String
orgNo
;
/**
* 0导入用户 1系统新增用户
*/
private
Integer
typ
;
/**
* 办公电话
*/
@Column
(
length
=
50
)
private
String
officePhone
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 修改时间
*/
private
Date
updateTime
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Long
getId
()
{
return
id
;
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
public
String
getUsername
()
{
return
username
;
}
public
String
getName
(
)
{
return
name
;
public
void
setUsername
(
String
username
)
{
this
.
username
=
user
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
public
String
getDisname
(
)
{
return
dis
name
;
}
public
String
getDName
(
)
{
return
d
name
;
public
void
setDisname
(
String
disname
)
{
this
.
disname
=
dis
name
;
}
public
void
setDName
(
String
dname
)
{
this
.
dname
=
dname
;
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getMobile
()
{
return
mobile
;
}
public
void
setMobile
(
String
mobile
)
{
this
.
mobile
=
mobile
;
}
public
String
getPassword
()
{
...
...
@@ -42,24 +146,62 @@ public class User {
}
public
void
setPassword
(
String
password
)
{
System
.
out
.
println
(
password
);
this
.
password
=
password
;
}
public
List
<
Role
>
getRoles
()
{
return
roles
;
public
String
getRemarks
()
{
return
remarks
;
}
public
void
setRemarks
(
String
remarks
)
{
this
.
remarks
=
remarks
;
}
public
void
setRoles
(
List
<
Role
>
roles
)
{
this
.
roles
=
role
s
;
public
Integer
getStatus
(
)
{
return
statu
s
;
}
public
List
<
Domain
>
getDomains
(
)
{
return
domain
s
;
public
void
setStatus
(
Integer
status
)
{
this
.
status
=
statu
s
;
}
public
void
setDomains
(
List
<
Domain
>
domains
)
{
this
.
domains
=
domains
;
public
Date
getCreateTime
(
)
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Date
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Date
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
String
getOrgNo
()
{
return
orgNo
;
}
public
void
setOrgNo
(
String
orgNo
)
{
this
.
orgNo
=
orgNo
;
}
public
Integer
getTyp
()
{
return
typ
;
}
public
void
setTyp
(
Integer
typ
)
{
this
.
typ
=
typ
;
}
public
String
getOfficePhone
()
{
return
officePhone
;
}
public
void
setOfficePhone
(
String
officePhone
)
{
this
.
officePhone
=
officePhone
;
}
}
src/main/java/com/keymobile/proxy/service/AuthService.java
deleted
100644 → 0
View file @
52cdc784
package
com
.
keymobile
.
proxy
.
service
;
import
com.keymobile.proxy.model.Author
;
import
com.keymobile.proxy.model.Domain
;
import
com.keymobile.proxy.model.Role
;
import
com.keymobile.proxy.model.User
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@FeignClient
(
value
=
"authService"
)
public
interface
AuthService
{
@RequestMapping
(
value
=
"/user"
)
User
getUserByName
(
@RequestParam
(
value
=
"name"
)
String
name
);
@PostMapping
(
value
=
"/users/{userId}"
)
User
updateUser
(
@PathVariable
(
value
=
"userId"
)
Long
userId
,
@RequestBody
User
user
);
@RequestMapping
(
value
=
"/users"
,
method
=
RequestMethod
.
POST
)
User
addUser
(
@RequestParam
(
value
=
"roleIds"
,
required
=
false
)
Long
[]
roleIds
,
@RequestParam
(
value
=
"domainIds"
,
required
=
false
)
Long
[]
domainIds
,
@RequestBody
User
user
);
@RequestMapping
(
value
=
"/roles/{roleId}/authors"
,
method
=
RequestMethod
.
GET
)
List
<
Author
>
getAuthorsOfRole
(
@PathVariable
(
value
=
"roleId"
)
Long
roleId
);
@RequestMapping
(
value
=
"/users/{userId}/roles"
,
method
=
RequestMethod
.
GET
)
List
<
Role
>
getRolesOfUser
(
@PathVariable
(
value
=
"userId"
)
Long
userId
);
@RequestMapping
(
value
=
"/users/{userId}/domains"
,
method
=
RequestMethod
.
GET
)
List
<
Domain
>
getDomainsOfUser
(
@PathVariable
(
value
=
"userId"
)
Long
userId
);
}
src/main/java/com/keymobile/proxy/service/PortalService.java
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
service
;
import
com.keymobile.proxy.model.User
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@FeignClient
(
value
=
"portal"
)
public
interface
PortalService
{
@RequestMapping
(
value
=
"/user/getStatus"
)
Integer
getUserStatus
(
@RequestParam
(
value
=
"userId"
)
String
userId
);
@GetMapping
(
"/user/getUserByUserId"
)
User
getUserByUserId
(
@RequestParam
String
userId
);
@GetMapping
(
"/author/getByUserId"
)
List
<
String
>
getByUserId
(
@RequestParam
String
userId
);
}
src/main/java/com/keymobile/proxy/util/IpUtil.java
0 → 100644
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
util
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
/**
* ip工具类
*/
public
class
IpUtil
{
/**
* 获取IP
* @param request request
* @return IP
*/
public
static
String
getIpAddr
(
HttpServletRequest
request
)
{
String
ipAddress
;
try
{
ipAddress
=
request
.
getHeader
(
"x-forwarded-for"
);
if
(
ipAddress
==
null
||
ipAddress
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ipAddress
))
{
ipAddress
=
request
.
getHeader
(
"Proxy-Client-IP"
);
}
if
(
ipAddress
==
null
||
ipAddress
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ipAddress
))
{
ipAddress
=
request
.
getHeader
(
"WL-Proxy-Client-IP"
);
}
if
(
ipAddress
==
null
||
ipAddress
.
length
()
==
0
||
"unknown"
.
equalsIgnoreCase
(
ipAddress
))
{
ipAddress
=
request
.
getRemoteAddr
();
if
(
"127.0.0.1"
.
equals
(
ipAddress
))
{
try
{
InetAddress
inet
=
InetAddress
.
getLocalHost
();
ipAddress
=
inet
.
getHostAddress
();
}
catch
(
UnknownHostException
e
)
{
e
.
printStackTrace
();
}
}
}
if
(
ipAddress
!=
null
&&
ipAddress
.
length
()
>
15
)
{
if
(
ipAddress
.
indexOf
(
","
)
>
0
)
{
ipAddress
=
ipAddress
.
substring
(
0
,
ipAddress
.
indexOf
(
","
));
}
}
}
catch
(
Exception
e
)
{
ipAddress
=
""
;
}
return
ipAddress
;
}
}
src/main/java/com/keymobile/proxy/util/LogManager.java
0 → 100644
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
util
;
import
com.keymobile.proxy.api.Constants
;
import
com.keymobile.proxy.enums.ModelPathEnum
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
/**
* 日志操作工具.
* @author linxu
* @version 1.0
* @date 2020/3/25 11:00
*/
public
class
LogManager
{
/**
* trace.
* @param context context
* @param e e
* @param message message
*/
public
static
void
logTrace
(
String
context
,
Throwable
e
,
String
message
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
context
);
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
message
,
e
);
}
}
/**
* trace.
* @param context context
* @param message message
*/
public
static
void
logTrace
(
String
context
,
String
message
)
{
logTrace
(
context
,
null
,
message
);
}
/**
* debug.
* @param context context
* @param message message
*/
public
static
void
logDebug
(
String
context
,
String
message
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
context
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
message
);
}
}
/**
* log.
* @param context context
* @param message message
*/
public
static
void
logInfo
(
String
context
,
String
message
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
context
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
message
);
}
}
/**
* info.
* @param context context
* @param message message
* @param objects objects
*/
public
static
void
logInfo
(
String
context
,
String
message
,
Object
...
objects
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
context
);
String
ip
=
getIp
();
// message = message + "; IP: " + ip;
message
=
StringUtils
.
replace
(
message
,
"{}"
,
"%s"
);
message
=
String
.
format
(
message
,
objects
);
String
menuPath
=
getMenuPath
(
context
);
String
[]
split
=
menuPath
.
split
(
Constants
.
SEP
);
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
message
,
getUser
(),
split
[
0
],
ip
,
getMenuPath
(
context
));
// logger.info(message, getUser(), getSessionId(), ip, getMenuPath(context));
}
}
/**
* warning.
* @param context context
* @param e e
* @param message message
*/
public
static
void
logWarning
(
String
context
,
Throwable
e
,
String
message
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
context
);
if
(
logger
.
isWarnEnabled
())
{
logger
.
warn
(
message
,
e
);
}
}
/**
* warning.
* @param context context
* @param message message
*/
public
static
void
logWarning
(
String
context
,
String
message
)
{
logWarning
(
context
,
null
,
message
);
}
/**
* error.
* @param context context
* @param e e
* @param message message
*/
public
static
void
logError
(
String
context
,
Throwable
e
,
String
message
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
context
);
if
(
logger
.
isErrorEnabled
())
{
logger
.
error
(
message
,
e
);
}
}
/**
* error.
* @param context context
* @param message message
*/
public
static
void
logError
(
String
context
,
String
message
)
{
Logger
logger
=
LoggerFactory
.
getLogger
(
context
);
if
(
logger
.
isErrorEnabled
())
{
logger
.
error
(
message
);
}
}
/**
* 获取sessionId.
* @return sessionId
*/
public
static
String
getSessionId
()
{
RequestAttributes
attrs
=
RequestContextHolder
.
getRequestAttributes
();
if
(
attrs
!=
null
)
{
return
attrs
.
getSessionId
();
}
return
"NO_SESSION"
;
}
/**
* 获取IP.
* @return ip
*/
public
static
String
getIp
()
{
RequestAttributes
attrs
=
RequestContextHolder
.
getRequestAttributes
();
if
(
attrs
!=
null
)
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
attrs
).
getRequest
();
return
IpUtil
.
getIpAddr
(
request
);
}
return
""
;
}
/**
* 获取用户.
* @return user
*/
public
static
String
getUser
()
{
return
SystemUserUtil
.
getCurrentUser
();
}
/**
* 获取模块路径
*/
public
static
String
getMenuPath
(
String
context
)
{
return
ModelPathEnum
.
getModelPath
(
context
);
}
}
src/main/java/com/keymobile/proxy/util/SystemUserUtil.java
0 → 100644
View file @
8fb67f02
package
com
.
keymobile
.
proxy
.
util
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
/**
* 获取当前登录用户信息
*/
public
class
SystemUserUtil
{
/**
* 获取当前登录用户名和id
* @return
*/
public
static
String
getCurrentUser
()
{
Authentication
auth
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
String
user
=
"NO_USER"
;
if
(
auth
!=
null
)
{
user
=
auth
.
getName
();
}
return
user
;
}
/**
* 获取当前登录用户id
* @return
*/
public
static
String
getCurrentUserId
()
{
Authentication
auth
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
String
userId
=
"NO_USER"
;
if
(
auth
!=
null
)
{
Object
obj
=
auth
.
getPrincipal
();
if
(
obj
!=
null
)
{
if
(
obj
instanceof
String
)
{
userId
=
obj
.
toString
();
}
else
{
UserDetails
userDetails
=
(
UserDetails
)
obj
;
String
userNameWithIdAttached
=
userDetails
.
getUsername
();
userId
=
userNameWithIdAttached
.
split
(
":"
)[
1
];
}
}
}
return
userId
;
}
/**
* 获取当前登录用户名
* @return
*/
public
static
String
getCurrentUserName
()
{
Authentication
auth
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
String
userId
=
"NO_USER"
;
if
(
auth
!=
null
)
{
Object
obj
=
auth
.
getPrincipal
();
if
(
obj
!=
null
)
{
if
(
obj
instanceof
String
)
{
userId
=
obj
.
toString
();
}
else
{
UserDetails
userDetails
=
(
UserDetails
)
obj
;
String
userNameWithIdAttached
=
userDetails
.
getUsername
();
userId
=
userNameWithIdAttached
.
split
(
":"
)[
0
];
}
}
}
return
userId
;
}
/**
* 获取当前登录用户所属组织id
* @return
*/
public
static
String
getCurrentUserOrgId
()
{
//TODO 待实现
return
"1"
;
}
/**
* 获取当前登录用户所属组织名称
* @return
*/
public
static
String
getCurrentUserOrgName
()
{
//TODO 待实现
return
"1"
;
}
}
src/main/java/com/keymobile/proxy/wss/WebServerService.java
View file @
8fb67f02
...
...
@@ -8,6 +8,6 @@ import javax.jws.WebService;
public
interface
WebServerService
{
@WebMethod
String
GetPermission
(
@WebParam
String
userId
);
String
GetP
ortalP
ermission
(
@WebParam
String
userId
);
}
src/main/java/com/keymobile/proxy/wss/impl/WebServerServiceImpl.java
View file @
8fb67f02
...
...
@@ -20,12 +20,12 @@ public class WebServerServiceImpl implements WebServerService {
private
PortalService
portalService
;
@Override
public
String
GetPermission
(
String
userId
)
{
public
String
GetP
ortalP
ermission
(
String
userId
)
{
if
(
null
==
userId
||
""
.
equals
(
userId
.
trim
())){
logger
.
info
(
"GetPermission传递userId参数为空"
);
logger
.
info
(
"GetP
ortalP
ermission传递userId参数为空"
);
return
"0"
;
}
logger
.
info
(
"GetPermission传递userId:"
+
userId
);
logger
.
info
(
"GetP
ortalP
ermission传递userId:"
+
userId
);
Integer
status
=
portalService
.
getUserStatus
(
userId
);
if
(
null
==
status
||
status
==
0
){
return
"0"
;
...
...
src/main/resources/application-local.yml
0 → 100644
View file @
8fb67f02
server
:
port
:
8766
spring
:
application
:
name
:
auth
session
:
store-type
:
redis
redis
:
namespace
:
hyycdev
redis
:
host
:
localhost
port
:
6379
datasource
:
url
:
jdbc:mysql://139.198.127.54:9306/xchyindicators?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&useSSL=false&serverTimezone=UTC
username
:
test
password
:
test
servlet
:
multipart
:
max-file-size
:
100Mb
max-request-size
:
100Mb
mvc
:
view
:
prefix
:
/WEB-INF/jsp/
suffix
:
.jsp
eureka
:
client
:
registerWithEureka
:
true
region
:
default
registryFetchIntervalSeconds
:
5
serviceUrl
:
defaultZone
:
http://localhost:8081/eureka/
zuul
:
prefix
:
/api
sensitive-headers
:
security
:
permit
:
true
authUser
:
root
authPwd
:
pwd
logging
:
level
:
org.springframework.security
:
DEBUG
com.keymobile.proxy
:
info
config
:
classpath:logback-custom.xml
redirect-url
:
system-management
:
http://192.168.0.216:9090/center-home/view/index
data-platform
:
http://192.168.0.216:9090/center-home/view/index
\ No newline at end of file
src/main/resources/logback-custom.xml
0 → 100644
View file @
8fb67f02
<?xml version="1.0" encoding="UTF-8"?>
<configuration
>
<springProperty
scope=
"context"
name=
"spring.datasource.url"
source=
"spring.datasource.url"
/>
<springProperty
scope=
"context"
name=
"spring.datasource.username"
source=
"spring.datasource.username"
/>
<springProperty
scope=
"context"
name=
"spring.datasource.password"
source=
"spring.datasource.password"
/>
<appender
name=
"stdout"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %X{user} %X{session} %-5level %logger{5} - %msg%n
</pattern>
</encoder>
</appender>
<appender
name=
"db"
class=
"ch.qos.logback.classic.db.DBAppender"
>
<connectionSource
class=
"ch.qos.logback.core.db.DriverManagerConnectionSource"
>
<driverClass>
com.mysql.cj.jdbc.Driver
</driverClass>
<url>
${spring.datasource.url}
</url>
<user>
${spring.datasource.username}
</user>
<password>
${spring.datasource.password}
</password>
</connectionSource>
</appender>
<logger
name=
"auth.login"
>
<appender-ref
ref=
"db"
/>
</logger>
<root
level=
"INFO"
>
<appender-ref
ref=
"stdout"
/>
</root>
</configuration>
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