Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibizlab-boot-starters
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibizlab-boot-starters
提交
47464f4d
提交
47464f4d
编写于
9月 12, 2022
作者:
ibiz4j
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cloud uaa 接入
上级
7166c8b4
变更
18
隐藏空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
552 行增加
和
86 行删除
+552
-86
DTOBase.java
...er-data/src/main/java/cn/ibizlab/util/domain/DTOBase.java
+13
-1
EntityBase.java
...data/src/main/java/cn/ibizlab/util/domain/EntityBase.java
+12
-2
IBZUSERServiceImpl.java
...main/java/cn/ibizlab/util/service/IBZUSERServiceImpl.java
+34
-2
pom.xml
ibizlab-boot-starter-gateway/pom.xml
+84
-4
pom.xml
ibizlab-boot-starter/pom.xml
+5
-0
IBZUAAFallback.java
.../src/main/java/cn/ibizlab/util/client/IBZUAAFallback.java
+7
-1
IBZUAAFeignClient.java
...c/main/java/cn/ibizlab/util/client/IBZUAAFeignClient.java
+5
-0
DynamicParamUtils.java
...c/main/java/cn/ibizlab/util/helper/DynamicParamUtils.java
+87
-0
JacksonUtils.java
...er/src/main/java/cn/ibizlab/util/helper/JacksonUtils.java
+156
-0
Setting.java
...starter/src/main/java/cn/ibizlab/util/helper/Setting.java
+26
-30
AppController.java
...ter/src/main/java/cn/ibizlab/util/rest/AppController.java
+2
-1
AuthenticationController.java
...n/java/cn/ibizlab/util/rest/AuthenticationController.java
+3
-7
AuthenticationUser.java
...ain/java/cn/ibizlab/util/security/AuthenticationUser.java
+17
-17
AuthenticationUserService.java
...va/cn/ibizlab/util/service/AuthenticationUserService.java
+13
-14
CloudUserService.java
...c/main/java/cn/ibizlab/util/service/CloudUserService.java
+25
-0
IBZUAAUserService.java
.../main/java/cn/ibizlab/util/service/IBZUAAUserService.java
+30
-4
SimpleUserService.java
.../main/java/cn/ibizlab/util/service/SimpleUserService.java
+33
-2
pom.xml
pom.xml
+0
-1
未找到文件。
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/DTOBase.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
domain
;
import
cn.ibizlab.util.helper.BeanCache
;
import
cn.ibizlab.util.helper.Setting
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonAnyGetter
;
import
com.fasterxml.jackson.annotation.JsonAnySetter
;
...
...
@@ -9,7 +10,7 @@ import lombok.Data;
import
org.springframework.cglib.beans.BeanMap
;
import
org.springframework.data.annotation.Transient
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.HashSet
;
...
...
@@ -126,5 +127,16 @@ public class DTOBase implements Serializable {
this
.
extensionparams
.
put
(
field
.
toLowerCase
(),
value
);
}
}
public
void
readSetting
(
String
field
)
{
Object
config
=
this
.
get
(
field
);
if
(!
ObjectUtils
.
isEmpty
(
config
))
{
Setting
.
getMap
(
config
.
toString
()).
entrySet
().
forEach
(
entry
->{
this
.
set
(
entry
.
getKey
(),
entry
.
getValue
());
});
}
}
}
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/domain/EntityBase.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
domain
;
import
cn.ibizlab.util.helper.BeanCache
;
import
cn.ibizlab.util.helper.Setting
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.fasterxml.jackson.annotation.JsonAnyGetter
;
...
...
@@ -11,8 +12,6 @@ import org.springframework.data.annotation.Transient;
import
org.springframework.util.AlternativeJdkIdGenerator
;
import
org.springframework.util.ObjectUtils
;
import
java.io.Serializable
;
import
java.lang.reflect.Field
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
public
class
EntityBase
implements
Serializable
{
...
...
@@ -141,4 +140,15 @@ public class EntityBase implements Serializable {
public
void
reset
(
String
field
){
}
public
void
readSetting
(
String
field
)
{
Object
config
=
this
.
get
(
field
);
if
(!
ObjectUtils
.
isEmpty
(
config
))
{
Setting
.
getMap
(
config
.
toString
()).
entrySet
().
forEach
(
entry
->{
this
.
set
(
entry
.
getKey
(),
entry
.
getValue
());
});
}
}
}
\ No newline at end of file
ibizlab-boot-starter-data/src/main/java/cn/ibizlab/util/service/IBZUSERServiceImpl.java
浏览文件 @
47464f4d
...
...
@@ -4,11 +4,16 @@ import cn.ibizlab.util.domain.IBZUSER;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.CachedBeanCopier
;
import
cn.ibizlab.util.mapper.IBZUSERMapper
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationInfo
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
...
...
@@ -25,7 +30,26 @@ public class IBZUSERServiceImpl extends ServiceImpl<IBZUSERMapper, IBZUSER> impl
@Value
(
"${ibiz.auth.pwencrymode:0}"
)
private
int
pwencrymode
;
@Value
(
"${ibiz.enablePermissionValid:false}"
)
boolean
enablePermissionValid
;
//是否开启权限校验
@Value
(
"${ibiz.systemid}"
)
private
String
systemId
;
@Override
public
boolean
isEnablePermissionValid
()
{
return
enablePermissionValid
;
}
@Override
public
String
getSystemId
()
{
return
systemId
;
}
@Override
@Cacheable
(
value
=
"sys_users"
,
key
=
"'getByUsername:'+#p0"
)
public
AuthenticationUser
loadUserByUsername
(
String
username
)
{
if
(
StringUtils
.
isEmpty
(
username
))
{
throw
new
UsernameNotFoundException
(
"用户名为空"
);
...
...
@@ -56,8 +80,13 @@ public class IBZUSERServiceImpl extends ServiceImpl<IBZUSERMapper, IBZUSER> impl
}
}
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
@Override
public
Authentication
User
loadUserByLogin
(
String
username
,
String
password
){
public
Authentication
Info
loadUserByLogin
(
String
username
,
String
password
){
AuthenticationUser
authuserdetail
=
loadUserByUsername
(
username
);
if
(
pwencrymode
==
1
){
password
=
DigestUtils
.
md5DigestAsHex
(
password
.
getBytes
());
...
...
@@ -68,10 +97,13 @@ public class IBZUSERServiceImpl extends ServiceImpl<IBZUSERMapper, IBZUSER> impl
if
(!
authuserdetail
.
getPassword
().
equals
(
password
))
{
throw
new
BadRequestAlertException
(
"用户名密码错误"
,
"IBZUSER"
,
username
);
}
return
authuserdetail
;
final
String
token
=
jwtTokenUtil
.
generateToken
(
authuserdetail
);
// 返回 token
return
new
AuthenticationInfo
(
token
,
authuserdetail
);
}
@CacheEvict
(
value
=
"sys_users"
,
key
=
"'getByUsername:'+#p0"
)
public
void
resetByUsername
(
String
username
)
{
}
...
...
ibizlab-boot-starter-gateway/pom.xml
浏览文件 @
47464f4d
...
...
@@ -3,10 +3,10 @@
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<
artifactId>
ibizlab-boot-starter-parent
</artifact
Id>
<
groupId>
cn.ibizlab
</group
Id>
<version>
2.4.0
-SNAPSHOT
</version>
<relativePath
>
../ibizlab-boot-starter-parent/pom.xml
</relativePath
>
<
groupId>
org.springframework.boot
</group
Id>
<
artifactId>
spring-boot-starter-parent
</artifact
Id>
<version>
2.4.0
</version>
<relativePath
/
>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
@@ -14,8 +14,48 @@
<version>
2.4.0-SNAPSHOT
</version>
<name>
iBizLab Boot Starter Gateway
</name>
<description>
iBizLab Boot Starter Gateway
</description>
<properties>
<spring-boot.version>
2.4.0
</spring-boot.version>
<spring-cloud.version>
2020.0.1
</spring-cloud.version>
<!-- Spring Cloud Alibaba compatibility -->
<spring-cloud-alibaba.version>
2021.1
</spring-cloud-alibaba.version>
<!-- eureka微服务注册中心 -->
<eureka-client.version>
2.2.5.RELEASE
</eureka-client.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot,not include plugin
management as the parent import style -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
${spring-boot.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<version>
${spring-cloud.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-alibaba-dependencies
</artifactId>
<version>
${spring-cloud-alibaba.version}
</version>
<type>
pom
</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
...
...
@@ -95,4 +135,44 @@
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>
ibizmvnrepository
</id>
<url>
http://172.16.240.220:8081/repository/releases
</url>
</repository>
<snapshotRepository>
<id>
ibizmvnrepository
</id>
<url>
http://172.16.240.220:8081/repository/snapshots
</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>
aliyunmaven
</id>
<name>
阿里云公共仓库
</name>
<url>
https://maven.aliyun.com/repository/public/
</url>
<layout>
default
</layout>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
true
</enabled>
<updatePolicy>
always
</updatePolicy>
</snapshots>
</repository>
<repository>
<id>
ibizmvnrepository
</id>
<name>
ibizmvnrepository
</name>
<url>
http://172.16.240.220:8081/repository/public/
</url>
<layout>
default
</layout>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
true
</enabled>
<updatePolicy>
always
</updatePolicy>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
ibizlab-boot-starter/pom.xml
浏览文件 @
47464f4d
...
...
@@ -98,6 +98,11 @@
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.dataformat
</groupId>
<artifactId>
jackson-dataformat-yaml
</artifactId>
</dependency>
<dependency>
<groupId>
io.jsonwebtoken
</groupId>
<artifactId>
jjwt
</artifactId>
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZUAAFallback.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.security.AuthenticationInfo
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthorizationLogin
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -25,7 +26,12 @@ public class IBZUAAFallback implements IBZUAAFeignClient {
return
null
;
}
@Override
@Override
public
AuthenticationInfo
v7Login
(
AuthorizationLogin
authorizationLogin
)
{
return
null
;
}
@Override
public
AuthenticationUser
loginByUsername
(
String
username
)
{
return
null
;
}
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/client/IBZUAAFeignClient.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
client
;
import
cn.ibizlab.util.security.AuthenticationInfo
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthorizationLogin
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -34,6 +35,10 @@ public interface IBZUAAFeignClient
AuthenticationUser
login
(
@RequestBody
AuthorizationLogin
authorizationLogin
);
@PostMapping
(
value
=
"/v7/login"
)
AuthenticationInfo
v7Login
(
@RequestBody
AuthorizationLogin
authorizationLogin
);
@PostMapping
(
value
=
"/uaa/loginbyusername"
)
AuthenticationUser
loginByUsername
(
@RequestBody
String
username
);
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/helper/DynamicParamUtils.java
0 → 100644
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
helper
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
DynamicParamUtils
{
private
static
final
String
DYNAMIC_PARAM_PREFIX
=
"${"
;
private
static
final
String
DYNAMIC_PARAM_SUFFIX
=
"}"
;
public
static
Object
processObject
(
Object
content
)
{
if
(
ObjectUtils
.
isEmpty
(
content
))
return
content
;
else
if
(
content
instanceof
Map
)
{
Map
newMap
=
new
LinkedHashMap
();
((
Map
<?,
?>)
content
).
entrySet
().
forEach
(
entry
->
{
newMap
.
put
(
entry
.
getKey
(),
processObject
(
entry
.
getValue
()));
});
return
newMap
;
}
else
if
(
content
instanceof
String
)
return
process
(
content
.
toString
());
else
if
(
content
instanceof
List
&&
((
List
)
content
).
get
(
0
)
instanceof
String
)
{
return
process
((
List
)
content
);
}
return
content
;
}
public
static
String
process
(
String
content
)
{
return
processDynamicParams
(
content
,
System
.
getenv
());
}
public
static
List
<
String
>
process
(
List
<
String
>
content
)
{
if
(
content
==
null
)
return
null
;
List
<
String
>
rt
=
new
ArrayList
<>();
content
.
forEach
(
item
->{
rt
.
add
(
process
(
item
));
});
return
rt
;
}
// 多变量,data 为 key - value 形式
public
static
String
processDynamicParams
(
String
content
,
Map
data
)
{
if
(
content
==
null
)
return
null
;
int
begin
=
content
.
indexOf
(
DYNAMIC_PARAM_PREFIX
);
int
end
=
content
.
indexOf
(
DYNAMIC_PARAM_SUFFIX
);
if
(
begin
==
-
1
||
end
==
-
1
||
begin
>
end
)
{
return
content
;
}
String
startContent
=
content
.
substring
(
0
,
begin
);
String
substring
=
content
.
substring
(
begin
,
end
+
1
);
if
(
StringUtils
.
isNotEmpty
(
substring
))
{
String
key
=
substring
.
replace
(
"${"
,
""
).
replace
(
"}"
,
""
);
String
[]
pairs
=
key
.
split
(
":"
);
String
defaultValue
=
null
;
if
(
pairs
.
length
>
1
)
{
key
=
pairs
[
0
];
defaultValue
=
pairs
[
1
];
}
Object
value
=
data
.
get
(
key
);
if
(
ObjectUtils
.
isEmpty
(
value
))
value
=
data
.
get
(
key
.
toUpperCase
());
if
(
ObjectUtils
.
isEmpty
(
value
))
value
=
data
.
getOrDefault
(
key
.
toUpperCase
().
replace
(
"."
,
"_"
),
defaultValue
);
if
(
value
!=
null
)
{
startContent
=
startContent
+
value
.
toString
();
}
else
{
startContent
+=
substring
;
}
}
int
length
=
content
.
length
();
if
(
length
==
end
+
1
)
{
return
startContent
;
}
else
{
return
startContent
+
processDynamicParams
(
content
.
substring
(
end
+
1
,
length
),
data
);
}
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/helper/JacksonUtils.java
0 → 100644
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
helper
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.jsontype.NamedType
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLFactory
;
import
com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
;
import
lombok.SneakyThrows
;
import
java.io.InputStream
;
import
java.io.IOException
;
import
java.lang.reflect.Type
;
import
java.util.List
;
public
final
class
JacksonUtils
{
public
static
ObjectMapper
mapper
=
new
ObjectMapper
();
public
static
ObjectMapper
ymlMapper
=
createYaml
();
static
ObjectMapper
createYaml
()
{
YAMLFactory
factory
=
new
YAMLFactory
();
factory
.
disable
(
YAMLGenerator
.
Feature
.
WRITE_DOC_START_MARKER
);
factory
.
enable
(
YAMLGenerator
.
Feature
.
MINIMIZE_QUOTES
);
factory
.
enable
(
YAMLGenerator
.
Feature
.
SPLIT_LINES
);
factory
.
enable
(
YAMLGenerator
.
Feature
.
ALWAYS_QUOTE_NUMBERS_AS_STRINGS
);
return
new
ObjectMapper
(
factory
);
}
static
{
mapper
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
mapper
.
setSerializationInclusion
(
Include
.
NON_NULL
);
}
@SneakyThrows
public
static
String
toJson
(
Object
obj
)
{
return
mapper
.
writeValueAsString
(
obj
);
}
@SneakyThrows
public
static
String
toYml
(
Object
obj
)
{
return
ymlMapper
.
writeValueAsString
(
obj
);
}
@SneakyThrows
public
static
<
T
>
T
toObj
(
Object
obj
,
Class
<
T
>
clazz
)
{
if
(
obj
==
null
)
return
null
;
else
if
(
obj
instanceof
String
)
return
mapper
.
readValue
(
obj
.
toString
(),
clazz
);
else
return
mapper
.
readValue
(
mapper
.
writeValueAsString
(
obj
),
clazz
);
}
@SneakyThrows
public
static
<
T
>
T
toObj
(
InputStream
inputStream
,
Class
<
T
>
cls
)
{
return
mapper
.
readValue
(
inputStream
,
cls
);
}
@SneakyThrows
public
static
<
T
>
T
toObj
(
String
json
,
Class
<
T
>
cls
)
{
return
mapper
.
readValue
(
json
,
cls
);
}
@SneakyThrows
public
static
<
T
>
List
<
T
>
toArray
(
String
jsonStr
,
Class
<
T
>
clazz
)
{
JavaType
javaType
=
mapper
.
getTypeFactory
().
constructCollectionType
(
List
.
class
,
clazz
);
return
mapper
.
readValue
(
jsonStr
,
javaType
);
}
@SneakyThrows
public
static
<
T
>
T
ymlToObj
(
String
json
,
Class
<
T
>
cls
)
{
return
ymlMapper
.
readValue
(
json
,
cls
);
}
@SneakyThrows
public
static
<
T
>
T
toObj
(
String
json
,
Type
type
)
{
return
mapper
.
readValue
(
json
,
mapper
.
constructType
(
type
));
}
@SneakyThrows
public
static
<
T
>
T
toObj
(
String
json
,
TypeReference
<
T
>
typeReference
)
{
return
mapper
.
readValue
(
json
,
typeReference
);
}
@SneakyThrows
public
static
<
T
>
T
toObj
(
InputStream
inputStream
,
Type
type
)
{
return
mapper
.
readValue
(
inputStream
,
mapper
.
constructType
(
type
));
}
@SneakyThrows
public
static
JsonNode
toObj
(
String
json
)
{
return
mapper
.
readTree
(
json
);
}
/**
* Register sub type for child class.
*
* @param clz child class
* @param type type name of child class
*/
public
static
void
registerSubtype
(
Class
<?>
clz
,
String
type
)
{
mapper
.
registerSubtypes
(
new
NamedType
(
clz
,
type
));
}
/**
* Create a new empty Jackson {@link ObjectNode}.
*
* @return {@link ObjectNode}
*/
public
static
ObjectNode
createEmptyJsonNode
()
{
return
new
ObjectNode
(
mapper
.
getNodeFactory
());
}
/**
* Create a new empty Jackson {@link ArrayNode}.
*
* @return {@link ArrayNode}
*/
public
static
ArrayNode
createEmptyArrayNode
()
{
return
new
ArrayNode
(
mapper
.
getNodeFactory
());
}
/**
* Parse object to Jackson {@link JsonNode}.
*
* @param obj object
* @return {@link JsonNode}
*/
public
static
JsonNode
transferToJsonNode
(
Object
obj
)
{
return
mapper
.
valueToTree
(
obj
);
}
/**
* construct java type -> Jackson Java Type.
*
* @param type java type
* @return JavaType {@link JavaType}
*/
public
static
JavaType
constructJavaType
(
Type
type
)
{
return
mapper
.
constructType
(
type
);
}
}
ibizlab-boot-starter
-data
/src/main/java/cn/ibizlab/util/helper/Setting.java
→
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/helper/Setting.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
helper
;
import
cn.ibizlab.util.domain.EntityBase
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONValidator
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.io.StringReader
;
...
...
@@ -29,45 +27,39 @@ public class Setting {
return
DataObject
.
getStringValue
(
getMap
(
configString
).
get
(
propertyName
),
""
);
}
public
static
<
T
extends
EntityBase
>
T
getEntity
(
String
configString
,
T
entityBase
)
{
if
(
entityBase
!=
null
)
{
Map
map
=
getMap
(
configString
);
map
.
keySet
().
forEach
(
key
->{
entityBase
.
set
(
key
.
toString
(),
map
.
get
(
key
));
});
}
return
entityBase
;
}
public
static
Map
getMap
(
String
configString
)
public
static
Map
<
String
,
Object
>
getMap
(
String
configString
)
{
Map
map
=
new
HashMap
();
map
.
put
(
"param"
,
configString
);
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
if
(!(
ObjectUtils
.
isEmpty
(
configString
)))
{
map
.
put
(
"param"
,
configString
);
try
{
Object
obj
=
JSON
.
parse
(
configString
);
if
(
obj
==
null
)
return
map
;
else
if
(
obj
instanceof
JSONArray
)
JSONValidator
validator
=
JSONValidator
.
from
(
configString
);
if
(
JSONValidator
.
Type
.
Array
.
equals
(
validator
.
getType
()))
{
List
<
Setting
>
settings
=
JSONArray
.
parseArray
(
configString
,
Setting
.
class
);
for
(
Setting
setting:
settings
)
map
.
put
(
setting
.
getProperty
(),
setting
.
getValue
(
));
map
.
put
(
setting
.
getProperty
(),
DynamicParamUtils
.
process
(
setting
.
getValue
()
));
}
else
if
(
obj
instanceof
JSONObject
)
else
if
(
JSONValidator
.
Type
.
Object
.
equals
(
validator
.
getType
())
)
{
JSONObject
jo
=
(
JSONObject
)
obj
;
jo
.
keySet
().
forEach
(
key
->{
map
.
put
(
key
,
jo
.
get
(
key
));
JSONObject
.
parseObject
(
configString
).
entrySet
().
forEach
(
entry
->{
map
.
put
(
entry
.
getKey
(),
DynamicParamUtils
.
processObject
(
entry
.
getValue
()));
});
}
}
catch
(
Exception
ex
)
{
if
(
configString
.
indexOf
(
"="
)>
0
)
else
if
(
configString
.
indexOf
(
": "
)>
0
)
{
Map
<
String
,
Object
>
newMap
=
JacksonUtils
.
ymlToObj
(
configString
,
LinkedHashMap
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
newMap
))
{
newMap
.
entrySet
().
forEach
(
entry
->{
map
.
put
(
entry
.
getKey
(),
DynamicParamUtils
.
processObject
(
entry
.
getValue
()));
});
}
}
else
if
(
configString
.
indexOf
(
"="
)>
0
)
{
Properties
proper
=
new
Properties
();
try
{
...
...
@@ -78,10 +70,14 @@ public class Setting {
while
(
enum1
.
hasMoreElements
())
{
String
strKey
=
(
String
)
enum1
.
nextElement
();
String
strValue
=
proper
.
getProperty
(
strKey
);
map
.
put
(
strKey
,
strValue
);
map
.
put
(
strKey
,
DynamicParamUtils
.
process
(
strValue
)
);
}
}
}
catch
(
Exception
ex
)
{
}
}
return
map
;
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/rest/AppController.java
浏览文件 @
47464f4d
...
...
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
import
java.util.*
;
@RestController
@RequestMapping
(
value
=
""
)
@RequestMapping
(
value
=
"
/
"
)
public
class
AppController
{
@Value
(
"${ibiz.enablePermissionValid:false}"
)
...
...
@@ -28,6 +28,7 @@ public class AppController {
@Autowired
private
AuthenticationUserService
userDetailsService
;
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"appdata"
)
public
ResponseEntity
<
Map
>
getAppData
()
{
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
userDetailsService
.
getAppData
());
}
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/rest/AuthenticationController.java
浏览文件 @
47464f4d
...
...
@@ -24,8 +24,7 @@ public class AuthenticationController
@Value
(
"${ibiz.jwt.header:Authorization}"
)
private
String
tokenHeader
;
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
@Autowired
private
AuthenticationUserService
userDetailsService
;
...
...
@@ -33,11 +32,8 @@ public class AuthenticationController
@PostMapping
(
value
=
"${ibiz.auth.path:v7/login}"
)
public
ResponseEntity
<
AuthenticationInfo
>
login
(
@Validated
@RequestBody
AuthorizationLogin
authorizationLogin
){
userDetailsService
.
resetByUsername
(
authorizationLogin
.
getUsername
());
final
AuthenticationUser
authuserdetail
=
userDetailsService
.
loadUserByLogin
(
authorizationLogin
.
getUsername
(),
authorizationLogin
.
getPassword
());
// 生成令牌
final
String
token
=
jwtTokenUtil
.
generateToken
(
authuserdetail
);
// 返回 token
return
ResponseEntity
.
ok
().
body
(
new
AuthenticationInfo
(
token
,
authuserdetail
));
final
AuthenticationInfo
authuserdetail
=
userDetailsService
.
loadUserByLogin
(
authorizationLogin
.
getUsername
(),
authorizationLogin
.
getPassword
());
return
ResponseEntity
.
ok
().
body
(
authuserdetail
);
}
@GetMapping
(
value
=
"${ibiz.auth.account:ibizutil/account}"
)
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/security/AuthenticationUser.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
security
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.*
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
io.jsonwebtoken.impl.DefaultClock
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
...
...
@@ -15,6 +15,7 @@ import org.springframework.security.core.userdetails.UserDetails;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.sql.Timestamp
;
import
java.util.*
;
...
...
@@ -23,6 +24,9 @@ import java.util.*;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
AuthenticationUser
implements
UserDetails
{
private
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
public
AuthenticationUser
(){}
/**
* 用戶标识
...
...
@@ -177,7 +181,7 @@ public class AuthenticationUser implements UserDetails
/**
* 用户权限资源
*/
private
JSONObject
permissionList
;
private
Map
permissionList
;
/**
* 用户上下文参数
*/
...
...
@@ -342,12 +346,13 @@ public class AuthenticationUser implements UserDetails
}
}
public
void
setPermissionList
(
JSONObject
permissionList
)
{
public
void
setPermissionList
(
Map
permissionList
)
{
this
.
permissionList
=
permissionList
;
if
(
authorities
==
null
&&
permissionList
!=
null
){
if
(
permissionList
.
get
JSONArray
(
"authorities"
)!=
null
){
if
(
permissionList
.
get
(
"authorities"
)!=
null
){
authorities
=
new
ArrayList
<>();
permissionList
.
getJSONArray
(
"authorities"
).
((
List
)
permissionList
.
get
(
"authorities"
)
).
forEach
(
item
->{
if
(
item
instanceof
String
)
authorities
.
add
(
new
SimpleGrantedAuthority
(
String
.
valueOf
(
item
)));
...
...
@@ -355,15 +360,10 @@ public class AuthenticationUser implements UserDetails
authorities
.
add
((
GrantedAuthority
)
item
);
else
{
JSONObject
json
=(
JSONObject
)
item
;
if
(
json
.
getString
(
"type"
).
equals
(
"OPPRIV"
))
{
authorities
.
add
(
JSONObject
.
parseObject
(
json
.
toString
(),
UAADEAuthority
.
class
));
}
else
if
(
json
.
getString
(
"type"
).
equals
(
"APPMENU"
))
{
authorities
.
add
(
JSONObject
.
parseObject
(
json
.
toString
(),
UAAMenuAuthority
.
class
));
}
else
if
(
json
.
getString
(
"type"
).
equals
(
"UNIRES"
))
{
authorities
.
add
(
JSONObject
.
parseObject
(
json
.
toString
(),
UAAUniResAuthority
.
class
));
}
else
if
(
json
.
getString
(
"type"
).
equals
(
"ROLE"
))
{
authorities
.
add
(
JSONObject
.
parseObject
(
json
.
toString
(),
UAARoleAuthority
.
class
));
try
{
authorities
.
add
(
objectMapper
.
readValue
(
objectMapper
.
writeValueAsBytes
(
item
),
UAAGrantedAuthority
.
class
));
}
catch
(
IOException
e
)
{
}
}
});
...
...
@@ -377,7 +377,7 @@ public class AuthenticationUser implements UserDetails
@JsonAnyGetter
@JSONField
(
name
=
"_any"
,
unwrapped
=
true
,
serialize
=
true
,
deserialize
=
false
)
public
Map
<
String
,
Object
>
any
()
{
return
userSessionParam
;
return
getUserSessionParam
()
;
}
...
...
@@ -385,11 +385,11 @@ public class AuthenticationUser implements UserDetails
@JsonAnySetter
@JSONField
(
name
=
"_any"
,
unwrapped
=
true
,
serialize
=
false
,
deserialize
=
true
)
public
void
set
(
String
field
,
Object
value
)
{
this
.
userSessionParam
.
put
(
field
,
value
);
this
.
getUserSessionParam
()
.
put
(
field
,
value
);
}
public
Object
get
(
String
field
)
{
return
this
.
userSessionParam
.
get
(
field
);
return
this
.
getUserSessionParam
()
.
get
(
field
);
}
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/AuthenticationUserService.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.security.AuthenticationInfo
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.annotation.CacheEvict
;
...
...
@@ -18,23 +19,21 @@ public interface AuthenticationUserService extends UserDetailsService {
@Override
@Cacheable
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
default
AuthenticationUser
loadUserByUsername
(
String
username
){
return
null
;
}
//@Cacheable( value="ibzuaa_users", key = "'getByUsername:'+#p0")
AuthenticationUser
loadUserByLogin
(
String
username
,
String
password
);
AuthenticationInfo
loadUserByLogin
(
String
username
,
String
password
);
@CacheEvict
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
default
void
resetByUsername
(
String
username
){}
@Value
(
"${ibiz.enablePermissionValid:false}"
)
boolean
enablePermissionValid
=
false
;
//是否开启权限校验
boolean
isEnablePermissionValid
();
//是否开启权限校验
@Value
(
"${ibiz.systemid}"
)
String
systemId
=
""
;
String
getSystemId
();
default
Map
getAppData
()
{
...
...
@@ -44,17 +43,17 @@ public interface AuthenticationUserService extends UserDetailsService {
Set
<
String
>
uniRes
=
new
HashSet
();
AuthenticationUser
curUser
=
AuthenticationUser
.
getAuthenticationUser
();
if
(
enablePermissionValid
&&(!
ObjectUtils
.
isEmpty
(
systemId
))){
if
(
isEnablePermissionValid
()&&(!
ObjectUtils
.
isEmpty
(
getSystemId
()
))){
Collection
<
GrantedAuthority
>
authorities
=
curUser
.
getAuthorities
();
Iterator
it
=
authorities
.
iterator
();
while
(
it
.
hasNext
())
{
GrantedAuthority
authority
=
(
GrantedAuthority
)
it
.
next
();
String
strAuthority
=
authority
.
getAuthority
();
if
(
strAuthority
.
startsWith
(
"UNIRES_"
+
systemId
))
{
uniRes
.
add
(
strAuthority
.
substring
(
systemId
.
length
()+
8
));
if
(
strAuthority
.
startsWith
(
"UNIRES_"
+
getSystemId
()
))
{
uniRes
.
add
(
strAuthority
.
substring
(
getSystemId
()
.
length
()+
8
));
}
else
if
(
strAuthority
.
startsWith
(
"APPMENU_"
+
systemId
)){
appMenu
.
add
(
strAuthority
.
substring
(
systemId
.
length
()+
9
));
else
if
(
strAuthority
.
startsWith
(
"APPMENU_"
+
getSystemId
()
)){
appMenu
.
add
(
strAuthority
.
substring
(
getSystemId
()
.
length
()+
9
));
}
}
}
...
...
@@ -70,12 +69,12 @@ public interface AuthenticationUserService extends UserDetailsService {
appData
.
put
(
"context"
,
context
);
appData
.
put
(
"unires"
,
uniRes
);
appData
.
put
(
"appmenu"
,
appMenu
);
appData
.
put
(
"enablepermissionvalid"
,
enablePermissionValid
);
appData
.
put
(
"enablepermissionvalid"
,
isEnablePermissionValid
()
);
if
(
curUser
.
getSuperuser
()==
1
){
appData
.
put
(
"enablepermissionvalid"
,
false
);
}
else
{
appData
.
put
(
"enablepermissionvalid"
,
enablePermissionValid
);
appData
.
put
(
"enablepermissionvalid"
,
isEnablePermissionValid
()
);
}
fillAppData
(
appData
);
return
appData
;
...
...
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/CloudUserService.java
浏览文件 @
47464f4d
...
...
@@ -13,6 +13,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -41,6 +43,23 @@ public class CloudUserService extends IBZUAAUserService {
@Lazy
private
RedisTemplate
redisTemplate
;
@Value
(
"${ibiz.enablePermissionValid:false}"
)
boolean
enablePermissionValid
;
//是否开启权限校验
@Value
(
"${ibiz.systemid}"
)
private
String
systemId
;
@Override
public
boolean
isEnablePermissionValid
()
{
return
enablePermissionValid
;
}
@Override
public
String
getSystemId
()
{
return
systemId
;
}
@Value
(
"${ibiz.jwt.header:Authorization}"
)
private
String
tokenHeader
;
...
...
@@ -49,6 +68,7 @@ public class CloudUserService extends IBZUAAUserService {
private
TypeReference
<
Collection
<
UAAGrantedAuthority
>>
UAAGrantedAuthorityListType
=
new
TypeReference
<
Collection
<
UAAGrantedAuthority
>>(){};
@Override
@Cacheable
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
public
AuthenticationUser
loadUserByUsername
(
String
username
)
{
Object
obj
=
redisTemplate
.
opsForValue
().
get
(
"ibiz-cloud-uaa-user-"
+
username
);
if
(
obj
==
null
)
{
...
...
@@ -204,4 +224,9 @@ public class CloudUserService extends IBZUAAUserService {
Map
appData
=
uaaFeignClient
.
getAppData
();
return
ObjectUtils
.
isEmpty
(
appData
)?
super
.
getAppData
():
appData
;
}
@Override
@CacheEvict
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
public
void
resetByUsername
(
String
username
)
{
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/IBZUAAUserService.java
浏览文件 @
47464f4d
...
...
@@ -2,10 +2,14 @@ package cn.ibizlab.util.service;
import
cn.ibizlab.util.client.IBZUAAFeignClient
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.security.AuthenticationInfo
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.security.AuthorizationLogin
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
/**
...
...
@@ -18,7 +22,25 @@ public class IBZUAAUserService implements AuthenticationUserService{
@Autowired
private
IBZUAAFeignClient
uaaFeignClient
;
@Value
(
"${ibiz.enablePermissionValid:false}"
)
boolean
enablePermissionValid
;
//是否开启权限校验
@Value
(
"${ibiz.systemid}"
)
private
String
systemId
;
@Override
public
boolean
isEnablePermissionValid
()
{
return
enablePermissionValid
;
}
@Override
public
String
getSystemId
()
{
return
systemId
;
}
@Override
@Cacheable
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
public
AuthenticationUser
loadUserByUsername
(
String
username
)
{
AuthenticationUser
user
=
uaaFeignClient
.
loginByUsername
(
username
);
if
(
user
==
null
)
{
...
...
@@ -28,7 +50,7 @@ public class IBZUAAUserService implements AuthenticationUserService{
}
@Override
public
Authentication
User
loadUserByLogin
(
String
username
,
String
password
)
{
public
Authentication
Info
loadUserByLogin
(
String
username
,
String
password
)
{
String
[]
data
=
username
.
split
(
"[|]"
);
String
loginname
=
username
;
String
domains
=
""
;
...
...
@@ -41,11 +63,15 @@ public class IBZUAAUserService implements AuthenticationUserService{
logininfo
.
setDomain
(
domains
);
logininfo
.
setLoginname
(
loginname
);
logininfo
.
setPassword
(
password
);
Authentication
User
user
=
uaaFeignClient
.
l
ogin
(
logininfo
);
if
(
user
==
null
){
Authentication
Info
info
=
uaaFeignClient
.
v7L
ogin
(
logininfo
);
if
(
info
.
getUser
()
==
null
){
throw
new
BadRequestAlertException
(
"登录失败"
,
"IBZUAAUser"
,
username
);
}
return
user
;
return
info
;
}
@Override
@CacheEvict
(
value
=
"ibzuaa_users"
,
key
=
"'getByUsername:'+#p0"
)
public
void
resetByUsername
(
String
username
)
{
}
}
ibizlab-boot-starter/src/main/java/cn/ibizlab/util/service/SimpleUserService.java
浏览文件 @
47464f4d
package
cn
.
ibizlab
.
util
.
service
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationInfo
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.authority.AuthorityUtils
;
import
org.springframework.stereotype.Service
;
...
...
@@ -14,7 +21,24 @@ import org.springframework.stereotype.Service;
@ConditionalOnExpression
(
"(!${ibiz.enablePermissionValid:false})&&'${ibiz.auth.service:IBZUAAUserService}'.equals('SimpleUserService')"
)
public
class
SimpleUserService
implements
AuthenticationUserService
{
@Value
(
"${ibiz.enablePermissionValid:false}"
)
boolean
enablePermissionValid
;
//是否开启权限校验
@Value
(
"${ibiz.systemid}"
)
private
String
systemId
;
@Override
public
boolean
isEnablePermissionValid
()
{
return
enablePermissionValid
;
}
@Override
public
String
getSystemId
()
{
return
systemId
;
}
@Override
@Cacheable
(
value
=
"simple_users"
,
key
=
"'getByUsername:'+#p0"
)
public
AuthenticationUser
loadUserByUsername
(
String
username
)
{
AuthenticationUser
user
=
new
AuthenticationUser
();
String
[]
data
=
username
.
split
(
"[|]"
);
...
...
@@ -43,15 +67,22 @@ public class SimpleUserService implements AuthenticationUserService {
return
user
;
}
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
@Override
public
Authentication
User
loadUserByLogin
(
String
username
,
String
password
)
{
public
Authentication
Info
loadUserByLogin
(
String
username
,
String
password
)
{
AuthenticationUser
authuserdetail
=
loadUserByUsername
(
username
);
return
authuserdetail
;
final
String
token
=
jwtTokenUtil
.
generateToken
(
authuserdetail
);
// 返回 token
return
new
AuthenticationInfo
(
token
,
authuserdetail
);
}
@Override
@CacheEvict
(
value
=
"simple_users"
,
key
=
"'getByUsername:'+#p0"
)
public
void
resetByUsername
(
String
username
)
{
}
...
...
pom.xml
浏览文件 @
47464f4d
...
...
@@ -27,7 +27,6 @@
<module>
ibizlab-boot-starter-parent
</module>
<module>
ibizlab-boot-starter
</module>
<module>
ibizlab-boot-starter-data
</module>
<module>
ibizlab-boot-starter-gateway
</module>
</modules>
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录