Skip to content

Commit

Permalink
port to 25 (#245)
Browse files Browse the repository at this point in the history
* port to 25. cleaned old team entities. still need to get events-dependent tests working and import config

* move migration to 0611

* update to java 21 dep. disabled test for entra saml xml import.
  • Loading branch information
xgp authored Jun 19, 2024
1 parent dfcdda0 commit 22a77ee
Show file tree
Hide file tree
Showing 25 changed files with 591 additions and 592 deletions.
35 changes: 7 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
</licenses>

<properties>
<java.version>17</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.java.package>io.phasetwo.service</main.java.package>
<junit.version>5.8.2</junit.version>
<keycloak.version>24.0.0</keycloak.version>
<keycloak.version>25.0.0</keycloak.version>
<resteasy.version>6.2.7.Final</resteasy.version>
<lombok.version>1.18.30</lombok.version>
<lombok.version>1.18.32</lombok.version>
<guava.version>33.0.0-jre</guava.version>
<auto-service.version>1.1.1</auto-service.version>
<jackson.version>2.15.2</jackson.version>
<jackson.databind.version>2.15.2</jackson.databind.version>
<ossrh.url>https://s01.oss.sonatype.org</ossrh.url>
</properties>

Expand Down Expand Up @@ -130,7 +129,7 @@
<plugin> <!-- pretty up the code using google java standards `mvn fmt:format` -->
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.21.1</version>
<version>2.23</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -247,31 +246,11 @@
<scope>provided</scope>
</dependency>

<!-- override jackson version for version problem. is this still an issue? todo -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.databind.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>

<!-- 3rd party deps -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.0.0-jre</version>
<version>${guava.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -321,7 +300,7 @@
<dependency>
<groupId>com.github.dasniko</groupId>
<artifactId>testcontainers-keycloak</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/phasetwo/service/auth/idp/Redirector.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private AuthenticationRequest createAuthenticationRequest(String providerId, Cli
if (clientSessionCode != null) {
authSession = clientSessionCode.getClientSession();
String relayState = clientSessionCode.getOrGenerateCode();
encodedState = IdentityBrokerState.decoded(relayState, authSession.getClient().getId(), authSession.getClient().getClientId(), authSession.getTabId());
encodedState = IdentityBrokerState.decoded(relayState, authSession.getClient().getId(), authSession.getClient().getClientId(), authSession.getTabId(), null);
}

KeycloakSession keycloakSession = context.getSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import io.phasetwo.service.model.OrganizationModel;
import io.phasetwo.service.model.OrganizationProvider;
import io.phasetwo.service.model.jpa.entity.DomainEntity;
import io.phasetwo.service.model.jpa.entity.ExtOrganizationEntity;
import io.phasetwo.service.model.jpa.entity.InvitationEntity;
import io.phasetwo.service.model.jpa.entity.OrganizationAttributeEntity;
import io.phasetwo.service.model.jpa.entity.OrganizationEntity;
import io.phasetwo.service.model.jpa.entity.OrganizationMemberEntity;
import io.phasetwo.service.resource.OrganizationAdminAuth;
import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -47,7 +47,7 @@ public JpaOrganizationProvider(KeycloakSession session, EntityManager em) {
@Override
public OrganizationModel createOrganization(
RealmModel realm, String name, UserModel createdBy, boolean admin) {
OrganizationEntity e = new OrganizationEntity();
ExtOrganizationEntity e = new ExtOrganizationEntity();
e.setId(KeycloakModelUtils.generateId());
e.setRealmId(realm.getId());
e.setName(name);
Expand All @@ -70,7 +70,7 @@ public OrganizationModel createOrganization(

@Override
public OrganizationModel getOrganizationById(RealmModel realm, String id) {
OrganizationEntity org = em.find(OrganizationEntity.class, id);
ExtOrganizationEntity org = em.find(ExtOrganizationEntity.class, id);
if (org != null && org.getRealmId().equals(realm.getId())) {
return new OrganizationAdapter(session, realm, em, org);
} else {
Expand Down Expand Up @@ -124,8 +124,9 @@ public Stream<OrganizationModel> searchForOrganizationStream(
attributes = ImmutableMap.of();
}
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<OrganizationEntity> queryBuilder = builder.createQuery(OrganizationEntity.class);
Root<OrganizationEntity> root = queryBuilder.from(OrganizationEntity.class);
CriteriaQuery<ExtOrganizationEntity> queryBuilder =
builder.createQuery(ExtOrganizationEntity.class);
Root<ExtOrganizationEntity> root = queryBuilder.from(ExtOrganizationEntity.class);

List<Predicate> predicates = attributePredicates(attributes, root);

Expand All @@ -135,7 +136,7 @@ public Stream<OrganizationModel> searchForOrganizationStream(

queryBuilder.where(predicates.toArray(new Predicate[0])).orderBy(builder.asc(root.get("name")));

TypedQuery<OrganizationEntity> query = em.createQuery(queryBuilder);
TypedQuery<ExtOrganizationEntity> query = em.createQuery(queryBuilder);

return closing(paginateQuery(query, firstResult, maxResults).getResultStream())
.map(orgEntity -> getOrganizationById(realm, orgEntity.getId()))
Expand All @@ -154,7 +155,7 @@ public Long getOrganizationsCount(RealmModel realm, String search) {
@Override
public boolean removeOrganization(RealmModel realm, String id) {
OrganizationModel org = getOrganizationById(realm, id);
OrganizationEntity e = em.find(OrganizationEntity.class, id);
ExtOrganizationEntity e = em.find(ExtOrganizationEntity.class, id);
em.remove(e);
session.getKeycloakSessionFactory().publish(orgRemovedEvent(realm, org));
em.flush();
Expand Down Expand Up @@ -220,7 +221,7 @@ public RealmModel getRealm() {
}

private List<Predicate> attributePredicates(
Map<String, String> attributes, Root<OrganizationEntity> root) {
Map<String, String> attributes, Root<ExtOrganizationEntity> root) {
CriteriaBuilder builder = em.getCriteriaBuilder();

List<Predicate> predicates = new ArrayList<>();
Expand All @@ -243,7 +244,7 @@ private List<Predicate> attributePredicates(
builder.lower(root.get("displayName")), "%" + value.toLowerCase() + "%")));
break;
default:
Join<OrganizationEntity, OrganizationAttributeEntity> attributesJoin =
Join<ExtOrganizationEntity, OrganizationAttributeEntity> attributesJoin =
root.join("attributes", JoinType.LEFT);

attributePredicates.add(
Expand All @@ -261,10 +262,10 @@ private List<Predicate> attributePredicates(
return predicates;
}

private Predicate memberPredicate(UserModel member, Root<OrganizationEntity> root) {
private Predicate memberPredicate(UserModel member, Root<ExtOrganizationEntity> root) {
CriteriaBuilder builder = em.getCriteriaBuilder();

Join<OrganizationEntity, OrganizationMemberEntity> membersJoin =
Join<ExtOrganizationEntity, OrganizationMemberEntity> membersJoin =
root.join("members", JoinType.LEFT);

return builder.equal(membersJoin.get("userId"), member.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import io.phasetwo.service.model.OrganizationModel;
import io.phasetwo.service.model.OrganizationRoleModel;
import io.phasetwo.service.model.jpa.entity.DomainEntity;
import io.phasetwo.service.model.jpa.entity.ExtOrganizationEntity;
import io.phasetwo.service.model.jpa.entity.InvitationEntity;
import io.phasetwo.service.model.jpa.entity.OrganizationAttributeEntity;
import io.phasetwo.service.model.jpa.entity.OrganizationEntity;
import io.phasetwo.service.model.jpa.entity.OrganizationMemberEntity;
import io.phasetwo.service.model.jpa.entity.OrganizationRoleEntity;
import io.phasetwo.service.model.jpa.entity.UserOrganizationRoleMappingEntity;
Expand All @@ -29,23 +29,23 @@
import org.keycloak.models.jpa.JpaModel;
import org.keycloak.models.utils.KeycloakModelUtils;

public class OrganizationAdapter implements OrganizationModel, JpaModel<OrganizationEntity> {
public class OrganizationAdapter implements OrganizationModel, JpaModel<ExtOrganizationEntity> {

protected final KeycloakSession session;
protected final OrganizationEntity org;
protected final ExtOrganizationEntity org;
protected final EntityManager em;
protected final RealmModel realm;

public OrganizationAdapter(
KeycloakSession session, RealmModel realm, EntityManager em, OrganizationEntity org) {
KeycloakSession session, RealmModel realm, EntityManager em, ExtOrganizationEntity org) {
this.session = session;
this.em = em;
this.org = org;
this.realm = realm;
}

@Override
public OrganizationEntity getEntity() {
public ExtOrganizationEntity getEntity() {
return org;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DomainEntity {

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ORGANIZATION_ID")
private OrganizationEntity organization;
private ExtOrganizationEntity organization;

public String getId() {
return id;
Expand All @@ -67,11 +67,11 @@ public void setVerified(boolean verified) {
this.verified = verified;
}

public OrganizationEntity getOrganization() {
public ExtOrganizationEntity getOrganization() {
return organization;
}

public void setOrganization(OrganizationEntity organization) {
public void setOrganization(ExtOrganizationEntity organization) {
this.organization = organization;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@
import java.util.Collection;
import org.hibernate.annotations.Nationalized;

// import org.hibernate.validator.constraints.URL; todo

/** */
@NamedQueries({
@NamedQuery(
name = "getOrganizationbyRealmIdAndId",
query = "SELECT o FROM OrganizationEntity o WHERE o.realmId = :realmId AND o.id = :id"),
query = "SELECT o FROM ExtOrganizationEntity o WHERE o.realmId = :realmId AND o.id = :id"),
@NamedQuery(
name = "getOrganizationsByRealmId",
query = "SELECT o FROM OrganizationEntity o WHERE o.realmId = :realmId"),
query = "SELECT o FROM ExtOrganizationEntity o WHERE o.realmId = :realmId"),
@NamedQuery(
name = "getOrganizationsByRealmIdAndName",
query =
"SELECT o FROM OrganizationEntity o WHERE o.realmId = :realmId AND lower(o.name) LIKE lower(:search) ORDER BY o.name"),
"SELECT o FROM ExtOrganizationEntity o WHERE o.realmId = :realmId AND lower(o.name) LIKE lower(:search) ORDER BY o.name"),
@NamedQuery(
name = "countOrganizationsByRealmIdAndName",
query =
"SELECT count(o) FROM OrganizationEntity o WHERE o.realmId = :realmId AND lower(o.name) LIKE lower(:search)"),
"SELECT count(o) FROM ExtOrganizationEntity o WHERE o.realmId = :realmId AND lower(o.name) LIKE lower(:search)"),
@NamedQuery(
name = "getOrganizationCount",
query = "select count(o) from OrganizationEntity o where o.realmId = :realmId"),
query = "select count(o) from ExtOrganizationEntity o where o.realmId = :realmId"),
@NamedQuery(
name = "removeAllOrganizations",
query = "delete from OrganizationEntity o where o.realmId = :realmId")
query = "delete from ExtOrganizationEntity o where o.realmId = :realmId")
})
@Entity
@Table(
name = "ORGANIZATION",
uniqueConstraints = {@UniqueConstraint(columnNames = {"REALM_ID", "NAME"})})
public class OrganizationEntity {
public class ExtOrganizationEntity {
@Id
@Column(name = "ID", length = 36)
@Access(
Expand Down Expand Up @@ -86,13 +84,6 @@ public class OrganizationEntity {
mappedBy = "organization")
protected Collection<OrganizationRoleEntity> roles = new ArrayList<OrganizationRoleEntity>();

@OneToMany(
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
orphanRemoval = true,
mappedBy = "organization")
protected Collection<TeamEntity> teams = new ArrayList<TeamEntity>();

@OneToMany(
fetch = FetchType.LAZY,
cascade = CascadeType.ALL,
Expand Down Expand Up @@ -140,14 +131,6 @@ public void setRoles(Collection<OrganizationRoleEntity> roles) {
setCollection(roles, this.roles);
}

public Collection<TeamEntity> getTeams() {
return teams;
}

public void setTeams(Collection<TeamEntity> teams) {
setCollection(teams, this.teams);
}

public Collection<InvitationEntity> getInvitations() {
return invitations;
}
Expand Down Expand Up @@ -200,9 +183,9 @@ public void setCreatedBy(String createdBy) {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (!(o instanceof OrganizationEntity)) return false;
if (!(o instanceof ExtOrganizationEntity)) return false;

OrganizationEntity that = (OrganizationEntity) o;
ExtOrganizationEntity that = (ExtOrganizationEntity) o;

if (!id.equals(that.id)) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@NamedQuery(
name = "getInvitationsByRealmAndEmail",
query =
"SELECT i FROM InvitationEntity i WHERE i.organization in (SELECT o FROM OrganizationEntity o WHERE o.realmId = :realmId) AND lower(i.email) = lower(:search) ORDER BY i.createdAt"),
"SELECT i FROM InvitationEntity i WHERE i.organization in (SELECT o FROM ExtOrganizationEntity o WHERE o.realmId = :realmId) AND lower(i.email) = lower(:search) ORDER BY i.createdAt"),
@NamedQuery(
name = "getInvitationCount",
query = "SELECT COUNT(t) FROM InvitationEntity t WHERE t.organization = :organization")
Expand Down Expand Up @@ -56,19 +56,12 @@ public class InvitationEntity {

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ORGANIZATION_ID")
private OrganizationEntity organization;
private ExtOrganizationEntity organization;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "invitation")
protected Collection<InvitationAttributeEntity> attributes =
new ArrayList<InvitationAttributeEntity>();

@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(
name = "INVITATION_TEAM",
joinColumns = @JoinColumn(name = "INVITATION_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "TEAM_ID", referencedColumnName = "ID"))
protected Collection<TeamEntity> teams = new ArrayList<TeamEntity>();

@ElementCollection
@Column(name = "ROLE")
@CollectionTable(
Expand All @@ -89,21 +82,6 @@ public void setId(String id) {
this.id = id;
}

public Collection<TeamEntity> getTeams() {
return teams;
}

public void setTeams(Collection<TeamEntity> teams) {
if (this.teams == null) {
this.teams = teams;
} else if (this.teams != teams) {
this.teams.clear();
if (teams != null) {
this.teams.addAll(teams);
}
}
}

public String getEmail() {
return email;
}
Expand Down Expand Up @@ -136,11 +114,11 @@ public void setCreatedAt(Date at) {
createdAt = at;
}

public OrganizationEntity getOrganization() {
public ExtOrganizationEntity getOrganization() {
return organization;
}

public void setOrganization(OrganizationEntity organization) {
public void setOrganization(ExtOrganizationEntity organization) {
this.organization = organization;
}

Expand Down
Loading

0 comments on commit 22a77ee

Please sign in to comment.