Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tagManager
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
tagManager
Commits
1044ba1c
Commit
1044ba1c
authored
Dec 18, 2019
by
lanmw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add customUserService
parent
f2377711
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
137 additions
and
16 deletions
+137
-16
MockCtrl.java
src/main/java/com/keymobile/tagmanager/api/MockCtrl.java
+56
-0
TagCtrl.java
src/main/java/com/keymobile/tagmanager/api/TagCtrl.java
+7
-6
TagFileCtrl.java
src/main/java/com/keymobile/tagmanager/api/TagFileCtrl.java
+4
-4
SecurityConfig.java
.../java/com/keymobile/tagmanager/config/SecurityConfig.java
+10
-2
CustomUserDetailService.java
...keymobile/tagmanager/service/CustomUserDetailService.java
+52
-0
TagFileService.java
...java/com/keymobile/tagmanager/service/TagFileService.java
+4
-3
TagService.java
...ain/java/com/keymobile/tagmanager/service/TagService.java
+0
-1
UserInfoUtils.java
...ain/java/com/keymobile/tagmanager/util/UserInfoUtils.java
+4
-0
No files found.
src/main/java/com/keymobile/tagmanager/api/MockCtrl.java
0 → 100644
View file @
1044ba1c
package
com
.
keymobile
.
tagmanager
.
api
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.keymobile.tagmanager.exception.TagNotExistException
;
import
com.keymobile.tagmanager.util.JsonTreeHelper
;
import
com.keymobile.tagmanager.util.JsonTreeHelper.JsonNode
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
@Api
(
value
=
"模拟数据"
,
tags
=
"模拟数据"
)
@RestController
@RequestMapping
(
value
=
"/mock"
)
public
class
MockCtrl
{
private
static
final
String
ORG_SEPERATOR
=
"\\"
;
private
static
final
String
ORG_TOP_NODE
=
"中广核集团"
;
private
static
final
String
ORG_SECOND_NODE
=
"工程公司"
;
@ApiOperation
(
value
=
"返回组织树"
,
notes
=
"返回组织树"
)
@GetMapping
(
value
=
"/queryOrgAsTree"
)
public
JsonNode
[]
queryPersonalTagAsTree
()
throws
TagNotExistException
{
List
<
JsonNode
>
jsonNodes
=
new
ArrayList
<>();
jsonNodes
.
add
(
new
JsonNode
(
ORG_TOP_NODE
,
UUID
.
randomUUID
().
toString
(),
ORG_TOP_NODE
));
addSecodeNodes
(
ORG_TOP_NODE
,
ORG_SECOND_NODE
,
jsonNodes
);
addThirdNodes
(
ORG_TOP_NODE
+
ORG_SEPERATOR
+
ORG_SECOND_NODE
,
"人力资源部"
,
jsonNodes
);
addThirdNodes
(
ORG_TOP_NODE
+
ORG_SEPERATOR
+
ORG_SECOND_NODE
,
"财务部"
,
jsonNodes
);
addThirdNodes
(
ORG_TOP_NODE
+
ORG_SEPERATOR
+
ORG_SECOND_NODE
,
"安全质保部"
,
jsonNodes
);
addThirdNodes
(
ORG_TOP_NODE
+
ORG_SEPERATOR
+
ORG_SECOND_NODE
,
"施工管理中心"
,
jsonNodes
);
addThirdNodes
(
ORG_TOP_NODE
+
ORG_SEPERATOR
+
ORG_SECOND_NODE
,
"设备采购与成套中心"
,
jsonNodes
);
JsonNode
root
=
JsonTreeHelper
.
toJsonTree
(
jsonNodes
,
ORG_SEPERATOR
+
ORG_SEPERATOR
);
if
(
root
.
children
!=
null
)
return
root
.
children
;
else
return
new
JsonNode
[]
{};
}
private
void
addThirdNodes
(
String
secondNode
,
String
thirdNode
,
List
<
JsonNode
>
jsonNodes
)
{
JsonNode
third
=
new
JsonNode
(
secondNode
+
ORG_SEPERATOR
+
thirdNode
,
UUID
.
randomUUID
().
toString
(),
secondNode
+
ORG_SEPERATOR
+
thirdNode
);
jsonNodes
.
add
(
third
);
}
private
void
addSecodeNodes
(
String
topNode
,
String
secodeNode
,
List
<
JsonNode
>
jsonNodes
)
{
JsonNode
second
=
new
JsonNode
(
topNode
+
ORG_SEPERATOR
+
secodeNode
,
UUID
.
randomUUID
().
toString
(),
topNode
+
ORG_SEPERATOR
+
secodeNode
);
jsonNodes
.
add
(
second
);
}
}
src/main/java/com/keymobile/tagmanager/api/TagCtrl.java
View file @
1044ba1c
...
...
@@ -36,7 +36,7 @@ public class TagCtrl {
@RequestBody
Tag
tag
)
throws
Exception
{
String
userName
=
UserInfoUtils
.
getUserName
();
tag
.
setCreator
(
userName
);
tag
.
setDept
(
userName
);
//这里暂时用userName代替,后面从session取出
tag
.
setDept
(
UserInfoUtils
.
getUserDept
());
return
tagService
.
addOrUpdateTag
(
parentId
,
tag
,
userName
);
}
...
...
@@ -51,6 +51,7 @@ public class TagCtrl {
@GetMapping
(
value
=
"/hasChild"
)
public
boolean
hasChild
(
@RequestParam
(
value
=
"tagId"
)
String
tagId
)
throws
Exception
{
String
userName
=
UserInfoUtils
.
getUserName
();
UserInfoUtils
.
getUserDomains
();
return
tagService
.
hasChild
(
tagId
,
userName
);
}
...
...
@@ -65,7 +66,7 @@ public class TagCtrl {
@ApiOperation
(
value
=
"查询维度标签树"
,
notes
=
"查询维度标签树"
)
@GetMapping
(
value
=
"/queryDimensionTagAsTree"
)
public
JsonNode
[]
queryDimensionTagAsTree
(
@RequestParam
(
value
=
"parentId"
,
required
=
false
)
String
parentId
)
throws
TagNotExistException
{
String
dept
=
UserInfoUtils
.
getUser
Name
();
String
dept
=
UserInfoUtils
.
getUser
Dept
();
return
tagService
.
queryDimensionTagAsTree
(
dept
,
parentId
);
}
...
...
@@ -73,7 +74,7 @@ public class TagCtrl {
@GetMapping
(
value
=
"/queryPersonalTagAsTree"
)
public
JsonNode
[]
queryPersonalTagAsTree
(
@RequestParam
(
value
=
"parentId"
,
required
=
false
)
String
parentId
)
throws
TagNotExistException
{
String
userName
=
UserInfoUtils
.
getUserName
();
String
dept
=
userName
;
String
dept
=
UserInfoUtils
.
getUserDept
()
;
return
tagService
.
queryPersonalTagAsTree
(
parentId
,
userName
,
dept
);
}
...
...
@@ -81,7 +82,7 @@ public class TagCtrl {
@GetMapping
(
value
=
"/queryPersonalTagExcludeOpenTypeAsTree"
)
public
JsonNode
[]
queryPersonalTagExcludeOpenTypeAsTree
(
@RequestParam
(
value
=
"parentId"
,
required
=
false
)
String
parentId
)
throws
TagNotExistException
{
String
userName
=
UserInfoUtils
.
getUserName
();
String
dept
=
userName
;
String
dept
=
UserInfoUtils
.
getUserDept
()
;
return
tagService
.
queryPersonalTagExcludeOpenTypeAsTree
(
parentId
,
userName
,
dept
);
}
...
...
@@ -105,7 +106,7 @@ public class TagCtrl {
@RequestParam
(
"pageNo"
)
Integer
pageNo
,
@RequestParam
(
"pageSize"
)
Integer
pageSize
)
{
String
userName
=
UserInfoUtils
.
getUserName
();
String
dept
=
userName
;
String
dept
=
UserInfoUtils
.
getUserDept
()
;
return
tagService
.
searchPersonalDimensionTagByPage
(
userName
,
dept
,
keyword
,
path
,
domain
,
new
Page
(
pageSize
,
pageNo
));
}
...
...
@@ -117,7 +118,7 @@ public class TagCtrl {
@RequestParam
(
"pageNo"
)
Integer
pageNo
,
@RequestParam
(
"pageSize"
)
Integer
pageSize
)
{
String
userName
=
UserInfoUtils
.
getUserName
();
String
dept
=
userName
;
String
dept
=
UserInfoUtils
.
getUserDept
()
;
return
tagService
.
searchPersonalTagByPage
(
userName
,
dept
,
keyword
,
path
,
domain
,
new
Page
(
pageSize
,
pageNo
));
}
...
...
src/main/java/com/keymobile/tagmanager/api/TagFileCtrl.java
View file @
1044ba1c
...
...
@@ -26,15 +26,14 @@ public class TagFileCtrl {
@GetMapping
(
"/exportTag"
)
public
int
export
(
HttpServletResponse
response
)
{
String
userName
=
UserInfoUtils
.
getUserName
();
String
dept
=
userName
;
String
dept
=
UserInfoUtils
.
getUserDept
();
return
tagExportService
.
exportExcel
(
dept
,
response
);
}
@PostMapping
(
"/importTag"
)
public
String
importExcel
(
MultipartFile
file
,
HttpServletResponse
response
)
throws
Exception
{
String
userName
=
UserInfoUtils
.
getUserName
();
String
dept
=
userName
;
String
dept
=
UserInfoUtils
.
getUserDept
()
;
return
tagExportService
.
importExcel
(
userName
,
dept
,
file
);
}
...
...
@@ -42,7 +41,8 @@ public class TagFileCtrl {
@GetMapping
(
value
=
"/listImportTagLogByPage"
)
public
Page
searchPersonalDimensionTagByPage
(
@RequestParam
(
"pageNo"
)
Integer
pageNo
,
@RequestParam
(
"pageSize"
)
Integer
pageSize
)
{
return
tagExportService
.
listImportlogByPage
(
new
Page
(
pageSize
,
pageNo
));
String
dept
=
UserInfoUtils
.
getUserDept
();
return
tagExportService
.
listImportlogByPage
(
dept
,
new
Page
(
pageSize
,
pageNo
));
}
@ApiOperation
(
value
=
"撤销导入"
,
notes
=
"撤销导入"
)
...
...
src/main/java/com/keymobile/tagmanager/config/SecurityConfig.java
View file @
1044ba1c
...
...
@@ -5,19 +5,26 @@ import javax.sql.DataSource;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
com.keymobile.tagmanager.service.CustomUserDetailService
;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
public
class
SecurityConfig
extends
WebSecurityConfigurerAdapter
{
@Autowired
private
CustomUserDetailService
customUserDetailService
;
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"
+
...
...
@@ -41,8 +48,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
jdbcAuthentication
().
usersByUsernameQuery
(
usersQuery
).
authoritiesByUsernameQuery
(
rolesQuery
)
.
dataSource
(
dataSource
).
passwordEncoder
(
new
SHA1PasswordEncoder
());
auth
.
userDetailsService
(
customUserDetailService
).
passwordEncoder
(
new
SHA1PasswordEncoder
());
// auth.jdbcAuthentication().usersByUsernameQuery(usersQuery).authoritiesByUsernameQuery(rolesQuery)
// .dataSource(dataSource).passwordEncoder(new SHA1PasswordEncoder());
}
@Override
...
...
src/main/java/com/keymobile/tagmanager/service/CustomUserDetailService.java
0 → 100644
View file @
1044ba1c
package
com
.
keymobile
.
tagmanager
.
service
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
import
javax.sql.DataSource
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl
;
import
org.springframework.stereotype.Service
;
@Service
public
class
CustomUserDetailService
extends
JdbcDaoImpl
implements
UserDetailsService
{
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"
+
" 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"
;
@Autowired
private
DataSource
dataSource
;
@PostConstruct
public
void
init
()
{
this
.
setDataSource
(
dataSource
);
this
.
setUsersByUsernameQuery
(
USERSQUERY
);
this
.
setAuthoritiesByUsernameQuery
(
ROLESQUERY
);
}
//DATA_ROLE infomataion
@Override
protected
void
addCustomAuthorities
(
String
username
,
List
<
GrantedAuthority
>
authorities
)
{
authorities
.
add
(
new
SimpleGrantedAuthority
(
"DATA_ROLE_1"
));
authorities
.
add
(
new
SimpleGrantedAuthority
(
"DATA_ROLE_1"
));
}
}
src/main/java/com/keymobile/tagmanager/service/TagFileService.java
View file @
1044ba1c
...
...
@@ -246,8 +246,8 @@ public class TagFileService {
}
}
public
Page
listImportlogByPage
(
Page
page
)
{
Query
q
=
createImportlogPageQuery
(
page
);
public
Page
listImportlogByPage
(
String
dept
,
Page
page
)
{
Query
q
=
createImportlogPageQuery
(
dept
,
page
);
List
<
ImportLog
>
logs
=
mongoOperations
.
find
(
q
,
ImportLog
.
class
);
long
count
=
mongoOperations
.
count
(
q
,
ImportLog
.
class
);
...
...
@@ -256,9 +256,10 @@ public class TagFileService {
return
page
;
}
private
Query
createImportlogPageQuery
(
Page
page
)
{
private
Query
createImportlogPageQuery
(
String
dept
,
Page
page
)
{
Query
q
=
new
Query
();
q
.
addCriteria
(
Criteria
.
where
(
"type"
).
is
(
Constants
.
COMMON_TAG_LOG_TYPE
));
q
.
addCriteria
(
Criteria
.
where
(
"dept"
).
is
(
dept
));
q
.
skip
(
page
.
getOffset
());
q
.
limit
(
page
.
getPageSize
());
q
.
with
(
Sort
.
by
(
Arrays
.
asList
(
new
Order
(
Direction
.
DESC
,
"startTime"
))));
...
...
src/main/java/com/keymobile/tagmanager/service/TagService.java
View file @
1044ba1c
...
...
@@ -16,7 +16,6 @@ import org.springframework.data.domain.Sort.Order;
import
org.springframework.data.mongodb.core.MongoOperations
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.stereotype.Service
;
import
com.keymobile.tagmanager.exception.TagDuplicateException
;
import
com.keymobile.tagmanager.exception.TagException
;
...
...
src/main/java/com/keymobile/tagmanager/util/UserInfoUtils.java
View file @
1044ba1c
...
...
@@ -42,6 +42,10 @@ public class UserInfoUtils {
return
SecurityContextHolder
.
getContext
().
getAuthentication
().
getName
().
split
(
":"
)[
0
];
}
public
static
String
getUserDept
()
{
return
SecurityContextHolder
.
getContext
().
getAuthentication
().
getName
().
split
(
":"
)[
0
];
}
public
static
Integer
getUserId
()
{
return
Integer
.
valueOf
(
SecurityContextHolder
.
getContext
().
getAuthentication
().
getName
().
split
(
":"
)[
1
]);
}
...
...
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