Gave OAuth2AccessTokenEntity a Long Id
parent
780839dbf9
commit
6b1dad7215
|
@ -29,6 +29,8 @@ import javax.persistence.Column;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.Lob;
|
import javax.persistence.Lob;
|
||||||
|
@ -55,7 +57,8 @@ import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
||||||
@NamedQuery(name = "OAuth2AccessTokenEntity.getByRefreshToken", query = "select a from OAuth2AccessTokenEntity a where a.refreshToken = :refreshToken"),
|
@NamedQuery(name = "OAuth2AccessTokenEntity.getByRefreshToken", query = "select a from OAuth2AccessTokenEntity a where a.refreshToken = :refreshToken"),
|
||||||
@NamedQuery(name = "OAuth2AccessTokenEntity.getByClient", query = "select a from OAuth2AccessTokenEntity a where a.client = :client"),
|
@NamedQuery(name = "OAuth2AccessTokenEntity.getByClient", query = "select a from OAuth2AccessTokenEntity a where a.client = :client"),
|
||||||
@NamedQuery(name = "OAuth2AccessTokenEntity.getExpired", query = "select a from OAuth2AccessTokenEntity a where a.expiration is not null and a.expiration < current_timestamp"),
|
@NamedQuery(name = "OAuth2AccessTokenEntity.getExpired", query = "select a from OAuth2AccessTokenEntity a where a.expiration is not null and a.expiration < current_timestamp"),
|
||||||
@NamedQuery(name = "OAuth2AccessTokenEntity.getByAuthentication", query = "select a from OAuth2AccessTokenEntity a where a.authentication = :authentication")
|
@NamedQuery(name = "OAuth2AccessTokenEntity.getByAuthentication", query = "select a from OAuth2AccessTokenEntity a where a.authentication = :authentication"),
|
||||||
|
@NamedQuery(name = "OAuth2AccessTokenEntity.getByTokenValue", query = "select a from OAuth2AccessTokenEntity a where a.value = :tokenValue")
|
||||||
})
|
})
|
||||||
//@JsonSerialize(using = OAuth2AccessTokenSerializer.class)
|
//@JsonSerialize(using = OAuth2AccessTokenSerializer.class)
|
||||||
//@JsonDeserialize(using = OAuth2AccessTokenDeserializer.class)
|
//@JsonDeserialize(using = OAuth2AccessTokenDeserializer.class)
|
||||||
|
@ -63,6 +66,8 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
|
||||||
|
|
||||||
public static String ID_TOKEN = "id_token";
|
public static String ID_TOKEN = "id_token";
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
private ClientDetailsEntity client;
|
private ClientDetailsEntity client;
|
||||||
|
|
||||||
private OAuth2Authentication authentication; // the authentication that made this access
|
private OAuth2Authentication authentication; // the authentication that made this access
|
||||||
|
@ -86,6 +91,22 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
|
||||||
setJwt(new Jwt()); // give us a blank jwt to work with at least
|
setJwt(new Jwt()); // give us a blank jwt to work with at least
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 all additional information to be sent to the serializer. Inserts a copy of the IdToken (in JWT String form).
|
* Get all additional information to be sent to the serializer. Inserts a copy of the IdToken (in JWT String form).
|
||||||
*/
|
*/
|
||||||
|
@ -132,8 +153,8 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
|
||||||
/**
|
/**
|
||||||
* Get the string-encoded value of this access token.
|
* Get the string-encoded value of this access token.
|
||||||
*/
|
*/
|
||||||
@Id
|
@Basic
|
||||||
@Column(name="id")
|
@Column(name="token_value")
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return jwtValue.toString();
|
return jwtValue.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ public interface OAuth2TokenRepository {
|
||||||
|
|
||||||
public OAuth2AccessTokenEntity getAccessTokenByValue(String accessTokenValue);
|
public OAuth2AccessTokenEntity getAccessTokenByValue(String accessTokenValue);
|
||||||
|
|
||||||
|
public OAuth2AccessTokenEntity getAccessTokenById(Long id);
|
||||||
|
|
||||||
public void removeAccessToken(OAuth2AccessTokenEntity accessToken);
|
public void removeAccessToken(OAuth2AccessTokenEntity accessToken);
|
||||||
|
|
||||||
public void clearTokensForClient(ClientDetailsEntity client);
|
public void clearTokensForClient(ClientDetailsEntity client);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
CREATE TABLE accesstoken (
|
CREATE TABLE accesstoken (
|
||||||
id VARCHAR(4096),
|
id VARCHAR(256),
|
||||||
|
token_value VARCHAR(4096),
|
||||||
expiration TIMESTAMP,
|
expiration TIMESTAMP,
|
||||||
tokenType VARCHAR(256),
|
tokenType VARCHAR(256),
|
||||||
refresh_token_id VARCHAR(256),
|
refresh_token_id VARCHAR(256),
|
||||||
|
|
|
@ -39,7 +39,14 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OAuth2AccessTokenEntity getAccessTokenByValue(String accessTokenValue) {
|
public OAuth2AccessTokenEntity getAccessTokenByValue(String accessTokenValue) {
|
||||||
return manager.find(OAuth2AccessTokenEntity.class, accessTokenValue);
|
TypedQuery<OAuth2AccessTokenEntity> query = manager.createNamedQuery("OAuth2AccessTokenEntity.getByTokenValue", OAuth2AccessTokenEntity.class);
|
||||||
|
query.setParameter("tokenValue", accessTokenValue);
|
||||||
|
return JpaUtil.getSingleResult(query.getResultList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuth2AccessTokenEntity getAccessTokenById(Long id) {
|
||||||
|
return manager.find(OAuth2AccessTokenEntity.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue