|
FAQ
History |
|
Search
Feedback |
Users, Groups, and Roles
A Web services user is similar to an operating system user. Typically, both types of users represent people. However, these two types of users are not the same. The Tomcat server authentication service has no knowledge of the user and password you provide when you log on to the operating system. The Tomcat server authentication service is not connected to the security mechanism of the operating system. The two security services manage users that belong to different realms.
The Tomcat server authentication service includes the following components:
- Role - an abstract name for the permission to access a particular set of resources. A role can be compared to a key that can open a lock. Many people might have a copy of the key, and the lock doesn't care who you are, just that you have the right key.
- User - an individual (or application program) identity that has been authenticated (authentication was discussed in the previous section). A user can have a set of roles associated with that identity, which entitles them to access all resources protected by those roles.
- Group - a set of authenticated users classified by common traits such as job title or customer profile. Groups are also associated with a set of roles, and every user that is a member of a group inherits all of the roles assigned to that group. In most cases, you will map users directly to roles and have no need to define a group.
- Realm - a complete database of roles, users, and groups that identify valid users of a Web application (or a set of Web applications).
Security Roles
When you design a Web component, you should always think about the kinds of users who will access the component. For example, a Web application for a Human Resources department might have a different request URL for someone who has been assigned the role of
adminthan for someone who has been assigned the role ofdirector. Theadminrole may let you view some employee data, but thedirectorrole enables you to view salary information. Each of these security roles is an abstract logical grouping of users that is defined by the person who assembles the application. When an application is deployed, the deployer will map the roles to security identities in the operational environment.To create a role for a Web services application, you can set up the users and roles using
admintool, or in a deployment descriptor, then declare it for the WAR file that is contained in the application. For information on setting up users and roles using admintool, see Managing Roles and Users.The following example code shows how you would set up roles in the
web.xmldeployment descriptor for the Web component. As is shown, you can define multiple security roles for an application.<security-role> <role-name>admin</role-name> </security-role> <security-role> <description>Book customer</description> <role-name>customer</role-name> </security-role>The
<role-name>that you specify in the deployment descriptor must have a corresponding entry in your server-specific deployment descriptor. For the Tomcat server, the file is<JWSDP_HOME>/conf/tomcat-users.xml. The entry needs to declare a mapping between a security role and one or more principals in the realm. An example for the Tomcat server might be as follows:<?xml version='1.0'?> <tomcat-users> <user username='your_name' password='your_password' roles='admin,manager,provider'/> <user username='Joe' password='scooby' roles='admin,manager,provider'/> <user username='Mikhail' password='goblin' roles='admin'/> </tomcat-users>Another example for another Web Server might be as follows:
<rolemapping> <role name="admin"> <principals> <principal> <name>Khalil Singh</name> </principal> </principals> </role> </rolemapping>Managing Roles and Users
To manage the information in the users file, we recommend that you use
admintool. To useadmintool, start Tomcat, then point your browser tohttp://localhost:8080/adminand log on with a user name and password combination that has been assigned theadminrole, such as the user name and password that you entered during installation.For security purposes,
admintool, the Tomcat Web Server Administration Tool, verifies that you (as defined by the information you provide when you log into the application) are a user who is authorized to install and reload applications (defined as a user with the role ofadminintomcat-users.xml) before granting you access to the server.The
<JWSDP_HOME>/conf/tomcat-users.xmlfile is created by the installer. It contains, in plain text, the user name and password created during installation of the Java WSDP. This user name is initially associated with the predefined roles ofadmin,manager, andprovider. You can edit the users file directly in order to add or remove users or modify roles, or you can useadmintoolto accomplish these tasks, as described herein.The
tomcat-users.xmlfile looks like this:<?xml version='1.0'?> <tomcat-users> <user username='your_name' password='your_password' roles='admin,manager,provider'/> </tomcat-users>The following sections describe how to add roles and users using
admintool. The fileJWSDP_HOME/conf/tomcat-users.xmlis updated as the changes are made inadmintool.Using the Tomcat Web Server Administration Tool
To use
admintool, the Tomcat Web Server Administration Tool, you must start Tomcat. Before starting Tomcat, make sure that yourPATHenvironment variables are set properly and that thebuild.propertiesfile has been created properly. These steps are described in Setting Up.Starting Tomcat
To start Tomcat, type the following command in a terminal window.
The startup script starts the task in the background and then returns the user to the command line prompt immediately. The startup script does not completely start Tomcat for several minutes.
Note: The startup script for Tomcat can take several minutes to complete. To verify that Tomcat is running, point your browser to
http://localhost:8080. When the Tomcat splash screen displays, you may continue. If the splash screen does not load immediately, wait up to several minutes and then retry. If, after several minutes, the Tomcat splash screen does not display, refer to the troubleshooting tips in "Unable to Locate the Server localhost:8080" Error.
Documentation for Tomcat can be found at <
JWSDP_HOME>/docs/tomcat/index.html.Starting admintool
Once the Tomcat server is started, follow these steps to start
admintool.The
admintoolutility displays in the Web browser window:
![]()
Figure 18-1 The Tomcat Web Server Administration Tool
The following sections show how to use
admintoolto do the following:The modifications discussed in the following sections are made to the running Tomcat server--it is not necessary to stop and restart Tomcat.
Managing Roles
To view all existing roles in the realm, select Roles from the User Definition section in the left pane.
The Roles List and Role Actions list display in the right pane. By default, the roles defined during Java WSDP installation are displayed. These roles include
admin,manager, andprovider.Use the following procedure to add a new role to the default realm.
Use the following procedure to remove a role from the default realm.
If you entered a new role of
customer, thetomcat-users.xmlfile would now look like this:<?xml version='1.0'?> <tomcat-users> <role rolename="customer" description="Customer of Java Web Service"/> <role rolename="provider"/> <role rolename="manager"/> <role rolename="admin"/> <user username="your_name" password="your_password" roles="admin,manager,provider"/> </tomcat-users>Managing Users
To view all existing users in the realm, select Users from the User Definition section in the left pane.
The Users List and Available Actions list for User Actions display in the right pane. By default, the user name defined during Java WSDP installation is displayed.
Use the following procedure to edit a user's profile.
Use the following procedure to add a new user to the default realm.
Use the following procedure to remove a user from the default realm.
The addition of a new role and user as described in the previous section are reflected in the updated
tomcat-users.xml. If I added a new user named Anil and assigned him the role ofcustomer, the updatedtomcat-users.xmlwould look like this:<?xml version='1.0'?> <tomcat-users> <role rolename="customer" description="Customer of Java Web Service"/> <role rolename="provider"/> <role rolename="manager"/> <role rolename="admin"/> <user username="your_name" password="your_password" roles="admin,manager,provider"/> <user username="Anil" password="12345" fullName="" roles="customer"/> </tomcat-users>Declaring and Linking Role References
A security role reference allows a Web component to reference an existing security role. A security role is an application-specific logical grouping of users, classified by common traits such as customer profile or job title. When an application is deployed, roles are mapped to security identities, such as principals (identities assigned to users as a result of authentication) or groups, in the operational environment. Based on this, a user with a certain security role has associated access rights to a Web application. The link is the actual name of the security role that is being referenced.
During application assembly, the assembler creates security roles for the application and associates these roles with available security mechanisms. The assembler then resolves the security role references in individual servlets and JSPs by linking them to roles defined for the application.
The security role reference defines a mapping between the name of a role that is called from a Web component using
isUserInRole(String name)(see Using Programmatic Security in the Web Tier) and the name of a security role that has been defined for the application.For example, the mapping of the security role reference
custto the security role with role namebankCustomer, is shown in the<security-role-ref>element of the deployment descriptor, as shown:<security-role-ref> <role-name>cust</role-name> <role-link>bankCustomer</role-link> </security-role-ref>In this example,
isUserInRole("bankCustomer")andisUserInRole("cust")will both returntrue.Because a coded name is linked to a role name, you can change the role name at a later time without having to change the coded name. For example, if you were to change the role name from
bankCustomerto something else, you wouldn't need to change thecustname in the code. However, you would need to relink thecustcoded name to the new role name.Mapping Application Roles to Realm Roles
When you are developing a Web services application, you don't need to know what roles have been defined for the realm in which the application will be run. In the Java WSDP, the Web services security architecture provides a mechanism for automatically mapping the roles defined in the application to the roles defined in the runtime realm. After your application has been deployed, the administrator of the Tomcat server will map the roles of the application to the roles of the
defaultrealm.The following example shows the role mapping between the application-defined role
adminand theadminrole that was defined when the Java WSDP was installed. The following is an example of the security constraint that could be added to the application's deployment descriptor.
- Select or open the Web application deployment descriptor, for example,
<JWSDP_HOME>/docs/tutorial/examples/gs/web/WEB-INF/web.xml.- Add a security constraint such as the one shown below. In this example, the role of
adminis authorized to access this application, and is assigned a security role. For example, in the Tomcat server, this information is reflected in the runtime XML, as shown:<!-- SECURITY CONSTRAINT -->
<security-constraint>
<web-resource-collection>
<web-resource-name>WRCollection</web-resource-name>
<url-pattern>/index.jsp</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!-- SECURITY ROLES -->
<security-role>
<description>the administrator role</description<
<role-name>admin</role-name>
</security-role>The
<role-name>that you specify in the deployment descriptor must have a corresponding entry in your server-specific deployment descriptor. For the Tomcat server, the file is<JWSDP_HOME>/conf/tomcat-users.xml. The entry needs to declare a mapping between a security role and one or more principals in the realm. An example for the Tomcat server might be as follows:<?xml version='1.0'?> <tomcat-users> <user username='your_name' password='your_password' roles='admin,manager,provider'/> </tomcat-users>Another example for another Web Server might be as follows:
|
FAQ
History |
|
Search
Feedback |
All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.