mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
migrate securityV1 permissions
This commit is contained in:
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
@@ -46,6 +47,44 @@ public class XmlSecurityV1UpdateStep implements UpdateStep {
|
||||
|
||||
forAllAdmins(user -> createSecurityEntry(user, false, securityStore),
|
||||
group -> createSecurityEntry(group, true, securityStore));
|
||||
|
||||
mapV1Permissions(securityStore);
|
||||
}
|
||||
|
||||
private void mapV1Permissions(ConfigurationEntryStore<AssignedPermission> securityStore) throws JAXBException {
|
||||
Path v1SecurityFile = determineConfigDirectory().resolve("securityV1" + StoreConstants.FILE_EXTENSION);
|
||||
|
||||
if (!v1SecurityFile.toFile().exists()) {
|
||||
LOG.info("no v1 file for security found");
|
||||
return;
|
||||
}
|
||||
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(XmlSecurityV1UpdateStep.V1Security.class);
|
||||
V1Security v1Security = (V1Security) jaxbContext.createUnmarshaller().unmarshal(v1SecurityFile.toFile());
|
||||
|
||||
v1Security.entries.forEach(assignedPermission -> {
|
||||
|
||||
String newPermission = "";
|
||||
if (assignedPermission.value.permission != null && !assignedPermission.value.permission.isEmpty()) {
|
||||
String[] splitPermission = assignedPermission.value.permission.split(":");
|
||||
switch(splitPermission[2]) {
|
||||
case "OWNER":
|
||||
newPermission = "repository:*";
|
||||
break;
|
||||
case "WRITE":
|
||||
newPermission = "repository:read,pull,push:*";
|
||||
break;
|
||||
case "READ":
|
||||
newPermission = "repository:read,pull:*";
|
||||
}
|
||||
}
|
||||
|
||||
securityStore.put(new AssignedPermission(
|
||||
assignedPermission.value.name,
|
||||
Boolean.parseBoolean(assignedPermission.value.groupPermission),
|
||||
newPermission
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
private void forAllAdmins(Consumer<String> userConsumer, Consumer<String> groupConsumer) throws JAXBException {
|
||||
@@ -70,10 +109,9 @@ public class XmlSecurityV1UpdateStep implements UpdateStep {
|
||||
Arrays.stream(entries.split(",")).forEach(consumer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Version getTargetVersion() {
|
||||
return parse("2.0.0");
|
||||
return parse("2.0.1");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,4 +140,29 @@ public class XmlSecurityV1UpdateStep implements UpdateStep {
|
||||
@XmlElement(name = "admin-groups")
|
||||
private String adminGroups;
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlRootElement(name = "configuration")
|
||||
private static class V1Security {
|
||||
@XmlElement(name = "entry")
|
||||
private List<Entry> entries;
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class Entry {
|
||||
@XmlElement(name = "key")
|
||||
private String key;
|
||||
@XmlElement(name = "value")
|
||||
private Value value;
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class Value {
|
||||
@XmlElement(name = "permission")
|
||||
String permission;
|
||||
@XmlElement(name = "name")
|
||||
String name;
|
||||
@XmlElement(name = "group-permission")
|
||||
String groupPermission;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user