Bumped to custom version 1.2.7.cnaf-SNAPSHOT.

Fix getAdditionalInformation() method.
pull/1079/head
Marco Caberletti 2016-05-30 14:13:23 +02:00
parent 326ce4cb6f
commit 641699cd99
8 changed files with 289 additions and 236 deletions

View File

@ -21,7 +21,7 @@
<parent> <parent>
<artifactId>openid-connect-parent</artifactId> <artifactId>openid-connect-parent</artifactId>
<groupId>org.mitre</groupId> <groupId>org.mitre</groupId>
<version>1.2.7-SNAPSHOT</version> <version>1.2.7.cnaf-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>openid-connect-client</artifactId> <artifactId>openid-connect-client</artifactId>

View File

@ -21,7 +21,7 @@
<parent> <parent>
<artifactId>openid-connect-parent</artifactId> <artifactId>openid-connect-parent</artifactId>
<groupId>org.mitre</groupId> <groupId>org.mitre</groupId>
<version>1.2.7-SNAPSHOT</version> <version>1.2.7.cnaf-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>openid-connect-common</artifactId> <artifactId>openid-connect-common</artifactId>

View File

@ -64,18 +64,34 @@ import com.nimbusds.jwt.JWT;
@Entity @Entity
@Table(name = "access_token") @Table(name = "access_token")
@NamedQueries({ @NamedQueries({
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_ALL, query = "select a from OAuth2AccessTokenEntity a"), @NamedQuery(name = OAuth2AccessTokenEntity.QUERY_ALL,
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_EXPIRED_BY_DATE, query = "select a from OAuth2AccessTokenEntity a where a.expiration <= :" + OAuth2AccessTokenEntity.PARAM_DATE), query = "select a from OAuth2AccessTokenEntity a"),
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_REFRESH_TOKEN, query = "select a from OAuth2AccessTokenEntity a where a.refreshToken = :" + OAuth2AccessTokenEntity.PARAM_REFERSH_TOKEN), @NamedQuery(name = OAuth2AccessTokenEntity.QUERY_EXPIRED_BY_DATE,
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_CLIENT, query = "select a from OAuth2AccessTokenEntity a where a.client = :" + OAuth2AccessTokenEntity.PARAM_CLIENT), query = "select a from OAuth2AccessTokenEntity a where a.expiration <= :"
@NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_ID_TOKEN, query = "select a from OAuth2AccessTokenEntity a where a.idToken = :" + OAuth2AccessTokenEntity.PARAM_ID_TOKEN), + OAuth2AccessTokenEntity.PARAM_DATE),
@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_REFRESH_TOKEN,
@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) query = "select a from OAuth2AccessTokenEntity a where a.refreshToken = :"
}) + OAuth2AccessTokenEntity.PARAM_REFERSH_TOKEN),
@org.codehaus.jackson.map.annotate.JsonSerialize(using = OAuth2AccessTokenJackson1Serializer.class) @NamedQuery(name = OAuth2AccessTokenEntity.QUERY_BY_CLIENT,
@org.codehaus.jackson.map.annotate.JsonDeserialize(using = OAuth2AccessTokenJackson1Deserializer.class) query = "select a from OAuth2AccessTokenEntity a where a.client = :"
@com.fasterxml.jackson.databind.annotation.JsonSerialize(using = OAuth2AccessTokenJackson2Serializer.class) + OAuth2AccessTokenEntity.PARAM_CLIENT),
@com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = OAuth2AccessTokenJackson2Deserializer.class) @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 class OAuth2AccessTokenEntity implements OAuth2AccessToken {
public static final String QUERY_BY_TOKEN_VALUE = "OAuth2AccessTokenEntity.getByTokenValue"; public static final String QUERY_BY_TOKEN_VALUE = "OAuth2AccessTokenEntity.getByTokenValue";
@ -99,7 +115,9 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
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
@ -115,6 +133,8 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
private Set<Permission> permissions; private Set<Permission> permissions;
private Map<String, Object> additionalInfo = new HashMap<>();
/** /**
* Create a new, blank access token * Create a new, blank access token
*/ */
@ -129,43 +149,52 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
public Long getId() { public Long getId() {
return id; return id;
} }
/** /**
* @param id the id to set * @param id
* the id to set
*/ */
public void setId(Long id) { public void setId(final Long id) {
this.id = 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).
*/ */
@Override @Override
@Transient @Transient
public Map<String, Object> getAdditionalInformation() { public Map<String, Object> getAdditionalInformation() {
Map<String, Object> map = new HashMap<>(); //super.getAdditionalInformation();
if (getIdToken() != null) { if (getIdToken() != null) {
map.put(ID_TOKEN_FIELD_NAME, getIdTokenString()); additionalInfo.put(ID_TOKEN_FIELD_NAME, getIdTokenString());
} }
return map; return additionalInfo;
} }
/** /**
* The authentication in place when this token was created. * The authentication in place when this token was created.
*
* @return the authentication * @return the authentication
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "auth_holder_id") @JoinColumn(name = "auth_holder_id")
public AuthenticationHolderEntity getAuthenticationHolder() { public AuthenticationHolderEntity getAuthenticationHolder() {
return authenticationHolder; return authenticationHolder;
} }
/** /**
* @param authentication the authentication to set * @param authentication
* the authentication to set
*/ */
public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) { public void setAuthenticationHolder(
final AuthenticationHolderEntity authenticationHolder) {
this.authenticationHolder = authenticationHolder; this.authenticationHolder = authenticationHolder;
} }
@ -175,13 +204,16 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@ManyToOne @ManyToOne
@JoinColumn(name = "client_id") @JoinColumn(name = "client_id")
public ClientDetailsEntity getClient() { public ClientDetailsEntity getClient() {
return client; return client;
} }
/** /**
* @param client the client to set * @param client
* the client to set
*/ */
public void setClient(ClientDetailsEntity client) { public void setClient(final ClientDetailsEntity client) {
this.client = client; this.client = client;
} }
@ -191,6 +223,7 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@Override @Override
@Transient @Transient
public String getValue() { public String getValue() {
return jwtValue.serialize(); return jwtValue.serialize();
} }
@ -199,10 +232,12 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@Temporal(javax.persistence.TemporalType.TIMESTAMP) @Temporal(javax.persistence.TemporalType.TIMESTAMP)
@Column(name = "expiration") @Column(name = "expiration")
public Date getExpiration() { public Date getExpiration() {
return expiration; return expiration;
} }
public void setExpiration(Date expiration) { public void setExpiration(final Date expiration) {
this.expiration = expiration; this.expiration = expiration;
} }
@ -210,10 +245,12 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@Basic @Basic
@Column(name = "token_type") @Column(name = "token_type")
public String getTokenType() { public String getTokenType() {
return tokenType; return tokenType;
} }
public void setTokenType(String tokenType) { public void setTokenType(final String tokenType) {
this.tokenType = tokenType; this.tokenType = tokenType;
} }
@ -221,16 +258,20 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@ManyToOne @ManyToOne
@JoinColumn(name = "refresh_token_id") @JoinColumn(name = "refresh_token_id")
public OAuth2RefreshTokenEntity getRefreshToken() { public OAuth2RefreshTokenEntity getRefreshToken() {
return refreshToken; return refreshToken;
} }
public void setRefreshToken(OAuth2RefreshTokenEntity refreshToken) { public void setRefreshToken(final OAuth2RefreshTokenEntity refreshToken) {
this.refreshToken = refreshToken; this.refreshToken = refreshToken;
} }
public void setRefreshToken(OAuth2RefreshToken refreshToken) { public void setRefreshToken(final OAuth2RefreshToken refreshToken) {
if (!(refreshToken instanceof OAuth2RefreshTokenEntity)) { if (!(refreshToken instanceof OAuth2RefreshTokenEntity)) {
throw new IllegalArgumentException("Not a storable refresh token entity!"); throw new IllegalArgumentException(
"Not a storable refresh token entity!");
} }
// force a pass through to the entity version // force a pass through to the entity version
setRefreshToken((OAuth2RefreshTokenEntity) refreshToken); setRefreshToken((OAuth2RefreshTokenEntity) refreshToken);
@ -238,22 +279,24 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@Override @Override
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@CollectionTable( @CollectionTable(joinColumns = @JoinColumn(name = "owner_id"),
joinColumns=@JoinColumn(name="owner_id"), name = "token_scope")
name="token_scope"
)
public Set<String> getScope() { public Set<String> getScope() {
return scope; return scope;
} }
public void setScope(Set<String> scope) { public void setScope(final Set<String> scope) {
this.scope = scope; this.scope = scope;
} }
@Override @Override
@Transient @Transient
public boolean isExpired() { public boolean isExpired() {
return getExpiration() == null ? false : System.currentTimeMillis() > getExpiration().getTime();
return getExpiration() == null ? false
: System.currentTimeMillis() > getExpiration().getTime();
} }
/** /**
@ -262,13 +305,16 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@OneToOne(cascade = CascadeType.ALL) // one-to-one mapping for now @OneToOne(cascade = CascadeType.ALL) // one-to-one mapping for now
@JoinColumn(name = "id_token_id") @JoinColumn(name = "id_token_id")
public OAuth2AccessTokenEntity getIdToken() { public OAuth2AccessTokenEntity getIdToken() {
return idToken; return idToken;
} }
/** /**
* @param idToken the idToken to set * @param idToken
* the idToken to set
*/ */
public void setIdToken(OAuth2AccessTokenEntity idToken) { public void setIdToken(final OAuth2AccessTokenEntity idToken) {
this.idToken = idToken; this.idToken = idToken;
} }
@ -277,8 +323,10 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
*/ */
@Transient @Transient
public String getIdTokenString() { public String getIdTokenString() {
if (idToken != null) { if (idToken != null) {
return idToken.getValue(); // get the JWT string value of the id token entity return idToken.getValue(); // get the JWT string value of the id token
// entity
} else { } else {
return null; return null;
} }
@ -291,13 +339,16 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
@Column(name = "token_value") @Column(name = "token_value")
@Convert(converter = JWTStringConverter.class) @Convert(converter = JWTStringConverter.class)
public JWT getJwt() { public JWT getJwt() {
return jwtValue; return jwtValue;
} }
/** /**
* @param jwtValue the jwtValue to set * @param jwtValue
* the jwtValue to set
*/ */
public void setJwt(JWT jwt) { public void setJwt(final JWT jwt) {
this.jwtValue = jwt; this.jwtValue = jwt;
} }
@ -308,7 +359,8 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
if (getExpiration() == null) { if (getExpiration() == null) {
return -1; // no expiration time return -1; // no expiration time
} else { } else {
int secondsRemaining = (int) ((getExpiration().getTime() - System.currentTimeMillis()) / 1000); int secondsRemaining = (int) ((getExpiration().getTime()
- System.currentTimeMillis()) / 1000);
if (isExpired()) { if (isExpired()) {
return 0; // has an expiration time and expired return 0; // has an expiration time and expired
} else { // has an expiration time and not expired } else { // has an expiration time and not expired
@ -321,19 +373,20 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
* @return the permissions * @return the permissions
*/ */
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable( @JoinTable(name = "access_token_permissions",
name = "access_token_permissions",
joinColumns = @JoinColumn(name = "access_token_id"), joinColumns = @JoinColumn(name = "access_token_id"),
inverseJoinColumns = @JoinColumn(name = "permission_id") inverseJoinColumns = @JoinColumn(name = "permission_id"))
)
public Set<Permission> getPermissions() { public Set<Permission> getPermissions() {
return permissions; return permissions;
} }
/** /**
* @param permissions the permissions to set * @param permissions
* the permissions to set
*/ */
public void setPermissions(Set<Permission> permissions) { public void setPermissions(final Set<Permission> permissions) {
this.permissions = permissions; this.permissions = permissions;
} }

View File

@ -20,7 +20,7 @@
<parent> <parent>
<groupId>org.mitre</groupId> <groupId>org.mitre</groupId>
<artifactId>openid-connect-parent</artifactId> <artifactId>openid-connect-parent</artifactId>
<version>1.2.7-SNAPSHOT</version> <version>1.2.7.cnaf-SNAPSHOT</version>
</parent> </parent>
<artifactId>openid-connect-server-webapp</artifactId> <artifactId>openid-connect-server-webapp</artifactId>
<packaging>war</packaging> <packaging>war</packaging>

View File

@ -22,7 +22,7 @@
<parent> <parent>
<groupId>org.mitre</groupId> <groupId>org.mitre</groupId>
<artifactId>openid-connect-parent</artifactId> <artifactId>openid-connect-parent</artifactId>
<version>1.2.7-SNAPSHOT</version> <version>1.2.7.cnaf-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<build> <build>

View File

@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.mitre</groupId> <groupId>org.mitre</groupId>
<artifactId>openid-connect-parent</artifactId> <artifactId>openid-connect-parent</artifactId>
<version>1.2.7-SNAPSHOT</version> <version>1.2.7.cnaf-SNAPSHOT</version>
<name>MITREid Connect</name> <name>MITREid Connect</name>
<packaging>pom</packaging> <packaging>pom</packaging>
<parent> <parent>

View File

@ -20,7 +20,7 @@
<parent> <parent>
<groupId>org.mitre</groupId> <groupId>org.mitre</groupId>
<artifactId>openid-connect-parent</artifactId> <artifactId>openid-connect-parent</artifactId>
<version>1.2.7-SNAPSHOT</version> <version>1.2.7.cnaf-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>uma-server-webapp</artifactId> <artifactId>uma-server-webapp</artifactId>

View File

@ -20,7 +20,7 @@
<parent> <parent>
<groupId>org.mitre</groupId> <groupId>org.mitre</groupId>
<artifactId>openid-connect-parent</artifactId> <artifactId>openid-connect-parent</artifactId>
<version>1.2.7-SNAPSHOT</version> <version>1.2.7.cnaf-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>uma-server</artifactId> <artifactId>uma-server</artifactId>