diff --git a/src/main/java/com/totopia/server/auth/controller/AuthController.java b/src/main/java/com/totopia/server/auth/controller/AuthController.java index 6b049c3..c976414 100644 --- a/src/main/java/com/totopia/server/auth/controller/AuthController.java +++ b/src/main/java/com/totopia/server/auth/controller/AuthController.java @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import java.net.URI; import java.util.Collections; @@ -51,7 +52,10 @@ public class AuthController { JwtTokenProvider tokenProvider; @PostMapping("/signin") - public ResponseEntity authenticateUser(@Valid @RequestBody SigninRequest signinRequest) { + public ResponseEntity authenticateUser(@Valid @RequestBody SigninRequest signinRequest, HttpServletRequest request) { + + String ipAddr = request.getRemoteAddr(); + System.out.println("ipAddr = " + ipAddr); Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken(signinRequest.getUsername(), signinRequest.getPassword())); diff --git a/src/main/java/com/totopia/server/auth/payload/JwtSigninResponse.java b/src/main/java/com/totopia/server/auth/payload/JwtSigninResponse.java index d55513c..d28d13f 100644 --- a/src/main/java/com/totopia/server/auth/payload/JwtSigninResponse.java +++ b/src/main/java/com/totopia/server/auth/payload/JwtSigninResponse.java @@ -1,5 +1,8 @@ package com.totopia.server.auth.payload; +import lombok.Data; + +@Data public class JwtSigninResponse { private String accessToken; private String tokenType = "Bearer"; @@ -7,53 +10,4 @@ public class JwtSigninResponse { public JwtSigninResponse(String accessToken) { this.accessToken = accessToken; } - - public String getAccessToken() { - return this.accessToken; - } - - public String getTokenType() { - return this.tokenType; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public void setTokenType(String tokenType) { - this.tokenType = tokenType; - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof JwtSigninResponse)) return false; - final JwtSigninResponse other = (JwtSigninResponse) o; - if (!other.canEqual((Object) this)) return false; - final Object this$accessToken = this.getAccessToken(); - final Object other$accessToken = other.getAccessToken(); - if (this$accessToken == null ? other$accessToken != null : !this$accessToken.equals(other$accessToken)) - return false; - final Object this$tokenType = this.getTokenType(); - final Object other$tokenType = other.getTokenType(); - if (this$tokenType == null ? other$tokenType != null : !this$tokenType.equals(other$tokenType)) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof JwtSigninResponse; - } - - public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $accessToken = this.getAccessToken(); - result = result * PRIME + ($accessToken == null ? 43 : $accessToken.hashCode()); - final Object $tokenType = this.getTokenType(); - result = result * PRIME + ($tokenType == null ? 43 : $tokenType.hashCode()); - return result; - } - - public String toString() { - return "JwtSigninResponse(accessToken=" + this.getAccessToken() + ", tokenType=" + this.getTokenType() + ")"; - } } diff --git a/src/main/java/com/totopia/server/auth/payload/SigninRequest.java b/src/main/java/com/totopia/server/auth/payload/SigninRequest.java index 4c10509..ebf6032 100644 --- a/src/main/java/com/totopia/server/auth/payload/SigninRequest.java +++ b/src/main/java/com/totopia/server/auth/payload/SigninRequest.java @@ -1,97 +1,20 @@ package com.totopia.server.auth.payload; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + import javax.validation.constraints.NotBlank; +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder public class SigninRequest { @NotBlank private String username; @NotBlank private String password; - - public SigninRequest(@NotBlank String username, @NotBlank String password) { - this.username = username; - this.password = password; - } - - public SigninRequest() { - } - - public static SigninRequestBuilder builder() { - return new SigninRequestBuilder(); - } - - public @NotBlank String getUsername() { - return this.username; - } - - public @NotBlank String getPassword() { - return this.password; - } - - public void setUsername(@NotBlank String username) { - this.username = username; - } - - public void setPassword(@NotBlank String password) { - this.password = password; - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof SigninRequest)) return false; - final SigninRequest other = (SigninRequest) o; - if (!other.canEqual((Object) this)) return false; - final Object this$username = this.getUsername(); - final Object other$username = other.getUsername(); - if (this$username == null ? other$username != null : !this$username.equals(other$username)) return false; - final Object this$password = this.getPassword(); - final Object other$password = other.getPassword(); - if (this$password == null ? other$password != null : !this$password.equals(other$password)) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof SigninRequest; - } - - public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $username = this.getUsername(); - result = result * PRIME + ($username == null ? 43 : $username.hashCode()); - final Object $password = this.getPassword(); - result = result * PRIME + ($password == null ? 43 : $password.hashCode()); - return result; - } - - public String toString() { - return "SigninRequest(username=" + this.getUsername() + ", password=" + this.getPassword() + ")"; - } - - public static class SigninRequestBuilder { - private @NotBlank String username; - private @NotBlank String password; - - SigninRequestBuilder() { - } - - public SigninRequest.SigninRequestBuilder username(@NotBlank String username) { - this.username = username; - return this; - } - - public SigninRequest.SigninRequestBuilder password(@NotBlank String password) { - this.password = password; - return this; - } - - public SigninRequest build() { - return new SigninRequest(username, password); - } - - public String toString() { - return "SigninRequest.SigninRequestBuilder(username=" + this.username + ", password=" + this.password + ")"; - } - } } diff --git a/src/main/java/com/totopia/server/auth/payload/SignupRequest.java b/src/main/java/com/totopia/server/auth/payload/SignupRequest.java index 9aaa542..a124512 100644 --- a/src/main/java/com/totopia/server/auth/payload/SignupRequest.java +++ b/src/main/java/com/totopia/server/auth/payload/SignupRequest.java @@ -1,9 +1,11 @@ package com.totopia.server.auth.payload; +import lombok.Data; + import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; - +@Data public class SignupRequest { @NotBlank @Size(min = 4, max = 40) @@ -21,81 +23,4 @@ public class SignupRequest { @NotBlank @Size(min = 6, max = 20) private String password; - - public SignupRequest() { - } - - public @NotBlank @Size(min = 4, max = 40) String getName() { - return this.name; - } - - public @NotBlank @Size(min = 3, max = 15) String getUsername() { - return this.username; - } - - public @NotBlank @Size(max = 40) @Email String getEmail() { - return this.email; - } - - public @NotBlank @Size(min = 6, max = 20) String getPassword() { - return this.password; - } - - public void setName(@NotBlank @Size(min = 4, max = 40) String name) { - this.name = name; - } - - public void setUsername(@NotBlank @Size(min = 3, max = 15) String username) { - this.username = username; - } - - public void setEmail(@NotBlank @Size(max = 40) @Email String email) { - this.email = email; - } - - public void setPassword(@NotBlank @Size(min = 6, max = 20) String password) { - this.password = password; - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof SignupRequest)) return false; - final SignupRequest other = (SignupRequest) o; - if (!other.canEqual((Object) this)) return false; - final Object this$name = this.getName(); - final Object other$name = other.getName(); - if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false; - final Object this$username = this.getUsername(); - final Object other$username = other.getUsername(); - if (this$username == null ? other$username != null : !this$username.equals(other$username)) return false; - final Object this$email = this.getEmail(); - final Object other$email = other.getEmail(); - if (this$email == null ? other$email != null : !this$email.equals(other$email)) return false; - final Object this$password = this.getPassword(); - final Object other$password = other.getPassword(); - if (this$password == null ? other$password != null : !this$password.equals(other$password)) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof SignupRequest; - } - - public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $name = this.getName(); - result = result * PRIME + ($name == null ? 43 : $name.hashCode()); - final Object $username = this.getUsername(); - result = result * PRIME + ($username == null ? 43 : $username.hashCode()); - final Object $email = this.getEmail(); - result = result * PRIME + ($email == null ? 43 : $email.hashCode()); - final Object $password = this.getPassword(); - result = result * PRIME + ($password == null ? 43 : $password.hashCode()); - return result; - } - - public String toString() { - return "SignupRequest(name=" + this.getName() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", password=" + this.getPassword() + ")"; - } } diff --git a/src/main/java/com/totopia/server/commons/data/entity/DateAuditEntity.java b/src/main/java/com/totopia/server/commons/data/entity/DateAuditEntity.java index 5c9b61c..cd97de1 100644 --- a/src/main/java/com/totopia/server/commons/data/entity/DateAuditEntity.java +++ b/src/main/java/com/totopia/server/commons/data/entity/DateAuditEntity.java @@ -1,6 +1,10 @@ package com.totopia.server.commons.data.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -15,8 +19,11 @@ import java.util.Date; @MappedSuperclass @EntityListeners(AuditingEntityListener.class) -@JsonIgnoreProperties(value = { "createdAt", "updatedAt" }, allowGetters = true) +@JsonIgnoreProperties(value = { "createdDate", "lastModifiedDate" }, allowGetters = true) @SuperBuilder +@Data +@NoArgsConstructor +@AllArgsConstructor public abstract class DateAuditEntity implements Serializable { private static final long serialVersionUID = 3495202400889041952L; @@ -28,60 +35,4 @@ public abstract class DateAuditEntity implements Serializable { @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) private Date updatedAt; - - public DateAuditEntity(Date createdAt, Date updatedAt) { - this.createdAt = createdAt; - this.updatedAt = updatedAt; - } - - public DateAuditEntity() { - } - - public Date getCreatedAt() { - return this.createdAt; - } - - public Date getUpdatedAt() { - return this.updatedAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof DateAuditEntity)) return false; - final DateAuditEntity other = (DateAuditEntity) o; - if (!other.canEqual((Object) this)) return false; - final Object this$createdAt = this.getCreatedAt(); - final Object other$createdAt = other.getCreatedAt(); - if (this$createdAt == null ? other$createdAt != null : !this$createdAt.equals(other$createdAt)) return false; - final Object this$updatedAt = this.getUpdatedAt(); - final Object other$updatedAt = other.getUpdatedAt(); - if (this$updatedAt == null ? other$updatedAt != null : !this$updatedAt.equals(other$updatedAt)) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof DateAuditEntity; - } - - public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $createdAt = this.getCreatedAt(); - result = result * PRIME + ($createdAt == null ? 43 : $createdAt.hashCode()); - final Object $updatedAt = this.getUpdatedAt(); - result = result * PRIME + ($updatedAt == null ? 43 : $updatedAt.hashCode()); - return result; - } - - public String toString() { - return "DateAuditEntity(createdAt=" + this.getCreatedAt() + ", updatedAt=" + this.getUpdatedAt() + ")"; - } } diff --git a/src/main/java/com/totopia/server/commons/data/entity/UserDateAuditEntity.java b/src/main/java/com/totopia/server/commons/data/entity/UserDateAuditEntity.java index 68caa09..b8fdea3 100644 --- a/src/main/java/com/totopia/server/commons/data/entity/UserDateAuditEntity.java +++ b/src/main/java/com/totopia/server/commons/data/entity/UserDateAuditEntity.java @@ -1,6 +1,10 @@ package com.totopia.server.commons.data.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.LastModifiedBy; @@ -12,8 +16,12 @@ import javax.persistence.MappedSuperclass; */ @MappedSuperclass -@JsonIgnoreProperties(value = { "createdBy", "updatedBy" }, allowGetters = true) +@JsonIgnoreProperties(value = { "createdBy", "lastModifiedBy" }, allowGetters = true) @SuperBuilder +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) public abstract class UserDateAuditEntity extends DateAuditEntity { private static final long serialVersionUID = 6379346917688414915L; @@ -24,59 +32,4 @@ public abstract class UserDateAuditEntity extends DateAuditEntity { @LastModifiedBy private Long updatedBy; - public UserDateAuditEntity(Long createdBy, Long updatedBy) { - this.createdBy = createdBy; - this.updatedBy = updatedBy; - } - - public UserDateAuditEntity() { - } - - public Long getCreatedBy() { - return this.createdBy; - } - - public Long getUpdatedBy() { - return this.updatedBy; - } - - public void setCreatedBy(Long createdBy) { - this.createdBy = createdBy; - } - - public void setUpdatedBy(Long updatedBy) { - this.updatedBy = updatedBy; - } - - public String toString() { - return "UserDateAuditEntity(createdBy=" + this.getCreatedBy() + ", updatedBy=" + this.getUpdatedBy() + ")"; - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof UserDateAuditEntity)) return false; - final UserDateAuditEntity other = (UserDateAuditEntity) o; - if (!other.canEqual((Object) this)) return false; - final Object this$createdBy = this.getCreatedBy(); - final Object other$createdBy = other.getCreatedBy(); - if (this$createdBy == null ? other$createdBy != null : !this$createdBy.equals(other$createdBy)) return false; - final Object this$updatedBy = this.getUpdatedBy(); - final Object other$updatedBy = other.getUpdatedBy(); - if (this$updatedBy == null ? other$updatedBy != null : !this$updatedBy.equals(other$updatedBy)) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof UserDateAuditEntity; - } - - public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $createdBy = this.getCreatedBy(); - result = result * PRIME + ($createdBy == null ? 43 : $createdBy.hashCode()); - final Object $updatedBy = this.getUpdatedBy(); - result = result * PRIME + ($updatedBy == null ? 43 : $updatedBy.hashCode()); - return result; - } } diff --git a/src/main/java/com/totopia/server/commons/data/payload/ApiResponse.java b/src/main/java/com/totopia/server/commons/data/payload/ApiResponse.java index 9492288..52f94aa 100644 --- a/src/main/java/com/totopia/server/commons/data/payload/ApiResponse.java +++ b/src/main/java/com/totopia/server/commons/data/payload/ApiResponse.java @@ -1,92 +1,15 @@ package com.totopia.server.commons.data.payload; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder public class ApiResponse { private Boolean success; private String message; - - public ApiResponse(Boolean success, String message) { - this.success = success; - this.message = message; - } - - public ApiResponse() { - } - - public static ApiResponseBuilder builder() { - return new ApiResponseBuilder(); - } - - public Boolean getSuccess() { - return this.success; - } - - public String getMessage() { - return this.message; - } - - public void setSuccess(Boolean success) { - this.success = success; - } - - public void setMessage(String message) { - this.message = message; - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof ApiResponse)) return false; - final ApiResponse other = (ApiResponse) o; - if (!other.canEqual((Object) this)) return false; - final Object this$success = this.getSuccess(); - final Object other$success = other.getSuccess(); - if (this$success == null ? other$success != null : !this$success.equals(other$success)) return false; - final Object this$message = this.getMessage(); - final Object other$message = other.getMessage(); - if (this$message == null ? other$message != null : !this$message.equals(other$message)) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof ApiResponse; - } - - public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $success = this.getSuccess(); - result = result * PRIME + ($success == null ? 43 : $success.hashCode()); - final Object $message = this.getMessage(); - result = result * PRIME + ($message == null ? 43 : $message.hashCode()); - return result; - } - - public String toString() { - return "ApiResponse(success=" + this.getSuccess() + ", message=" + this.getMessage() + ")"; - } - - public static class ApiResponseBuilder { - private Boolean success; - private String message; - - ApiResponseBuilder() { - } - - public ApiResponse.ApiResponseBuilder success(Boolean success) { - this.success = success; - return this; - } - - public ApiResponse.ApiResponseBuilder message(String message) { - this.message = message; - return this; - } - - public ApiResponse build() { - return new ApiResponse(success, message); - } - - public String toString() { - return "ApiResponse.ApiResponseBuilder(success=" + this.success + ", message=" + this.message + ")"; - } - } } diff --git a/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationEntryPoint.java b/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationEntryPoint.java index b140c1a..2e55fa8 100644 --- a/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationEntryPoint.java +++ b/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationEntryPoint.java @@ -1,5 +1,6 @@ package com.totopia.server.config.jwt; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; @@ -11,10 +12,9 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; @Component +@Slf4j public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { - private static final Logger log = org.slf4j.LoggerFactory.getLogger(JwtAuthenticationEntryPoint.class); - @Override public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { diff --git a/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationFilter.java b/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationFilter.java index 1b4a81f..ce82204 100644 --- a/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationFilter.java +++ b/src/main/java/com/totopia/server/config/jwt/JwtAuthenticationFilter.java @@ -1,6 +1,7 @@ package com.totopia.server.config.jwt; import com.totopia.server.config.security.SecurityUserDetailsService; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -16,9 +17,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +@Slf4j public class JwtAuthenticationFilter extends OncePerRequestFilter { - private static final Logger log = org.slf4j.LoggerFactory.getLogger(JwtAuthenticationFilter.class); @Autowired private JwtTokenProvider tokenProvider; diff --git a/src/main/java/com/totopia/server/config/jwt/JwtTokenProvider.java b/src/main/java/com/totopia/server/config/jwt/JwtTokenProvider.java index c06dbc8..3ffb220 100644 --- a/src/main/java/com/totopia/server/config/jwt/JwtTokenProvider.java +++ b/src/main/java/com/totopia/server/config/jwt/JwtTokenProvider.java @@ -2,6 +2,7 @@ package com.totopia.server.config.jwt; import com.totopia.server.config.security.SecurityUserDetails; import io.jsonwebtoken.*; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; @@ -14,10 +15,10 @@ import java.util.stream.Collectors; /** * Created by rajeevkumarsingh on 19/08/17. */ +@Slf4j @Component public class JwtTokenProvider { private static final String AUTHORITIES_KEY = "authorities"; - private static final Logger log = org.slf4j.LoggerFactory.getLogger(JwtTokenProvider.class); @Value("${app.jwt.secret}") private String jwtSecret; diff --git a/src/main/java/com/totopia/server/config/security/SecurityUserDetails.java b/src/main/java/com/totopia/server/config/security/SecurityUserDetails.java index 56822c8..d9ba00c 100644 --- a/src/main/java/com/totopia/server/config/security/SecurityUserDetails.java +++ b/src/main/java/com/totopia/server/config/security/SecurityUserDetails.java @@ -2,6 +2,10 @@ package com.totopia.server.config.security; import com.fasterxml.jackson.annotation.JsonIgnore; import com.totopia.server.modules.user.entity.UserEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; @@ -11,6 +15,10 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder public class SecurityUserDetails implements UserDetails { private static final long serialVersionUID = 1L; @@ -28,22 +36,6 @@ public class SecurityUserDetails implements UserDetails { private Collection authorities; - public SecurityUserDetails(Long id, String name, String username, String email, String password, Collection authorities) { - this.id = id; - this.name = name; - this.username = username; - this.email = email; - this.password = password; - this.authorities = authorities; - } - - public SecurityUserDetails() { - } - - public static SecurityUserDetailsBuilder builder() { - return new SecurityUserDetailsBuilder(); - } - @Override public String getUsername() { return username; @@ -102,93 +94,4 @@ public class SecurityUserDetails implements UserDetails { .authorities(authorities).build(); } - public Long getId() { - return this.id; - } - - public String getName() { - return this.name; - } - - public String getEmail() { - return this.email; - } - - public void setId(Long id) { - this.id = id; - } - - public void setName(String name) { - this.name = name; - } - - public void setUsername(String username) { - this.username = username; - } - - public void setEmail(String email) { - this.email = email; - } - - public void setPassword(String password) { - this.password = password; - } - - public void setAuthorities(Collection authorities) { - this.authorities = authorities; - } - - public String toString() { - return "SecurityUserDetails(id=" + this.getId() + ", name=" + this.getName() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", password=" + this.getPassword() + ", authorities=" + this.getAuthorities() + ")"; - } - - public static class SecurityUserDetailsBuilder { - private Long id; - private String name; - private String username; - private String email; - private String password; - private Collection authorities; - - SecurityUserDetailsBuilder() { - } - - public SecurityUserDetails.SecurityUserDetailsBuilder id(Long id) { - this.id = id; - return this; - } - - public SecurityUserDetails.SecurityUserDetailsBuilder name(String name) { - this.name = name; - return this; - } - - public SecurityUserDetails.SecurityUserDetailsBuilder username(String username) { - this.username = username; - return this; - } - - public SecurityUserDetails.SecurityUserDetailsBuilder email(String email) { - this.email = email; - return this; - } - - public SecurityUserDetails.SecurityUserDetailsBuilder password(String password) { - this.password = password; - return this; - } - - public SecurityUserDetails.SecurityUserDetailsBuilder authorities(Collection authorities) { - this.authorities = authorities; - return this; - } - - public SecurityUserDetails build() { - return new SecurityUserDetails(id, name, username, email, password, authorities); - } - - public String toString() { - return "SecurityUserDetails.SecurityUserDetailsBuilder(id=" + this.id + ", name=" + this.name + ", username=" + this.username + ", email=" + this.email + ", password=" + this.password + ", authorities=" + this.authorities + ")"; - } - } } diff --git a/src/main/java/com/totopia/server/modules/user/controller/UserController.java b/src/main/java/com/totopia/server/modules/user/controller/UserController.java index 57e7644..1f36f3e 100644 --- a/src/main/java/com/totopia/server/modules/user/controller/UserController.java +++ b/src/main/java/com/totopia/server/modules/user/controller/UserController.java @@ -8,6 +8,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; +import org.springframework.data.web.SortDefault; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -24,14 +25,14 @@ public class UserController { } @GetMapping(value = "/users") - public @ResponseBody Page all(@PageableDefault(sort = {"username"}, direction = Sort.Direction.DESC, size = 10)Pageable pageable) { - Page users = userRepository.findAll(pageable); -// Gson gson = new Gson(); -// -// String json = gson.toJson(users); - return users; -// public Page all(Pageable pageable) { -// return userRepository.findAll(pageable); + public Page all(@RequestParam(value = "username", required = false) String username, + @SortDefault.SortDefaults({ @SortDefault(sort = "createdDate", direction = Sort.Direction.DESC) }) Pageable pageable) { + + if (null == username) { + return userRepository.findAll(pageable); + } else { + return userRepository.findByUsernameContainingIgnoreCase(username, pageable); + } } @GetMapping(value = "/users/{userId}") diff --git a/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java b/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java index bb3a495..a2fe068 100644 --- a/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java +++ b/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java @@ -12,6 +12,8 @@ public interface UserRepository extends JpaRepository { Optional findByUsername(String username); + Page findByUsernameContainingIgnoreCase(String username, Pageable pageable); + Boolean existsByEmail(String email); Optional findByEmail(String email); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bb13d86..6da1e7e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,19 @@ +# Server configuration +server: + port: 8088 + servlet: + context-path: /api + # Spring Boot configuration spring: -# autoconfigure: -# exclude: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration + data: + web: + pageable: + size-parameter: size + page-parameter: page + default-page-size: 20 + one-indexed-parameters: true + max-page-size: 2000 application: name: totopia-server datasource: @@ -37,11 +49,6 @@ logging: org.springframework: INFO org.hibernate: DEBUG -# Server configuration -server: - port: 8088 - servlet: - context-path: /api #JWT properties app: