From c8e2752ffa82a635c3b4d6a486cfc024214040d9 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Tue, 16 Nov 2021 12:30:42 +0100 Subject: [PATCH] Make some entity classes serializable DeviceCode not being serializable causes issues when externalizing sessions to Redis. --- .../model/AuthenticationHolderEntity.java | 7 +- .../oauth2/model/AuthorizationCodeEntity.java | 7 +- .../org/mitre/oauth2/model/DeviceCode.java | 324 +++++++++--------- 3 files changed, 173 insertions(+), 165 deletions(-) diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthenticationHolderEntity.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthenticationHolderEntity.java index 28accd47e..2caeff7c8 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthenticationHolderEntity.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthenticationHolderEntity.java @@ -58,9 +58,12 @@ import org.springframework.security.oauth2.provider.OAuth2Request; "a.id not in (select r.authenticationHolder.id from OAuth2RefreshTokenEntity r) and " + "a.id not in (select c.authenticationHolder.id from AuthorizationCodeEntity c)") }) -public class AuthenticationHolderEntity { +public class AuthenticationHolderEntity implements Serializable { - public static final String QUERY_GET_UNUSED = "AuthenticationHolderEntity.getUnusedAuthenticationHolders"; + + private static final long serialVersionUID = 1L; + public static final String QUERY_GET_UNUSED = + "AuthenticationHolderEntity.getUnusedAuthenticationHolders"; public static final String QUERY_ALL = "AuthenticationHolderEntity.getAll"; private Long id; diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthorizationCodeEntity.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthorizationCodeEntity.java index 385f46768..9894e1376 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthorizationCodeEntity.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/model/AuthorizationCodeEntity.java @@ -17,6 +17,7 @@ *******************************************************************************/ package org.mitre.oauth2.model; +import java.io.Serializable; import java.util.Date; import javax.persistence.Basic; @@ -44,9 +45,11 @@ import javax.persistence.Temporal; @NamedQuery(name = AuthorizationCodeEntity.QUERY_BY_VALUE, query = "select a from AuthorizationCodeEntity a where a.code = :code"), @NamedQuery(name = AuthorizationCodeEntity.QUERY_EXPIRATION_BY_DATE, query = "select a from AuthorizationCodeEntity a where a.expiration <= :" + AuthorizationCodeEntity.PARAM_DATE) }) -public class AuthorizationCodeEntity { +public class AuthorizationCodeEntity implements Serializable { - public static final String QUERY_BY_VALUE = "AuthorizationCodeEntity.getByValue"; + private static final long serialVersionUID = 1L; + + public static final String QUERY_BY_VALUE = "AuthorizationCodeEntity.getByValue"; public static final String QUERY_EXPIRATION_BY_DATE = "AuthorizationCodeEntity.expirationByDate"; public static final String PARAM_DATE = "date"; diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/DeviceCode.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/DeviceCode.java index c15a95fe1..d0725a66c 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/DeviceCode.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/model/DeviceCode.java @@ -16,6 +16,7 @@ package org.mitre.oauth2.model; +import java.io.Serializable; import java.util.Date; import java.util.Map; import java.util.Set; @@ -44,191 +45,192 @@ import javax.persistence.Temporal; @Entity @Table(name = "device_code") @NamedQueries({ - @NamedQuery(name = DeviceCode.QUERY_BY_USER_CODE, query = "select d from DeviceCode d where d.userCode = :" + DeviceCode.PARAM_USER_CODE), - @NamedQuery(name = DeviceCode.QUERY_BY_DEVICE_CODE, query = "select d from DeviceCode d where d.deviceCode = :" + DeviceCode.PARAM_DEVICE_CODE), - @NamedQuery(name = DeviceCode.QUERY_EXPIRED_BY_DATE, query = "select d from DeviceCode d where d.expiration <= :" + DeviceCode.PARAM_DATE) -}) -public class DeviceCode { + @NamedQuery(name = DeviceCode.QUERY_BY_USER_CODE, + query = "select d from DeviceCode d where d.userCode = :" + DeviceCode.PARAM_USER_CODE), + @NamedQuery(name = DeviceCode.QUERY_BY_DEVICE_CODE, + query = "select d from DeviceCode d where d.deviceCode = :" + DeviceCode.PARAM_DEVICE_CODE), + @NamedQuery(name = DeviceCode.QUERY_EXPIRED_BY_DATE, + query = "select d from DeviceCode d where d.expiration <= :" + DeviceCode.PARAM_DATE)}) +public class DeviceCode implements Serializable { - public static final String QUERY_BY_USER_CODE = "DeviceCode.queryByUserCode"; - public static final String QUERY_BY_DEVICE_CODE = "DeviceCode.queryByDeviceCode"; - public static final String QUERY_EXPIRED_BY_DATE = "DeviceCode.queryExpiredByDate"; + private static final long serialVersionUID = 1L; - public static final String PARAM_USER_CODE = "userCode"; - public static final String PARAM_DEVICE_CODE = "deviceCode"; - public static final String PARAM_DATE = "date"; + public static final String QUERY_BY_USER_CODE = "DeviceCode.queryByUserCode"; + public static final String QUERY_BY_DEVICE_CODE = "DeviceCode.queryByDeviceCode"; + public static final String QUERY_EXPIRED_BY_DATE = "DeviceCode.queryExpiredByDate"; - private Long id; - private String deviceCode; - private String userCode; - private Set scope; - private Date expiration; - private String clientId; - private Map requestParameters; - private boolean approved; - private AuthenticationHolderEntity authenticationHolder; + public static final String PARAM_USER_CODE = "userCode"; + public static final String PARAM_DEVICE_CODE = "deviceCode"; + public static final String PARAM_DATE = "date"; - public DeviceCode() { + private Long id; + private String deviceCode; + private String userCode; + private Set scope; + private Date expiration; + private String clientId; + private Map requestParameters; + private boolean approved; + private AuthenticationHolderEntity authenticationHolder; - } + public DeviceCode() { - public DeviceCode(String deviceCode, String userCode, Set scope, String clientId, Map params) { - this.deviceCode = deviceCode; - this.userCode = userCode; - this.scope = scope; - this.clientId = clientId; - this.requestParameters = params; - } + } - /** - * @return the id - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - public Long getId() { - return id; - } + public DeviceCode(String deviceCode, String userCode, Set scope, String clientId, + Map params) { + this.deviceCode = deviceCode; + this.userCode = userCode; + this.scope = scope; + this.clientId = clientId; + this.requestParameters = params; + } - /** - * @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() { + return id; + } - /** - * @return the deviceCode - */ - @Basic - @Column(name = "device_code") - public String getDeviceCode() { - return deviceCode; - } + /** + * @param id the id to set + */ + public void setId(Long id) { + this.id = id; + } - /** - * @param deviceCode the deviceCode to set - */ - public void setDeviceCode(String deviceCode) { - this.deviceCode = deviceCode; - } + /** + * @return the deviceCode + */ + @Basic + @Column(name = "device_code") + public String getDeviceCode() { + return deviceCode; + } - /** - * @return the userCode - */ - @Basic - @Column(name = "user_code") - public String getUserCode() { - return userCode; - } + /** + * @param deviceCode the deviceCode to set + */ + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; + } - /** - * @param userCode the userCode to set - */ - public void setUserCode(String userCode) { - this.userCode = userCode; - } + /** + * @return the userCode + */ + @Basic + @Column(name = "user_code") + public String getUserCode() { + return userCode; + } - /** - * @return the scope - */ - @ElementCollection(fetch = FetchType.EAGER) - @CollectionTable( - name="device_code_scope", - joinColumns=@JoinColumn(name="owner_id") - ) - @Column(name="scope") - public Set getScope() { - return scope; - } + /** + * @param userCode the userCode to set + */ + public void setUserCode(String userCode) { + this.userCode = userCode; + } - /** - * @param scope the scope to set - */ - public void setScope(Set scope) { - this.scope = scope; - } + /** + * @return the scope + */ + @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "device_code_scope", joinColumns = @JoinColumn(name = "owner_id")) + @Column(name = "scope") + public Set getScope() { + return scope; + } - @Basic - @Temporal(javax.persistence.TemporalType.TIMESTAMP) - @Column(name = "expiration") - public Date getExpiration() { - return expiration; - } + /** + * @param scope the scope to set + */ + public void setScope(Set scope) { + this.scope = scope; + } - public void setExpiration(Date expiration) { - this.expiration = expiration; - } + @Basic + @Temporal(javax.persistence.TemporalType.TIMESTAMP) + @Column(name = "expiration") + public Date getExpiration() { + return expiration; + } - /** - * @return the clientId - */ - @Basic - @Column(name = "client_id") - public String getClientId() { - return clientId; - } + public void setExpiration(Date expiration) { + this.expiration = expiration; + } - /** - * @param clientId the clientId to set - */ - public void setClientId(String clientId) { - this.clientId = clientId; - } + /** + * @return the clientId + */ + @Basic + @Column(name = "client_id") + public String getClientId() { + return clientId; + } - /** - * @return the params - */ - @ElementCollection(fetch = FetchType.EAGER) - @CollectionTable( - name="device_code_request_parameter", - joinColumns=@JoinColumn(name="owner_id") - ) - @Column(name="val") - @MapKeyColumn(name="param") - public Map getRequestParameters() { - return requestParameters; - } + /** + * @param clientId the clientId to set + */ + public void setClientId(String clientId) { + this.clientId = clientId; + } - /** - * @param params the params to set - */ - public void setRequestParameters(Map params) { - this.requestParameters = params; - } + /** + * @return the params + */ + @ElementCollection(fetch = FetchType.EAGER) + @CollectionTable(name = "device_code_request_parameter", + joinColumns = @JoinColumn(name = "owner_id")) + @Column(name = "val") + @MapKeyColumn(name = "param") + public Map getRequestParameters() { + return requestParameters; + } - /** - * @return the approved - */ - @Basic - @Column(name = "approved") - public boolean isApproved() { - return approved; - } + /** + * @param params the params to set + */ + public void setRequestParameters(Map params) { + this.requestParameters = params; + } - /** - * @param approved the approved to set - */ - public void setApproved(boolean approved) { - this.approved = approved; - } + /** + * @return the approved + */ + @Basic + @Column(name = "approved") + public boolean isApproved() { + return approved; + } - /** - * The authentication in place when this token was created. - * @return the authentication - */ - @ManyToOne - @JoinColumn(name = "auth_holder_id") - public AuthenticationHolderEntity getAuthenticationHolder() { - return authenticationHolder; - } + /** + * @param approved the approved to set + */ + public void setApproved(boolean approved) { + this.approved = approved; + } - /** - * @param authentication the authentication to set - */ - public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) { - this.authenticationHolder = authenticationHolder; - } + /** + * The authentication in place when this token was created. + * + * @return the authentication + */ + @ManyToOne + @JoinColumn(name = "auth_holder_id") + public AuthenticationHolderEntity getAuthenticationHolder() { + return authenticationHolder; + } + + /** + * @param authentication the authentication to set + */ + public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) { + this.authenticationHolder = authenticationHolder; + } }