-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
flawmop
committed
Aug 31, 2024
1 parent
e7b6e25
commit 7721522
Showing
14 changed files
with
314 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/insilicosoft/portal/svc/rip/config/JpaAuditingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.insilicosoft.portal.svc.rip.config; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; | ||
|
||
/** | ||
* JPA Auditing configuration. | ||
* <p> | ||
* Contains mechanism to map the JWT token claims to an identity for auditing purposes. | ||
* | ||
* @author geoff | ||
*/ | ||
@Configuration | ||
@EnableJpaAuditing(auditorAwareRef = "auditorAware") | ||
public class JpaAuditingConfig { | ||
|
||
@Bean | ||
AuditorAware<String> auditorAware() { | ||
return new AuditorAware<String>() { | ||
@Override | ||
public Optional<String> getCurrentAuditor() { | ||
String auditor = null; | ||
if (SecurityContextHolder.getContext().getAuthentication() != null) { | ||
JwtAuthenticationToken token = (JwtAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); | ||
// Use the JWT 'subject' claim as identifier for audit purposes! | ||
auditor = token.getName(); | ||
} | ||
return Optional.ofNullable(auditor); | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/com/insilicosoft/portal/svc/rip/persistence/entity/Simulation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.insilicosoft.portal.svc.rip.persistence.entity; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
import java.time.Instant; | ||
|
||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedBy; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.annotation.Version; | ||
|
||
/** | ||
* Simulation entity. | ||
* | ||
* @author geoff | ||
*/ | ||
@Entity | ||
@EntityListeners(AuditingEntityListener.class) | ||
@Table(name = "simulation") | ||
public class Simulation { | ||
|
||
@Id | ||
@Column(name = "id") | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long entityId; | ||
|
||
// See JPA auditing | ||
@CreatedDate | ||
Instant createdDate; | ||
|
||
// See JPA auditing | ||
@LastModifiedDate | ||
Instant lastModifiedDate; | ||
|
||
// See JPA auditing | ||
@CreatedBy | ||
String createdBy; | ||
|
||
// See JPA auditing | ||
@LastModifiedBy | ||
String lastModifiedBy; | ||
|
||
@Version | ||
int version; | ||
|
||
public Simulation() {} | ||
|
||
// Getters/Setters | ||
|
||
/** | ||
* Retrieve the entity id. | ||
* | ||
* @return Id of entity. | ||
*/ | ||
public Long getEntityId() { | ||
return entityId; | ||
} | ||
|
||
// Boilerplate implementations | ||
|
||
@Override | ||
public String toString() { | ||
return "Simulation [entityId=" + entityId + ", createdDate=" + createdDate + ", lastModifiedDate=" | ||
+ lastModifiedDate + ", createdBy=" + createdBy + ", lastModifiedBy=" + lastModifiedBy + ", version=" + version | ||
+ "]"; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ain/java/com/insilicosoft/portal/svc/rip/persistence/repository/SimulationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.insilicosoft.portal.svc.rip.persistence.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.insilicosoft.portal.svc.rip.persistence.entity.Simulation; | ||
|
||
/** | ||
* Repository for {@link Simulation} objects. | ||
* | ||
* @author geoff | ||
*/ | ||
public interface SimulationRepository extends JpaRepository<Simulation, Long> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:tc:postgresql:14.4:/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.