03.05.2015 Views

IBM WebSphere V5.0 Security - CGISecurity

IBM WebSphere V5.0 Security - CGISecurity

IBM WebSphere V5.0 Security - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.1 Programmatic security<br />

J2EE security can be applied declaratively or programmatically. This chapter will<br />

focus on the latter option. Programmatic security can be used by security aware<br />

applications when declarative security alone is not sufficient to express the<br />

security model of the application.<br />

As an example, the ITSOBank application supplied with this book is configured<br />

such that only managers and employees (clerks and accountants) can transfer<br />

funds but anyone can check their balance. This is possible because the method<br />

permissions for the getCustomerBalance method on the Consultation EJB allows<br />

the necessary role (in this case, Consultant) access. The request simply passes<br />

the account key as a parameter.<br />

8.2 J2EE API<br />

<strong>WebSphere</strong> provides a security infrastructure for application security which is<br />

transparent to the application developer. That is, the developer does not need to<br />

code for security, since it will all be handled at deployment and runtime.<br />

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

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

allowed to do than is provided by the infrastructure.<br />

8.2.1 EJB security methods<br />

The EJB 2.0 specification defines two methods that allow programmatic access<br />

to the caller’s security context, javax.ejb.EJBContext.<br />

► java.security.Principal getCallerPrincipal()<br />

The getCallerPrincipal method allows the developer to get the name of the<br />

current caller. To do this, you need to call getName() on the<br />

java.security.Principal object returned.<br />

EJBContext ejbContext;<br />

...<br />

// get the caller principal<br />

java.security.Principal callerPrincipal = ejbContext.getCallerPrincipal();<br />

// get the caller’s name<br />

String callerName = callerPrincipal.getName();<br />

The Principal.getName() method returns the login name of the user.<br />

180 <strong>IBM</strong> <strong>WebSphere</strong> <strong>V5.0</strong> <strong>Security</strong> Handbook

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

Saved successfully!

Ooh no, something went wrong!