Skip to content

Commit

Permalink
Merge pull request #26 from handong-app/junglesub/fix/new-user-uuid-m…
Browse files Browse the repository at this point in the history
…ismatch

Junglesub/fix/new user UUID mismatch
  • Loading branch information
junglesub authored Oct 15, 2024
2 parents 9b6bfe9 + ae3912b commit 30834ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/main/java/com/thc/realspr/domain/Tbuser.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ public static Tbuser of(String email, String uuid, String name, LocalDateTime la
}




@PrePersist
public void onPrePersist() {
this.id = UUID.randomUUID().toString().replace("-", "");
if (this.id == null || this.id.isEmpty()) {
this.id = UUID.randomUUID().toString().replace("-", "");
}
}

public TbuserDto.CreateResDto toCreateResDto() {
return TbuserDto.CreateResDto.builder().email(this.getEmail()).build();
}



// public String getRoleKey(){
// return this.role.getKey();
// }
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/thc/realspr/util/TokenFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@

import com.thc.realspr.exception.InvalidTokenException;
import com.thc.realspr.exception.NoAuthenticatedException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Arrays;

@Component
public class TokenFactory {

// private final String SECRET_KEY = "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";
@Value("${TOKEN_KEY:${TOKEN_KEY_DEFAULT:#{null}}}")
String tempKey;

private static String staticTempKey;

static String temp_key = "21098765432109876543210987654321";
static int intervalRefreshToken = 86400 * 7; // 7 days
int intervalAccessToken = 6000;

@PostConstruct
public void init() {
staticTempKey = tempKey;
}

public static String issueRefreshToken(String tbuserId) {
return generateToken(tbuserId, intervalRefreshToken);
}
Expand All @@ -33,9 +44,10 @@ public static String generateToken(String tbuserId, int second) {
String due = now.getDue(second);
System.out.println("tbuserId : " + tbuserId);
System.out.println("due : " + due);
returnVal = aes.AES_Encode(temp_key, tbuserId + "_" + due);
returnVal = aes.AES_Encode(staticTempKey, tbuserId + "_" + due);
} catch (Exception e) {
System.out.println("error....");
e.printStackTrace();
}
return returnVal;
}
Expand All @@ -45,9 +57,10 @@ public String verifyToken(String token) throws Exception {
AES256Cipher aes = new AES256Cipher();
try {
// id_만료일
returnVal = aes.AES_Decode(temp_key, token);
returnVal = aes.AES_Decode(staticTempKey, token);
} catch (Exception e) {
System.out.println("error....");
e.printStackTrace();
}
if ("".equals(returnVal)) {
throw new NoAuthenticatedException("Not Authenticated User");
Expand Down

0 comments on commit 30834ef

Please sign in to comment.