diff --git a/audit/jpa/src/main/java/org/keycloak/audit/jpa/EventEntity.java b/audit/jpa/src/main/java/org/keycloak/audit/jpa/EventEntity.java index 4593d2e673..b22b576198 100644 --- a/audit/jpa/src/main/java/org/keycloak/audit/jpa/EventEntity.java +++ b/audit/jpa/src/main/java/org/keycloak/audit/jpa/EventEntity.java @@ -3,34 +3,44 @@ package org.keycloak.audit.jpa; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Table; /** * @author Stian Thorgersen */ @Entity +@Table(name="EVENT_ENTITY") public class EventEntity { @Id - @Column(length = 36) + @Column(name="ID", length = 36) private String id; + @Column(name="TIME") private long time; + @Column(name="EVENT") private String event; + @Column(name="REALM_ID") private String realmId; + @Column(name="CLIENT_ID") private String clientId; + @Column(name="USER_ID") private String userId; + @Column(name="SESSION_ID") private String sessionId; + @Column(name="IP_ADDRESS") private String ipAddress; + @Column(name="ERROR") private String error; - @Column(length = 2550) + @Column(name="DETAILS_JSON", length = 2550) private String detailsJson; public String getId() { diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ApplicationEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ApplicationEntity.java index 890a9b4ebb..c34761fa5f 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ApplicationEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ApplicationEntity.java @@ -4,6 +4,7 @@ import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -33,7 +34,7 @@ public class ApplicationEntity extends ClientEntity { Collection roles = new ArrayList(); @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) - @JoinTable(name="APPLICATION_DEFAULT_ROLES") + @JoinTable(name="APPLICATION_DEFAULT_ROLES", joinColumns = { @JoinColumn(name="APPLICATION_ID")}, inverseJoinColumns = { @JoinColumn(name="ROLE_ID")}) Collection defaultRoles = new ArrayList(); public boolean isSurrogateAuthRequired() { diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationProviderEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationProviderEntity.java index f3d9d3b717..89cfe49e50 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationProviderEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/AuthenticationProviderEntity.java @@ -18,7 +18,7 @@ import java.util.Map; * @author Marek Posolda */ @Entity -@Table(name="AUTH_PROVIDER_ENTITY") +@Table(name="AUTH_PROVIDER") @IdClass(AuthenticationProviderEntity.Key.class) public class AuthenticationProviderEntity { @@ -36,9 +36,11 @@ public class AuthenticationProviderEntity { private int priority; @ElementCollection - @MapKeyColumn(name="name") - @Column(name="value") - @CollectionTable(name="AUTH_PROVIDER_CONFIG") + @MapKeyColumn(name="NAME") + @Column(name="VALUE") + @CollectionTable(name="AUTH_PROVIDER_CONFIG", joinColumns = { + @JoinColumn(name="REALM_ID", referencedColumnName = "REALM_ID"), + @JoinColumn(name="AUTH_PROVIDER_NAME", referencedColumnName = "PROVIDER_NAME")}) private Map config; public RealmEntity getRealm() { diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java index 4ba21f0d98..2f8625b0f3 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/ClientEntity.java @@ -44,11 +44,13 @@ public abstract class ClientEntity { protected RealmEntity realm; @ElementCollection - @CollectionTable(name = "WEB_ORIGINS") + @Column(name="VALUE") + @CollectionTable(name = "WEB_ORIGINS", joinColumns={ @JoinColumn(name="CLIENT_ID") }) protected Set webOrigins = new HashSet(); @ElementCollection - @CollectionTable(name = "REDIRECT_URIS") + @Column(name="VALUE") + @CollectionTable(name = "REDIRECT_URIS", joinColumns={ @JoinColumn(name="CLIENT_ID") }) protected Set redirectUris = new HashSet(); public RealmEntity getRealm() { diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/CredentialEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/CredentialEntity.java index 9b7864e933..d67402e614 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/CredentialEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/CredentialEntity.java @@ -25,7 +25,7 @@ import java.io.Serializable; @Entity public class CredentialEntity { @Id - @Column(length = 36) + @Column(name="ID", length = 36) protected String id; @Column(name="TYPE") diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java index d16543b1c1..e77e0e5397 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/RealmEntity.java @@ -108,41 +108,40 @@ public class RealmEntity { @Column(name="EMAIL_THEME") protected String emailTheme; - @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true) - @JoinTable(name="USER_REQUIRED_CREDS") + @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") Collection requiredCredentials = new ArrayList(); - @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true) - @JoinTable(name="AUTH_PROVIDERS") + @OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") List authenticationProviders = new ArrayList(); @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) + @JoinTable(name="REALM_APPLICATION", joinColumns={ @JoinColumn(name="APPLICATION_ID") }, inverseJoinColumns={ @JoinColumn(name="REALM_ID") }) Collection applications = new ArrayList(); @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm") Collection roles = new ArrayList(); @ElementCollection - @MapKeyColumn(name="name") - @Column(name="value") - @CollectionTable(name="REALM_SMTP_CONFIG") + @MapKeyColumn(name="NAME") + @Column(name="VALUE") + @CollectionTable(name="REALM_SMTP_CONFIG", joinColumns={ @JoinColumn(name="REALM_ID") }) protected Map smtpConfig = new HashMap(); @ElementCollection - @MapKeyColumn(name="name") - @Column(name="value") - @CollectionTable(name="REALM_SOCIAL_CONFIG") + @MapKeyColumn(name="NAME") + @Column(name="VALUE") + @CollectionTable(name="REALM_SOCIAL_CONFIG", joinColumns={ @JoinColumn(name="REALM_ID") }) protected Map socialConfig = new HashMap(); @ElementCollection - @MapKeyColumn(name="name") - @Column(name="value") - @CollectionTable(name="REALM_LDAP_CONFIG") + @MapKeyColumn(name="NAME") + @Column(name="VALUE") + @CollectionTable(name="REALM_LDAP_CONFIG", joinColumns={ @JoinColumn(name="REALM_ID") }) protected Map ldapServerConfig = new HashMap(); @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true) - @JoinTable(name="REALM_DEFAULT_ROLES") + @JoinTable(name="REALM_DEFAULT_ROLES", joinColumns = { @JoinColumn(name="REALM_ID")}, inverseJoinColumns = { @JoinColumn(name="ROLE_ID")}) protected Collection defaultRoles = new ArrayList(); @Column(name="AUDIT_ENABLED") @@ -151,7 +150,8 @@ public class RealmEntity { protected long auditExpiration; @ElementCollection - @CollectionTable(name="REALM_AUDIT_LISTENERS") + @Column(name="VALUE") + @CollectionTable(name="REALM_AUDIT_LISTENERS", joinColumns={ @JoinColumn(name="REALM_ID") }) protected Set auditListeners= new HashSet(); @OneToOne diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java index 376bceadae..16d986a635 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserEntity.java @@ -42,7 +42,7 @@ import java.util.Set; @NamedQuery(name="deleteUsersByRealm", query="delete from UserEntity u where u.realmId = :realmId") }) @Entity -@Table(name="USER", uniqueConstraints = { +@Table(name="USER_ENTITY", uniqueConstraints = { @UniqueConstraint(columnNames = { "REALM_ID", "USERNAME" }), @UniqueConstraint(columnNames = { "REALM_ID", "EMAIL_CONSTRAINT" }) }) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserRequiredActionEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserRequiredActionEntity.java index 2e1b21dbc1..2d3ddbde5f 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserRequiredActionEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/UserRequiredActionEntity.java @@ -2,6 +2,7 @@ package org.keycloak.models.jpa.entities; import org.keycloak.models.UserModel; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; @@ -10,6 +11,8 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import javax.persistence.Table; + import java.io.Serializable; /** @@ -20,15 +23,17 @@ import java.io.Serializable; @NamedQuery(name="deleteUserRequiredActionsByRealm", query="delete from UserRequiredActionEntity action where action.user IN (select u from UserEntity u where realm=:realm)") }) @Entity +@Table(name="USER_REQUIRED_ACTION") @IdClass(UserRequiredActionEntity.Key.class) public class UserRequiredActionEntity { @Id @ManyToOne(fetch= FetchType.LAZY) - @JoinColumn(name="userId") + @JoinColumn(name="USER_ID") protected UserEntity user; @Id + @Column(name="ACTION") protected UserModel.RequiredAction action; public UserModel.RequiredAction getAction() { diff --git a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/ClientUserSessionAssociationEntity.java b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/ClientUserSessionAssociationEntity.java index 3675d50394..99eb40ee5c 100755 --- a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/ClientUserSessionAssociationEntity.java +++ b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/ClientUserSessionAssociationEntity.java @@ -5,6 +5,7 @@ import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.IdClass; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -16,7 +17,7 @@ import java.io.Serializable; * @version $Revision: 1 $ */ @Entity -@Table(name = "ClientUserSessionAscEntity") +@Table(name = "CLIENT_USERSESSION") @NamedQueries({ @NamedQuery(name = "removeClientUserSessionByRealm", query = "delete from ClientUserSessionAssociationEntity a where a.session IN (select s from UserSessionEntity s where s.realmId = :realmId)"), @NamedQuery(name = "removeClientUserSessionByUser", query = "delete from ClientUserSessionAssociationEntity a where a.session IN (select s from UserSessionEntity s where s.realmId = :realmId and s.userId = :userId)"), @@ -28,10 +29,11 @@ public class ClientUserSessionAssociationEntity { @Id @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "SESSION_ID") protected UserSessionEntity session; @Id - @Column(length = 36) + @Column(name="CLIENT_ID",length = 36) protected String clientId; public UserSessionEntity getSession() { diff --git a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UserSessionEntity.java b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UserSessionEntity.java index 2cefb1c592..3d03df12e5 100755 --- a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UserSessionEntity.java +++ b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UserSessionEntity.java @@ -1,16 +1,15 @@ package org.keycloak.models.sessions.jpa.entities; -import org.hibernate.annotations.GenericGenerator; - import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; +import javax.persistence.Table; + import java.util.ArrayList; import java.util.Collection; @@ -18,6 +17,7 @@ import java.util.Collection; * @author Stian Thorgersen */ @Entity +@Table(name = "USER_SESSION") @NamedQueries({ @NamedQuery(name = "getUserSessionByUser", query = "select s from UserSessionEntity s where s.realmId = :realmId and s.userId = :userId order by s.started, s.id"), @NamedQuery(name = "getUserSessionByClient", query = "select s from UserSessionEntity s join s.clients c where s.realmId = :realmId and c.clientId = :clientId order by s.started, s.id"), @@ -29,16 +29,22 @@ import java.util.Collection; public class UserSessionEntity { @Id - @Column(length = 36) + @Column(name="ID",length = 36) protected String id; + @Column(name="USER_ID") protected String userId; + + @Column(name="REALM_ID") protected String realmId; + @Column(name="IP_ADDRESS") protected String ipAddress; + @Column(name="STARTED") protected int started; + @Column(name="LAST_SESSION_REFRESH") protected int lastSessionRefresh; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="session") diff --git a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UsernameLoginFailureEntity.java b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UsernameLoginFailureEntity.java index ed4d483adf..23dd52f041 100755 --- a/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UsernameLoginFailureEntity.java +++ b/model/sessions-jpa/src/main/java/org/keycloak/models/sessions/jpa/entities/UsernameLoginFailureEntity.java @@ -6,6 +6,8 @@ import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import javax.persistence.Table; + import java.io.Serializable; /** @@ -13,6 +15,7 @@ import java.io.Serializable; * @version $Revision: 1 $ */ @Entity +@Table(name="USERNAME_LOGIN_FAILURE") @NamedQueries({ @NamedQuery(name="getAllFailures", query="select failure from UsernameLoginFailureEntity failure"), @NamedQuery(name = "removeLoginFailuresByRealm", query = "delete from UsernameLoginFailureEntity f where f.realmId = :realmId"), @@ -22,16 +25,23 @@ import java.io.Serializable; public class UsernameLoginFailureEntity { @Id - @Column(length = 200) + @Column(name="USERNAME",length = 200) protected String username; @Id - @Column(length = 36) + @Column(name="REALM_ID",length = 36) protected String realmId; + @Column(name="FAILED_LOGIN_NOT_BEFORE") protected int failedLoginNotBefore; + + @Column(name="NUM_FAILURES") protected int numFailures; + + @Column(name="LAST_FAILURE") protected long lastFailure; + + @Column(name="LAST_IP_FAILURE") protected String lastIPFailure; public String getUsername() { diff --git a/testsuite/integration/src/main/resources/META-INF/keycloak-server.json b/testsuite/integration/src/main/resources/META-INF/keycloak-server.json index fb18bfc516..9c23dad55c 100755 --- a/testsuite/integration/src/main/resources/META-INF/keycloak-server.json +++ b/testsuite/integration/src/main/resources/META-INF/keycloak-server.json @@ -66,7 +66,9 @@ "driverDialect": "${keycloak.connectionsJpa.driverDialect:}", "user": "${keycloak.connectionsJpa.user:sa}", "password": "${keycloak.connectionsJpa.password:}", - "databaseSchema": "${keycloak.connectionsJpa.databaseSchema:create-drop}" + "databaseSchema": "${keycloak.connectionsJpa.databaseSchema:create-drop}", + "showSql": "${keycloak.connectionsJpa.showSql:false}", + "formatSql": "${keycloak.connectionsJpa.formatSql:true}" } },