Skip to content

Commit 8e9b1ab

Browse files
fix : Remove the duplicate CORS settings and correct the handling message for a 403 authorization error (permission denied)
1 parent 5ebad6e commit 8e9b1ab

File tree

3 files changed

+5
-24
lines changed

3 files changed

+5
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Authentication management based on a combination of username, client id, and an extra token (referred to in the source code as App-Token, which receives a unique value from the calling devices).
77
* Separated UserDetails implementation for Admin and Customer roles.
88
* Integration with spring-security-oauth2-authorization-server.
9-
* Provide MySQL DDL, which consists of oauth\_access\_token, oauth\_refresh\_token and oauth\_client\_details, which is tables in Security 5. As I mean to migrate current security system to Security 6, I haven't changed them to the ``oauth2_authorization`` table indicated in https://github.com/spring-projects/spring-authorization-server.
9+
* Provide MySQL DDL, which consists of oauth\_access\_token, oauth\_refresh\_token and oauth\_client\_details, which is tables in Security 5. As I mean to migrate current security system to Security 6, I haven't changed them to the ``authorization`` table indicated in https://github.com/spring-projects/spring-authorization-server.
1010
* Application of Spring Rest Docs.
1111
## Dependencies
1212

src/main/java/com/patternknife/securityhelper/oauth2/config/response/error/GlobalExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public ResponseEntity<?> authenticationException(Exception ex, WebRequest reques
6060
@ExceptionHandler({UnauthorizedException.class, AccessDeniedException.class, DisabledException.class})
6161
public ResponseEntity<?> authorizationException(Exception ex, WebRequest request) {
6262
ErrorDetails errorDetails = new ErrorDetails(ex.getMessage() != null ? ex.getMessage() : CustomExceptionUtils.getAllCauses(ex), request.getDescription(false),
63-
ex.getMessage() == null ? SecurityExceptionMessage.AUTHENTICATION_ERROR.getMessage() : ex.getMessage(), ex.getStackTrace()[0].toString());
63+
ex.getMessage() == null || ex.getMessage().equals("Access Denied") ? SecurityExceptionMessage.AUTHORIZATION_FAILURE.getMessage() : ex.getMessage(), ex.getStackTrace()[0].toString());
6464
return new ResponseEntity<>(errorDetails, HttpStatus.FORBIDDEN);
6565
}
6666
// Custom or Admin

src/main/java/com/patternknife/securityhelper/oauth2/config/security/web/WebMvcConfig.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,18 @@
33

44
import lombok.RequiredArgsConstructor;
55
import org.springframework.context.annotation.Configuration;
6-
import org.springframework.http.HttpMethod;
7-
import org.springframework.web.servlet.config.annotation.*;
6+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
7+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
8+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
89

910
@RequiredArgsConstructor
1011
@Configuration
1112
@EnableWebMvc
1213
public class WebMvcConfig implements WebMvcConfigurer {
1314

14-
@Override
15-
public void addCorsMappings(CorsRegistry registry) {
16-
registry
17-
.addMapping("/**")
18-
.allowedOrigins("*")
19-
.allowedMethods(
20-
HttpMethod.GET.name(),
21-
HttpMethod.HEAD.name(),
22-
HttpMethod.POST.name(),
23-
HttpMethod.PUT.name(),
24-
HttpMethod.PATCH.name(),
25-
HttpMethod.DELETE.name());
26-
}
27-
2815
@Override
2916
public void addResourceHandlers(ResourceHandlerRegistry registry) {
3017
registry.addResourceHandler("/docs/**").addResourceLocations("classpath:/static/docs/");
3118
}
3219

33-
34-
35-
@Override
36-
public void addInterceptors(InterceptorRegistry registry) {
37-
38-
}
3920
}

0 commit comments

Comments
 (0)