Gave OAuth2RefreshTokenEntity a Long Id
parent
6b1dad7215
commit
d6d80c3e60
|
@ -27,6 +27,8 @@ import javax.persistence.Column;
|
|||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
@ -47,10 +49,13 @@ import org.springframework.security.oauth2.common.OAuth2RefreshToken;
|
|||
@Table(name="refreshtoken")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "OAuth2RefreshTokenEntity.getByClient", query = "select r from OAuth2RefreshTokenEntity r where r.client = :client"),
|
||||
@NamedQuery(name = "OAuth2RefreshTokenEntity.getExpired", query = "select r from OAuth2RefreshTokenEntity r where r.expiration is not null and r.expiration < current_timestamp")
|
||||
@NamedQuery(name = "OAuth2RefreshTokenEntity.getExpired", query = "select r from OAuth2RefreshTokenEntity r where r.expiration is not null and r.expiration < current_timestamp"),
|
||||
@NamedQuery(name = "OAuth2RefreshTokenEntity.getByTokenValue", query = "selecr r from OAuth2RefreshTokenEntity r where r.tokenValue = :tokenValue")
|
||||
})
|
||||
public class OAuth2RefreshTokenEntity implements OAuth2RefreshToken {
|
||||
|
||||
private Long id;
|
||||
|
||||
private ClientDetailsEntity client;
|
||||
|
||||
//JWT-encoded representation of this access token entity
|
||||
|
@ -68,13 +73,28 @@ public class OAuth2RefreshTokenEntity implements OAuth2RefreshToken {
|
|||
setJwt(new Jwt()); // start with a blank JWT value
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JWT-encoded value of this token
|
||||
*/
|
||||
@Id
|
||||
@Column(name="id")
|
||||
@Basic
|
||||
@Column(name="tokenValue")
|
||||
public String getValue() {
|
||||
// TODO Auto-generated method stub
|
||||
return jwt.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ public interface OAuth2TokenRepository {
|
|||
public OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity token);
|
||||
|
||||
public OAuth2RefreshTokenEntity getRefreshTokenByValue(String refreshTokenValue);
|
||||
|
||||
public OAuth2RefreshTokenEntity getRefreshTokenById(Long Id);
|
||||
|
||||
public void clearAccessTokensForRefreshToken(OAuth2RefreshTokenEntity refreshToken);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
CREATE TABLE refreshtoken (
|
||||
id VARCHAR(4096),
|
||||
id VARCHAR(256),
|
||||
tokenValue VARCHAR(4096),
|
||||
expiration TIMESTAMP,
|
||||
client_id VARCHAR(256)
|
||||
);
|
|
@ -79,7 +79,14 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
|
|||
|
||||
@Override
|
||||
public OAuth2RefreshTokenEntity getRefreshTokenByValue(String refreshTokenValue) {
|
||||
return manager.find(OAuth2RefreshTokenEntity.class, refreshTokenValue);
|
||||
TypedQuery<OAuth2RefreshTokenEntity> query = manager.createNamedQuery("OAuth2RefreshTokenEntity.getByTokenValue", OAuth2RefreshTokenEntity.class);
|
||||
query.setParameter("tokenValue", refreshTokenValue);
|
||||
return JpaUtil.getSingleResult(query.getResultList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2RefreshTokenEntity getRefreshTokenById(Long id) {
|
||||
return manager.find(OAuth2RefreshTokenEntity.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue