Skip to content

Commit

Permalink
Deprectated access key migration stuff and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
golsch committed Oct 24, 2024
1 parent b2481d5 commit 5a6b98c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static void migrateAccessKeyPairs() throws MCRException {
migrateAccessKeys();
}

@Deprecated
@MCRCommand(syntax = "migrate all access keys",
help = "Migrates all MIR access key to MCR access keys."
+ " Should be used to migrate from version 2021.05.")
Expand All @@ -99,6 +100,7 @@ public static void migrateAccessKeys() throws MCRException {
LOGGER.info("migrated all keys to MCR access keys");
}

@Deprecated
@MCRCommand(syntax = "migrate all access key user attributes",
help = "Hashes all access key user attributes."
+ " Is only necessary if the secrets are hashed."
Expand All @@ -111,20 +113,19 @@ public static void migrateAccessKeyUserAttributes() {
users = listUsersWithMIRAccessKeyUserAttribute(offset, limit);
for (final MCRUser user : users) {
final List<MCRUserAttribute> attributes = user.getAttributes()
.stream()
.filter(attribute -> attribute.getName().startsWith(ACCESS_KEY_PREFIX))
.collect(Collectors.toList());
.stream()
.filter(attribute -> attribute.getName().startsWith(ACCESS_KEY_PREFIX))
.collect(Collectors.toList());
for (MCRUserAttribute attribute : attributes) {
final String attributeName = attribute.getName();
final MCRObjectID objectId = MCRObjectID.getInstance(attributeName.substring(
attributeName.indexOf("_") + 1));
attributeName.indexOf("_") + 1));
attribute.setName(MCRAccessKeyUtils.ACCESS_KEY_PREFIX + objectId.toString());
attribute.setValue(MCRAccessKeyManager.hashSecret(attribute.getValue(), objectId));
}
}
offset += limit;
}
while (users.size() == limit);
} while (users.size() == limit);
}

/**
Expand Down Expand Up @@ -216,7 +217,7 @@ private static synchronized void createAccessKey(final MCRObjectID objectId, fin
}
}

/**
/**
* Removes {@link MIRAccessKey}
*
* @param accessKey the {@link MIRAccessKey}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.mycore.mcr.acl.accesskey.model.MCRAccessKey;
import org.mycore.mir.authorization.accesskeys.backend.MIRAccessKeyPair;

@Deprecated
public class MIRAccessKeyManagerTest extends MCRJPATestCase {

private static final String OBJECT_ID = "mcr_test_00000001";
Expand Down Expand Up @@ -103,7 +104,6 @@ public void testCreateSameKeyPair() {
MIRAccessKeyManager.createKeyPair(sameAccKP);
}


@Test
public void testGetKeyPair() {
final MCRAccessKey accessKeyRead = new MCRAccessKey(READ_KEY, PERMISSION_READ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ public void setUp() throws Exception {
super.setUp();
objectId = MCRObjectID.getInstance(OBJECT_ID);
}

@Override
protected Map<String, String> getTestProperties() {
Map<String, String> testProperties = super.getTestProperties();
testProperties.put("MCR.Metadata.Type.test", Boolean.TRUE.toString());
return testProperties;
}

@Deprecated
@Test
public void testMigrationAccessKeyPair() throws Exception {
final MIRAccessKeyPair accessKeyPair = new MIRAccessKeyPair(objectId, READ_KEY, WRITE_KEY);
Expand All @@ -83,6 +84,7 @@ public void testMigrationAccessKeyPair() throws Exception {
assertEquals(PERMISSION_WRITE, accessKeyWrite.getType());
}

@Deprecated
@Test
public void testMigrateMIRAccessKey() throws Exception {
final MIRAccessKey mirAccessKey = new MIRAccessKey(READ_KEY, PERMISSION_READ);
Expand All @@ -103,6 +105,7 @@ public void testMigrateMIRAccessKey() throws Exception {
assertTrue(accessKey.getIsActive());
}

@Deprecated
@Test
public void testUserAttributeMigration() throws Exception {
final MCRUser user1 = new MCRUser("junit");
Expand Down

0 comments on commit 5a6b98c

Please sign in to comment.