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

Create successful ePaper yourself

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

312 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>s(continued)}}catch( Exception ex){// Log exception details.throw new Exception("Failed to credit account balance for customer: " +customerID, ex);}}private void AuditTransaction(string customerID, double amount){// (8) Original caller identity is obtained from call context for// logging purposes.<strong>Security</strong>Identity caller = <strong>Security</strong>CallContext.CurrentCall.OriginalCaller;try{if (!EventLog.SourceExists(appName)){EventLog.CreateEventSource(appName,eventLog);}StringBuilder logmessage = new StringBuilder();logmessage.AppendFormat("{0}User {1} performed the following transaction"+ "{2} Account balance for customer {3} "+ "credited by {4}",Environment.NewLine, caller.AccountName,Environment.NewLine, customerID, amount);EventLog.WriteEntry(appName, logmessage.ToString(),EventLogEntryType.Information);}catch(<strong>Security</strong>Exception secex){throw new <strong>Security</strong>Exception("Event source does not exist <strong>and</strong> cannot be created", secex);}}The code shown above exhibits the following security characteristics (identified bythe numbers in the comment lines):1. An interface is defined <strong>and</strong> implemented explicitly to support interface <strong>and</strong>method level authorization with COM+ roles.2. Component level access checks are enabled for the class by using the[ComponentAccessControl] attribute at the class level.3. The [<strong>Security</strong>Role] attribute is used on the CreditAccountBalance method torestrict access to members of the Manager or Senior Managers role.4. Structured exception h<strong>and</strong>ling is used to protect implementation. Exceptions arecaught, logged, <strong>and</strong> an appropriate exception is propagated to the caller.

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

Saved successfully!

Ooh no, something went wrong!