Skip to content

Commit 1388115

Browse files
committed
clean codes.
1 parent cf03691 commit 1388115

File tree

9 files changed

+23
-16
lines changed

9 files changed

+23
-16
lines changed

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.1.3.RELEASE</version>
17+
<version>2.1.6.RELEASE</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

@@ -82,13 +82,11 @@
8282
<dependency>
8383
<groupId>io.rest-assured</groupId>
8484
<artifactId>rest-assured</artifactId>
85-
<version>3.1.0</version>
8685
<scope>test</scope>
8786
</dependency>
8887
<dependency>
8988
<groupId>io.rest-assured</groupId>
9089
<artifactId>json-path</artifactId>
91-
<version>3.1.0</version>
9290
<scope>test</scope>
9391
</dependency>
9492
<dependency>

src/main/java/com/example/demo/config/SecurityConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.example.demo.config;
22

3-
import com.example.demo.security.jwt.JwtConfigurer;
3+
import com.example.demo.security.jwt.JwtSecurityConfigurer;
44
import com.example.demo.security.jwt.JwtTokenProvider;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.context.annotation.Bean;
@@ -39,7 +39,7 @@ protected void configure(HttpSecurity http) throws Exception {
3939
.antMatchers(HttpMethod.GET, "/v1/vehicles/**").permitAll()
4040
.anyRequest().authenticated()
4141
.and()
42-
.apply(new JwtConfigurer(jwtTokenProvider));
42+
.apply(new JwtSecurityConfigurer(jwtTokenProvider));
4343
//@formatter:on
4444
}
4545

src/main/java/com/example/demo/security/jwt/InvalidJwtAuthenticationException.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import org.springframework.security.core.AuthenticationException;
44

55
public class InvalidJwtAuthenticationException extends AuthenticationException {
6-
public InvalidJwtAuthenticationException(String e) {
6+
/**
7+
*
8+
*/
9+
private static final long serialVersionUID = -761503632186596342L;
10+
11+
public InvalidJwtAuthenticationException(String e) {
712
super(e);
813
}
914
}

src/main/java/com/example/demo/security/jwt/JwtProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.example.demo.security.jwt;
22

3-
import org.springframework.beans.factory.annotation.Value;
43
import org.springframework.boot.context.properties.ConfigurationProperties;
54

65
import lombok.Data;
@@ -11,5 +10,6 @@ public class JwtProperties {
1110

1211
private String secretKey = "secret";
1312

14-
private long validityInMilliseconds = 3600000; // 1h
13+
//validity in milliseconds
14+
private long validityInMs = 3600000; // 1h
1515
}

src/main/java/com/example/demo/security/jwt/JwtConfigurer.java renamed to src/main/java/com/example/demo/security/jwt/JwtSecurityConfigurer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
import org.springframework.security.web.DefaultSecurityFilterChain;
66
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
77

8-
public class JwtConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
8+
public class JwtSecurityConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
99

1010
private JwtTokenProvider jwtTokenProvider;
1111

12-
public JwtConfigurer(JwtTokenProvider jwtTokenProvider) {
12+
public JwtSecurityConfigurer(JwtTokenProvider jwtTokenProvider) {
1313
this.jwtTokenProvider = jwtTokenProvider;
1414
}
1515

1616
@Override
1717
public void configure(HttpSecurity http) throws Exception {
18-
JwtTokenFilter customFilter = new JwtTokenFilter(jwtTokenProvider);
18+
JwtTokenAuthenticationFilter customFilter = new JwtTokenAuthenticationFilter(jwtTokenProvider);
1919
http.exceptionHandling()
2020
.authenticationEntryPoint(new JwtAuthenticationEntryPoint())
2121
.and()

src/main/java/com/example/demo/security/jwt/JwtTokenFilter.java renamed to src/main/java/com/example/demo/security/jwt/JwtTokenAuthenticationFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import javax.servlet.http.HttpServletRequest;
1212
import java.io.IOException;
1313

14-
public class JwtTokenFilter extends GenericFilterBean {
14+
public class JwtTokenAuthenticationFilter extends GenericFilterBean {
1515

1616
private JwtTokenProvider jwtTokenProvider;
1717

18-
public JwtTokenFilter(JwtTokenProvider jwtTokenProvider) {
18+
public JwtTokenAuthenticationFilter(JwtTokenProvider jwtTokenProvider) {
1919
this.jwtTokenProvider = jwtTokenProvider;
2020
}
2121

src/main/java/com/example/demo/security/jwt/JwtTokenProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public String createToken(String username, List<String> roles) {
4141
claims.put("roles", roles);
4242

4343
Date now = new Date();
44-
Date validity = new Date(now.getTime() + jwtProperties.getValidityInMilliseconds());
44+
Date validity = new Date(now.getTime() + jwtProperties.getValidityInMs());
4545

4646
return Jwts.builder()//
4747
.setClaims(claims)//

src/main/java/com/example/demo/web/AuthController.java renamed to src/main/java/com/example/demo/web/AuthenticationController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
@RestController
2323
@RequestMapping("/auth")
24-
public class AuthController {
24+
public class AuthenticationController {
2525

2626
@Autowired
2727
AuthenticationManager authenticationManager;

src/main/java/com/example/demo/web/AuthenticationRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
@NoArgsConstructor
1313
@AllArgsConstructor
1414
public class AuthenticationRequest implements Serializable {
15-
private String username;
15+
/**
16+
*
17+
*/
18+
private static final long serialVersionUID = -6986746375915710855L;
19+
private String username;
1620
private String password;
1721
}

0 commit comments

Comments
 (0)