Make some entity classes serializable

DeviceCode not being serializable causes issues when externalizing
sessions to Redis.
pull/1611/head
Andrea Ceccanti 2021-11-16 12:30:42 +01:00
parent 5b96fb6512
commit c8e2752ffa
3 changed files with 173 additions and 165 deletions

View File

@ -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 r.authenticationHolder.id from OAuth2RefreshTokenEntity r) and " +
"a.id not in (select c.authenticationHolder.id from AuthorizationCodeEntity c)") "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"; public static final String QUERY_ALL = "AuthenticationHolderEntity.getAll";
private Long id; private Long id;

View File

@ -17,6 +17,7 @@
*******************************************************************************/ *******************************************************************************/
package org.mitre.oauth2.model; package org.mitre.oauth2.model;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import javax.persistence.Basic; import javax.persistence.Basic;
@ -44,7 +45,9 @@ import javax.persistence.Temporal;
@NamedQuery(name = AuthorizationCodeEntity.QUERY_BY_VALUE, query = "select a from AuthorizationCodeEntity a where a.code = :code"), @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) @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 {
private static final long serialVersionUID = 1L;
public static final String QUERY_BY_VALUE = "AuthorizationCodeEntity.getByValue"; public static final String QUERY_BY_VALUE = "AuthorizationCodeEntity.getByValue";
public static final String QUERY_EXPIRATION_BY_DATE = "AuthorizationCodeEntity.expirationByDate"; public static final String QUERY_EXPIRATION_BY_DATE = "AuthorizationCodeEntity.expirationByDate";

View File

@ -16,6 +16,7 @@
package org.mitre.oauth2.model; package org.mitre.oauth2.model;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -44,11 +45,15 @@ import javax.persistence.Temporal;
@Entity @Entity
@Table(name = "device_code") @Table(name = "device_code")
@NamedQueries({ @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_USER_CODE,
@NamedQuery(name = DeviceCode.QUERY_BY_DEVICE_CODE, query = "select d from DeviceCode d where d.deviceCode = :" + DeviceCode.PARAM_DEVICE_CODE), query = "select d from DeviceCode d where d.userCode = :" + DeviceCode.PARAM_USER_CODE),
@NamedQuery(name = DeviceCode.QUERY_EXPIRED_BY_DATE, query = "select d from DeviceCode d where d.expiration <= :" + DeviceCode.PARAM_DATE) @NamedQuery(name = DeviceCode.QUERY_BY_DEVICE_CODE,
}) query = "select d from DeviceCode d where d.deviceCode = :" + DeviceCode.PARAM_DEVICE_CODE),
public class DeviceCode { @NamedQuery(name = DeviceCode.QUERY_EXPIRED_BY_DATE,
query = "select d from DeviceCode d where d.expiration <= :" + DeviceCode.PARAM_DATE)})
public class DeviceCode implements Serializable {
private static final long serialVersionUID = 1L;
public static final String QUERY_BY_USER_CODE = "DeviceCode.queryByUserCode"; 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_BY_DEVICE_CODE = "DeviceCode.queryByDeviceCode";
@ -72,7 +77,8 @@ public class DeviceCode {
} }
public DeviceCode(String deviceCode, String userCode, Set<String> scope, String clientId, Map<String, String> params) { public DeviceCode(String deviceCode, String userCode, Set<String> scope, String clientId,
Map<String, String> params) {
this.deviceCode = deviceCode; this.deviceCode = deviceCode;
this.userCode = userCode; this.userCode = userCode;
this.scope = scope; this.scope = scope;
@ -133,10 +139,7 @@ public class DeviceCode {
* @return the scope * @return the scope
*/ */
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@CollectionTable( @CollectionTable(name = "device_code_scope", joinColumns = @JoinColumn(name = "owner_id"))
name="device_code_scope",
joinColumns=@JoinColumn(name="owner_id")
)
@Column(name = "scope") @Column(name = "scope")
public Set<String> getScope() { public Set<String> getScope() {
return scope; return scope;
@ -180,10 +183,8 @@ public class DeviceCode {
* @return the params * @return the params
*/ */
@ElementCollection(fetch = FetchType.EAGER) @ElementCollection(fetch = FetchType.EAGER)
@CollectionTable( @CollectionTable(name = "device_code_request_parameter",
name="device_code_request_parameter", joinColumns = @JoinColumn(name = "owner_id"))
joinColumns=@JoinColumn(name="owner_id")
)
@Column(name = "val") @Column(name = "val")
@MapKeyColumn(name = "param") @MapKeyColumn(name = "param")
public Map<String, String> getRequestParameters() { public Map<String, String> getRequestParameters() {
@ -215,6 +216,7 @@ public class DeviceCode {
/** /**
* 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