From 74b2cb9acd5c1248af52a6216abf3054783a02e5 Mon Sep 17 00:00:00 2001 From: ard333 Date: Sun, 22 Jul 2018 21:36:08 +0700 Subject: [PATCH] refactoring --- README.md | 4 ++ pom.xml | 2 +- .../SpringBootWebfluxJjwtApplication.java | 2 +- .../springbootwebfluxjjwt/model/Message.java | 8 +--- .../springbootwebfluxjjwt/model/User.java | 45 +++++-------------- .../rest/AuthenticationREST.java | 23 ++++------ .../rest/ResourceREST.java | 4 +- .../security/AuthenticationManager.java | 39 +++++++--------- .../security/CORSFilter.java | 8 +--- .../security/JWTUtil.java | 10 ++--- .../security/PBKDF2Encoder.java | 8 +--- .../security/SecurityContextRepository.java | 8 +--- .../security/WebSecurityConfig.java | 4 +- .../security/model/AuthRequest.java | 8 +--- .../security/model/AuthResponse.java | 8 +--- .../security/model/Role.java | 9 ++++ .../service/UserService.java | 14 ++---- .../security/UserDetailsServiceImpl.java | 29 ------------ .../security/model/Role.java | 13 ------ 19 files changed, 73 insertions(+), 173 deletions(-) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/SpringBootWebfluxJjwtApplication.java (88%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/model/Message.java (66%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/model/User.java (73%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/rest/AuthenticationREST.java (62%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/rest/ResourceREST.java (92%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/AuthenticationManager.java (56%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/CORSFilter.java (81%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/JWTUtil.java (91%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/PBKDF2Encoder.java (90%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/SecurityContextRepository.java (93%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/WebSecurityConfig.java (94%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/model/AuthRequest.java (68%) rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/security/model/AuthResponse.java (65%) create mode 100644 src/main/java/com/ard333/springbootwebfluxjjwt/security/model/Role.java rename src/main/java/{id/web/ard => com/ard333}/springbootwebfluxjjwt/service/UserService.java (84%) delete mode 100644 src/main/java/id/web/ard/springbootwebfluxjjwt/security/UserDetailsServiceImpl.java delete mode 100644 src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/Role.java diff --git a/README.md b/README.md index 5bfd606..1b86c09 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ # spring-boot-webflux-jjwt +Example Spring Boot and WebFlux (Reactive Web) with Spring Security and JWT for token Authentication and Authorization + +### Documantation +You can se my Medium story, [Authentication and Authorization Using JWT on Spring Webflux](https://medium.com/@ard333/29b81f813e78) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4b310cb..9620ac0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - id.web.ard + com.ard333 spring-boot-webflux-jjwt 0.0.1-SNAPSHOT jar diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/SpringBootWebfluxJjwtApplication.java b/src/main/java/com/ard333/springbootwebfluxjjwt/SpringBootWebfluxJjwtApplication.java similarity index 88% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/SpringBootWebfluxJjwtApplication.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/SpringBootWebfluxJjwtApplication.java index dad036e..85dcd49 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/SpringBootWebfluxJjwtApplication.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/SpringBootWebfluxJjwtApplication.java @@ -1,4 +1,4 @@ -package id.web.ard.springbootwebfluxjjwt; +package com.ard333.springbootwebfluxjjwt; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/model/Message.java b/src/main/java/com/ard333/springbootwebfluxjjwt/model/Message.java similarity index 66% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/model/Message.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/model/Message.java index fe2e9af..d73d1ac 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/model/Message.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/model/Message.java @@ -1,8 +1,4 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.model; +package com.ard333.springbootwebfluxjjwt.model; import lombok.AllArgsConstructor; import lombok.Data; @@ -11,7 +7,7 @@ import lombok.ToString; /** * - * @author ardiansyah + * @author ard333 */ @Data @NoArgsConstructor @AllArgsConstructor @ToString public class Message { diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/model/User.java b/src/main/java/com/ard333/springbootwebfluxjjwt/model/User.java similarity index 73% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/model/User.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/model/User.java index 2f2c10a..f57a2bd 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/model/User.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/model/User.java @@ -1,26 +1,23 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.model; +package com.ard333.springbootwebfluxjjwt.model; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import id.web.ard.springbootwebfluxjjwt.security.model.Role; +import com.ard333.springbootwebfluxjjwt.security.model.Role; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; - import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import lombok.AllArgsConstructor; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.ToString; /** * - * @author ardiansyah + * @author ard333 */ @ToString @AllArgsConstructor @NoArgsConstructor public class User implements UserDetails { @@ -29,20 +26,21 @@ public class User implements UserDetails { private String password; + @Getter @Setter private Boolean enabled; + @Getter @Setter private List roles; - public User(String username) { - this.username = username; - } - @Override public String getUsername() { return username; } + + public void setUsername(String username) { + this.username = username; + } - //============================== @Override public boolean isAccountNonExpired() { return false; @@ -63,15 +61,10 @@ public class User implements UserDetails { return this.enabled; } - public void setUsername(String username) { - this.username = username; - } - @Override public Collection getAuthorities() { return this.roles.stream().map(authority -> new SimpleGrantedAuthority(authority.name())).collect(Collectors.toList()); } - //============================== @JsonIgnore @Override @@ -84,20 +77,4 @@ public class User implements UserDetails { this.password = password; } - public Boolean getEnabled() { - return enabled; - } - - public void setEnabled(Boolean enabled) { - this.enabled = enabled; - } - - public List getRoles() { - return roles; - } - - public void setRoles(List roles) { - this.roles = roles; - } - } \ No newline at end of file diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/rest/AuthenticationREST.java b/src/main/java/com/ard333/springbootwebfluxjjwt/rest/AuthenticationREST.java similarity index 62% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/rest/AuthenticationREST.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/rest/AuthenticationREST.java index 41a8b7b..f960d74 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/rest/AuthenticationREST.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/rest/AuthenticationREST.java @@ -1,18 +1,13 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.rest; +package com.ard333.springbootwebfluxjjwt.rest; -import id.web.ard.springbootwebfluxjjwt.security.JWTUtil; -import id.web.ard.springbootwebfluxjjwt.security.PBKDF2Encoder; -import id.web.ard.springbootwebfluxjjwt.security.model.AuthRequest; -import id.web.ard.springbootwebfluxjjwt.security.model.AuthResponse; -import id.web.ard.springbootwebfluxjjwt.service.UserService; +import com.ard333.springbootwebfluxjjwt.security.JWTUtil; +import com.ard333.springbootwebfluxjjwt.security.PBKDF2Encoder; +import com.ard333.springbootwebfluxjjwt.security.model.AuthRequest; +import com.ard333.springbootwebfluxjjwt.security.model.AuthResponse; +import com.ard333.springbootwebfluxjjwt.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.authentication.ReactiveAuthenticationManager; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -21,13 +16,13 @@ import reactor.core.publisher.Mono; /** * - * @author ardiansyah + * @author ard333 */ @RestController public class AuthenticationREST { @Autowired - private JWTUtil jwtTokenUtil; + private JWTUtil jwtUtil; @Autowired private PBKDF2Encoder passwordEncoder; @@ -39,7 +34,7 @@ public class AuthenticationREST { public Mono> auth(@RequestBody AuthRequest ar) { return userRepository.findByUsername(ar.getUsername()).map((userDetails) -> { if (passwordEncoder.encode(ar.getPassword()).equals(userDetails.getPassword())) { - return ResponseEntity.ok(new AuthResponse(jwtTokenUtil.generateToken(userDetails))); + return ResponseEntity.ok(new AuthResponse(jwtUtil.generateToken(userDetails))); } else { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); } diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/rest/ResourceREST.java b/src/main/java/com/ard333/springbootwebfluxjjwt/rest/ResourceREST.java similarity index 92% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/rest/ResourceREST.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/rest/ResourceREST.java index 487d1e3..4bdc16d 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/rest/ResourceREST.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/rest/ResourceREST.java @@ -2,9 +2,9 @@ * Ardiansyah | http://ard.web.id * */ -package id.web.ard.springbootwebfluxjjwt.rest; +package com.ard333.springbootwebfluxjjwt.rest; -import id.web.ard.springbootwebfluxjjwt.model.Message; +import com.ard333.springbootwebfluxjjwt.model.Message; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/AuthenticationManager.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/AuthenticationManager.java similarity index 56% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/AuthenticationManager.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/AuthenticationManager.java index 14460e8..74a7728 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/AuthenticationManager.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/AuthenticationManager.java @@ -1,10 +1,6 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security; +package com.ard333.springbootwebfluxjjwt.security; -import id.web.ard.springbootwebfluxjjwt.security.model.Role; +import com.ard333.springbootwebfluxjjwt.security.model.Role; import io.jsonwebtoken.Claims; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.ReactiveAuthenticationManager; @@ -16,11 +12,10 @@ import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import org.springframework.security.web.server.context.ServerSecurityContextRepository; /** * - * @author ardiansyah + * @author ard333 */ @Component public class AuthenticationManager implements ReactiveAuthenticationManager { @@ -32,29 +27,25 @@ public class AuthenticationManager implements ReactiveAuthenticationManager { public Mono authenticate(Authentication authentication) { String authToken = authentication.getCredentials().toString(); - String username = null; + String username; try { username = jwtUtil.getUsernameFromToken(authToken); } catch (Exception e) { username = null; } - if (username != null) { + if (username != null && jwtUtil.validateToken(authToken)) { Claims claims = jwtUtil.getAllClaimsFromToken(authToken); - if (jwtUtil.validateToken(authToken)) { - List rolesMap = claims.get("role", List.class); - List roles = new ArrayList<>(); - for (String rolemap : rolesMap) { - roles.add(Role.valueOf(rolemap)); - } - UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken( - username, - null, - roles.stream().map(authority -> new SimpleGrantedAuthority(authority.name())).collect(Collectors.toList()) - ); - return Mono.just(auth); - } else { - return Mono.empty(); + List rolesMap = claims.get("role", List.class); + List roles = new ArrayList<>(); + for (String rolemap : rolesMap) { + roles.add(Role.valueOf(rolemap)); } + UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken( + username, + null, + roles.stream().map(authority -> new SimpleGrantedAuthority(authority.name())).collect(Collectors.toList()) + ); + return Mono.just(auth); } else { return Mono.empty(); } diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/CORSFilter.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/CORSFilter.java similarity index 81% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/CORSFilter.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/CORSFilter.java index 1817475..56830be 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/CORSFilter.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/CORSFilter.java @@ -1,8 +1,4 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security; +package com.ard333.springbootwebfluxjjwt.security; import org.springframework.context.annotation.Configuration; import org.springframework.web.reactive.config.CorsRegistry; @@ -11,7 +7,7 @@ import org.springframework.web.reactive.config.WebFluxConfigurer; /** * - * @author ardiansyah + * @author ard333 */ @Configuration @EnableWebFlux diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/JWTUtil.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/JWTUtil.java similarity index 91% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/JWTUtil.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/JWTUtil.java index 1426ef4..228890a 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/JWTUtil.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/JWTUtil.java @@ -1,10 +1,6 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security; +package com.ard333.springbootwebfluxjjwt.security; -import id.web.ard.springbootwebfluxjjwt.model.User; +import com.ard333.springbootwebfluxjjwt.model.User; import java.io.Serializable; import java.util.Date; import java.util.HashMap; @@ -17,7 +13,7 @@ import org.springframework.stereotype.Component; /** * - * @author ardiansyah + * @author ard333 */ @Component public class JWTUtil implements Serializable { diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/PBKDF2Encoder.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/PBKDF2Encoder.java similarity index 90% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/PBKDF2Encoder.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/PBKDF2Encoder.java index 60df094..920e9ed 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/PBKDF2Encoder.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/PBKDF2Encoder.java @@ -1,8 +1,4 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security; +package com.ard333.springbootwebfluxjjwt.security; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; @@ -15,7 +11,7 @@ import org.springframework.stereotype.Component; /** * - * @author ardiansyah + * @author ard333 */ @Component public class PBKDF2Encoder implements PasswordEncoder{ diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/SecurityContextRepository.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/SecurityContextRepository.java similarity index 93% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/SecurityContextRepository.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/SecurityContextRepository.java index a2bc194..aab0761 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/SecurityContextRepository.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/SecurityContextRepository.java @@ -1,8 +1,4 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security; +package com.ard333.springbootwebfluxjjwt.security; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; @@ -18,7 +14,7 @@ import reactor.core.publisher.Mono; /** * - * @author ardiansyah + * @author ard333 */ @Component public class SecurityContextRepository implements ServerSecurityContextRepository{ diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/WebSecurityConfig.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/WebSecurityConfig.java similarity index 94% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/WebSecurityConfig.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/WebSecurityConfig.java index 097e1e9..148752f 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/WebSecurityConfig.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/WebSecurityConfig.java @@ -1,4 +1,4 @@ -package id.web.ard.springbootwebfluxjjwt.security; +package com.ard333.springbootwebfluxjjwt.security; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -10,7 +10,7 @@ import org.springframework.security.web.server.SecurityWebFilterChain; /** * - * @author ardiansyah + * @author ard333 */ @EnableWebFluxSecurity @EnableReactiveMethodSecurity diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/AuthRequest.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/model/AuthRequest.java similarity index 68% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/AuthRequest.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/model/AuthRequest.java index 38bc5d8..576a0ca 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/AuthRequest.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/model/AuthRequest.java @@ -1,8 +1,4 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security.model; +package com.ard333.springbootwebfluxjjwt.security.model; import lombok.AllArgsConstructor; import lombok.Data; @@ -11,7 +7,7 @@ import lombok.ToString; /** * - * @author ardiansyah + * @author ard333 */ @Data @NoArgsConstructor @AllArgsConstructor @ToString public class AuthRequest { diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/AuthResponse.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/model/AuthResponse.java similarity index 65% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/AuthResponse.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/security/model/AuthResponse.java index 3314e57..2f522a3 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/AuthResponse.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/model/AuthResponse.java @@ -1,8 +1,4 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security.model; +package com.ard333.springbootwebfluxjjwt.security.model; import lombok.AllArgsConstructor; import lombok.Data; @@ -11,7 +7,7 @@ import lombok.ToString; /** * - * @author ardiansyah + * @author ard333 */ @Data @NoArgsConstructor @AllArgsConstructor @ToString public class AuthResponse { diff --git a/src/main/java/com/ard333/springbootwebfluxjjwt/security/model/Role.java b/src/main/java/com/ard333/springbootwebfluxjjwt/security/model/Role.java new file mode 100644 index 0000000..556b887 --- /dev/null +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/security/model/Role.java @@ -0,0 +1,9 @@ +package com.ard333.springbootwebfluxjjwt.security.model; + +/** + * + * @author ard333 + */ +public enum Role { + ROLE_USER, ROLE_ADMIN +} \ No newline at end of file diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/service/UserService.java b/src/main/java/com/ard333/springbootwebfluxjjwt/service/UserService.java similarity index 84% rename from src/main/java/id/web/ard/springbootwebfluxjjwt/service/UserService.java rename to src/main/java/com/ard333/springbootwebfluxjjwt/service/UserService.java index 210b672..663eab7 100644 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/service/UserService.java +++ b/src/main/java/com/ard333/springbootwebfluxjjwt/service/UserService.java @@ -1,11 +1,7 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.service; +package com.ard333.springbootwebfluxjjwt.service; -import id.web.ard.springbootwebfluxjjwt.model.User; -import id.web.ard.springbootwebfluxjjwt.security.model.Role; +import com.ard333.springbootwebfluxjjwt.model.User; +import com.ard333.springbootwebfluxjjwt.security.model.Role; import java.util.Arrays; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Service; @@ -13,7 +9,7 @@ import reactor.core.publisher.Mono; /** * - * @author ardiansyah + * @author ard333 */ @Service public class UserService { @@ -49,6 +45,4 @@ public class UserService { } } - - } diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/UserDetailsServiceImpl.java b/src/main/java/id/web/ard/springbootwebfluxjjwt/security/UserDetailsServiceImpl.java deleted file mode 100644 index 8e809c9..0000000 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/UserDetailsServiceImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security; - -import id.web.ard.springbootwebfluxjjwt.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.userdetails.ReactiveUserDetailsService; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; - -/** - * - * @author ardiansyah - */ -@Service -public class UserDetailsServiceImpl implements ReactiveUserDetailsService { - - @Autowired - private UserService userRepository; - - @Override - public Mono findByUsername(String username) { - return userRepository.findUserDetailsByUsername(username); - } - -} diff --git a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/Role.java b/src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/Role.java deleted file mode 100644 index f5823a6..0000000 --- a/src/main/java/id/web/ard/springbootwebfluxjjwt/security/model/Role.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Ardiansyah | http://ard.web.id - * - */ -package id.web.ard.springbootwebfluxjjwt.security.model; - -/** - * - * @author ardiansyah - */ -public enum Role { - ROLE_USER, ROLE_ADMIN -} \ No newline at end of file