forked from wildfly-security-incubator/elytron-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
## Using a regex role mapper | ||
|
||
This example demonstrates the use of `regex-role-mapper` resource that was added to elytron subsystem in order to simplify a mapping of roles in the Elytron security domain to other roles with the use of regular expressions. | ||
|
||
### Set Up | ||
|
||
Clone the ```elytron-examples``` repo locally: | ||
|
||
``` | ||
git clone https://github.com/wildfly-security-incubator/elytron-examples | ||
cd elytron-examples/regex-role-mapper | ||
``` | ||
|
||
### Server configuration | ||
|
||
Run the server with: | ||
|
||
``` | ||
$SERVER_HOME/bin/standalone.sh | ||
``` | ||
|
||
The following command can now be used to configure the ```regex-role-mapper``` in the subsystem. | ||
|
||
``` | ||
$SERVER_HOME/bin/jboss-cli.sh --connect --file=$PATH_TO_ELYTRON_EXAMPLES/regex-role-mapper/configure-elytron.cli | ||
``` | ||
|
||
The configure-elytron.cli script configured the server to use the regular expression role mapper that maps the roles to only represent a last letters of a role that are after the last `-` sign. | ||
In other words it maps roles that match .*-([a-z]*) to the role $1. | ||
|
||
Then the script added a user `joe` with the following roles: `["123-user","123-admin"]` | ||
|
||
|
||
### Test regex role mapper | ||
|
||
Now connect to the WildFly CLI with | ||
|
||
``` | ||
$SERVER_HOME/bin/jboss-cli.sh --connect | ||
``` | ||
|
||
and run the following command: | ||
|
||
``` | ||
/subsystem=elytron/security-domain=mySD:read-identity(name=joe) | ||
``` | ||
|
||
you will see the following output: | ||
``` | ||
{ | ||
"outcome" => "success", | ||
"result" => { | ||
"name" => "joe", | ||
"attributes" => {"Roles" => [ | ||
"123-user", | ||
"123-admin" | ||
]}, | ||
"roles" => [ | ||
"admin", | ||
"user" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
The above output means that the regex role mapper successfully mapped roles from the `Roles` attribute to be `admin` and `user` only. |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Batch script to enable elytron for the quickstart application in the JBoss EAP server | ||
|
||
# Start batching commands | ||
batch | ||
|
||
/subsystem=elytron/filesystem-realm=myFsRealm:add(path=my-fs-realm-users,relative-to=jboss.server.config.dir) | ||
|
||
/subsystem=elytron/filesystem-realm=myFsRealm:add-identity(identity=joe) | ||
|
||
/subsystem=elytron/filesystem-realm=myFsRealm:add-identity-attribute(identity=joe, name=Roles, value=["123-user","123-admin"]) | ||
|
||
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=Roles) | ||
|
||
/subsystem=elytron/regex-role-mapper=rrm:add(pattern=".*-([a-z]*)", replacement="$1", keep-non-mapped="false", replace-all="false") | ||
|
||
/subsystem=elytron/security-domain=mySD:add(realms=[{realm=myFsRealm,role-decoder=from-roles-attribute}],role-mapper=rrm,default-realm=myFsRealm,permission-mapper=default-permission-mapper) | ||
|
||
# Run the batch commands | ||
run-batch | ||
|
||
# Reload the server configuration | ||
reload | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/subsystem=elytron/security-domain=mySD:remove() | ||
|
||
/subsystem=elytron/regex-role-mapper=rrm:remove() | ||
|
||
/subsystem=elytron/simple-role-decoder=from-roles-attribute:remove() | ||
|
||
/subsystem=elytron/filesystem-realm=myFsRealm:remove-identity(identity=joe) | ||
|
||
/subsystem=elytron/filesystem-realm=myFsRealm:remove() | ||
|
||
reload | ||
|