Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
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
Jan Hrabal
jh-boot
Commits
602ea7c5
Commit
602ea7c5
authored
Oct 02, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
roles
parent
a70bfc2e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
11 deletions
+12
-11
JhSecurityConfig.java
src/main/java/com/jh/boot/security/JhSecurityConfig.java
+5
-2
AppRole.java
src/main/java/com/jh/boot/security/model/AppRole.java
+1
-8
AppUserAuthService.java
...java/com/jh/boot/security/service/AppUserAuthService.java
+6
-1
No files found.
src/main/java/com/jh/boot/security/JhSecurityConfig.java
View file @
602ea7c5
...
...
@@ -8,9 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.security.authentication.AuthenticationProvider
;
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.config.http.SessionCreationPolicy
;
import
org.springframework.security.core.AuthenticationException
;
...
...
@@ -96,4 +94,9 @@ public class JhSecurityConfig extends WebSecurityConfigurerAdapter {
return
new
AppUserRepository
();
}
// @Bean
// public GrantedAuthorityDefaults grantedAuthorityDefaults() {
// return new GrantedAuthorityDefaults(""); // Remove the ROLE_ prefix
// }
}
src/main/java/com/jh/boot/security/model/AppRole.java
View file @
602ea7c5
...
...
@@ -8,8 +8,6 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
import
org.springframework.security.core.GrantedAuthority
;
import
com.jh.boot.jpa.AbstractIdEntity
;
/**
...
...
@@ -19,7 +17,7 @@ import com.jh.boot.jpa.AbstractIdEntity;
*/
@Entity
@Table
(
name
=
"APP_ROLE"
)
public
class
AppRole
extends
AbstractIdEntity
implements
GrantedAuthority
{
public
class
AppRole
extends
AbstractIdEntity
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -47,9 +45,4 @@ public class AppRole extends AbstractIdEntity implements GrantedAuthority {
this
.
name
=
name
;
}
@Override
public
String
getAuthority
()
{
return
getName
();
}
}
src/main/java/com/jh/boot/security/service/AppUserAuthService.java
View file @
602ea7c5
...
...
@@ -3,7 +3,9 @@ package com.jh.boot.security.service;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.Locale
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.security.authentication.BadCredentialsException
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.StringUtils
;
...
...
@@ -58,7 +61,9 @@ public class AppUserAuthService implements AuthService {
//initialize roles
user
.
initRolesMap
();
AppUserAuthentication
auth
=
new
AppUserAuthentication
(
user
,
user
.
getRoles
());
Set
<
SimpleGrantedAuthority
>
authorities
=
user
.
getRoles
().
stream
().
map
(
r
->
new
SimpleGrantedAuthority
(
"ROLE_"
+
r
.
getName
())).
collect
(
Collectors
.
toSet
());
AppUserAuthentication
auth
=
new
AppUserAuthentication
(
user
,
authorities
);
return
auth
;
}
...
...
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