11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - 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.

Chapter 11: Building Secure Serviced Components 311Serviced Component Class ImplementationThe following code fragment highlights the security configuration of a partiallyimplemented Customer class.namespace busCustomer{// (1) Explicit interface definition to support method level authorizationpublic interface ICustomerAdmin{void CreditAccountBalance(string customerID, double amount);}// (2) Enforce component level access checks.[ComponentAccessControl]public sealed class Customer : ServicedComponent, ICustomerAdmin{private string appName = "Customer";private string eventLog = "<strong>Application</strong>";// ICustomer implementation// (3) Access to CreditAccountBalance is limited to members of the// Manager <strong>and</strong> Senior Manager role.[<strong>Security</strong>Role("Manager")][<strong>Security</strong>Role("Senior Manager")]public void CreditAccountBalance(string customerID, double amount){// (4) Structured exception h<strong>and</strong>ling to protect implementation.try{// (5) Check that security is enabled.if (ContextUtil.Is<strong>Security</strong>Enabled){// Only managers can credit accounts with sums of money// in excess of $1,000.if (amount > 1000) {// (6) Programmatic role check to authorize credit operationif (ContextUtil.IsCallerInRole("Senior Manager")) {// Call data access component to update database.. . .// (7) Audit the transaction.AuditTransaction(customerID, amount);}else {throw new <strong>Security</strong>Exception("Caller not authorized");}}}else {throw new <strong>Security</strong>Exception("<strong>Security</strong> is not enabled");}}(continued)

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

Saved successfully!

Ooh no, something went wrong!