Skip to content

Commit bb40423

Browse files
committed
apply lombook constractor instead of autowired
1 parent 8b60b28 commit bb40423

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

core/src/main/java/com/flowci/core/auth/controller/WebAuth.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.flowci.exception.AuthenticationException;
2626
import com.flowci.util.StringHelper;
2727
import com.google.common.base.Strings;
28+
import lombok.AllArgsConstructor;
2829
import org.springframework.beans.factory.annotation.Autowired;
2930
import org.springframework.messaging.MessageHeaders;
3031
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
@@ -43,17 +44,16 @@
4344
* @author yang
4445
*/
4546
@Component("webAuth")
47+
@AllArgsConstructor
4648
public class WebAuth implements HandlerInterceptor {
4749

4850
private static final String HeaderToken = "Token";
4951

5052
private static final String ParameterToken = "token";
5153

52-
@Autowired
53-
private AuthService authService;
54+
private final AuthService authService;
5455

55-
@Autowired
56-
private SessionManager sessionManager;
56+
private final SessionManager sessionManager;
5757

5858
/**
5959
* Get user object from ws message header
@@ -73,7 +73,7 @@ public User validate(MessageHeaders headers) {
7373
}
7474

7575
Optional<User> user = authService.get(token);
76-
if (!user.isPresent()) {
76+
if (user.isEmpty()) {
7777
throw new AuthenticationException("Invalid token");
7878
}
7979

core/src/main/java/com/flowci/core/common/adviser/CorsFilter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616

1717
package com.flowci.core.common.adviser;
1818

19+
import org.springframework.web.bind.annotation.RequestMethod;
20+
1921
import javax.servlet.*;
2022
import javax.servlet.annotation.WebFilter;
2123
import javax.servlet.http.HttpServletRequest;
2224
import javax.servlet.http.HttpServletResponse;
23-
import org.springframework.web.bind.annotation.RequestMethod;
24-
import org.springframework.web.servlet.HandlerInterceptor;
25-
2625
import java.io.IOException;
2726

2827
/**
@@ -34,6 +33,8 @@ public class CorsFilter implements Filter {
3433
private static final String AllowedHeaders =
3534
"Origin, X-Requested-With, Content-Disposition, Content-Type, Accept, Token, Authorization";
3635

36+
private static final String AllowedMethods = "GET, POST, PATCH, OPTIONS, DELETE";
37+
3738
@Override
3839
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
3940
if (!isHttpRequest(request, response)) {
@@ -45,10 +46,10 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
4546
var httpResponse = (HttpServletResponse) response;
4647

4748
httpResponse.setHeader("Access-Control-Allow-Origin", "*");
48-
httpResponse.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS, DELETE");
49+
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
50+
httpResponse.setHeader("Access-Control-Allow-Methods", AllowedMethods);
4951
httpResponse.setHeader("Access-Control-Max-Age", "1800");
5052
httpResponse.setHeader("Access-Control-Allow-Headers", AllowedHeaders);
51-
httpResponse.setHeader("Access-Control-Expose-Headers", AllowedHeaders);
5253

5354
if (httpRequest.getMethod().equals(RequestMethod.OPTIONS.name())) {
5455
httpResponse.setStatus(HttpServletResponse.SC_OK);

core/src/main/java/com/flowci/core/common/config/WebConfig.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.flowci.core.plugin.domain.Plugin;
2323
import com.flowci.domain.Vars;
2424
import com.google.common.collect.ImmutableList;
25+
import lombok.AllArgsConstructor;
2526
import org.springframework.beans.factory.annotation.Autowired;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2728
import org.springframework.context.annotation.Bean;
@@ -35,10 +36,7 @@
3536
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
3637
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
3738
import org.springframework.web.servlet.HandlerInterceptor;
38-
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
39-
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
40-
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
41-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
39+
import org.springframework.web.servlet.config.annotation.*;
4240

4341
import javax.servlet.Filter;
4442
import java.nio.file.Path;
@@ -48,16 +46,14 @@
4846

4947
@EnableWebMvc
5048
@Configuration
49+
@AllArgsConstructor
5150
public class WebConfig {
5251

53-
@Autowired
54-
private HandlerInterceptor apiAuth;
52+
private final HandlerInterceptor apiAuth;
5553

56-
@Autowired
57-
private HandlerInterceptor webAuth;
54+
private final HandlerInterceptor webAuth;
5855

59-
@Autowired
60-
private AppProperties appProperties;
56+
private final AppProperties appProperties;
6157

6258
@Bean("staticResourceDir")
6359
public Path staticResourceDir() {

0 commit comments

Comments
 (0)