mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-04 08:58:22 +02:00
Add created date to api key
This commit is contained in:
@@ -31,6 +31,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -40,6 +41,7 @@ public class ApiKeyDto extends HalRepresentation {
|
||||
private String displayName;
|
||||
@NotEmpty
|
||||
private String permissionRole;
|
||||
private Instant created;
|
||||
|
||||
public ApiKeyDto(Links links) {
|
||||
super(links);
|
||||
|
||||
@@ -27,14 +27,22 @@ package sonia.scm.security;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ApiKey {
|
||||
private final String id;
|
||||
private final String displayName;
|
||||
private final String permissionRole;
|
||||
private final Instant created;
|
||||
|
||||
ApiKey(ApiKeyWithPassphrase apiKeyWithPassphrase) {
|
||||
this(apiKeyWithPassphrase.getId(), apiKeyWithPassphrase.getDisplayName(), apiKeyWithPassphrase.getPermissionRole());
|
||||
this(
|
||||
apiKeyWithPassphrase.getId(),
|
||||
apiKeyWithPassphrase.getDisplayName(),
|
||||
apiKeyWithPassphrase.getPermissionRole(),
|
||||
apiKeyWithPassphrase.getCreated()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.time.Instant.now;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.apache.commons.lang.RandomStringUtils.random;
|
||||
@@ -79,7 +80,7 @@ public class ApiKeyService {
|
||||
String passphrase = passphraseGenerator.get();
|
||||
String hashedPassphrase = passwordService.encryptPassword(passphrase);
|
||||
final String id = keyGenerator.createKey();
|
||||
ApiKeyWithPassphrase key = new ApiKeyWithPassphrase(id, name, permissionRole, hashedPassphrase);
|
||||
ApiKeyWithPassphrase key = new ApiKeyWithPassphrase(id, name, permissionRole, hashedPassphrase, now());
|
||||
Lock lock = locks.get(user).writeLock();
|
||||
lock.lock();
|
||||
try {
|
||||
|
||||
@@ -28,10 +28,13 @@ import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import sonia.scm.xml.XmlInstantAdapter;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import java.time.Instant;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@@ -44,4 +47,6 @@ class ApiKeyWithPassphrase {
|
||||
@XmlElement(name = "permission-role")
|
||||
private String permissionRole;
|
||||
private String passphrase;
|
||||
@XmlJavaTypeAdapter(XmlInstantAdapter.class)
|
||||
private Instant created;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user