From 2dd08cc27b972ef2de7d1f2853cf9448cd6ad5f7 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 1 Jul 2022 13:23:36 +0530 Subject: [PATCH] 1.0.2: Comment adjustments for JavaDoc --- .../LemonCommonsWebAutoConfiguration.java | 28 +++------ ...faultExceptionHandlerControllerAdvice.java | 3 - .../exceptions/LemonErrorAttributes.java | 5 -- ...onCommonsWebTokenAuthenticationFilter.java | 4 +- .../security/LemonWebSecurityConfig.java | 63 +++++++++---------- 5 files changed, 39 insertions(+), 64 deletions(-) diff --git a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/LemonCommonsWebAutoConfiguration.java b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/LemonCommonsWebAutoConfiguration.java index 74949ce..e763956 100644 --- a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/LemonCommonsWebAutoConfiguration.java +++ b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/LemonCommonsWebAutoConfiguration.java @@ -85,7 +85,10 @@ public LemonCommonsWebAutoConfiguration() { /** * Prefixes JSON responses for JSON vulnerability. Disabled by default. * To enable, add this to your application properties: - * lemon.enabled.json-prefix: true + * lemon.enabled.json-prefix: true + * + * @param objectMapper Object Mapper (configured by Spring Boot) + * @return Message converted */ @Bean @ConditionalOnProperty(name="lemon.enabled.json-prefix") @@ -100,9 +103,12 @@ public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter( return converter; } - + /** * Configures DefaultExceptionHandlerControllerAdvice if missing + * @param exception + * @param errorResponseComposer the configured errorResponseComposer + * @return configured defaultExceptionHandlerControllerAdvice */ @Bean @ConditionalOnMissingBean(DefaultExceptionHandlerControllerAdvice.class) @@ -114,9 +120,6 @@ DefaultExceptionHandlerControllerAdvice defaultExceptionHandlerControllerAdvi return new DefaultExceptionHandlerControllerAdvice<>(errorResponseComposer); } - /** - * Configures an Error Attributes if missing - */ @Bean @ConditionalOnMissingBean(ErrorAttributes.class) public @@ -126,9 +129,6 @@ ErrorAttributes errorAttributes(ErrorResponseComposer errorResponseComposer) return new LemonErrorAttributes<>(errorResponseComposer); } - /** - * Configures an Error Controller if missing - */ @Bean @ConditionalOnMissingBean(ErrorController.class) public ErrorController errorController(ErrorAttributes errorAttributes, @@ -139,9 +139,6 @@ public ErrorController errorController(ErrorAttributes errorAttributes, return new LemonErrorController(errorAttributes, serverProperties, errorViewResolvers); } - /** - * Configures LemonCorsConfig if missing and lemon.cors.allowed-origins is provided - */ @Bean @ConditionalOnProperty(name="lemon.cors.allowed-origins") @ConditionalOnMissingBean(CorsConfigurationSource.class) @@ -151,9 +148,6 @@ public LemonCorsConfigurationSource corsConfigurationSource(LemonProperties prop return new LemonCorsConfigurationSource(properties); } - /** - * Configures LemonSecurityConfig if missing - */ @Bean @ConditionalOnBean(LemonWebSecurityConfig.class) public SecurityFilterChain lemonSecurityFilterChain(HttpSecurity http, LemonWebSecurityConfig securityConfig) throws Exception { @@ -162,9 +156,6 @@ public SecurityFilterChain lemonSecurityFilterChain(HttpSecurity http, LemonWebS return securityConfig.configure(http).build(); } - /** - * Configures an Auditor Aware if missing - */ @Bean @ConditionalOnMissingBean(AuditorAware.class) public @@ -174,9 +165,6 @@ AuditorAware auditorAware() { return new LemonWebAuditorAware<>(); } - /** - * Configures LemonUtils - */ @Bean public LecwUtils lecwUtils(ApplicationContext applicationContext, ObjectMapper objectMapper) { diff --git a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/DefaultExceptionHandlerControllerAdvice.java b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/DefaultExceptionHandlerControllerAdvice.java index a9aefa2..aad6814 100644 --- a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/DefaultExceptionHandlerControllerAdvice.java +++ b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/DefaultExceptionHandlerControllerAdvice.java @@ -46,9 +46,6 @@ public DefaultExceptionHandlerControllerAdvice(ErrorResponseComposer errorRes } - /** - * Handles exceptions - */ @RequestMapping(produces = "application/json") @ExceptionHandler(Throwable.class) public ResponseEntity handleException(T ex) throws T { diff --git a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/LemonErrorAttributes.java b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/LemonErrorAttributes.java index 4e24abc..14808f6 100644 --- a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/LemonErrorAttributes.java +++ b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/exceptions/LemonErrorAttributes.java @@ -19,8 +19,6 @@ import com.naturalprogrammer.spring.lemon.exceptions.ErrorResponseComposer; import com.naturalprogrammer.spring.lemon.exceptions.util.LexUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.servlet.error.DefaultErrorAttributes; import org.springframework.web.context.request.WebRequest; @@ -59,9 +57,6 @@ public Map getErrorAttributes(WebRequest request, return errorAttributes; } - /** - * Handles exceptions - */ @SuppressWarnings("unchecked") protected void addLemonErrorDetails( Map errorAttributes, WebRequest request) { diff --git a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonCommonsWebTokenAuthenticationFilter.java b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonCommonsWebTokenAuthenticationFilter.java index 36ee2ac..eb0d3a9 100644 --- a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonCommonsWebTokenAuthenticationFilter.java +++ b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonCommonsWebTokenAuthenticationFilter.java @@ -24,8 +24,6 @@ import com.nimbusds.jwt.JWTClaimsSet; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.http.HttpHeaders; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -97,7 +95,7 @@ protected Authentication createAuthToken(String token) { return new UsernamePasswordAuthenticationToken(principal, token, principal.getAuthorities()); } - /** + /* * Default behaviour is to throw error. To be overridden in auth service. */ protected UserDto fetchUserDto(JWTClaimsSet claims) { diff --git a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonWebSecurityConfig.java b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonWebSecurityConfig.java index fdd4b02..f044ca7 100644 --- a/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonWebSecurityConfig.java +++ b/spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/security/LemonWebSecurityConfig.java @@ -45,7 +45,7 @@ public void createLemonWebSecurityConfig(BlueTokenService blueTokenService) { log.info("Created"); } - /** + /* * Security configuration, calling protected methods */ public HttpSecurity configure(HttpSecurity http) throws Exception { @@ -61,45 +61,45 @@ public HttpSecurity configure(HttpSecurity http) throws Exception { return http; } - - /** + + /* * Configuring session creation policy */ protected void sessionCreationPolicy(HttpSecurity http) throws Exception { - + // No session http.sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS); + .sessionCreationPolicy(SessionCreationPolicy.STATELESS); } - - /** + + /* * Logout related configuration */ protected void logout(HttpSecurity http) throws Exception { - + http - .logout().disable(); // we are stateless; so /logout endpoint not needed + .logout().disable(); // we are stateless; so /logout endpoint not needed } - - /** + + /* * Configures exception-handling */ protected void exceptionHandling(HttpSecurity http) throws Exception { - + http - .exceptionHandling() - - /*********************************************** - * To prevent redirection to the login page - * when someone tries to access a restricted page - **********************************************/ - .authenticationEntryPoint(new Http403ForbiddenEntryPoint()); + .exceptionHandling() + + /*********************************************** + * To prevent redirection to the login page + * when someone tries to access a restricted page + **********************************************/ + .authenticationEntryPoint(new Http403ForbiddenEntryPoint()); } - /** + /* * Configuring token authentication filter */ protected void tokenAuthentication(HttpSecurity http) { @@ -113,37 +113,34 @@ protected void tokenAuthentication(HttpSecurity http) { * Disables CSRF. We are stateless. */ protected void csrf(HttpSecurity http) throws Exception { - + http - .csrf().disable(); + .csrf().disable(); } - - /** + + /* * Configures CORS */ protected void cors(HttpSecurity http) throws Exception { - + http - .cors(); + .cors(); } - - /** + + /* * URL based authorization configuration. Override this if needed. */ protected void authorizeRequests(HttpSecurity http) throws Exception { http.authorizeRequests() - .mvcMatchers("/**").permitAll(); + .mvcMatchers("/**").permitAll(); } - /** + /* * Override this to add more http configurations, * such as more authentication methods. - * - * @param http - * @throws Exception */ protected void otherConfigurations(HttpSecurity http) { // Override this method to provide other configurations