update spring boot and jjwt version
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -23,4 +23,7 @@
|
|||||||
/dist/
|
/dist/
|
||||||
/nbdist/
|
/nbdist/
|
||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
nbactions.xml
|
nbactions.xml
|
||||||
|
|
||||||
|
# VS Code #
|
||||||
|
.vscode
|
||||||
24
pom.xml
24
pom.xml
@@ -14,7 +14,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.0.0.RELEASE</version>
|
<version>2.1.1.RELEASE</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@@ -33,15 +33,27 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
|
||||||
<artifactId>jjwt</artifactId>
|
|
||||||
<version>0.7.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-api</artifactId>
|
||||||
|
<version>0.10.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-impl</artifactId>
|
||||||
|
<version>0.10.5</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-jackson</artifactId>
|
||||||
|
<version>0.10.5</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class AuthenticationREST {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserService userRepository;
|
private UserService userRepository;
|
||||||
|
|
||||||
@RequestMapping(value = "login", method = RequestMethod.POST)
|
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||||
public Mono<ResponseEntity<?>> login(@RequestBody AuthRequest ar) {
|
public Mono<ResponseEntity<?>> login(@RequestBody AuthRequest ar) {
|
||||||
return userRepository.findByUsername(ar.getUsername()).map((userDetails) -> {
|
return userRepository.findByUsername(ar.getUsername()).map((userDetails) -> {
|
||||||
if (passwordEncoder.encode(ar.getPassword()).equals(userDetails.getPassword())) {
|
if (passwordEncoder.encode(ar.getPassword()).equals(userDetails.getPassword())) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.ard333.springbootwebfluxjjwt.security;
|
|||||||
|
|
||||||
import com.ard333.springbootwebfluxjjwt.model.User;
|
import com.ard333.springbootwebfluxjjwt.model.User;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -27,7 +28,7 @@ public class JWTUtil implements Serializable {
|
|||||||
private String expirationTime;
|
private String expirationTime;
|
||||||
|
|
||||||
public Claims getAllClaimsFromToken(String token) {
|
public Claims getAllClaimsFromToken(String token) {
|
||||||
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
return Jwts.parser().setSigningKey(Base64.getEncoder().encodeToString(secret.getBytes())).parseClaimsJws(token).getBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsernameFromToken(String token) {
|
public String getUsernameFromToken(String token) {
|
||||||
@@ -46,7 +47,6 @@ public class JWTUtil implements Serializable {
|
|||||||
public String generateToken(User user) {
|
public String generateToken(User user) {
|
||||||
Map<String, Object> claims = new HashMap<>();
|
Map<String, Object> claims = new HashMap<>();
|
||||||
claims.put("role", user.getRoles());
|
claims.put("role", user.getRoles());
|
||||||
claims.put("enable", user.getEnabled());
|
|
||||||
return doGenerateToken(claims, user.getUsername());
|
return doGenerateToken(claims, user.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class JWTUtil implements Serializable {
|
|||||||
.setSubject(username)
|
.setSubject(username)
|
||||||
.setIssuedAt(createdDate)
|
.setIssuedAt(createdDate)
|
||||||
.setExpiration(expirationDate)
|
.setExpiration(expirationDate)
|
||||||
.signWith(SignatureAlgorithm.HS512, secret)
|
.signWith(SignatureAlgorithm.HS512, Base64.getEncoder().encodeToString(secret.getBytes()))
|
||||||
.compact();
|
.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class WebSecurityConfig {
|
|||||||
.securityContextRepository(securityContextRepository)
|
.securityContextRepository(securityContextRepository)
|
||||||
.authorizeExchange()
|
.authorizeExchange()
|
||||||
.pathMatchers(HttpMethod.OPTIONS).permitAll()
|
.pathMatchers(HttpMethod.OPTIONS).permitAll()
|
||||||
.pathMatchers("/auth").permitAll()
|
.pathMatchers("/login").permitAll()
|
||||||
.anyExchange().authenticated()
|
.anyExchange().authenticated()
|
||||||
.and().build();
|
.and().build();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
springbootwebfluxjjwt.password.encoder.secret=mysecret
|
springbootwebfluxjjwt.password.encoder.secret=mysecret
|
||||||
springbootwebfluxjjwt.password.encoder.iteration=33
|
springbootwebfluxjjwt.password.encoder.iteration=33
|
||||||
springbootwebfluxjjwt.password.encoder.keylength=256
|
springbootwebfluxjjwt.password.encoder.keylength=256
|
||||||
springbootwebfluxjjwt.jjwt.secret=mysecret
|
|
||||||
|
springbootwebfluxjjwt.jjwt.secret=ThisIsSecretForJWTHS512SignatureAlgorithmThatMUSTHave512bitsKeySize
|
||||||
springbootwebfluxjjwt.jjwt.expiration=28800
|
springbootwebfluxjjwt.jjwt.expiration=28800
|
||||||
Reference in New Issue
Block a user