此内容没有您所选择的语言版本。
11.4. Authentication
Task: Authenticate a Web Service User
Task Summary
Secure access to the Stateless Session Bean
Secure access to the Stateless Session Bean (SLSB) using the@RolesAllowed
,@PermitAll
,@DenyAll
annotations.The allowed user roles can be set with these annotations both on the bean class and on any of its business methods.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Secure POJO endpoints
Secure Plain Old Java Object (POJO) endpoints by defining a <security-constraint> in theWEB-INF/web.xml
file of the application. The <auth-constraint> <role-name> element specifies whether authentication is mandatory. It can be set to "not required" by specifying an asterisk value in the <role-name> element.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the security domain for EJB3 endpoints
Declare the security domain by appending the @SecurityDomain annotationCopy to Clipboard Copied! Toggle word wrap Toggle overflow - You can also modify
JBOSS_HOME/server/PROFILE/deploy/jbossws.sar/jboss-management.war/WEB-INF/jboss-web.xml
and specify the security domain.<jboss-web> <security-domain>JBossWS</security-domain> </jboss-web>
<jboss-web> <security-domain>JBossWS</security-domain> </jboss-web>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note
For more information about Security Domains, refer to the JBoss Security Guide.Define the security domain for POJO endpoints
Modify theJBOSS_HOME/server/PROFILE/deploy/jbossws.sar/jboss-management.war/WEB-INF/jboss-web.xml
and specify the security domain.<jboss-web> <security-domain>JBossWS</security-domain> </jboss-web>
<jboss-web> <security-domain>JBossWS</security-domain> </jboss-web>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the security context
Configure the security context in theJBOSS_HOME/server/PROFILE/conf/login-config.xml
file.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note
The defaultUsersRolesLoginModule
should be changed to another login module that offers security suitable for your enterprise deployment. Follow Task: Enable LDAP Authentication for steps to use the LdapLoginModule to control user authentication.Define HTTP basic authentication for EJB3 endpoints
Use @WebContext annotation on the bean class.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define HTTP basic authentication for POJO endpoints
Add into WEB-INF/web.xml of your web application<login-config> <auth-method>BASIC</auth-method> <realm-name>Test Realm</realm-name> </login-config>
<login-config> <auth-method>BASIC</auth-method> <realm-name>Test Realm</realm-name> </login-config>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Client side - set username and password
A web service client can use thejavax.xml.ws.BindingProvider
interface to set the username and password combination.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Client side - WSDL secured
Use java.net.Authenticator to set username and password when accessing wsdl file.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Task: Enable LDAP Authentication
Task Summary
Secure access to the Stateless Session Bean
Secure access to the Stateless Session Bean (SLSB) using the@RolesAllowed
,@PermitAll
,@DenyAll
annotations.The allowed user roles can be set with these annotations both on the bean class and on any of its business methods.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Secure POJO endpoints
Secure Plain Old Java Object (POJO) endpoints by defining a <security-constraint> in theWEB-INF/web.xml
file of the application.The <auth-constraint> <role-name> element specifies whether authentication is mandatory. It can be set to "not required" by specifying an asterisk (*) value in the <role-name> element.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note
For more information about valid <auth-method> values, refer to the Web Content Security Constraints section of the JBoss Security Guide.Define the security domain
Declare the security domain by appending the @SecurityDomain annotationCopy to Clipboard Copied! Toggle word wrap Toggle overflow - You can also modify
JBOSS_HOME/server/PROFILE/deploy/jbossws.sar/jboss-management.war/WEB-INF/jboss-web.xml
and specify the security domain.<jboss-web> <security-domain>JBossWS</security-domain> </jboss-web>
<jboss-web> <security-domain>JBossWS</security-domain> </jboss-web>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note
For more information about Security Domains, refer to the JBoss Security Guide.Define the security context
Configure the security context in theJBOSS_HOME/server/PROFILE/conf/login-config.xml
file.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note
Refer to the Security Guide for information about the LdapLoginModule and other available login modules.
11.4.1. Java Authentication and Authorization Service 复制链接链接已复制到粘贴板!
Procedure 11.1. On the Server
Specify Interceptors
Specify (possibly by using ajbossws-cxf.xml
descriptor):- An interceptor for performing authentication and populating a valid
SecurityContext
; the provided interceptor should extendorg.apache.cxf.ws.security.wss4j.AbstractUsernameTokenAuthenticatingInterceptor
.JBossWS integration comes withorg.jboss.wsf.stack.cxf.security.authentication.SubjectCreatingInterceptor
for this use. - An interceptor for performing authorization; CXF requires this to extend
org.apache.cxf.interceptor.security.AbstractAuthorizingInInterceptor
.For instance, theSimpleAuthorizingInterceptor
can be used for mapping endpoint operations to allowed roles.
Example 11.1.
SimpleAuthorizingInterceptor
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Authentication and authorization will be delegated to the security domain configured for the endpoint.
Note
Procedure 11.2. On the Client
- Ensure the username is provided through the API (or a custom Spring configuration used to load the Bus):
Example 11.2. Username API
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The password instead is provided through a password callback handler that needs to implement
javax.security.auth.callback.CallbackHandler
, similarly to the keystore's password callback handler.If you are using an older JBossWS-CXF version, or you are not configuring the application server authorization integration, you can use a password callback handler on server side too, configured through aWSS4JInInterceptor
:Example 11.3. Callback Handler
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example 11.4.
WSS4JInInterceptor
callback handlerCopy to Clipboard Copied! Toggle word wrap Toggle overflow