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
367f05cb
Commit
367f05cb
authored
Aug 25, 2019
by
jhrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BT
parent
f53f7c16
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
AuthApiController.java
...main/java/com/jh/boot/security/api/AuthApiController.java
+15
-10
ErrorMessage.java
src/main/java/com/jh/boot/web/error/ErrorMessage.java
+1
-1
No files found.
src/main/java/com/jh/boot/security/api/AuthApiController.java
View file @
367f05cb
...
@@ -8,6 +8,7 @@ import java.util.ArrayList;
...
@@ -8,6 +8,7 @@ import java.util.ArrayList;
import
java.util.Base64
;
import
java.util.Base64
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.logging.ErrorManager
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
...
@@ -113,20 +114,20 @@ public class AuthApiController {
...
@@ -113,20 +114,20 @@ public class AuthApiController {
throw
new
BadRequestException
();
throw
new
BadRequestException
();
}
}
List
<
AuthError
>
errors
=
new
ArrayList
<>();
List
<
ErrorMessage
>
errors
=
new
ArrayList
<>();
//TODO validate email
//TODO validate email
if
(!
StringUtils
.
hasText
(
signup
.
getLogin
()))
{
if
(!
StringUtils
.
hasText
(
signup
.
getLogin
()))
{
errors
.
add
(
new
AuthError
(
"username"
,
"BadUsername
"
));
errors
.
add
(
ErrorMessage
.
withFieldCode
(
"username"
,
"AUTH.BAD_USERNAME
"
));
}
}
if
(!
PasswordUtils
.
validatePassword
(
signup
.
getPassword
()))
{
if
(!
PasswordUtils
.
validatePassword
(
signup
.
getPassword
()))
{
errors
.
add
(
new
AuthError
(
"password"
,
"BadPassword
"
));
errors
.
add
(
ErrorMessage
.
withFieldCode
(
"password"
,
"AUTH.BAD_PASSWORD
"
));
}
}
if
(!
errors
.
isEmpty
())
{
if
(!
errors
.
isEmpty
())
{
// throw new BadRequestException(
errors);
throw
new
RestApiException
(
HttpStatus
.
BAD_REQUEST
,
errors
);
throw
new
BadRequestException
();
//
throw new BadRequestException();
}
}
try
{
try
{
...
@@ -136,10 +137,14 @@ public class AuthApiController {
...
@@ -136,10 +137,14 @@ public class AuthApiController {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
errors
.
add
(
new
AuthError
(
null
,
e
.
getMessage
()));
errors
.
add
(
ErrorMessage
.
withMessage
(
e
.
getMessage
()));
}
}
return
new
LoginResponse
(
"Authorization"
,
"Basic "
+
Base64
.
getEncoder
().
encodeToString
((
signup
.
getLogin
()
+
":"
+
signup
.
getPassword
()).
getBytes
()));
if
(
errors
.
isEmpty
())
{
return
new
LoginResponse
(
"Authorization"
,
"Basic "
+
Base64
.
getEncoder
().
encodeToString
((
signup
.
getLogin
()
+
":"
+
signup
.
getPassword
()).
getBytes
()));
}
throw
new
RestApiException
(
HttpStatus
.
BAD_REQUEST
,
errors
);
}
}
...
@@ -165,7 +170,7 @@ public class AuthApiController {
...
@@ -165,7 +170,7 @@ public class AuthApiController {
return
new
ResponseEntity
<>(
Collections
.
singletonList
(
new
AuthError
(
null
,
"NO_TOKEN"
)),
HttpStatus
.
BAD_REQUEST
);
return
new
ResponseEntity
<>(
Collections
.
singletonList
(
new
AuthError
(
null
,
"NO_TOKEN"
)),
HttpStatus
.
BAD_REQUEST
);
}
}
List
<
AuthError
>
errors
=
new
ArrayList
<>();
List
<
ErrorMessage
>
errors
=
new
ArrayList
<>();
try
{
try
{
authService
.
resetPassword
(
resetPassword
.
getLogin
(),
resetPassword
.
getToken
(),
resetPassword
.
getPassword
());
authService
.
resetPassword
(
resetPassword
.
getLogin
(),
resetPassword
.
getToken
(),
resetPassword
.
getPassword
());
...
@@ -177,7 +182,7 @@ public class AuthApiController {
...
@@ -177,7 +182,7 @@ public class AuthApiController {
// }
// }
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
errors
.
add
(
new
AuthError
(
null
,
e
.
getMessage
()));
errors
.
add
(
ErrorMessage
.
withMessage
(
e
.
getMessage
()));
}
}
if
(
errors
.
isEmpty
())
{
if
(
errors
.
isEmpty
())
{
...
@@ -185,7 +190,7 @@ public class AuthApiController {
...
@@ -185,7 +190,7 @@ public class AuthApiController {
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
}
}
return
new
ResponseEntity
<>(
errors
,
HttpStatus
.
BAD_REQUEST
);
throw
new
RestApiException
(
HttpStatus
.
BAD_REQUEST
,
errors
);
}
}
...
...
src/main/java/com/jh/boot/web/error/ErrorMessage.java
View file @
367f05cb
...
@@ -110,7 +110,7 @@ public class ErrorMessage {
...
@@ -110,7 +110,7 @@ public class ErrorMessage {
*/
*/
public
static
ErrorMessage
withCode
(
String
code
)
{
public
static
ErrorMessage
withCode
(
String
code
)
{
ErrorMessage
em
=
new
ErrorMessage
();
ErrorMessage
em
=
new
ErrorMessage
();
em
.
messag
e
=
code
;
em
.
cod
e
=
code
;
return
em
;
return
em
;
}
}
...
...
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