Skip to content

Commit

Permalink
Add client last used info (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Davide Marcato <[email protected]>
  • Loading branch information
enricovianello and darcato authored Apr 3, 2024
1 parent 1924382 commit 543fc64
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 4 deletions.
2 changes: 1 addition & 1 deletion openid-connect-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>openid-connect-parent</artifactId>
<groupId>org.mitre</groupId>
<version>1.3.6.cnaf-20240119</version>
<version>1.3.6.cnaf-20240207</version>
<relativePath>..</relativePath>
</parent>
<artifactId>openid-connect-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openid-connect-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>openid-connect-parent</artifactId>
<groupId>org.mitre</groupId>
<version>1.3.6.cnaf-20240119</version>
<version>1.3.6.cnaf-20240207</version>
<relativePath>..</relativePath>
</parent>
<artifactId>openid-connect-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.Convert;
Expand All @@ -42,8 +43,10 @@
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
Expand Down Expand Up @@ -149,6 +152,7 @@ public class ClientDetailsEntity implements ClientDetails {
private Date createdAt; // time the client was created
private boolean clearAccessTokensOnRefresh = true; // do we clear access tokens on refresh?
private Integer deviceCodeValiditySeconds; // timeout for device codes
private ClientLastUsedEntity clientLastUsed; // last used info

/** fields for UMA */
private Set<String> claimsRedirectUris;
Expand Down Expand Up @@ -982,6 +986,22 @@ public void setClearAccessTokensOnRefresh(boolean clearAccessTokensOnRefresh) {
this.clearAccessTokensOnRefresh = clearAccessTokensOnRefresh;
}

/**
* @return the clientLastUsed entity
*/
@OneToOne(mappedBy="client", cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
public ClientLastUsedEntity getClientLastUsed() {
return clientLastUsed;
}

/**
* @param clientLastUsed instance with the date of last use of this client
*/
public void setClientLastUsed(ClientLastUsedEntity clientLastUsed) {
this.clientLastUsed = clientLastUsed;
}

/**
* @return the claimsRedirectUris
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mitre.oauth2.model;

import java.time.LocalDate;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "client_last_used")
public class ClientLastUsedEntity {

@Id
@Column(name = "client_details_id")
private Long id;

@OneToOne(cascade = CascadeType.ALL)
@MapsId
@JoinColumn(name = "client_details_id")
private ClientDetailsEntity client;

@Column(name = "last_used", nullable = false)
private LocalDate lastUsed;

public ClientLastUsedEntity() {
// empty constructor
}

public ClientLastUsedEntity(ClientDetailsEntity client, LocalDate lastUsed) {
this.client = client;
this.lastUsed = lastUsed;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public ClientDetailsEntity getClient() {
return client;
}

public void setClient(ClientDetailsEntity client) {
this.client = client;
}

public LocalDate getLastUsed() {
return lastUsed;
}

public void setLastUsed(LocalDate lastUsed) {
this.lastUsed = lastUsed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ CREATE TABLE IF NOT EXISTS client_details (
UNIQUE (client_id)
);

CREATE TABLE IF NOT EXISTS client_last_used (
client_details_id BIGINT PRIMARY KEY,
last_used TIMESTAMP NOT NULL,
CONSTRAINT fk_client_last_used FOREIGN KEY (client_details_id) REFERENCES client_details(id)
);

CREATE TABLE IF NOT EXISTS client_request_uri (
owner_id BIGINT,
request_uri VARCHAR(2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ CREATE TABLE IF NOT EXISTS client_details (
UNIQUE (client_id)
);

CREATE TABLE IF NOT EXISTS client_last_used (
client_details_id BIGINT PRIMARY KEY,
last_used TIMESTAMP NOT NULL,
CONSTRAINT fk_client_last_used FOREIGN KEY (client_details_id) REFERENCES client_details(id)
);

CREATE TABLE IF NOT EXISTS client_request_uri (
owner_id BIGINT,
request_uri VARCHAR(2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ CREATE TABLE IF NOT EXISTS client_details (
UNIQUE (client_id)
);

CREATE TABLE IF NOT EXISTS client_last_used (
client_details_id BIGINT PRIMARY KEY,
last_used TIMESTAMP NOT NULL,
CONSTRAINT fk_client_last_used FOREIGN KEY (client_details_id) REFERENCES client_details(id)
);

CREATE TABLE IF NOT EXISTS client_request_uri (
owner_id BIGINT,
request_uri VARCHAR(2000)
Expand Down
2 changes: 1 addition & 1 deletion openid-connect-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.mitre</groupId>
<artifactId>openid-connect-parent</artifactId>
<version>1.3.6.cnaf-20240119</version>
<version>1.3.6.cnaf-20240207</version>
<relativePath>..</relativePath>
</parent>
<build>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.mitre</groupId>
<artifactId>openid-connect-parent</artifactId>
<version>1.3.6.cnaf-20240119</version>
<version>1.3.6.cnaf-20240207</version>
<name>MITREid Connect</name>
<packaging>pom</packaging>
<parent>
Expand Down

0 comments on commit 543fc64

Please sign in to comment.