此内容没有您所选择的语言版本。

11.4. Authentication


Read this section to learn how to authenticate a web service user using a number of available methods.

Procedure 11.1. Authenticate a Web Service User

The following procedure describes how to authenticate a web service user with JBossWS.
  1. 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.
    @Stateless
    @RolesAllowed("friend")
    public class EndpointEJB implements EndpointInterface
    {
      ...
    }
    Copy to Clipboard Toggle word wrap
  2. Secure POJO endpoints

    Secure Plain Old Java Object (POJO) endpoints by defining a <security-constraint> in the WEB-INF/web.xml file of the application.
    <security-constraint>
      <web-resource-collection>
        <web-resource-name>All resources</web-resource-name>
        <url-pattern>/*</url-pattern>
      </web-resource-collection>
      <auth-constraint>
        <role-name>friend</role-name>
      </auth-constraint>
    </security-constraint>
    
    <security-role>
      <role-name>friend</role-name>
    </security-role>
    Copy to Clipboard Toggle word wrap
  3. Define the security domain

    Declare the security domain by appending the @SecurityDomain annotation
    @Stateless
    @SecurityDomain("JBossWS")
    @RolesAllowed("friend")
    public class EndpointEJB implements EndpointInterface
    {
      ...
    }
    Copy to Clipboard Toggle word wrap
    • 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>
      Copy to Clipboard Toggle word wrap

    Note

    For more information about Security Domains, refer to the JBoss Security Guide.
  4. Define the security context

    Configure the security context in the JBOSS_HOME/server/PROFILE/conf/login-config.xml file.
    <!-- 
        A template configuration for the JBossWS security domain.
        This defaults to the UsersRolesLoginModule the same as other and should be
        changed to a stronger authentication mechanism as required.
    -->
    <application-policy name="JBossWS">
      <authentication>
        <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
          <module-option name="usersProperties">props/jbossws-users.properties</module-option>
          <module-option name="rolesProperties">props/jbossws-roles.properties</module-option>
          <module-option name="unauthenticatedIdentity">anonymous</module-option>
        </login-module>
      </authentication>
    </application-policy>
    Copy to Clipboard Toggle word wrap

    Note

    The default UsersRolesLoginModule should be changed to another login module that offers security suitable for your enterprise deployment. Refer to the JBoss Security Guide for more information about the available login modules, and how you can create your own custom login module.
A web service client can use the javax.xml.ws.BindingProvider interface to set the username and password combination.

Example 11.1. BindingProvider Configuration

URL wsdlURL = new File("resources/jaxws/samples/context/WEB-INF/wsdl/TestEndpoint.wsdl").toURL();
QName qname = new QName("http://org.jboss.ws/jaxws/context", "TestEndpointService");
Service service = Service.create(wsdlURL, qname);
port = (TestEndpoint)service.getPort(TestEndpoint.class);
 
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jsmith");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "PaSSw0rd");
Copy to Clipboard Toggle word wrap
HTTP Basic Authentication

You can enable HTTP Basic Authentication by using the @WebContext annotation on the bean class, or by appending an <auth-method> element to the JBOSS_HOME/server/PROFILE/deploy/jbossws.sar/jboss-management.war/WEB-INF/jboss-web.xml <login-config> element.

Example 11.2. @WebContext HTTP Basic Authentication

@Stateless
@SecurityDomain("JBossWS")
@RolesAllowed("friend")
@WebContext(contextRoot="/my-cxt", urlPattern="/*", authMethod="BASIC", transportGuarantee="NONE", secureWSDLAccess=false)
public class EndpointEJB implements EndpointInterface
{
  ...
}
Copy to Clipboard Toggle word wrap

Example 11.3. jboss-web.xml HTTP Basic Authentication

<login-config>
  <auth-method>BASIC</auth-method>
  <realm-name>Test Realm</realm-name>
</login-config>
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat