db schema

This commit is contained in:
Bill Burke 2014-07-17 16:32:36 -04:00
parent 20cde9cd00
commit aa2d1bcc93
17 changed files with 163 additions and 85 deletions

View file

@ -145,7 +145,7 @@ public class ApplicationAdapter extends ClientAdapter implements ApplicationMode
applicationEntity.getRoles().remove(role); applicationEntity.getRoles().remove(role);
applicationEntity.getDefaultRoles().remove(role); applicationEntity.getDefaultRoles().remove(role);
em.createNativeQuery("delete from CompositeRole where childRole = :role").setParameter("role", role).executeUpdate(); em.createNativeQuery("delete from COMPOSITE_ROLE where CHILD_ROLE = :role").setParameter("role", role).executeUpdate();
em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", role).executeUpdate(); em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", role).executeUpdate();
role.setApplication(null); role.setApplication(null);
em.flush(); em.flush();

View file

@ -769,7 +769,7 @@ public class RealmAdapter implements RealmModel {
realm.getRoles().remove(role); realm.getRoles().remove(role);
realm.getDefaultRoles().remove(role); realm.getDefaultRoles().remove(role);
em.createNativeQuery("delete from CompositeRole where childRole = :role").setParameter("role", roleEntity).executeUpdate(); em.createNativeQuery("delete from COMPOSITE_ROLE where CHILD_ROLE = :role").setParameter("role", roleEntity).executeUpdate();
em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", roleEntity).executeUpdate(); em.createNamedQuery("deleteScopeMappingByRole").setParameter("role", roleEntity).executeUpdate();
em.remove(roleEntity); em.remove(roleEntity);

View file

@ -15,6 +15,7 @@ import org.keycloak.models.jpa.entities.UserAttributeEntity;
import org.keycloak.models.jpa.entities.UserEntity; import org.keycloak.models.jpa.entities.UserEntity;
import org.keycloak.models.jpa.entities.UserRequiredActionEntity; import org.keycloak.models.jpa.entities.UserRequiredActionEntity;
import org.keycloak.models.jpa.entities.UserRoleMappingEntity; import org.keycloak.models.jpa.entities.UserRoleMappingEntity;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.Pbkdf2PasswordEncoder; import org.keycloak.models.utils.Pbkdf2PasswordEncoder;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
@ -215,6 +216,7 @@ public class UserAdapter implements UserModel {
if (credentialEntity == null) { if (credentialEntity == null) {
credentialEntity = new CredentialEntity(); credentialEntity = new CredentialEntity();
credentialEntity.setId(KeycloakModelUtils.generateId());
credentialEntity.setType(cred.getType()); credentialEntity.setType(cred.getType());
credentialEntity.setDevice(cred.getDevice()); credentialEntity.setDevice(cred.getDevice());
credentialEntity.setUser(user); credentialEntity.setUser(user);
@ -276,6 +278,7 @@ public class UserAdapter implements UserModel {
if (credentialEntity == null) { if (credentialEntity == null) {
credentialEntity = new CredentialEntity(); credentialEntity = new CredentialEntity();
credentialEntity.setId(KeycloakModelUtils.generateId());
credentialEntity.setType(credModel.getType()); credentialEntity.setType(credModel.getType());
credentialEntity.setUser(user); credentialEntity.setUser(user);
em.persist(credentialEntity); em.persist(credentialEntity);

View file

@ -1,10 +1,12 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -15,16 +17,23 @@ import java.util.Collection;
@Entity @Entity
public class ApplicationEntity extends ClientEntity { public class ApplicationEntity extends ClientEntity {
@Column(name="SURROGATE_AUTH_REQUIRED")
private boolean surrogateAuthRequired; private boolean surrogateAuthRequired;
@Column(name="BASE_URL")
private String baseUrl; private String baseUrl;
@Column(name="MANAGEMENT_URL")
private String managementUrl; private String managementUrl;
@Column(name="BEARER_ONLY")
private boolean bearerOnly; private boolean bearerOnly;
@OneToMany(fetch = FetchType.EAGER, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "application") @OneToMany(fetch = FetchType.EAGER, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "application")
Collection<RoleEntity> roles = new ArrayList<RoleEntity>(); Collection<RoleEntity> roles = new ArrayList<RoleEntity>();
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="ApplicationDefaultRoles") @JoinTable(name="APPLICATION_DEFAULT_ROLES")
Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>(); Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>();
public boolean isSurrogateAuthRequired() { public boolean isSurrogateAuthRequired() {

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
@ -9,6 +10,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -17,12 +19,15 @@ import java.io.Serializable;
@NamedQueries({ @NamedQueries({
@NamedQuery(name="deleteAuthenticationLinksByRealm", query="delete from AuthenticationLinkEntity authLink where authLink.user IN (select u from UserEntity u where u.realmId=:realmId)") @NamedQuery(name="deleteAuthenticationLinksByRealm", query="delete from AuthenticationLinkEntity authLink where authLink.user IN (select u from UserEntity u where u.realmId=:realmId)")
}) })
@Table(name="AUTHENTICATION_LINK")
@Entity @Entity
@IdClass(AuthenticationLinkEntity.Key.class) @IdClass(AuthenticationLinkEntity.Key.class)
public class AuthenticationLinkEntity { public class AuthenticationLinkEntity {
@Id @Id
@Column(name="AUTH_PROVIDER")
protected String authProvider; protected String authProvider;
@Column(name="AUTH_USER_ID")
protected String authUserId; protected String authUserId;
// NOTE: @OnetoOne creates a constraint race condition if the join column is on AuthenticationLinkEntity. // NOTE: @OnetoOne creates a constraint race condition if the join column is on AuthenticationLinkEntity.
@ -30,7 +35,7 @@ public class AuthenticationLinkEntity {
// a @ManyToOne on both sides. Broken yes, but, I think we're going to replace AuthenticationLinkEntity anyways. // a @ManyToOne on both sides. Broken yes, but, I think we're going to replace AuthenticationLinkEntity anyways.
@Id @Id
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="userId") @JoinColumn(name="USER_ID")
protected UserEntity user; protected UserEntity user;
public String getAuthProvider() { public String getAuthProvider() {

View file

@ -18,23 +18,27 @@ import java.util.Map;
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a> * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/ */
@Entity @Entity
@Table(name="AuthProviderEntity") @Table(name="AUTH_PROVIDER_ENTITY")
@IdClass(AuthenticationProviderEntity.Key.class) @IdClass(AuthenticationProviderEntity.Key.class)
public class AuthenticationProviderEntity { public class AuthenticationProviderEntity {
@Id @Id
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "REALM_ID")
protected RealmEntity realm; protected RealmEntity realm;
@Id @Id
@Column(name="PROVIDER_NAME")
private String providerName; private String providerName;
@Column(name="PASSWORD_UPDATE_SUPPORTED")
private boolean passwordUpdateSupported; private boolean passwordUpdateSupported;
@Column(name="PRIORITY")
private int priority; private int priority;
@ElementCollection @ElementCollection
@MapKeyColumn(name="name") @MapKeyColumn(name="name")
@Column(name="value") @Column(name="value")
@CollectionTable(name="AuthProviderEntity_cfg") @CollectionTable(name="AUTH_PROVIDER_CONFIG")
private Map<String, String> config; private Map<String, String> config;
public RealmEntity getRealm() { public RealmEntity getRealm() {

View file

@ -21,28 +21,34 @@ import java.util.Set;
*/ */
@Entity @Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"realm", "name"})}) @Table(name="CLIENT", uniqueConstraints = {@UniqueConstraint(columnNames = {"REALM_ID", "NAME"})})
public abstract class ClientEntity { public abstract class ClientEntity {
@Id @Id
@Column(length = 36) @Column(name="ID", length = 36)
private String id; private String id;
@Column(name = "name") @Column(name = "NAME")
private String name; private String name;
@Column(name="ENABLED")
private boolean enabled; private boolean enabled;
@Column(name="SECRET")
private String secret; private String secret;
@Column(name="ALLOWED_CLAIMS_MASK")
private long allowedClaimsMask; private long allowedClaimsMask;
@Column(name="NOT_BEFORE")
private int notBefore; private int notBefore;
@Column(name="PUBLIC_CLIENT")
private boolean publicClient; private boolean publicClient;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "realm") @JoinColumn(name = "REALM_ID")
protected RealmEntity realm; protected RealmEntity realm;
@ElementCollection @ElementCollection
@CollectionTable @CollectionTable(name = "WEB_ORIGINS")
protected Set<String> webOrigins = new HashSet<String>(); protected Set<String> webOrigins = new HashSet<String>();
@ElementCollection @ElementCollection
@CollectionTable @CollectionTable(name = "REDIRECT_URIS")
protected Set<String> redirectUris = new HashSet<String>(); protected Set<String> redirectUris = new HashSet<String>();
public RealmEntity getRealm() { public RealmEntity getRealm() {

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
@ -8,6 +9,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -19,22 +21,36 @@ import java.io.Serializable;
@NamedQuery(name="deleteCredentialsByRealm", query="delete from CredentialEntity cred where cred.user IN (select u from UserEntity u where u.realmId=:realmId)") @NamedQuery(name="deleteCredentialsByRealm", query="delete from CredentialEntity cred where cred.user IN (select u from UserEntity u where u.realmId=:realmId)")
}) })
@Table(name="CREDENTIAL")
@Entity @Entity
@IdClass(CredentialEntity.Key.class)
public class CredentialEntity { public class CredentialEntity {
@Id @Id
@Column(length = 36)
protected String id;
@Column(name="TYPE")
protected String type; protected String type;
@Column(name="VALUE")
protected String value; protected String value;
@Column(name="DEVICE")
protected String device; protected String device;
@Column(name="SALT")
protected byte[] salt; protected byte[] salt;
@Column(name="HASH_ITERATIONS")
protected int hashIterations; protected int hashIterations;
@Id
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="userId") @JoinColumn(name="USER_ID")
protected UserEntity user; protected UserEntity user;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getValue() { public String getValue() {
return value; return value;
} }
@ -82,48 +98,4 @@ public class CredentialEntity {
public void setHashIterations(int hashIterations) { public void setHashIterations(int hashIterations) {
this.hashIterations = hashIterations; this.hashIterations = hashIterations;
} }
public static class Key implements Serializable {
protected UserEntity user;
protected String type;
public Key() {
}
public Key(UserEntity user, String type) {
this.user = user;
this.type = type;
}
public UserEntity getUser() {
return user;
}
public String getType() {
return type;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Key key = (Key) o;
if (type != null ? !type.equals(key.type) : key.type != null) return false;
if (user != null ? !user.getId().equals(key.user != null ? key.user.getId() : null) : key.user != null) return false;
return true;
}
@Override
public int hashCode() {
int result = user != null ? user.getId().hashCode() : 0;
result = 31 * result + (type != null ? type.hashCode() : 0);
return result;
}
}
} }

View file

@ -1,6 +1,8 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
@ -15,6 +17,7 @@ import javax.persistence.NamedQuery;
}) })
@Entity @Entity
public class OAuthClientEntity extends ClientEntity { public class OAuthClientEntity extends ClientEntity {
@Column(name="DIRECT_GRANTS_ONLY")
protected boolean directGrantsOnly; protected boolean directGrantsOnly;
public boolean isDirectGrantsOnly() { public boolean isDirectGrantsOnly() {

View file

@ -8,12 +8,14 @@ import javax.persistence.ElementCollection;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.MapKeyColumn; import javax.persistence.MapKeyColumn;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -26,6 +28,7 @@ import java.util.Set;
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
@Table(name="REALM")
@Entity @Entity
@NamedQueries({ @NamedQueries({
@NamedQuery(name="getAllRealms", query="select realm from RealmEntity realm"), @NamedQuery(name="getAllRealms", query="select realm from RealmEntity realm"),
@ -33,59 +36,85 @@ import java.util.Set;
}) })
public class RealmEntity { public class RealmEntity {
@Id @Id
@Column(length = 36) @Column(name="ID", length = 36)
protected String id; protected String id;
@Column(unique = true) @Column(name="NAME", unique = true)
protected String name; protected String name;
@Column(name="ENABLED")
protected boolean enabled; protected boolean enabled;
@Column(name="SSL_NOT_REQUIRED")
protected boolean sslNotRequired; protected boolean sslNotRequired;
@Column(name="REGISTRATION_ALLOWED")
protected boolean registrationAllowed; protected boolean registrationAllowed;
@Column(name="PASSWORD_CRED_GRANT_ALLOWED")
protected boolean passwordCredentialGrantAllowed; protected boolean passwordCredentialGrantAllowed;
@Column(name="VERIFY_EMAIL")
protected boolean verifyEmail; protected boolean verifyEmail;
@Column(name="RESET_PASSWORD_ALLOWED")
protected boolean resetPasswordAllowed; protected boolean resetPasswordAllowed;
@Column(name="SOCIAL")
protected boolean social; protected boolean social;
@Column(name="REMEMBER_ME")
protected boolean rememberMe; protected boolean rememberMe;
//--- brute force settings //--- brute force settings
@Column(name="BRUTE_FORCE_PROTECTED")
protected boolean bruteForceProtected; protected boolean bruteForceProtected;
@Column(name="MAX_FAILURE_WAIT")
protected int maxFailureWaitSeconds; protected int maxFailureWaitSeconds;
@Column(name="MINIMUM_QUICK_LOGIN_WAIT")
protected int minimumQuickLoginWaitSeconds; protected int minimumQuickLoginWaitSeconds;
@Column(name="WAIT_INCREMENT_SECONDS")
protected int waitIncrementSeconds; protected int waitIncrementSeconds;
@Column(name="QUICK_LOGIN_CHECK")
protected long quickLoginCheckMilliSeconds; protected long quickLoginCheckMilliSeconds;
@Column(name="MAX_DELTA_TIME")
protected int maxDeltaTimeSeconds; protected int maxDeltaTimeSeconds;
@Column(name="FAILURE_FACTOR")
protected int failureFactor; protected int failureFactor;
//--- end brute force settings //--- end brute force settings
@Column(name="updateProfileOnInitSocLogin") @Column(name="UPDATE_PROFILE_ON_SOC_LOGIN")
protected boolean updateProfileOnInitialSocialLogin; protected boolean updateProfileOnInitialSocialLogin;
@Column(name="PASSWORD_POLICY")
protected String passwordPolicy; protected String passwordPolicy;
@Column(name="SSO_IDLE_TIMEOUT")
private int ssoSessionIdleTimeout; private int ssoSessionIdleTimeout;
@Column(name="SSO_MAX_LIFESPAN")
private int ssoSessionMaxLifespan; private int ssoSessionMaxLifespan;
@Column(name="ACCESS_TOKEN_LIFESPAN")
protected int accessTokenLifespan; protected int accessTokenLifespan;
@Column(name="ACCESS_CODE_LIFESPAN")
protected int accessCodeLifespan; protected int accessCodeLifespan;
@Column(name="USER_ACTION_LIFESPAN")
protected int accessCodeLifespanUserAction; protected int accessCodeLifespanUserAction;
@Column(name="NOT_BEFORE")
protected int notBefore; protected int notBefore;
@Column(length = 2048) @Column(name="PUBLIC_KEY", length = 2048)
protected String publicKeyPem; protected String publicKeyPem;
@Column(length = 2048) @Column(name="PRIVATE_KEY", length = 2048)
protected String privateKeyPem; protected String privateKeyPem;
@Column(name="LOGIN_THEME")
protected String loginTheme; protected String loginTheme;
@Column(name="ACCOUNT_THEME")
protected String accountTheme; protected String accountTheme;
@Column(name="ADMIN_THEME")
protected String adminTheme; protected String adminTheme;
@Column(name="EMAIL_THEME")
protected String emailTheme; protected String emailTheme;
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true) @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="User_RequiredCreds") @JoinTable(name="USER_REQUIRED_CREDS")
Collection<RequiredCredentialEntity> requiredCredentials = new ArrayList<RequiredCredentialEntity>(); Collection<RequiredCredentialEntity> requiredCredentials = new ArrayList<RequiredCredentialEntity>();
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true) @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="AuthProviders") @JoinTable(name="AUTH_PROVIDERS")
List<AuthenticationProviderEntity> authenticationProviders = new ArrayList<AuthenticationProviderEntity>(); List<AuthenticationProviderEntity> authenticationProviders = new ArrayList<AuthenticationProviderEntity>();
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@ -97,32 +126,36 @@ public class RealmEntity {
@ElementCollection @ElementCollection
@MapKeyColumn(name="name") @MapKeyColumn(name="name")
@Column(name="value") @Column(name="value")
@CollectionTable @CollectionTable(name="REALM_SMTP_CONFIG")
protected Map<String, String> smtpConfig = new HashMap<String, String>(); protected Map<String, String> smtpConfig = new HashMap<String, String>();
@ElementCollection @ElementCollection
@MapKeyColumn(name="name") @MapKeyColumn(name="name")
@Column(name="value") @Column(name="value")
@CollectionTable @CollectionTable(name="REALM_SOCIAL_CONFIG")
protected Map<String, String> socialConfig = new HashMap<String, String>(); protected Map<String, String> socialConfig = new HashMap<String, String>();
@ElementCollection @ElementCollection
@MapKeyColumn(name="name") @MapKeyColumn(name="name")
@Column(name="value") @Column(name="value")
@CollectionTable @CollectionTable(name="REALM_LDAP_CONFIG")
protected Map<String, String> ldapServerConfig = new HashMap<String, String>(); protected Map<String, String> ldapServerConfig = new HashMap<String, String>();
@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true)
@JoinTable(name="RealmDefaultRoles") @JoinTable(name="REALM_DEFAULT_ROLES")
protected Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>(); protected Collection<RoleEntity> defaultRoles = new ArrayList<RoleEntity>();
@Column(name="AUDIT_ENABLED")
protected boolean auditEnabled; protected boolean auditEnabled;
@Column(name="AUDIT_EXPIRATION")
protected long auditExpiration; protected long auditExpiration;
@ElementCollection @ElementCollection
@CollectionTable(name="REALM_AUDIT_LISTENERS")
protected Set<String> auditListeners= new HashSet<String>(); protected Set<String> auditListeners= new HashSet<String>();
@OneToOne @OneToOne
@JoinColumn(name="MASTER_ADMIN_APP")
protected ApplicationEntity masterAdminApp; protected ApplicationEntity masterAdminApp;
public String getId() { public String getId() {

View file

@ -1,30 +1,37 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.IdClass; import javax.persistence.IdClass;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a> * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
@Table(name="REALM_REQUIRED_CREDENTIAL")
@Entity @Entity
@IdClass(RequiredCredentialEntity.Key.class) @IdClass(RequiredCredentialEntity.Key.class)
public class RequiredCredentialEntity { public class RequiredCredentialEntity {
@Id @Id
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "realm") @JoinColumn(name = "REALM_ID")
protected RealmEntity realm; protected RealmEntity realm;
@Id @Id
@Column(name = "TYPE")
protected String type; protected String type;
@Column(name = "INPUT")
protected boolean input; protected boolean input;
@Column(name = "SECRET")
protected boolean secret; protected boolean secret;
@Column(name = "FORM_LABEL")
protected String formLabel; protected String formLabel;
public RealmEntity getRealm() { public RealmEntity getRealm() {

View file

@ -20,8 +20,8 @@ import java.util.Collection;
* @version $Revision: 1 $ * @version $Revision: 1 $
*/ */
@Entity @Entity
@Table(uniqueConstraints = { @Table(name="KEYCLOAK_ROLE", uniqueConstraints = {
@UniqueConstraint(columnNames = { "name", "appRealmConstraint" }) @UniqueConstraint(columnNames = { "NAME", "APP_REALM_CONSTRAINT" })
}) })
@NamedQueries({ @NamedQueries({
@NamedQuery(name="getAppRoleByName", query="select role from RoleEntity role where role.name = :name and role.application = :application"), @NamedQuery(name="getAppRoleByName", query="select role from RoleEntity role where role.name = :name and role.application = :application"),
@ -33,29 +33,32 @@ public class RoleEntity {
@Column(name="id", length = 36) @Column(name="id", length = 36)
private String id; private String id;
@Column(name = "NAME")
private String name; private String name;
@Column(name = "DESCRIPTION")
private String description; private String description;
// hax! couldn't get constraint to work properly // hax! couldn't get constraint to work properly
@Column(name = "REALM_ID")
private String realmId; private String realmId;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "realm") @JoinColumn(name = "REALM")
private RealmEntity realm; private RealmEntity realm;
@Column(name="applicationRole") @Column(name="APPLICATION_ROLE")
private boolean applicationRole; private boolean applicationRole;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application") @JoinColumn(name = "APPLICATION")
private ApplicationEntity application; private ApplicationEntity application;
// Hack to ensure that either name+application or name+realm are unique. Needed due to MS-SQL as it don't allow multiple NULL values in the column, which is part of constraint // Hack to ensure that either name+application or name+realm are unique. Needed due to MS-SQL as it don't allow multiple NULL values in the column, which is part of constraint
@Column(length = 36) @Column(name="APP_REALM_CONSTRAINT", length = 36)
private String appRealmConstraint; private String appRealmConstraint;
@ManyToMany(fetch = FetchType.LAZY, cascade = {}) @ManyToMany(fetch = FetchType.LAZY, cascade = {})
@JoinTable(name = "CompositeRole", joinColumns = @JoinColumn(name = "composite"), inverseJoinColumns = @JoinColumn(name = "childRole")) @JoinTable(name = "COMPOSITE_ROLE", joinColumns = @JoinColumn(name = "COMPOSITE"), inverseJoinColumns = @JoinColumn(name = "CHILD_ROLE"))
private Collection<RoleEntity> compositeRoles = new ArrayList<RoleEntity>(); private Collection<RoleEntity> compositeRoles = new ArrayList<RoleEntity>();
public String getId() { public String getId() {

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
@ -8,6 +9,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -21,17 +23,19 @@ import java.io.Serializable;
@NamedQuery(name="deleteScopeMappingByRole", query="delete from ScopeMappingEntity where role = :role"), @NamedQuery(name="deleteScopeMappingByRole", query="delete from ScopeMappingEntity where role = :role"),
@NamedQuery(name="deleteScopeMappingByClient", query="delete from ScopeMappingEntity where client = :client") @NamedQuery(name="deleteScopeMappingByClient", query="delete from ScopeMappingEntity where client = :client")
}) })
@Table(name="SCOPE_MAPPING")
@Entity @Entity
@IdClass(ScopeMappingEntity.Key.class) @IdClass(ScopeMappingEntity.Key.class)
public class ScopeMappingEntity { public class ScopeMappingEntity {
@Id @Id
@ManyToOne(fetch= FetchType.LAZY) @ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name = "CLIENT_ID")
protected ClientEntity client; protected ClientEntity client;
@Id @Id
@ManyToOne(fetch= FetchType.LAZY) @ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="roleId") @JoinColumn(name="ROLE_ID")
protected RoleEntity role; protected RoleEntity role;
public ClientEntity getClient() { public ClientEntity getClient() {

View file

@ -1,12 +1,15 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.IdClass; import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -20,19 +23,25 @@ import java.io.Serializable;
@NamedQuery(name="deleteSocialLinkByRealm", query="delete from SocialLinkEntity social where social.user IN (select u from UserEntity u where realmId=:realmId)"), @NamedQuery(name="deleteSocialLinkByRealm", query="delete from SocialLinkEntity social where social.user IN (select u from UserEntity u where realmId=:realmId)"),
@NamedQuery(name="deleteSocialLinkByUser", query="delete from SocialLinkEntity social where social.user = :user") @NamedQuery(name="deleteSocialLinkByUser", query="delete from SocialLinkEntity social where social.user = :user")
}) })
@Table(name="USER_SOCIAL_LINK")
@Entity @Entity
@IdClass(SocialLinkEntity.Key.class) @IdClass(SocialLinkEntity.Key.class)
public class SocialLinkEntity { public class SocialLinkEntity {
@Id @Id
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID")
private UserEntity user; private UserEntity user;
@Column(name = "REALM_ID")
protected String realmId; protected String realmId;
@Id @Id
@Column(name = "SOCIAL_PROVIDER")
protected String socialProvider; protected String socialProvider;
@Column(name = "SOCIAL_USER_ID")
protected String socialUserId; protected String socialUserId;
@Column(name = "SOCIAL_USERNAME")
protected String socialUsername; protected String socialUsername;
public UserEntity getUser() { public UserEntity getUser() {

View file

@ -1,12 +1,15 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.IdClass; import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -16,16 +19,20 @@ import java.io.Serializable;
@NamedQueries({ @NamedQueries({
@NamedQuery(name="deleteUserAttributesByRealm", query="delete from UserAttributeEntity attr where attr.user IN (select u from UserEntity u where u.realmId=:realmId)") @NamedQuery(name="deleteUserAttributesByRealm", query="delete from UserAttributeEntity attr where attr.user IN (select u from UserEntity u where u.realmId=:realmId)")
}) })
@Table(name="USER_ATTRIBUTE")
@Entity @Entity
@IdClass(UserAttributeEntity.Key.class) @IdClass(UserAttributeEntity.Key.class)
public class UserAttributeEntity { public class UserAttributeEntity {
@Id @Id
@ManyToOne(fetch= FetchType.LAZY) @ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name = "USER_ID")
protected UserEntity user; protected UserEntity user;
@Id @Id
@Column(name = "NAME")
protected String name; protected String name;
@Column(name = "VALUE")
protected String value; protected String value;
public String getName() { public String getName() {

View file

@ -42,26 +42,35 @@ import java.util.Set;
@NamedQuery(name="deleteUsersByRealm", query="delete from UserEntity u where u.realmId = :realmId") @NamedQuery(name="deleteUsersByRealm", query="delete from UserEntity u where u.realmId = :realmId")
}) })
@Entity @Entity
@Table(uniqueConstraints = { @Table(name="USER", uniqueConstraints = {
@UniqueConstraint(columnNames = { "realmId", "username" }), @UniqueConstraint(columnNames = { "REALM_ID", "USERNAME" }),
@UniqueConstraint(columnNames = { "realmId", "emailConstraint" }) @UniqueConstraint(columnNames = { "REALM_ID", "EMAIL_CONSTRAINT" })
}) })
public class UserEntity { public class UserEntity {
@Id @Id
@Column(length = 36) @Column(name="ID", length = 36)
protected String id; protected String id;
@Column(name = "USERNAME")
protected String username; protected String username;
@Column(name = "FIRST_NAME")
protected String firstName; protected String firstName;
@Column(name = "LAST_NAME")
protected String lastName; protected String lastName;
@Column(name = "EMAIL")
protected String email; protected String email;
@Column(name = "ENABLED")
protected boolean enabled; protected boolean enabled;
@Column(name = "TOTP")
protected boolean totp; protected boolean totp;
@Column(name = "EMAIL_VERIFIED")
protected boolean emailVerified; protected boolean emailVerified;
// Hack just to workaround the fact that on MS-SQL you can't have unique constraint with multiple NULL values TODO: Find better solution (like unique index with 'where' but that's proprietary) // Hack just to workaround the fact that on MS-SQL you can't have unique constraint with multiple NULL values TODO: Find better solution (like unique index with 'where' but that's proprietary)
@Column(name = "EMAIL_CONSTRAINT")
protected String emailConstraint = KeycloakModelUtils.generateId(); protected String emailConstraint = KeycloakModelUtils.generateId();
@Column(name = "REALM_ID")
protected String realmId; protected String realmId;
@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="user") @OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="user")

View file

@ -1,5 +1,6 @@
package org.keycloak.models.jpa.entities; package org.keycloak.models.jpa.entities;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
@ -8,6 +9,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
/** /**
@ -23,16 +25,18 @@ import java.io.Serializable;
@NamedQuery(name="deleteUserRoleMappingsByUser", query="delete from UserRoleMappingEntity m where m.user = :user") @NamedQuery(name="deleteUserRoleMappingsByUser", query="delete from UserRoleMappingEntity m where m.user = :user")
}) })
@Table(name="USER_ROLE_MAPPING")
@Entity @Entity
@IdClass(UserRoleMappingEntity.Key.class) @IdClass(UserRoleMappingEntity.Key.class)
public class UserRoleMappingEntity { public class UserRoleMappingEntity {
@Id @Id
@ManyToOne(fetch= FetchType.LAZY) @ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="userId") @JoinColumn(name="USER_ID")
protected UserEntity user; protected UserEntity user;
@Id @Id
@Column(name = "ROLE_ID")
protected String roleId; protected String roleId;
public UserEntity getUser() { public UserEntity getUser() {