generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from ita-social-projects/develop
refresh_token_logic
- Loading branch information
Showing
16 changed files
with
463 additions
and
146 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/softserveinc/dokazovi/dto/payload/RefreshToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.softserveinc.dokazovi.dto.payload; | ||
|
||
import com.softserveinc.dokazovi.entity.UserEntity; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToOne; | ||
import javax.persistence.Table; | ||
import java.time.Instant; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@Entity(name = "refresh_token") | ||
@Table(name = "refreshtoken") | ||
public class RefreshToken { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "refreshtoken_id") | ||
private Integer id; | ||
|
||
@OneToOne | ||
@JoinColumn(name = "user_id", referencedColumnName = "user_id") | ||
private UserEntity user; | ||
|
||
@Column(nullable = false, unique = true) | ||
private String token; | ||
|
||
@Column(nullable = false) | ||
private Instant expiryDate; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/softserveinc/dokazovi/dto/payload/RefreshTokenRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.softserveinc.dokazovi.dto.payload; | ||
|
||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@Data | ||
public class RefreshTokenRequest { | ||
|
||
@NotBlank | ||
private String refreshToken; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/softserveinc/dokazovi/exception/TokenRefreshException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.softserveinc.dokazovi.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(HttpStatus.FORBIDDEN) | ||
public class TokenRefreshException extends RuntimeException { | ||
|
||
public TokenRefreshException(String token, String message) { | ||
super(String.format("Failed for [%s]: %s", token, message)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/softserveinc/dokazovi/repositories/RefreshTokenRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.softserveinc.dokazovi.repositories; | ||
|
||
import com.softserveinc.dokazovi.dto.payload.RefreshToken; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface RefreshTokenRepository extends JpaRepository<RefreshToken, Integer> { | ||
|
||
Optional<RefreshToken> findByToken(String token); | ||
} |
Oops, something went wrong.