Author: anil.saldhana(a)jboss.com
Date: 2011-04-18 11:54:20 -0400 (Mon, 18 Apr 2011)
New Revision: 893
Modified:
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/WSAuthorizationHandler.java
Log:
PLFED-177: simple cache to avoid reparsing
Modified:
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/WSAuthorizationHandler.java
===================================================================
---
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/WSAuthorizationHandler.java 2011-04-18
15:43:43 UTC (rev 892)
+++
trust/trunk/jbossws/src/main/java/org/picketlink/trust/jbossws/handler/WSAuthorizationHandler.java 2011-04-18
15:54:20 UTC (rev 893)
@@ -23,9 +23,10 @@
import java.io.InputStream;
import java.security.Principal;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.security.auth.Subject;
@@ -51,6 +52,9 @@
{
public static final String UNCHECKED = "unchecked";
+ //A simple hashmap that reduces the reparsing of jboss-wsse.xml for the same keys
+ protected Map<String, List<String>> cache = new
HashMap<String,List<String>>();
+
@Override
protected boolean handleInbound(MessageContext msgContext)
{
@@ -66,15 +70,29 @@
QName portName = (QName) msgContext.get(MessageContext.WSDL_PORT);
QName opName = (QName) msgContext.get(MessageContext.WSDL_OPERATION);
- List<String> roles = new ArrayList<String>();
- try
+
+ List<String> roles = null;
+
+ String key = portName.getLocalPart()+"_" + opName.toString();
+
+ //First check in cache
+ if( cache.containsKey(key))
{
- roles = JBossWSSERoleExtractor.getRoles(is, portName.getLocalPart(),
opName.toString());
+ roles = cache.get(key);
}
- catch (ProcessingException e)
+ else
{
- throw new RuntimeException(e);
+ try
+ {
+ roles = JBossWSSERoleExtractor.getRoles(is, portName.getLocalPart(),
opName.toString());
+ }
+ catch (ProcessingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ cache.put(key, roles);
}
+
if( !roles.contains(UNCHECKED))
{
AuthorizationManager authorizationManager = getAuthorizationManager();