-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added database tables and java object to handle ISS tokens
- Loading branch information
Showing
11 changed files
with
328 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
*/ | ||
|
||
package com.redhat.rhn.domain.iss; | ||
|
||
public enum IssRole { | ||
HUB, | ||
PERIPHERAL | ||
} |
187 changes: 187 additions & 0 deletions
187
java/code/src/com/suse/manager/model/hub/IssAccessToken.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,187 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
*/ | ||
|
||
package com.suse.manager.model.hub; | ||
|
||
import org.hibernate.annotations.Type; | ||
|
||
import java.time.Instant; | ||
import java.time.ZonedDateTime; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import javax.persistence.Temporal; | ||
import javax.persistence.TemporalType; | ||
import javax.persistence.Transient; | ||
|
||
@Entity | ||
@Table(name = "suseISSAccessToken") | ||
public class IssAccessToken { | ||
|
||
private long id; | ||
|
||
private String token; | ||
|
||
private TokenType type; | ||
|
||
private String serverFqdn; | ||
|
||
private Date expirationDate; | ||
|
||
private boolean valid; | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
protected IssAccessToken() { | ||
// Used by Hibernate | ||
} | ||
|
||
/** | ||
* Build a new access token with the default expiration period of 1 year | ||
* @param typeIn the type of token | ||
* @param tokenIn the token | ||
* @param serverFqdnIn the FQDN of the server related to this token | ||
*/ | ||
public IssAccessToken(TokenType typeIn, String tokenIn, String serverFqdnIn) { | ||
this(typeIn, tokenIn, serverFqdnIn, Date.from(ZonedDateTime.now().plusYears(1).toInstant())); | ||
} | ||
|
||
/** | ||
* Build a new access token | ||
* @param typeIn the type of token | ||
* @param tokenIn the token | ||
* @param serverFqdnIn the FQDN of the server related to this token | ||
* @param expirationDateIn the instant the token expires | ||
*/ | ||
public IssAccessToken(TokenType typeIn, String tokenIn, String serverFqdnIn, Instant expirationDateIn) { | ||
this(typeIn, tokenIn, serverFqdnIn, Date.from(expirationDateIn)); | ||
} | ||
|
||
/** | ||
* Build a new access token | ||
* @param typeIn the type of token | ||
* @param tokenIn the token | ||
* @param serverFqdnIn the FQDN of the server related to this token | ||
* @param expirationDateIn the instant the token expires | ||
*/ | ||
public IssAccessToken(TokenType typeIn, String tokenIn, String serverFqdnIn, Date expirationDateIn) { | ||
this.token = tokenIn; | ||
this.type = typeIn; | ||
this.serverFqdn = serverFqdnIn; | ||
this.expirationDate = expirationDateIn; | ||
this.valid = true; | ||
} | ||
|
||
@Id | ||
@Column(name = "id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long idIn) { | ||
this.id = idIn; | ||
} | ||
|
||
@Column(name = "token") | ||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public void setToken(String tokenIn) { | ||
this.token = tokenIn; | ||
} | ||
|
||
@Column(name = "type") | ||
@Type(type = "com.suse.manager.model.hub.TokenTypeEnumType") | ||
public TokenType getType() { | ||
return type; | ||
} | ||
|
||
public void setType(TokenType typeIn) { | ||
this.type = typeIn; | ||
} | ||
|
||
@Column(name = "server_fqdn") | ||
public String getServerFqdn() { | ||
return serverFqdn; | ||
} | ||
|
||
public void setServerFqdn(String serverFqdnIn) { | ||
this.serverFqdn = serverFqdnIn; | ||
} | ||
|
||
@Column(name = "expiration_date") | ||
@Temporal(TemporalType.TIMESTAMP) | ||
public Date getExpirationDate() { | ||
return expirationDate; | ||
} | ||
|
||
public void setExpirationDate(Date expirationDateIn) { | ||
this.expirationDate = expirationDateIn; | ||
} | ||
|
||
@Column(name = "valid") | ||
public boolean isValid() { | ||
return valid; | ||
} | ||
|
||
public void setValid(boolean validIn) { | ||
this.valid = validIn; | ||
} | ||
|
||
/** | ||
* Checks if the current instance is expired. | ||
* @return true if the current date is after the expiration date | ||
*/ | ||
@Transient | ||
public boolean isExpired() { | ||
if (expirationDate == null) { | ||
return false; | ||
} | ||
|
||
return new Date().after(expirationDate); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof IssAccessToken issAccessToken)) { | ||
return false; | ||
} | ||
return Objects.equals(getToken(), issAccessToken.getToken()) && | ||
Objects.equals(getType(), issAccessToken.getType()) && | ||
Objects.equals(getServerFqdn(), issAccessToken.getServerFqdn()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getToken(), getType(), getServerFqdn()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("IssAccessToken{"); | ||
sb.append(", type=").append(type); | ||
sb.append(", serverFqdn='").append(serverFqdn).append('\''); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} |
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,24 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
*/ | ||
|
||
package com.suse.manager.model.hub; | ||
|
||
import com.redhat.rhn.domain.Labeled; | ||
|
||
public enum TokenType implements Labeled { | ||
ISSUED, | ||
CONSUMED; | ||
|
||
@Override | ||
public String getLabel() { | ||
return this.name().toLowerCase(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
java/code/src/com/suse/manager/model/hub/TokenTypeEnumType.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,27 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
*/ | ||
|
||
package com.suse.manager.model.hub; | ||
|
||
import com.redhat.rhn.domain.DatabaseEnumType; | ||
|
||
/** | ||
* Maps the {@link TokenType} enum to its label | ||
*/ | ||
public class TokenTypeEnumType extends DatabaseEnumType<TokenType> { | ||
|
||
/** | ||
* Default Constructor | ||
*/ | ||
public TokenTypeEnumType() { | ||
super(TokenType.class); | ||
} | ||
} |
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 @@ | ||
- Added entities to handle token authentication |
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,24 @@ | ||
-- | ||
-- Copyright (c) 2024 SUSE LLC | ||
-- | ||
-- This software is licensed to you under the GNU General Public License, | ||
-- version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
-- implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
-- along with this software; if not, see | ||
-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
-- | ||
|
||
CREATE TABLE suseISSAccessToken | ||
( | ||
id BIGINT CONSTRAINT suse_isstoken_id_pk PRIMARY KEY | ||
GENERATED ALWAYS AS IDENTITY, | ||
token VARCHAR(1024) NOT NULL, | ||
type iss_access_token_type_t NOT NULL, | ||
server_fqdn VARCHAR(512) NOT NULL, | ||
valid BOOLEAN, | ||
expiration_date TIMESTAMPTZ NULL | ||
); | ||
|
||
CREATE INDEX suse_isstoken_server_fqdn_type_idx | ||
ON suseISSAccessToken (server_fqdn, type); |
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
15 changes: 15 additions & 0 deletions
15
schema/spacewalk/postgres/class/iss_access_token_type_t.sql
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,15 @@ | ||
-- | ||
-- Copyright (c) 2024 SUSE LLC | ||
-- | ||
-- This software is licensed to you under the GNU General Public License, | ||
-- version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
-- implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
-- along with this software; if not, see | ||
-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
-- | ||
|
||
CREATE TYPE iss_access_token_type_t AS ENUM ( | ||
'issued', | ||
'consumed' | ||
); |
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 @@ | ||
- Added tables to handle token authentication |
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