diff --git a/.gitignore b/.gitignore
index 265b65a..4b06616 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,4 +23,7 @@
/dist/
/nbdist/
/.nb-gradle/
-nbactions.xml
\ No newline at end of file
+nbactions.xml
+
+# VS Code #
+.vscode
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9620ac0..ff6fc6d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 2.0.0.RELEASE
+ 2.1.1.RELEASE
@@ -33,15 +33,27 @@
org.springframework.boot
spring-boot-starter-webflux
-
- io.jsonwebtoken
- jjwt
- 0.7.0
-
org.projectlombok
lombok
+
+ io.jsonwebtoken
+ jjwt-api
+ 0.10.5
+
+
+ io.jsonwebtoken
+ jjwt-impl
+ 0.10.5
+ runtime
+
+
+ io.jsonwebtoken
+ jjwt-jackson
+ 0.10.5
+ runtime
+
diff --git a/src/main/java/com/ard333/springbootwebfluxjjwt/rest/AuthenticationREST.java b/src/main/java/com/ard333/springbootwebfluxjjwt/rest/AuthenticationREST.java
index ac3fa1c..42ecf88 100644
--- a/src/main/java/com/ard333/springbootwebfluxjjwt/rest/AuthenticationREST.java
+++ b/src/main/java/com/ard333/springbootwebfluxjjwt/rest/AuthenticationREST.java
@@ -30,7 +30,7 @@ public class AuthenticationREST {
@Autowired
private UserService userRepository;
- @RequestMapping(value = "login", method = RequestMethod.POST)
+ @RequestMapping(value = "/login", method = RequestMethod.POST)
public Mono> login(@RequestBody AuthRequest ar) {
return userRepository.findByUsername(ar.getUsername()).map((userDetails) -> {
if (passwordEncoder.encode(ar.getPassword()).equals(userDetails.getPassword())) {
diff --git a/src/main/java/com/ard333/springbootwebfluxjjwt/security/JWTUtil.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/JWTUtil.java
index 228890a..adacec5 100644
--- a/src/main/java/com/ard333/springbootwebfluxjjwt/security/JWTUtil.java
+++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/JWTUtil.java
@@ -2,6 +2,7 @@ package com.ard333.springbootwebfluxjjwt.security;
import com.ard333.springbootwebfluxjjwt.model.User;
import java.io.Serializable;
+import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -27,7 +28,7 @@ public class JWTUtil implements Serializable {
private String expirationTime;
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) {
@@ -46,7 +47,6 @@ public class JWTUtil implements Serializable {
public String generateToken(User user) {
Map claims = new HashMap<>();
claims.put("role", user.getRoles());
- claims.put("enable", user.getEnabled());
return doGenerateToken(claims, user.getUsername());
}
@@ -60,7 +60,7 @@ public class JWTUtil implements Serializable {
.setSubject(username)
.setIssuedAt(createdDate)
.setExpiration(expirationDate)
- .signWith(SignatureAlgorithm.HS512, secret)
+ .signWith(SignatureAlgorithm.HS512, Base64.getEncoder().encodeToString(secret.getBytes()))
.compact();
}
diff --git a/src/main/java/com/ard333/springbootwebfluxjjwt/security/WebSecurityConfig.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/WebSecurityConfig.java
index 148752f..add99f4 100644
--- a/src/main/java/com/ard333/springbootwebfluxjjwt/security/WebSecurityConfig.java
+++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/WebSecurityConfig.java
@@ -31,7 +31,7 @@ public class WebSecurityConfig {
.securityContextRepository(securityContextRepository)
.authorizeExchange()
.pathMatchers(HttpMethod.OPTIONS).permitAll()
- .pathMatchers("/auth").permitAll()
+ .pathMatchers("/login").permitAll()
.anyExchange().authenticated()
.and().build();
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 7c37487..662a749 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,5 +1,6 @@
springbootwebfluxjjwt.password.encoder.secret=mysecret
springbootwebfluxjjwt.password.encoder.iteration=33
springbootwebfluxjjwt.password.encoder.keylength=256
-springbootwebfluxjjwt.jjwt.secret=mysecret
+
+springbootwebfluxjjwt.jjwt.secret=ThisIsSecretForJWTHS512SignatureAlgorithmThatMUSTHave512bitsKeySize
springbootwebfluxjjwt.jjwt.expiration=28800
\ No newline at end of file