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
514b0131
Commit
514b0131
authored
Oct 17, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
075664bf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
12 deletions
+15
-12
pom.xml
pom.xml
+1
-1
SecurityHelper.java
src/main/java/com/jh/boot/security/SecurityHelper.java
+6
-3
AuthApiController.java
...main/java/com/jh/boot/security/api/AuthApiController.java
+2
-2
ValidationFailedException.java
...java/com/jh/boot/web/error/ValidationFailedException.java
+6
-6
No files found.
pom.xml
View file @
514b0131
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.
1.6
.RELEASE
</version>
<version>
2.
2.0
.RELEASE
</version>
<relativePath
/>
<relativePath
/>
</parent>
</parent>
...
...
src/main/java/com/jh/boot/security/SecurityHelper.java
View file @
514b0131
...
@@ -27,11 +27,14 @@ public class SecurityHelper {
...
@@ -27,11 +27,14 @@ public class SecurityHelper {
public
static
boolean
hasAnyRole
(
Authentication
auth
,
String
...
roles
)
{
public
static
boolean
hasAnyRole
(
Authentication
auth
,
String
...
roles
)
{
AppUser
user
=
auth
instanceof
AppUserAuthentication
?
((
AppUserAuthentication
)
auth
).
getUser
()
:
null
;
AppUser
user
=
auth
instanceof
AppUserAuthentication
?
((
AppUserAuthentication
)
auth
).
getUser
()
:
null
;
return
hasAnyRole
(
user
,
roles
);
if
(
user
==
null
||
user
.
getRoles
()
==
null
||
roles
==
null
||
roles
.
length
==
0
)
{
}
public
static
boolean
hasAnyRole
(
AppUser
user
,
String
...
roles
)
{
if
(
user
==
null
||
user
.
getRolesMap
()
==
null
||
roles
==
null
||
roles
.
length
==
0
)
{
return
false
;
return
false
;
}
}
for
(
String
role
:
roles
)
{
for
(
String
role
:
roles
)
{
if
(
user
.
getRolesMap
().
containsKey
(
role
))
{
if
(
user
.
getRolesMap
().
containsKey
(
role
))
{
...
...
src/main/java/com/jh/boot/security/api/AuthApiController.java
View file @
514b0131
...
@@ -40,7 +40,7 @@ import com.jh.boot.security.AuthService;
...
@@ -40,7 +40,7 @@ import com.jh.boot.security.AuthService;
import
com.jh.boot.security.PasswordUtils
;
import
com.jh.boot.security.PasswordUtils
;
import
com.jh.boot.security.model.AppUser
;
import
com.jh.boot.security.model.AppUser
;
import
com.jh.boot.utils.Utils
;
import
com.jh.boot.utils.Utils
;
import
com.jh.boot.web.error.
BadRequest
Exception
;
import
com.jh.boot.web.error.
ValidationFailed
Exception
;
import
com.jh.boot.web.error.ErrorMessage
;
import
com.jh.boot.web.error.ErrorMessage
;
import
com.jh.boot.web.error.NotFoundException
;
import
com.jh.boot.web.error.NotFoundException
;
import
com.jh.boot.web.error.RestApiException
;
import
com.jh.boot.web.error.RestApiException
;
...
@@ -120,7 +120,7 @@ public class AuthApiController {
...
@@ -120,7 +120,7 @@ public class AuthApiController {
}
}
//validate
//validate
if
(
signup
==
null
)
{
if
(
signup
==
null
)
{
throw
new
BadRequest
Exception
();
throw
new
ValidationFailed
Exception
();
}
}
List
<
ErrorMessage
>
errors
=
new
ArrayList
<>();
List
<
ErrorMessage
>
errors
=
new
ArrayList
<>();
...
...
src/main/java/com/jh/boot/web/error/
BadRequest
Exception.java
→
src/main/java/com/jh/boot/web/error/
ValidationFailed
Exception.java
View file @
514b0131
...
@@ -6,30 +6,30 @@ import org.springframework.http.HttpStatus;
...
@@ -6,30 +6,30 @@ import org.springframework.http.HttpStatus;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
/**
/**
* The Class
BadRequest
Exception.
* The Class
ValidationFailed
Exception.
*/
*/
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
)
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
)
public
class
BadRequest
Exception
extends
RestApiException
{
public
class
ValidationFailed
Exception
extends
RestApiException
{
/** The Constant serialVersionUID. */
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
/**
/**
* Instantiates a new
bad request
exception.
* Instantiates a new
validation failed
exception.
*
*
* @param errors the errors
* @param errors the errors
*/
*/
public
BadRequest
Exception
(
Collection
<
ErrorMessage
>
errors
)
{
public
ValidationFailed
Exception
(
Collection
<
ErrorMessage
>
errors
)
{
super
(
HttpStatus
.
BAD_REQUEST
,
errors
);
super
(
HttpStatus
.
BAD_REQUEST
,
errors
);
}
}
/**
/**
* Instantiates a new
bad request
exception.
* Instantiates a new
validation failed
exception.
*
*
* @param errors the errors
* @param errors the errors
*/
*/
public
BadRequest
Exception
(
ErrorMessage
...
errors
)
{
public
ValidationFailed
Exception
(
ErrorMessage
...
errors
)
{
super
(
HttpStatus
.
BAD_REQUEST
,
errors
);
super
(
HttpStatus
.
BAD_REQUEST
,
errors
);
}
}
...
...
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