13.07.2015 Views

IBM WebSphere V5.0 Security - CGISecurity

IBM WebSphere V5.0 Security - CGISecurity

IBM WebSphere V5.0 Security - CGISecurity

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

►Boolean isCallerInRole(String roleName)The isCallerInRole method allows the developer to make additional checkson the authorization rights of a user which are not possible, or more difficult,to perform through the deployment descriptor of the EJB.EJBContext ejbContext;...if (ejbContext.isCallerInRole(““))// Perform some fuctionelse// Throw a security exceptionThe isCallerInRole(String role) method returns true if the user is in thespecified role, and false if it is not. The role name specified in the method isreally a security role reference, not a role. If the security role reference is notdefined for the EJB, the method will return null.Sample usage of security methodsThe following example is a modified code snippet from the ITSOBank sampleapplication. You can find similar code in the TransferBean.java in thetransferBranch2Customer() method. For more details, check the comments inthe source below, or in the original sample application.Example 8-1 Sample code using the EJB security methods// getting the environment variables for restricted role// and for maximum transferable amountrestrictedRole=(String)environment.lookup("RestrictedRole");maxEJBTransferAmount=(Integer)environment.lookup("MaxEJBTransferAmount");// checking if the user is restricted to a certain amount of transferif(mySessionCtx.isCallerInRole(restrictedRole) &&transferAmount>maxEJBTransferAmount.intValue()) {// the user cannot transfer the requested amountreturn false;}// get the caller principal, then the user namejava.security.Principal callerPrincipal=mySessionCtx.getCallerPrincipal();String callerName =callerPrincipal.getName();// print out the user information about the EJB method invocationSystem.out.println("... method was invoked on the Transfer EJB by:"+callerName);With the security methods, the EJB will not let the user in a restricted role tosubmit a transfer greater than the maximum transferable amount.Chapter 8. Programmatic security 181

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

Saved successfully!

Ooh no, something went wrong!