Skip to content

Commit a54c8e3

Browse files
committed
add #40
1 parent d3d9509 commit a54c8e3

38 files changed

+195
-132
lines changed

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>3.1.10</version>
15+
<version>3.2.0.dev</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>
@@ -145,7 +145,7 @@
145145

146146
<dependency>
147147
<groupId>com.codingapi.springboot</groupId>
148-
<artifactId>springboot-starter-security-jwt</artifactId>
148+
<artifactId>springboot-starter-security</artifactId>
149149
<version>${codingapi.framework.version}</version>
150150
</dependency>
151151

@@ -251,7 +251,7 @@
251251
</activation>
252252
<modules>
253253
<module>springboot-starter</module>
254-
<module>springboot-starter-security-jwt</module>
254+
<module>springboot-starter-security</module>
255255
<module>springboot-starter-data-fast</module>
256256
</modules>
257257
</profile>
@@ -262,7 +262,7 @@
262262

263263
<modules>
264264
<module>springboot-starter</module>
265-
<module>springboot-starter-security-jwt</module>
265+
<module>springboot-starter-security</module>
266266
<module>springboot-starter-data-fast</module>
267267
</modules>
268268

@@ -311,7 +311,7 @@
311311

312312
<modules>
313313
<module>springboot-starter</module>
314-
<module>springboot-starter-security-jwt</module>
314+
<module>springboot-starter-security</module>
315315
<module>springboot-starter-data-fast</module>
316316
</modules>
317317

springboot-starter-data-fast/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.1.10</version>
8+
<version>3.2.0.dev</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-security-jwt/src/main/java/com/codingapi/springboot/security/crypto/MyCryptoConfiguration.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

springboot-starter-security-jwt/pom.xml renamed to springboot-starter-security/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.1.10</version>
9+
<version>3.2.0.dev</version>
1010
</parent>
1111

12-
<artifactId>springboot-starter-security-jwt</artifactId>
12+
<artifactId>springboot-starter-security</artifactId>
1313

14-
<name>springboot-starter-security-jwt</name>
15-
<description>springboot-starter-security-jwt project for Spring Boot</description>
14+
<name>springboot-starter-security</name>
15+
<description>springboot-starter-security project for Spring Boot</description>
1616

1717
<properties>
1818
<java.version>17</java.version>
Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import com.codingapi.springboot.security.controller.VersionController;
55
import com.codingapi.springboot.security.dto.request.LoginRequest;
66
import com.codingapi.springboot.security.filter.*;
7-
import com.codingapi.springboot.security.jwt.Jwt;
8-
import com.codingapi.springboot.security.jwt.Token;
9-
import com.codingapi.springboot.security.properties.SecurityJwtProperties;
7+
import com.codingapi.springboot.security.gateway.Token;
8+
import com.codingapi.springboot.security.gateway.TokenGateway;
9+
import com.codingapi.springboot.security.properties.CodingApiSecurityProperties;
1010
import jakarta.servlet.http.HttpServletRequest;
1111
import jakarta.servlet.http.HttpServletResponse;
1212
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -60,23 +60,23 @@ public PasswordEncoder passwordEncoder() {
6060

6161
@Bean
6262
@ConditionalOnMissingBean
63-
public SecurityLoginHandler securityLoginHandler(){
64-
return new SecurityLoginHandler() {
65-
@Override
66-
public void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler) throws Exception {
63+
public SecurityLoginHandler securityLoginHandler() {
64+
return new SecurityLoginHandler() {
65+
@Override
66+
public void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler) throws Exception {
6767

68-
}
68+
}
6969

70-
@Override
71-
public void postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler, Token token) {
70+
@Override
71+
public void postHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler, Token token) {
7272

73-
}
74-
};
73+
}
74+
};
7575
}
7676

