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.

Tip: If you are using Internet Explorer, once you have authenticated with basic<br />

authentication, the Web browser remembers this. There is no logout<br />

mechanism. You will not be challenged on subsequent accesses to secure<br />

resources. This is OK if you are accessing a resource that requires the same<br />

user ID and password, but may cause a problem if you need a second<br />

challenge to enter a new user ID/password. The only way to force a new<br />

challenge is to close the browser and reopen it.<br />

With form-based authentication, the user has the option to log out of one user<br />

ID and log in with another.<br />

16.4.2 Programmatic security<br />

The declarative J2EE security provided by <strong>WebSphere</strong> provides a security<br />

infrastructure for application security that is transparent to the application<br />

developer. That is, the developer does not need to code for security, since it will<br />

all be handled at deployment and runtime.<br />

Having said that, when developing servlets there are a few security calls<br />

available if the developer wants greater control of what the end user is allowed to<br />

do than is provided by the infrastructure. Programmatic security can be used as<br />

an extension of declarative security.<br />

The Servlet 2.3 specification defines three methods that allow programmatic<br />

access to the caller’s security information of the HttpServletRequest interface:<br />

► String getRemoteUser()<br />

The getRemoteUser method returns the user name that the client used to log<br />

in.<br />

String user = request.getRemoteUser()<br />

► Boolean isUserInRole(String roleName)<br />

The isUserInRole method allows the developer to perform additional checks<br />

on the authorization rights of a user, which is not possible (or is more difficult)<br />

to perform through the deployment descriptor of the servlet.<br />

if (request.isUserInRole("Manager")) {<br />

// the user is in the manager role<br />

// ...<br />

}<br />

568 <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!