mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
cleanup
This commit is contained in:
@@ -36,6 +36,7 @@ import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory;
|
||||
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.security.PublicKey;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -52,9 +53,9 @@ public class GpgKey implements PublicKey {
|
||||
private final String id;
|
||||
private final String owner;
|
||||
private final String raw;
|
||||
private final Set<String> contacts;
|
||||
private final Set<Person> contacts;
|
||||
|
||||
public GpgKey(String id, String owner, String raw, Set<String> contacts) {
|
||||
public GpgKey(String id, String owner, String raw, Set<Person> contacts) {
|
||||
this.id = id;
|
||||
this.owner = owner;
|
||||
this.raw = raw;
|
||||
@@ -80,7 +81,7 @@ public class GpgKey implements PublicKey {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getContacts() {
|
||||
public Set<Person> getContacts() {
|
||||
return contacts;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public abstract class PublicKeyMapper {
|
||||
}
|
||||
|
||||
@Mapping(target = "attributes", ignore = true)
|
||||
@Mapping(target = "raw", ignore = true)
|
||||
abstract RawGpgKeyDto map(RawGpgKey rawGpgKey);
|
||||
|
||||
@ObjectFactory
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
package sonia.scm.security.gpg;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.ContextEntry;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.security.NotPublicKeyException;
|
||||
import sonia.scm.security.PublicKeyCreatedEvent;
|
||||
import sonia.scm.security.PublicKeyDeletedEvent;
|
||||
import sonia.scm.store.DataStore;
|
||||
import sonia.scm.store.DataStoreFactory;
|
||||
@@ -38,6 +38,7 @@ import sonia.scm.user.UserPermissions;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -80,22 +81,24 @@ public class PublicKeyStore {
|
||||
RawGpgKey key = new RawGpgKey(master, displayName, username, rawKey, getContactsFromPublicKey(rawKey), Instant.now());
|
||||
|
||||
store.put(master, key);
|
||||
eventBus.post(new PublicKeyCreatedEvent());
|
||||
|
||||
return key;
|
||||
|
||||
}
|
||||
|
||||
private Set<String> getContactsFromPublicKey(String rawKey) {
|
||||
Set<String> contacts = new HashSet<>();
|
||||
private Set<Person> getContactsFromPublicKey(String rawKey) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
Optional<PGPPublicKey> publicKeyFromRawKey = getFromRawKey(rawKey);
|
||||
publicKeyFromRawKey.ifPresent(pgpPublicKey -> pgpPublicKey.getUserIDs().forEachRemaining(contacts::add));
|
||||
return contacts;
|
||||
publicKeyFromRawKey.ifPresent(pgpPublicKey -> pgpPublicKey.getUserIDs().forEachRemaining(userIds::add));
|
||||
|
||||
return userIds.stream().map(Person::toPerson).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
RawGpgKey rawGpgKey = store.get(id);
|
||||
if (rawGpgKey != null) {
|
||||
UserPermissions.modify(rawGpgKey.getOwner()).check();
|
||||
UserPermissions.changePublicKeys(rawGpgKey.getOwner()).check();
|
||||
store.remove(id);
|
||||
eventBus.post(new PublicKeyDeletedEvent());
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.xml.XmlInstantAdapter;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
@@ -49,7 +50,7 @@ public class RawGpgKey {
|
||||
private String displayName;
|
||||
private String owner;
|
||||
private String raw;
|
||||
private Set<String> contacts;
|
||||
private Set<Person> contacts;
|
||||
|
||||
@XmlJavaTypeAdapter(XmlInstantAdapter.class)
|
||||
private Instant created;
|
||||
|
||||
Reference in New Issue
Block a user