7777
@Bean
7878
@ConditionalOnMissingBean
79-
public AuthenticationTokenFilter authenticationTokenFilter(){
79+
public AuthenticationTokenFilter authenticationTokenFilter() {
8080
return (request, response, chain) -> {
8181

8282
};
@@ -85,17 +85,17 @@ public AuthenticationTokenFilter authenticationTokenFilter(){
8585

8686
@Bean
8787
@ConditionalOnMissingBean
88-
public SecurityFilterChain filterChain(HttpSecurity security, Jwt jwt,SecurityLoginHandler loginHandler,
89-
SecurityJwtProperties properties,AuthenticationTokenFilter authenticationTokenFilter) throws Exception {
88+
public SecurityFilterChain filterChain(HttpSecurity security, TokenGateway tokenGateway, SecurityLoginHandler loginHandler,
89+
CodingApiSecurityProperties properties, AuthenticationTokenFilter authenticationTokenFilter) throws Exception {
9090
//disable basic auth
9191
security.httpBasic().disable();
9292

9393
//before add addCorsMappings to enable cors.
9494
security.cors();
95-
if(properties.isDisableCsrf() ){
95+
if (properties.isDisableCsrf()) {
9696
security.csrf().disable();
9797
}
98-
security.apply(new HttpSecurityConfigurer(jwt,loginHandler,properties,authenticationTokenFilter));
98+
security.apply(new HttpSecurityConfigurer(tokenGateway, loginHandler, properties, authenticationTokenFilter));
9999
security
100100
.exceptionHandling()
101101
.authenticationEntryPoint(new MyUnAuthenticationEntryPoint())
@@ -135,18 +135,11 @@ public AuthenticationProvider authenticationProvider(UserDetailsService userDeta
135135

136136

137137
@Bean
138-
@ConditionalOnMissingBean
139-
public Jwt jwt(SecurityJwtProperties properties) {
140-
return new Jwt(properties.getJwtSecretKey(), properties.getJwtTime(), properties.getJwtRestTime());
141-
}
142-
143-
144-
@Bean
145-
public WebMvcConfigurer corsConfigurer(SecurityJwtProperties securityJwtProperties) {
138+
public WebMvcConfigurer corsConfigurer(CodingApiSecurityProperties securityJwtProperties) {
146139
return new WebMvcConfigurer() {
147140
@Override
148141
public void addCorsMappings(CorsRegistry registry) {
149-
if(securityJwtProperties.isDisableCors()) {
142+
if (securityJwtProperties.isDisableCors()) {
150143
registry.addMapping("/**")
151144
.allowedHeaders("*")
152145
.allowedMethods("*")
@@ -163,14 +156,14 @@ public void addCorsMappings(CorsRegistry registry) {
163156

164157
@Bean
165158
@ConfigurationProperties(prefix = "codingapi.security")
166-
public SecurityJwtProperties securityJwtProperties() {
167-
return new SecurityJwtProperties();
159+
public CodingApiSecurityProperties codingApiSecurityProperties() {
160+
return new CodingApiSecurityProperties();
168161
}
169162

170163

171164
@Bean
172165
@ConditionalOnMissingBean
173-
public VersionController versionController(Environment environment){
166+
public VersionController versionController(Environment environment) {
174167
return new VersionController(environment);
175168
}
176169

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.codingapi.springboot.security.filter.MyAuthenticationFilter;
55
import com.codingapi.springboot.security.filter.MyLoginFilter;
66
import com.codingapi.springboot.security.filter.SecurityLoginHandler;
7-
import com.codingapi.springboot.security.jwt.Jwt;
8-
import com.codingapi.springboot.security.properties.SecurityJwtProperties;
7+
import com.codingapi.springboot.security.gateway.TokenGateway;
8+
import com.codingapi.springboot.security.properties.CodingApiSecurityProperties;
99
import lombok.AllArgsConstructor;
1010
import org.springframework.security.authentication.AuthenticationManager;
1111
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -14,16 +14,16 @@
1414
@AllArgsConstructor
1515
public class HttpSecurityConfigurer extends AbstractHttpConfigurer<HttpSecurityConfigurer, HttpSecurity> {
1616

17-
private final Jwt jwt;
17+
private final TokenGateway tokenGateway;
1818

1919
private final SecurityLoginHandler securityLoginHandler;
20-
private final SecurityJwtProperties securityJwtProperties;
20+
private final CodingApiSecurityProperties securityJwtProperties;
2121
private final AuthenticationTokenFilter authenticationTokenFilter;
2222

2323
@Override
2424
public void configure(HttpSecurity security) throws Exception {
2525
AuthenticationManager manager = security.getSharedObject(AuthenticationManager.class);
26-
security.addFilter(new MyLoginFilter(manager, jwt,securityLoginHandler, securityJwtProperties));
27-
security.addFilter(new MyAuthenticationFilter(manager,securityJwtProperties,jwt,authenticationTokenFilter));
26+
security.addFilter(new MyLoginFilter(manager, tokenGateway, securityLoginHandler, securityJwtProperties));
27+
security.addFilter(new MyAuthenticationFilter(manager, securityJwtProperties, tokenGateway, authenticationTokenFilter));
2828
}
2929
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.codingapi.springboot.security.configurer;
22

3-
import com.codingapi.springboot.security.properties.SecurityJwtProperties;
3+
import com.codingapi.springboot.security.properties.CodingApiSecurityProperties;
44
import lombok.AllArgsConstructor;
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.security.config.annotation.web.builders.WebSecurity;
@@ -10,7 +10,7 @@
1010
@AllArgsConstructor
1111
public class WebSecurityConfigurer implements WebSecurityCustomizer {
1212

13-
private final SecurityJwtProperties securityJwtProperties;
13+
private final CodingApiSecurityProperties securityJwtProperties;
1414

1515
@Override
1616
public void customize(WebSecurity web) {

0 commit comments

Comments
 (0)