29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

// get the principal from the request<br />

Principal principal=req.getUserPrincipal();<br />

// print out the user information about the servlet invocation<br />

System.out.println("Transfer Servlet was invoked by user:<br />

"+req.getRemoteUser()+", principal: "+principal.getName());<br />

16.5 JAAS security<br />

Java Authentication and Authorization Services (JAAS) is an alternative to the<br />

built-in security support in <strong>WebSphere</strong> allowing programmatic authentication and<br />

authorization to be used within an application. It is a standard extension to the<br />

Java 2 SDK Version 1.3 and it is part of Java 2 SDK Version 1.4. The current<br />

version for JAAS is 1.0.<br />

To illustrated this type of security, let us take an example from the Online Catalog<br />

sample. As supplied with this publication, the sample uses two different methods<br />

of authenticating to the SALESAPP database.<br />

In the first method, the user ID and password required to access the database<br />

are coded within the Web module. The JSPs generated by the Database Web<br />

Pages wizard use this method. The wizard registers each JSP as a servlet in the<br />

Web deployment descriptor and defines three initialization parameters to hold<br />

values for accessing the database: The data source name, the user ID, and<br />

password.<br />

When the JSP connects to the database, the user ID and password are retrieved<br />

from the initialization parameters and used by the jspsql taglib to authenticate to<br />

the database. This method is a little awkward in larger applications because<br />

every JSP that accesses the database need to have the user name and<br />

password initialization parameters defined in the deployment descriptor. The<br />

wizard does this for you automatically, but if you ever need to change the values<br />

you have to update every servlet. Secondly, the password is stored in the clear.<br />

In the second method, JAAS security is used for authentication. This is shown in<br />

Figure 16-12 on page 571. In this case, you do not supply the user ID or<br />

password for database authentication in the application. They are stored under<br />

an alias in the server configuration, and a pointer to that alias is put in the data<br />

source. Whenever the database is accessed, the user ID and password<br />

information in the alias is used for authentication. The advantage is that the user<br />

ID and password are stored in one place and the password is encrypted.<br />

570 <strong>IBM</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> - Express V5.0.2 Developer Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!