switched id tokens to entities, they're now access tokens also

still needs some work to get the auth object right, for now we're just copying from the access token
pull/263/head
Justin Richer 2012-12-06 10:19:21 -05:00
parent eda84e1d58
commit b8f701d9d8
3 changed files with 19 additions and 19 deletions

View File

@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
@ -36,6 +37,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.Transient;
@ -72,7 +74,7 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
private Jwt jwtValue; // JWT-encoded access token value
private IdToken idToken; // JWT-encoded OpenID Connect IdToken
private OAuth2AccessTokenEntity idToken; // JWT-encoded OpenID Connect IdToken
private Date expiration;
@ -225,43 +227,33 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
}
/**
* This is transient b/c the IdToken is not serializable. Instead,
* the toString of the IdToken is persisted in idTokenString
* @return the idToken
*/
@Transient
public IdToken getIdToken() {
@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(IdToken idToken) {
public void setIdToken(OAuth2AccessTokenEntity idToken) {
this.idToken = idToken;
}
/**
* @return the idTokenString
*/
@Basic
@Column(name="id_token_string")
@Transient
public String getIdTokenString() {
if (idToken != null) {
return idToken.toString();
return idToken.getValue(); // get the JWT string value of the id token entity
} else {
return null;
}
}
/**
* @param idTokenString the idTokenString to set
* @throws IllegalArgumentException if "value" is not a properly formatted JWT string
*/
public void setIdTokenString(String idTokenString) {
this.idToken = IdToken.parse(idTokenString);
}
/**
* @return the jwtValue
*/

View File

@ -87,6 +87,7 @@ public class ConnectTokenEnhancer implements TokenEnhancer {
String userId = authentication.getName();
OAuth2AccessTokenEntity idTokenEntity = new OAuth2AccessTokenEntity();
IdToken idToken = new IdToken();
IdTokenClaims claims = new IdTokenClaims();
@ -98,6 +99,7 @@ public class ConnectTokenEnhancer implements TokenEnhancer {
if (client.getIdTokenValiditySeconds() != null) {
Date expiration = new Date(System.currentTimeMillis() + (client.getIdTokenValiditySeconds() * 1000L));
claims.setExpiration(expiration);
idTokenEntity.setExpiration(expiration);
}
claims.setIssuer(configBean.getIssuer());
@ -119,7 +121,13 @@ public class ConnectTokenEnhancer implements TokenEnhancer {
logger.warn("Couldn't sign id token", e);
}
token.setIdToken(idToken);
idTokenEntity.setJwt(idToken);
idTokenEntity.setAuthenticationHolder(token.getAuthenticationHolder());
idTokenEntity.setScope(token.getScope());
token.setIdToken(idTokenEntity);
}
return token;

View File

@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS access_token (
refresh_token_id BIGINT,
client_id VARCHAR(256),
auth_holder_id BIGINT,
id_token_string VARCHAR(4096)
id_token_id BIGINT
);
CREATE TABLE IF NOT EXISTS address (