Misc. clean up.
This commit is contained in:
parent
51cae79daa
commit
fc19361ab6
@ -1,7 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.jwt;
|
package app.mealsmadeeasy.api.jwt;
|
||||||
|
|
||||||
import app.mealsmadeeasy.api.security.AuthToken;
|
import app.mealsmadeeasy.api.security.AuthToken;
|
||||||
import app.mealsmadeeasy.api.security.SimpleAuthToken;
|
|
||||||
import io.jsonwebtoken.JwtException;
|
import io.jsonwebtoken.JwtException;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.io.Serializer;
|
import io.jsonwebtoken.io.Serializer;
|
||||||
@ -43,7 +42,7 @@ public final class JwtServiceImpl implements JwtService {
|
|||||||
.signWith(this.secretKey)
|
.signWith(this.secretKey)
|
||||||
.json(this.serializer)
|
.json(this.serializer)
|
||||||
.compact();
|
.compact();
|
||||||
return new SimpleAuthToken(
|
return new AuthToken(
|
||||||
token,
|
token,
|
||||||
this.accessTokenLifetime,
|
this.accessTokenLifetime,
|
||||||
LocalDateTime.ofInstant(expires, ZoneId.systemDefault())
|
LocalDateTime.ofInstant(expires, ZoneId.systemDefault())
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import java.time.OffsetDateTime;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity(name = "Recipe")
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
public final class Recipe {
|
public final class Recipe {
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
package app.mealsmadeeasy.api.security;
|
package app.mealsmadeeasy.api.security;
|
||||||
|
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public interface AuthToken {
|
@Value
|
||||||
String getToken();
|
public class AuthToken {
|
||||||
long getLifetime();
|
String token;
|
||||||
LocalDateTime getExpires();
|
long lifetime;
|
||||||
|
LocalDateTime expires;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,31 +1,16 @@
|
|||||||
package app.mealsmadeeasy.api.security;
|
package app.mealsmadeeasy.api.security;
|
||||||
|
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
@Value
|
||||||
public class SecurityExceptionView {
|
public class SecurityExceptionView {
|
||||||
|
|
||||||
public enum Action {
|
public enum Action {
|
||||||
LOGIN, REFRESH
|
LOGIN, REFRESH
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int status;
|
int status;
|
||||||
private final Action action;
|
Action action;
|
||||||
private final String message;
|
String message;
|
||||||
|
|
||||||
public SecurityExceptionView(int status, Action action, String message) {
|
|
||||||
this.status = status;
|
|
||||||
this.action = action;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStatus() {
|
|
||||||
return this.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action getAction() {
|
|
||||||
return this.action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,32 +0,0 @@
|
|||||||
package app.mealsmadeeasy.api.security;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
public final class SimpleAuthToken implements AuthToken {
|
|
||||||
|
|
||||||
private final String token;
|
|
||||||
private final long lifetime;
|
|
||||||
private final LocalDateTime expires;
|
|
||||||
|
|
||||||
public SimpleAuthToken(String token, long lifetime, LocalDateTime expires) {
|
|
||||||
this.token = token;
|
|
||||||
this.lifetime = lifetime;
|
|
||||||
this.expires = expires;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getToken() {
|
|
||||||
return this.token;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLifetime() {
|
|
||||||
return this.lifetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LocalDateTime getExpires() {
|
|
||||||
return this.expires;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -12,7 +12,7 @@ import java.util.Set;
|
|||||||
@Entity(name = "User")
|
@Entity(name = "User")
|
||||||
@Table(name = "\"user\"")
|
@Table(name = "\"user\"")
|
||||||
@Data
|
@Data
|
||||||
public final class User implements UserDetails {
|
public class User implements UserDetails {
|
||||||
|
|
||||||
public static User getDefaultDraft() {
|
public static User getDefaultDraft() {
|
||||||
final var user = new User();
|
final var user = new User();
|
||||||
|
|||||||
@ -4,10 +4,10 @@ import jakarta.persistence.*;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
|
||||||
@Entity(name = "UserGrantedAuthority")
|
@Entity
|
||||||
@Table(name = "user_granted_authority")
|
@Table(name = "user_granted_authority")
|
||||||
@Data
|
@Data
|
||||||
public final class UserGrantedAuthority implements GrantedAuthority {
|
public class UserGrantedAuthority implements GrantedAuthority {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
|||||||
@ -2,4 +2,4 @@ package app.mealsmadeeasy.api.user;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface UserGrantedAuthorityRepository extends JpaRepository<UserGrantedAuthority, Long> {}
|
public interface UserGrantedAuthorityRepository extends JpaRepository<UserGrantedAuthority, Integer> {}
|
||||||
|
|||||||
@ -1,33 +1,16 @@
|
|||||||
package app.mealsmadeeasy.api.user.view;
|
package app.mealsmadeeasy.api.user.view;
|
||||||
|
|
||||||
import app.mealsmadeeasy.api.user.User;
|
import app.mealsmadeeasy.api.user.User;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
@Value
|
||||||
public class UserInfoView {
|
public class UserInfoView {
|
||||||
|
|
||||||
public static UserInfoView from(User user) {
|
public static UserInfoView from(User user) {
|
||||||
final UserInfoView userInfoView = new UserInfoView();
|
return new UserInfoView(user.getId(), user.getUsername());
|
||||||
userInfoView.setId(user.getId());
|
|
||||||
userInfoView.setUsername(user.getUsername());
|
|
||||||
return userInfoView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer id;
|
Integer id;
|
||||||
private String username;
|
String username;
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return this.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,9 @@
|
|||||||
package app.mealsmadeeasy.api.util;
|
package app.mealsmadeeasy.api.util;
|
||||||
|
|
||||||
public final class AccessDeniedView {
|
import lombok.Value;
|
||||||
|
|
||||||
private final int statusCode;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
public AccessDeniedView(int statusCode, String message) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStatusCode() {
|
|
||||||
return this.statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public class AccessDeniedView {
|
||||||
|
int statusCode;
|
||||||
|
String message;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user