Commit 514b0131 by Jan Hrabal

fixes

parent 075664bf
...@@ -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>
......
...@@ -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)) {
......
...@@ -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.BadRequestException; import com.jh.boot.web.error.ValidationFailedException;
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 BadRequestException(); throw new ValidationFailedException();
} }
List<ErrorMessage> errors = new ArrayList<>(); List<ErrorMessage> errors = new ArrayList<>();
......
...@@ -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 BadRequestException. * The Class ValidationFailedException.
*/ */
@ResponseStatus(value = HttpStatus.BAD_REQUEST) @ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class BadRequestException extends RestApiException { public class ValidationFailedException 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 BadRequestException(Collection<ErrorMessage> errors) { public ValidationFailedException(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 BadRequestException(ErrorMessage... errors) { public ValidationFailedException(ErrorMessage... errors) {
super(HttpStatus.BAD_REQUEST, errors); super(HttpStatus.BAD_REQUEST, errors);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment