-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELY-2496] Add integrity to existing filesystem realms using Elytron …
…Tool
- Loading branch information
1 parent
babbb20
commit 161a2fe
Showing
7 changed files
with
1,292 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
|
||
import java.util.List; | ||
|
||
import org.wildfly.common.Assert; | ||
import org.wildfly.security.auth.principal.NamePrincipal; | ||
import org.wildfly.security.auth.server.ModifiableRealmIdentity; | ||
|
@@ -31,34 +32,34 @@ | |
* A utility class to utilize methods from the {@code FileSystemSecurityRealm} class for the Elytron Tool. | ||
* | ||
* @author <a href="mailto:[email protected]">Ashpan Raskar</a> | ||
* @author <a href="mailto:[email protected]">Cameron Rodriguez</a> | ||
*/ | ||
public class FileSystemRealmUtil { | ||
|
||
/** | ||
* Converts a pre-existing unencrypted {@code FileSystemSecurityRealm} to a newly created encrypted {@code FileSystemSecurityRealm} | ||
* Copies identities from an existing {@code FileSystemSecurityRealm} to a new one. | ||
* | ||
* @param unencryptedRealm the {@code FileSystemSecurityRealm} without any encryption applied | ||
* @param encryptedRealm the {@code FileSystemSecurityRealm} configured with a SecretKey to encrypt identity data | ||
* @throws RealmUnavailableException if either realm is unavailable | ||
* @param oldRealm the existing {@code FileSystemSecurityRealm} with the identities | ||
* @param newRealm the new {@code FileSystemSecurityRealm} | ||
* @throws RealmUnavailableException if either realm is unavailable or an operation fails | ||
*/ | ||
public static void createEncryptedRealmFromUnencrypted(FileSystemSecurityRealm unencryptedRealm, FileSystemSecurityRealm encryptedRealm) throws RealmUnavailableException { | ||
Assert.checkNotNullParam("unencryptedRealm", unencryptedRealm); | ||
Assert.checkNotNullParam("encryptedRealm", encryptedRealm); | ||
public static void cloneIdentitiesToNewRealm(FileSystemSecurityRealm oldRealm, FileSystemSecurityRealm newRealm) throws RealmUnavailableException { | ||
Assert.checkNotNullParam("Old FileSystem Realm", oldRealm); | ||
Assert.checkNotNullParam("New FileSystem Realm", newRealm); | ||
|
||
ModifiableRealmIdentityIterator realmIterator = unencryptedRealm.getRealmIdentityIterator(); | ||
ModifiableRealmIdentityIterator realmIterator = oldRealm.getRealmIdentityIterator(); | ||
|
||
while (realmIterator.hasNext()) { | ||
ModifiableRealmIdentity identity = realmIterator.next(); | ||
List<Credential> credentials = ((FileSystemSecurityRealm.Identity) identity).loadCredentials(); | ||
Attributes attributes = identity.getAttributes(); | ||
ModifiableRealmIdentity oldIdentity = realmIterator.next(); | ||
List<Credential> credentials = ((FileSystemSecurityRealm.Identity) oldIdentity).loadCredentials(); | ||
Attributes attributes = oldIdentity.getAttributes(); | ||
|
||
ModifiableRealmIdentity newIdentity = encryptedRealm.getRealmIdentityForUpdate(new NamePrincipal(identity.getRealmIdentityPrincipal().getName())); | ||
ModifiableRealmIdentity newIdentity = newRealm.getRealmIdentityForUpdate(new NamePrincipal(oldIdentity.getRealmIdentityPrincipal().getName())); | ||
newIdentity.create(); | ||
newIdentity.setCredentials(credentials); | ||
newIdentity.setAttributes(attributes); | ||
newIdentity.dispose(); | ||
} | ||
realmIterator.close(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.