Use an LDAP security scheme to secure an application.
| Resources | |
|---|---|
| Files: |
/home/student/AD248/labs/security-ldaprealm
|
| Application URL: | http://127.0.0.1:8080/guessLDAP |
Outcomes
You should be able to enable authentication in an application using a LDAP login module.
Before beginning the guided exercise, run the following command to prepare the environment:
[student@workstation ~]$ lab start security-ldaprealm
This exercise uses an LDAP server that runs as a container in the workstation machine.
You can inspect the LDAP schema in the /home/student/AD248/labs/security-ldaprealm/schema.ldif file.
Instructions
Start the standalone instance of Red Hat JBoss Enterprise Application Platform (JBoss EAP) by running the following command that uses /home/student/AD248/labs/security-ldaprealm/standalone as the base directory:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./standalone.sh \-Djboss.server.base.dir=/home/student/AD248/labs/security-ldaprealm/standalone/
Review the guessLDAP application security configuration.
The guessLDAP application is already configured to require authentication. Step through the following configuration files to see how it requires authentication.
Inspect the application in the /home/student/AD248/labs/security-ldaprealm/guessLDAP directory.
Explore the /home/student/AD248/labs/security-ldaprealm/guessLDAP/src/main/webapp/WEB-INF/jboss-web.xml file.
...output omitted...
<jboss-web>
<security-domain>ad248_ldap</security-domain>
</jboss-web>The security-domain points to an ad248_ldap security domain used by the application.
Configure the ad248_ldap security domain.
The LDAP server is running in a ldap container on the workstation machine on the 10389 port.
In a new terminal window, run the following command to execute an ldapsearch within the LDAP container:
[student@workstation ~]$podman exec -it ldap \ldapsearch -x -D "cn=admin,dc=example,dc=com" \-w redhat123 -b "dc=example,dc=com"...output omitted... # Admin, Roles, example.com dn: cn=Admin,ou=Roles,dc=example,dc=com objectClass: top objectClass: groupOfNames cn: Admin member: uid=alice,ou=Users,dc=example,dc=com # search result search: 2 result: 0 Success # numResponses: 7 # numEntries: 6
Start the management CLI with the following commands:
[student@workstation ~]$cd /opt/jboss-eap-7.4/bin[student@workstation bin]$./jboss-cli.sh --connect
Create the ad248_ldap security domain with a default cache type:
[standalone@localhost:9990]/subsystem=security/security-domain\=ad248_ldap:add(cache-type=default){"outcome" => "success"}
Create the authentication child of the security domain:
[standalone@localhost:9990]/subsystem=security/security-domain\=ad248_ldap/authentication=classic:add{ "outcome" => "success", "response-headers" => { "operation-requires-reload" => true, "process-state" => "reload-required" } }
The output indicates that a server reload is required. You can safely ignore that message, because you reload the server in next steps.
Create an LDAP login module within the new legacy security domain with the following characteristics:
| Parameter | Value |
|---|---|
Name
|
LdapExtended
|
Code
|
LdapExtended
|
Module option java.naming.factory.initial
|
com.sun.jndi.ldap.LdapCtxFactory
|
Module option java.naming.provider.url
|
ldap://localhost:10389
|
Module option java.naming.security.authentication
|
simple
|
Module option bindDN
|
cn=admin,dc=example,dc=com
|
Module option bindCredential
|
redhat123
|
Module option baseCtxDN
|
ou=Users,dc=example,dc=com
|
Module option baseFilter
|
(uid={0})
|
Module option rolesCtxDN
|
ou=Roles,dc=example,dc=com
|
Module option roleFilter
|
(member={1})
|
Module option roleAttributeID
|
uid
|
Use the following command to create the security domain:
[standalone@localhost:9990]/subsystem=security/security-domain=ad248_ldap\/authentication=classic/login-module=LdapExtended:add\(code=LdapExtended, flag=required, module-options=\[("java.naming.factory.initial"=>"com.sun.jndi.ldap.LdapCtxFactory"),\("java.naming.provider.url"=>"ldap://localhost:10389"),\("java.naming.security.authentication"=>"simple"),\("bindDN"=>"cn=admin,dc=example,dc=com"),("bindCredential"=>"redhat123"),\("baseCtxDN"=>"ou=Users,dc=example,dc=com"),\("baseFilter"=>"(uid={0})"),("rolesCtxDN"=>"ou=Roles,dc=example,dc=com"),\("roleFilter"=>"(member={1})"), ("roleAttributeID"=>"uid")]){ "outcome" => "success", "response-headers" => { "operation-requires-reload" => true, "process-state" => "reload-required" } }
Enter the following command in the CLI to verify the ad248_ldap security domain settings:
[standalone@localhost:9990]/subsystem=security/security-domain=\ad248_ldap:read-resource(recursive=true){ "outcome" => "success", "result" => { "cache-type" => "default", "acl" => undefined, "audit" => undefined, "authentication" => {"classic" => { "login-modules" => [{ "code" => "LdapExtended", "flag" => "required", "module" => undefined, "module-options" => { "java.naming.factory.initial" => "com.sun.jndi.ldap.LdapCtxFactory", "java.naming.provider.url" => "ldap://localhost:10389", "java.naming.security.authentication" => "simple", "bindDN" => "cn=admin,dc=example,dc=com", "bindCredential" => "redhat123", "baseCtxDN" => "ou=Users,dc=example,dc=com", "baseFilter" => "(uid={0})", "rolesCtxDN" => "ou=Roles,dc=example,dc=com", "roleFilter" => "(member={1})", "roleAttributeID" => "uid" } }], "login-module" => {"LdapExtended" => { "code" => "LdapExtended", "flag" => "required", "module" => undefined, "module-options" => { "java.naming.factory.initial" => "com.sun.jndi.ldap.LdapCtxFactory", "java.naming.provider.url" => "ldap://localhost:10389", "java.naming.security.authentication" => "simple", "bindDN" => "cn=admin,dc=example,dc=com", "bindCredential" => "redhat123", "baseCtxDN" => "ou=Users,dc=example,dc=com", "baseFilter" => "(uid={0})", "rolesCtxDN" => "ou=Roles,dc=example,dc=com", "roleFilter" => "(member={1})", "roleAttributeID" => "uid" } }} }}, "authorization" => undefined, "identity-trust" => undefined, "jsse" => undefined, "mapping" => undefined }, "response-headers" => {"process-state" => "reload-required"} }
Reload the server to allow the changes to take effect.
[standalone@localhost:9990] :reloadTest the LDAP security domain.
Package the guessLDAP application.
Open a new terminal and enter the following command to create a WAR file:
[student@workstation ~]$cd /home/student/AD248/labs/security-ldaprealm/\guessLDAP/src/main/webapp[student@workstation webapp]$jar -cvf /tmp/guessLDAP.war .
Use the management console or the management CLI, deploy the /tmp/guessLDAP.war file.
[standalone@localhost:9990 /] deploy /tmp/guessLDAP.warOn the workstation machine, navigate to http://localhost:8080/guessLDAP.
You should be prompted to log in if the login module was configured correctly.
Use alice as the username and password123 as the password to log in successfully.
If authentication is successful, then you should see the guessLDAP application.
Undeploy the guessLDAP application form the standalone server using the CLI:
[standalone@localhost:9990] undeploy guessLDAP.warExit the CLI and stop the running instance of JBoss EAP.