-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated code lifecycle: Support multiple SSH keys per user (#9478)
- Loading branch information
1 parent
462eca1
commit 2c6c792
Showing
47 changed files
with
1,917 additions
and
587 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
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
131 changes: 131 additions & 0 deletions
131
src/main/java/de/tum/cit/aet/artemis/programming/domain/UserSshPublicKey.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,131 @@ | ||
package de.tum.cit.aet.artemis.programming.domain; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import jakarta.annotation.Nullable; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
|
||
import org.hibernate.annotations.Cache; | ||
import org.hibernate.annotations.CacheConcurrencyStrategy; | ||
|
||
import de.tum.cit.aet.artemis.core.domain.DomainObject; | ||
|
||
/** | ||
* A public SSH key of a user. | ||
*/ | ||
@Entity | ||
@Table(name = "user_public_ssh_key") | ||
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | ||
public class UserSshPublicKey extends DomainObject { | ||
|
||
/** | ||
* The user who is owner of the public key | ||
*/ | ||
@NotNull | ||
@Column(name = "user_id") | ||
private long userId; | ||
|
||
/** | ||
* The label of the SSH key shwon in the UI | ||
*/ | ||
@Size(max = 50) | ||
@Column(name = "label", length = 50) | ||
private String label; | ||
|
||
/** | ||
* The actual full public ssh key of a user used to authenticate git clone and git push operations if available | ||
*/ | ||
@NotNull | ||
@Column(name = "public_key") | ||
private String publicKey; | ||
|
||
/** | ||
* A hash of the public ssh key for fast comparison in the database (with an index) | ||
*/ | ||
@Size(max = 100) | ||
@Column(name = "key_hash") | ||
private String keyHash; | ||
|
||
/** | ||
* The creation date of the public SSH key | ||
*/ | ||
@Column(name = "creation_date") | ||
private ZonedDateTime creationDate = null; | ||
|
||
/** | ||
* The last used date of the public SSH key | ||
*/ | ||
@Nullable | ||
@Column(name = "last_used_date") | ||
private ZonedDateTime lastUsedDate = null; | ||
|
||
/** | ||
* The expiry date of the public SSH key | ||
*/ | ||
@Nullable | ||
@Column(name = "expiry_date") | ||
private ZonedDateTime expiryDate = null; | ||
|
||
public @NotNull long getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(@NotNull long userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public @Size(max = 50) String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(@Size(max = 50) String label) { | ||
this.label = label; | ||
} | ||
|
||
public String getPublicKey() { | ||
return publicKey; | ||
} | ||
|
||
public void setPublicKey(String publicKey) { | ||
this.publicKey = publicKey; | ||
} | ||
|
||
@Nullable | ||
public @Size(max = 100) String getKeyHash() { | ||
return keyHash; | ||
} | ||
|
||
public void setKeyHash(@Nullable @Size(max = 100) String keyHash) { | ||
this.keyHash = keyHash; | ||
} | ||
|
||
public ZonedDateTime getCreationDate() { | ||
return creationDate; | ||
} | ||
|
||
public void setCreationDate(ZonedDateTime creationDate) { | ||
this.creationDate = creationDate; | ||
} | ||
|
||
@Nullable | ||
public ZonedDateTime getLastUsedDate() { | ||
return lastUsedDate; | ||
} | ||
|
||
public void setLastUsedDate(@Nullable ZonedDateTime lastUsedDate) { | ||
this.lastUsedDate = lastUsedDate; | ||
} | ||
|
||
@Nullable | ||
public ZonedDateTime getExpiryDate() { | ||
return expiryDate; | ||
} | ||
|
||
public void setExpiryDate(@Nullable ZonedDateTime expiryDate) { | ||
this.expiryDate = expiryDate; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/de/tum/cit/aet/artemis/programming/dto/UserSshPublicKeyDTO.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,16 @@ | ||
package de.tum.cit.aet.artemis.programming.dto; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import de.tum.cit.aet.artemis.programming.domain.UserSshPublicKey; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record UserSshPublicKeyDTO(Long id, String label, String publicKey, String keyHash, ZonedDateTime creationDate, ZonedDateTime lastUsedDate, ZonedDateTime expiryDate) { | ||
|
||
public static UserSshPublicKeyDTO of(UserSshPublicKey userSshPublicKey) { | ||
return new UserSshPublicKeyDTO(userSshPublicKey.getId(), userSshPublicKey.getLabel(), userSshPublicKey.getPublicKey(), userSshPublicKey.getKeyHash(), | ||
userSshPublicKey.getCreationDate(), userSshPublicKey.getLastUsedDate(), userSshPublicKey.getExpiryDate()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/de/tum/cit/aet/artemis/programming/repository/UserSshPublicKeyRepository.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 @@ | ||
package de.tum.cit.aet.artemis.programming.repository; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository; | ||
import de.tum.cit.aet.artemis.programming.domain.UserSshPublicKey; | ||
|
||
@Profile(PROFILE_CORE) | ||
@Repository | ||
public interface UserSshPublicKeyRepository extends ArtemisJpaRepository<UserSshPublicKey, Long> { | ||
|
||
List<UserSshPublicKey> findAllByUserId(Long userId); | ||
|
||
Optional<UserSshPublicKey> findByKeyHash(String keyHash); | ||
|
||
Optional<UserSshPublicKey> findByIdAndUserId(Long keyId, Long userId); | ||
|
||
boolean existsByIdAndUserId(Long id, Long userId); | ||
|
||
boolean existsByUserId(Long userId); | ||
} |
Oops, something went wrong.