此内容没有您所选择的语言版本。
7.6.5. Pass Additional Security For EJB Authentication
By default, when you make a remote call to an EJB deployed to the application server, the connection to the server is authenticated and any request received over this connection is executed using the credentials that authenticated the connection. Authentication at the connection level is dependent on the capabilities of the underlying SASL (Simple Authentication and Security Layer) mechanisms. Rather than write custom SASL mechanisms, you can open and authenticate a connection to the server, then later add additional security tokens prior to invoking an EJB. This topic describes how to pass additional information on the existing client connection for EJB authentication.
Procedure 7.13. Pass Security Information for EJB Authentication
Create the client side interceptor
This interceptor must implement theorg.jboss.ejb.client.EJBClientInterceptor
. The interceptor is expected to pass the additional security token through the context data map, which can be obtained via a call toEJBClientInvocationContext.getContextData()
. The following is an example of client side interceptor code that creates an additional security token:Copy to Clipboard Copied! Toggle word wrap Toggle overflow For information on how to plug the client interceptor into an application, refer to Section 7.6.6, “Use a Client Side Interceptor in an Application”.Create and configure the server side container interceptor
Container interceptor classes are simple Plain Old Java Objects (POJOs). They use the@javax.annotation.AroundInvoke
to mark the method that is invoked during the invocation on the bean. For more information about container interceptors, refer to: Section 7.6.1, “About Container Interceptors”.Create the container interceptor
This interceptor retrieves the security authentication token from the context and passes it to the JAAS (Java Authentication and Authorization Service) domain for verification. The following is an example of container interceptor code:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure the container interceptor
For information on how to configure server side container interceptors, refer to: Section 7.6.3, “Configure a Container Interceptor”.
Create the JAAS LoginModule
This custom module performs the authentication using the existing authenticated connection information plus any additional security token. The following is a shortened example of code that uses the additional security token and performs the authentication. The complete code example can be viewed in theejb-security-interceptors
quickstart that ships with JBoss EAP 6.3 or later.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the Custom LoginModule to the Chain
You must add the new custom LoginModule to the correct location the chain so that it is invoked in the correct order. In this example, theSaslPlusLoginModule
must be chained before the LoginModule that loads the roles with thepassword-stacking
option set.Configure the LoginModule Order using the Management CLI
The following is an example of Management CLI commands that chain the customSaslPlusLoginModule
before theRealmDirect
LoginModule that sets thepassword-stacking
option.For more information about the Management CLI, refer to the chapter entitled Management Interfaces in the Administration and Configuration Guide for JBoss EAP 6 located on the Customer Portal at https://access.redhat.com/site/documentation/JBoss_Enterprise_Application_Platform//subsystem=security/security-domain=quickstart-domain:add(cache-type=default) /subsystem=security/security-domain=quickstart-domain/authentication=classic:add /subsystem=security/security-domain=quickstart-domain/authentication=classic/login-module=DelegationLoginModule:add(code=org.jboss.as.quickstarts.ejb_security_plus.SaslPlusLoginModule,flag=optional,module-options={password-stacking=useFirstPass}) /subsystem=security/security-domain=quickstart-domain/authentication=classic/login-module=RealmDirect:add(code=RealmDirect,flag=required,module-options={password-stacking=useFirstPass})
/subsystem=security/security-domain=quickstart-domain:add(cache-type=default) /subsystem=security/security-domain=quickstart-domain/authentication=classic:add /subsystem=security/security-domain=quickstart-domain/authentication=classic/login-module=DelegationLoginModule:add(code=org.jboss.as.quickstarts.ejb_security_plus.SaslPlusLoginModule,flag=optional,module-options={password-stacking=useFirstPass}) /subsystem=security/security-domain=quickstart-domain/authentication=classic/login-module=RealmDirect:add(code=RealmDirect,flag=required,module-options={password-stacking=useFirstPass})
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure the LoginModule Order Manually
The following is an example of XML that configures the LoginModule order in thesecurity
subsystem of the server configuration file. The customSaslPlusLoginModule
must precede theRealmDirect
LoginModule so that it can verify the remote user before the user roles are loaded and thepassword-stacking
option is set.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Create the Remote Client
In the following code example, assume theadditional-secret.properties
file accessed by the JAAS LoginModule above contains the following property:quickstartUser=7f5cc521-5061-4a5b-b814-bdc37f021acc
quickstartUser=7f5cc521-5061-4a5b-b814-bdc37f021acc
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following code demonstrates how create the security token and set it before the EJB call. The secret token is hard-coded for demonstration purposes only. This client simply prints the results to the console.Copy to Clipboard Copied! Toggle word wrap Toggle overflow