|
|
|
@ -64,277 +64,330 @@ import com.nimbusds.jwt.JWT;
|
|
|
|
|
@Entity
|
|
|
|
|
@Table(name = "access_token")
|
|
|
|
|
@NamedQueries({
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_ALL, query = "select a from OAuth2AccessTokenEntity a"),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_EXPIRED_BY_DATE, query = "select a from OAuth2AccessTokenEntity a where a.expiration <= :" + OAuth2AccessTokenEntity.PARAM_DATE),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_REFRESH_TOKEN, query = "select a from OAuth2AccessTokenEntity a where a.refreshToken = :" + OAuth2AccessTokenEntity.PARAM_REFERSH_TOKEN),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_CLIENT, query = "select a from OAuth2AccessTokenEntity a where a.client = :" + OAuth2AccessTokenEntity.PARAM_CLIENT),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_ID_TOKEN, query = "select a from OAuth2AccessTokenEntity a where a.idToken = :" + OAuth2AccessTokenEntity.PARAM_ID_TOKEN),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_TOKEN_VALUE, query = "select a from OAuth2AccessTokenEntity a where a.jwt = :" + OAuth2AccessTokenEntity.PARAM_TOKEN_VALUE),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_RESOURCE_SET, query = "select a from OAuth2AccessTokenEntity a join a.permissions p where p.resourceSet.id = :" + OAuth2AccessTokenEntity.PARAM_RESOURCE_SET_ID)
|
|
|
|
|
})
|
|
|
|
|
@org.codehaus.jackson.map.annotate.JsonSerialize(using = OAuth2AccessTokenJackson1Serializer.class)
|
|
|
|
|
@org.codehaus.jackson.map.annotate.JsonDeserialize(using = OAuth2AccessTokenJackson1Deserializer.class)
|
|
|
|
|
@com.fasterxml.jackson.databind.annotation.JsonSerialize(using = OAuth2AccessTokenJackson2Serializer.class)
|
|
|
|
|
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = OAuth2AccessTokenJackson2Deserializer.class)
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_ALL,
|
|
|
|
|
query = "select a from OAuth2AccessTokenEntity a"),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_EXPIRED_BY_DATE,
|
|
|
|
|
query = "select a from OAuth2AccessTokenEntity a where a.expiration <= :"
|
|
|
|
|
+ OAuth2AccessTokenEntity.PARAM_DATE),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_REFRESH_TOKEN,
|
|
|
|
|
query = "select a from OAuth2AccessTokenEntity a where a.refreshToken = :"
|
|
|
|
|
+ OAuth2AccessTokenEntity.PARAM_REFERSH_TOKEN),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_CLIENT,
|
|
|
|
|
query = "select a from OAuth2AccessTokenEntity a where a.client = :"
|
|
|
|
|
+ OAuth2AccessTokenEntity.PARAM_CLIENT),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_ID_TOKEN,
|
|
|
|
|
query = "select a from OAuth2AccessTokenEntity a where a.idToken = :"
|
|
|
|
|
+ OAuth2AccessTokenEntity.PARAM_ID_TOKEN),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_TOKEN_VALUE,
|
|
|
|
|
query = "select a from OAuth2AccessTokenEntity a where a.jwt = :"
|
|
|
|
|
+ OAuth2AccessTokenEntity.PARAM_TOKEN_VALUE),
|
|
|
|
|
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_RESOURCE_SET,
|
|
|
|
|
query = "select a from OAuth2AccessTokenEntity a join a.permissions p where p.resourceSet.id = :"
|
|
|
|
|
+ OAuth2AccessTokenEntity.PARAM_RESOURCE_SET_ID) })
|
|
|
|
|
@org.codehaus.jackson.map.annotate.JsonSerialize(
|
|
|
|
|
using = OAuth2AccessTokenJackson1Serializer.class)
|
|
|
|
|
@org.codehaus.jackson.map.annotate.JsonDeserialize(
|
|
|
|
|
using = OAuth2AccessTokenJackson1Deserializer.class)
|
|
|
|
|
@com.fasterxml.jackson.databind.annotation.JsonSerialize(
|
|
|
|
|
using = OAuth2AccessTokenJackson2Serializer.class)
|
|
|
|
|
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(
|
|
|
|
|
using = OAuth2AccessTokenJackson2Deserializer.class)
|
|
|
|
|
public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
|
|
|
|
|
|
|
|
|
|
public static final String QUERY_BY_TOKEN_VALUE = "OAuth2AccessTokenEntity.getByTokenValue";
|
|
|
|
|
public static final String QUERY_BY_ID_TOKEN = "OAuth2AccessTokenEntity.getByIdToken";
|
|
|
|
|
public static final String QUERY_BY_CLIENT = "OAuth2AccessTokenEntity.getByClient";
|
|
|
|
|
public static final String QUERY_BY_REFRESH_TOKEN = "OAuth2AccessTokenEntity.getByRefreshToken";
|
|
|
|
|
public static final String QUERY_EXPIRED_BY_DATE = "OAuth2AccessTokenEntity.getAllExpiredByDate";
|
|
|
|
|
public static final String QUERY_ALL = "OAuth2AccessTokenEntity.getAll";
|
|
|
|
|
public static final String QUERY_BY_RESOURCE_SET = "OAuth2AccessTokenEntity.getByResourceSet";
|
|
|
|
|
public static final String QUERY_BY_TOKEN_VALUE = "OAuth2AccessTokenEntity.getByTokenValue";
|
|
|
|
|
public static final String QUERY_BY_ID_TOKEN = "OAuth2AccessTokenEntity.getByIdToken";
|
|
|
|
|
public static final String QUERY_BY_CLIENT = "OAuth2AccessTokenEntity.getByClient";
|
|
|
|
|
public static final String QUERY_BY_REFRESH_TOKEN = "OAuth2AccessTokenEntity.getByRefreshToken";
|
|
|
|
|
public static final String QUERY_EXPIRED_BY_DATE = "OAuth2AccessTokenEntity.getAllExpiredByDate";
|
|
|
|
|
public static final String QUERY_ALL = "OAuth2AccessTokenEntity.getAll";
|
|
|
|
|
public static final String QUERY_BY_RESOURCE_SET = "OAuth2AccessTokenEntity.getByResourceSet";
|
|
|
|
|
|
|
|
|
|
public static final String PARAM_TOKEN_VALUE = "tokenValue";
|
|
|
|
|
public static final String PARAM_ID_TOKEN = "idToken";
|
|
|
|
|
public static final String PARAM_CLIENT = "client";
|
|
|
|
|
public static final String PARAM_REFERSH_TOKEN = "refreshToken";
|
|
|
|
|
public static final String PARAM_DATE = "date";
|
|
|
|
|
public static final String PARAM_RESOURCE_SET_ID = "rsid";
|
|
|
|
|
public static final String PARAM_TOKEN_VALUE = "tokenValue";
|
|
|
|
|
public static final String PARAM_ID_TOKEN = "idToken";
|
|
|
|
|
public static final String PARAM_CLIENT = "client";
|
|
|
|
|
public static final String PARAM_REFERSH_TOKEN = "refreshToken";
|
|
|
|
|
public static final String PARAM_DATE = "date";
|
|
|
|
|
public static final String PARAM_RESOURCE_SET_ID = "rsid";
|
|
|
|
|
|
|
|
|
|
public static String ID_TOKEN_FIELD_NAME = "id_token";
|
|
|
|
|
public static String ID_TOKEN_FIELD_NAME = "id_token";
|
|
|
|
|
|
|
|
|
|
private Long id;
|
|
|
|
|
private Long id;
|
|
|
|
|
|
|
|
|
|
private ClientDetailsEntity client;
|
|
|
|
|
private ClientDetailsEntity client;
|
|
|
|
|
|
|
|
|
|
private AuthenticationHolderEntity authenticationHolder; // the authentication that made this access
|
|
|
|
|
private AuthenticationHolderEntity authenticationHolder; // the authentication
|
|
|
|
|
// that made this
|
|
|
|
|
// access
|
|
|
|
|
|
|
|
|
|
private JWT jwtValue; // JWT-encoded access token value
|
|
|
|
|
private JWT jwtValue; // JWT-encoded access token value
|
|
|
|
|
|
|
|
|
|
private OAuth2AccessTokenEntity idToken; // JWT-encoded OpenID Connect IdToken
|
|
|
|
|
private OAuth2AccessTokenEntity idToken; // JWT-encoded OpenID Connect IdToken
|
|
|
|
|
|
|
|
|
|
private Date expiration;
|
|
|
|
|
private Date expiration;
|
|
|
|
|
|
|
|
|
|
private String tokenType = OAuth2AccessToken.BEARER_TYPE;
|
|
|
|
|
private String tokenType = OAuth2AccessToken.BEARER_TYPE;
|
|
|
|
|
|
|
|
|
|
private OAuth2RefreshTokenEntity refreshToken;
|
|
|
|
|
private OAuth2RefreshTokenEntity refreshToken;
|
|
|
|
|
|
|
|
|
|
private Set<String> scope;
|
|
|
|
|
private Set<String> scope;
|
|
|
|
|
|
|
|
|
|
private Set<Permission> permissions;
|
|
|
|
|
private Set<Permission> permissions;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new, blank access token
|
|
|
|
|
*/
|
|
|
|
|
public OAuth2AccessTokenEntity() {
|
|
|
|
|
private Map<String, Object> additionalInfo = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Create a new, blank access token
|
|
|
|
|
*/
|
|
|
|
|
public OAuth2AccessTokenEntity() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the id
|
|
|
|
|
*/
|
|
|
|
|
@Id
|
|
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
|
|
@Column(name = "id")
|
|
|
|
|
public Long getId() {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param id the id to set
|
|
|
|
|
*/
|
|
|
|
|
public void setId(Long id) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return the id
|
|
|
|
|
*/
|
|
|
|
|
@Id
|
|
|
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
|
|
@Column(name = "id")
|
|
|
|
|
public Long getId() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all additional information to be sent to the serializer. Inserts a copy of the IdToken (in JWT String form).
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public Map<String, Object> getAdditionalInformation() {
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); //super.getAdditionalInformation();
|
|
|
|
|
if (getIdToken() != null) {
|
|
|
|
|
map.put(ID_TOKEN_FIELD_NAME, getIdTokenString());
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The authentication in place when this token was created.
|
|
|
|
|
* @return the authentication
|
|
|
|
|
*/
|
|
|
|
|
@ManyToOne
|
|
|
|
|
@JoinColumn(name = "auth_holder_id")
|
|
|
|
|
public AuthenticationHolderEntity getAuthenticationHolder() {
|
|
|
|
|
return authenticationHolder;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @param id
|
|
|
|
|
* the id to set
|
|
|
|
|
*/
|
|
|
|
|
public void setId(final Long id) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param authentication the authentication to set
|
|
|
|
|
*/
|
|
|
|
|
public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
|
|
|
|
|
this.authenticationHolder = authenticationHolder;
|
|
|
|
|
}
|
|
|
|
|
this.id = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the client
|
|
|
|
|
*/
|
|
|
|
|
@ManyToOne
|
|
|
|
|
@JoinColumn(name = "client_id")
|
|
|
|
|
public ClientDetailsEntity getClient() {
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get all additional information to be sent to the serializer. Inserts a copy
|
|
|
|
|
* of the IdToken (in JWT String form).
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public Map<String, Object> getAdditionalInformation() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param client the client to set
|
|
|
|
|
*/
|
|
|
|
|
public void setClient(ClientDetailsEntity client) {
|
|
|
|
|
this.client = client;
|
|
|
|
|
}
|
|
|
|
|
if (getIdToken() != null) {
|
|
|
|
|
additionalInfo.put(ID_TOKEN_FIELD_NAME, getIdTokenString());
|
|
|
|
|
}
|
|
|
|
|
return additionalInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the string-encoded value of this access token.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public String getValue() {
|
|
|
|
|
return jwtValue.serialize();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* The authentication in place when this token was created.
|
|
|
|
|
*
|
|
|
|
|
* @return the authentication
|
|
|
|
|
*/
|
|
|
|
|
@ManyToOne
|
|
|
|
|
@JoinColumn(name = "auth_holder_id")
|
|
|
|
|
public AuthenticationHolderEntity getAuthenticationHolder() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Basic
|
|
|
|
|
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
|
|
|
|
@Column(name = "expiration")
|
|
|
|
|
public Date getExpiration() {
|
|
|
|
|
return expiration;
|
|
|
|
|
}
|
|
|
|
|
return authenticationHolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setExpiration(Date expiration) {
|
|
|
|
|
this.expiration = expiration;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @param authentication
|
|
|
|
|
* the authentication to set
|
|
|
|
|
*/
|
|
|
|
|
public void setAuthenticationHolder(
|
|
|
|
|
final AuthenticationHolderEntity authenticationHolder) {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Basic
|
|
|
|
|
@Column(name="token_type")
|
|
|
|
|
public String getTokenType() {
|
|
|
|
|
return tokenType;
|
|
|
|
|
}
|
|
|
|
|
this.authenticationHolder = authenticationHolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTokenType(String tokenType) {
|
|
|
|
|
this.tokenType = tokenType;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return the client
|
|
|
|
|
*/
|
|
|
|
|
@ManyToOne
|
|
|
|
|
@JoinColumn(name = "client_id")
|
|
|
|
|
public ClientDetailsEntity getClient() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ManyToOne
|
|
|
|
|
@JoinColumn(name="refresh_token_id")
|
|
|
|
|
public OAuth2RefreshTokenEntity getRefreshToken() {
|
|
|
|
|
return refreshToken;
|
|
|
|
|
}
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
|
|
|
|
this.refreshToken = refreshToken;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @param client
|
|
|
|
|
* the client to set
|
|
|
|
|
*/
|
|
|
|
|
public void setClient(final ClientDetailsEntity client) {
|
|
|
|
|
|
|
|
|
|
public void setRefreshToken(OAuth2RefreshToken refreshToken) {
|
|
|
|
|
if (!(refreshToken instanceof OAuth2RefreshTokenEntity)) {
|
|
|
|
|
throw new IllegalArgumentException("Not a storable refresh token entity!");
|
|
|
|
|
}
|
|
|
|
|
// force a pass through to the entity version
|
|
|
|
|
setRefreshToken((OAuth2RefreshTokenEntity)refreshToken);
|
|
|
|
|
}
|
|
|
|
|
this.client = client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ElementCollection(fetch=FetchType.EAGER)
|
|
|
|
|
@CollectionTable(
|
|
|
|
|
joinColumns=@JoinColumn(name="owner_id"),
|
|
|
|
|
name="token_scope"
|
|
|
|
|
)
|
|
|
|
|
public Set<String> getScope() {
|
|
|
|
|
return scope;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Get the string-encoded value of this access token.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public String getValue() {
|
|
|
|
|
|
|
|
|
|
public void setScope(Set<String> scope) {
|
|
|
|
|
this.scope = scope;
|
|
|
|
|
}
|
|
|
|
|
return jwtValue.serialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public boolean isExpired() {
|
|
|
|
|
return getExpiration() == null ? false : System.currentTimeMillis() > getExpiration().getTime();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
@Basic
|
|
|
|
|
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
|
|
|
|
@Column(name = "expiration")
|
|
|
|
|
public Date getExpiration() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the idToken
|
|
|
|
|
*/
|
|
|
|
|
@OneToOne(cascade=CascadeType.ALL) // one-to-one mapping for now
|
|
|
|
|
@JoinColumn(name = "id_token_id")
|
|
|
|
|
public OAuth2AccessTokenEntity getIdToken() {
|
|
|
|
|
return idToken;
|
|
|
|
|
}
|
|
|
|
|
return expiration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param idToken the idToken to set
|
|
|
|
|
*/
|
|
|
|
|
public void setIdToken(OAuth2AccessTokenEntity idToken) {
|
|
|
|
|
this.idToken = idToken;
|
|
|
|
|
}
|
|
|
|
|
public void setExpiration(final Date expiration) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the idTokenString
|
|
|
|
|
*/
|
|
|
|
|
@Transient
|
|
|
|
|
public String getIdTokenString() {
|
|
|
|
|
if (idToken != null) {
|
|
|
|
|
return idToken.getValue(); // get the JWT string value of the id token entity
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.expiration = expiration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the jwtValue
|
|
|
|
|
*/
|
|
|
|
|
@Basic
|
|
|
|
|
@Column(name="token_value")
|
|
|
|
|
@Convert(converter = JWTStringConverter.class)
|
|
|
|
|
public JWT getJwt() {
|
|
|
|
|
return jwtValue;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
@Basic
|
|
|
|
|
@Column(name = "token_type")
|
|
|
|
|
public String getTokenType() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param jwtValue the jwtValue to set
|
|
|
|
|
*/
|
|
|
|
|
public void setJwt(JWT jwt) {
|
|
|
|
|
this.jwtValue = jwt;
|
|
|
|
|
}
|
|
|
|
|
return tokenType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public int getExpiresIn() {
|
|
|
|
|
public void setTokenType(final String tokenType) {
|
|
|
|
|
|
|
|
|
|
if (getExpiration() == null) {
|
|
|
|
|
return -1; // no expiration time
|
|
|
|
|
} else {
|
|
|
|
|
int secondsRemaining = (int) ((getExpiration().getTime() - System.currentTimeMillis()) / 1000);
|
|
|
|
|
if (isExpired()) {
|
|
|
|
|
return 0; // has an expiration time and expired
|
|
|
|
|
} else { // has an expiration time and not expired
|
|
|
|
|
return secondsRemaining;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.tokenType = tokenType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the permissions
|
|
|
|
|
*/
|
|
|
|
|
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
|
|
|
|
@JoinTable(
|
|
|
|
|
name = "access_token_permissions",
|
|
|
|
|
joinColumns = @JoinColumn(name = "access_token_id"),
|
|
|
|
|
inverseJoinColumns = @JoinColumn(name = "permission_id")
|
|
|
|
|
)
|
|
|
|
|
public Set<Permission> getPermissions() {
|
|
|
|
|
return permissions;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
@ManyToOne
|
|
|
|
|
@JoinColumn(name = "refresh_token_id")
|
|
|
|
|
public OAuth2RefreshTokenEntity getRefreshToken() {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param permissions the permissions to set
|
|
|
|
|
*/
|
|
|
|
|
public void setPermissions(Set<Permission> permissions) {
|
|
|
|
|
this.permissions = permissions;
|
|
|
|
|
}
|
|
|
|
|
return refreshToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRefreshToken(final OAuth2RefreshTokenEntity refreshToken) {
|
|
|
|
|
|
|
|
|
|
this.refreshToken = refreshToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRefreshToken(final OAuth2RefreshToken refreshToken) {
|
|
|
|
|
|
|
|
|
|
if (!(refreshToken instanceof OAuth2RefreshTokenEntity)) {
|
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
|
"Not a storable refresh token entity!");
|
|
|
|
|
}
|
|
|
|
|
// force a pass through to the entity version
|
|
|
|
|
setRefreshToken((OAuth2RefreshTokenEntity) refreshToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ElementCollection(fetch = FetchType.EAGER)
|
|
|
|
|
@CollectionTable(joinColumns = @JoinColumn(name = "owner_id"),
|
|
|
|
|
name = "token_scope")
|
|
|
|
|
public Set<String> getScope() {
|
|
|
|
|
|
|
|
|
|
return scope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setScope(final Set<String> scope) {
|
|
|
|
|
|
|
|
|
|
this.scope = scope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public boolean isExpired() {
|
|
|
|
|
|
|
|
|
|
return getExpiration() == null ? false
|
|
|
|
|
: System.currentTimeMillis() > getExpiration().getTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the idToken
|
|
|
|
|
*/
|
|
|
|
|
@OneToOne(cascade = CascadeType.ALL) // one-to-one mapping for now
|
|
|
|
|
@JoinColumn(name = "id_token_id")
|
|
|
|
|
public OAuth2AccessTokenEntity getIdToken() {
|
|
|
|
|
|
|
|
|
|
return idToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param idToken
|
|
|
|
|
* the idToken to set
|
|
|
|
|
*/
|
|
|
|
|
public void setIdToken(final OAuth2AccessTokenEntity idToken) {
|
|
|
|
|
|
|
|
|
|
this.idToken = idToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the idTokenString
|
|
|
|
|
*/
|
|
|
|
|
@Transient
|
|
|
|
|
public String getIdTokenString() {
|
|
|
|
|
|
|
|
|
|
if (idToken != null) {
|
|
|
|
|
return idToken.getValue(); // get the JWT string value of the id token
|
|
|
|
|
// entity
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the jwtValue
|
|
|
|
|
*/
|
|
|
|
|
@Basic
|
|
|
|
|
@Column(name = "token_value")
|
|
|
|
|
@Convert(converter = JWTStringConverter.class)
|
|
|
|
|
public JWT getJwt() {
|
|
|
|
|
|
|
|
|
|
return jwtValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param jwtValue
|
|
|
|
|
* the jwtValue to set
|
|
|
|
|
*/
|
|
|
|
|
public void setJwt(final JWT jwt) {
|
|
|
|
|
|
|
|
|
|
this.jwtValue = jwt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transient
|
|
|
|
|
public int getExpiresIn() {
|
|
|
|
|
|
|
|
|
|
if (getExpiration() == null) {
|
|
|
|
|
return -1; // no expiration time
|
|
|
|
|
} else {
|
|
|
|
|
int secondsRemaining = (int) ((getExpiration().getTime()
|
|
|
|
|
- System.currentTimeMillis()) / 1000);
|
|
|
|
|
if (isExpired()) {
|
|
|
|
|
return 0; // has an expiration time and expired
|
|
|
|
|
} else { // has an expiration time and not expired
|
|
|
|
|
return secondsRemaining;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the permissions
|
|
|
|
|
*/
|
|
|
|
|
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
|
|
|
|
@JoinTable(name = "access_token_permissions",
|
|
|
|
|
joinColumns = @JoinColumn(name = "access_token_id"),
|
|
|
|
|
inverseJoinColumns = @JoinColumn(name = "permission_id"))
|
|
|
|
|
public Set<Permission> getPermissions() {
|
|
|
|
|
|
|
|
|
|
return permissions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param permissions
|
|
|
|
|
* the permissions to set
|
|
|
|
|
*/
|
|
|
|
|
public void setPermissions(final Set<Permission> permissions) {
|
|
|
|
|
|
|
|
|
|
this.permissions = permissions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|