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
ad71e2c6
Commit
ad71e2c6
authored
Aug 26, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api
parent
db503a46
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
AuthApiController.java
...main/java/com/jh/boot/security/api/AuthApiController.java
+1
-1
AppUserAuthService.java
...java/com/jh/boot/security/service/AppUserAuthService.java
+10
-7
No files found.
src/main/java/com/jh/boot/security/api/AuthApiController.java
View file @
ad71e2c6
...
...
@@ -179,7 +179,7 @@ public class AuthApiController {
Utils
.
sleep
(
250
);
String
token
=
resetPassword
.
getToken
();
if
(!
StringUtils
.
hasText
(
token
))
{
return
new
ResponseEntity
<>(
Collections
.
singletonList
(
new
AuthError
(
null
,
"NO_TOKEN"
)),
HttpStatus
.
BAD_REQUEST
);
return
new
ResponseEntity
<>(
Collections
.
singletonList
(
new
AuthError
(
null
,
"
AUTH.
NO_TOKEN"
)),
HttpStatus
.
BAD_REQUEST
);
}
List
<
ErrorMessage
>
errors
=
new
ArrayList
<>();
...
...
src/main/java/com/jh/boot/security/service/AppUserAuthService.java
View file @
ad71e2c6
...
...
@@ -41,10 +41,10 @@ public class AppUserAuthService implements AuthService {
public
Authentication
authenticate
(
String
login
,
String
password
)
throws
BadCredentialsException
{
AppUser
user
=
appUserRepository
.
fetchByLoginDetached
(
login
);
if
(
user
==
null
)
{
throw
new
BadCredentialsException
(
"
User not found"
);
throw
new
BadCredentialsException
(
"
AUTH.USER_NOT_FOUND"
);
}
if
(!
PasswordUtils
.
checkPassword
(
password
,
user
.
getPassword
(),
user
.
getPasswordSalt
()))
{
throw
new
BadCredentialsException
(
"
Bad password"
);
throw
new
BadCredentialsException
(
"
AUTH.BAD_PASSWORD"
);
}
//sanitize object
...
...
@@ -64,10 +64,13 @@ public class AppUserAuthService implements AuthService {
public
void
register
(
String
login
,
String
password
)
throws
AuthenticationException
{
AppUser
user
=
appUserRepository
.
findByLogin
(
login
);
if
(
user
!=
null
)
{
throw
new
BadCredentialsException
(
"
User already exists"
);
throw
new
BadCredentialsException
(
"
AUTH.USER_ALREADY_EXISTS"
);
}
if
(!
StringUtils
.
hasText
(
login
)
||
!
StringUtils
.
hasText
(
password
))
{
throw
new
BadCredentialsException
(
"Bad username or password"
);
throw
new
BadCredentialsException
(
"AUTH.BAD_USERNAME_OR_PASSWORD"
);
}
if
(!
PasswordUtils
.
validatePassword
(
password
))
{
throw
new
BadCredentialsException
(
"AUTH.BAD_PASSWORD"
);
}
AppUser
appUser
=
appUserRepository
.
registerUser
(
login
,
password
);
...
...
@@ -81,7 +84,7 @@ public class AppUserAuthService implements AuthService {
public
String
generateResetToken
(
String
login
)
{
AppUser
user
=
appUserRepository
.
findByLogin
(
login
);
if
(
user
==
null
)
{
throw
new
BadCredentialsException
(
"
User does not exist"
);
throw
new
BadCredentialsException
(
"
AUTH.USER_NOT_FOUND"
);
}
ResetPasswordToken
token
=
new
ResetPasswordToken
(
login
,
new
Date
(),
UUID
.
randomUUID
().
toString
());
...
...
@@ -100,12 +103,12 @@ public class AppUserAuthService implements AuthService {
public
void
resetPassword
(
String
login
,
String
token
,
String
newPassword
)
throws
AuthenticationException
{
ResetPasswordToken
rpt
=
appUserRepository
.
findResetPasswordToken
(
login
,
token
);
if
(
rpt
==
null
)
{
throw
new
BadCredentialsException
(
"
Invalid token"
);
throw
new
BadCredentialsException
(
"
AUTH.INVALID_TOKEN"
);
}
AppUser
user
=
appUserRepository
.
findByLogin
(
login
);
if
(
user
==
null
)
{
throw
new
BadCredentialsException
(
"
User does not exist"
);
throw
new
BadCredentialsException
(
"
AUTH.USER_NOT_FOUND"
);
}
PasswordHash
hash
=
PasswordUtils
.
hashPassword
(
newPassword
);
...
...
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