You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by th...@apache.org on 2011/02/19 12:39:43 UTC

svn commit: r1072315 - in /axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas: TokenRequestDispatcher.java client/STSClient.java impl/SAMLTokenIssuerConfig.java

Author: thilinamb
Date: Sat Feb 19 11:39:43 2011
New Revision: 1072315

URL: http://svn.apache.org/viewvc?rev=1072315&view=rev
Log:
Improving logging in Rampart-Trust module.

Modified:
    axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/TokenRequestDispatcher.java
    axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java
    axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/TokenRequestDispatcher.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/TokenRequestDispatcher.java?rev=1072315&r1=1072314&r2=1072315&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/TokenRequestDispatcher.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/TokenRequestDispatcher.java Sat Feb 19 11:39:43 2011
@@ -20,7 +20,6 @@ import org.apache.axiom.soap.SOAPEnvelop
 import org.apache.axis2.context.MessageContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.rahas.impl.SAMLTokenValidator;
 
 public class TokenRequestDispatcher {
 
@@ -28,6 +27,7 @@ public class TokenRequestDispatcher {
     
     private static Log mlog = LogFactory.getLog("org.apache.rampart.messages");
     private static Log log = LogFactory.getLog(TokenRequestDispatcher.class.getName());
+    private static boolean doDebug = log.isDebugEnabled();
 
     public TokenRequestDispatcher(TokenRequestDispatcherConfig config) throws TrustException {
         this.config = config;
@@ -59,7 +59,9 @@ public class TokenRequestDispatcher {
         String tokenType = data.getTokenType();
         if ((RahasConstants.WST_NS_05_02 + RahasConstants.REQ_TYPE_ISSUE).equals(reqType) ||
                 (RahasConstants.WST_NS_05_12 + RahasConstants.REQ_TYPE_ISSUE).equals(reqType)) {
-        	log.debug("issue");
+            if (doDebug) {
+                log.debug("issue");
+            }
             TokenIssuer issuer;
             if (tokenType == null ||  tokenType.trim().length() == 0) {
                 issuer = config.getDefaultIssuerInstace();
@@ -79,9 +81,11 @@ public class TokenRequestDispatcher {
             return response;
         } else if((RahasConstants.WST_NS_05_02 + RahasConstants.REQ_TYPE_VALIDATE).equals(reqType) ||
                 (RahasConstants.WST_NS_05_12 + RahasConstants.REQ_TYPE_VALIDATE).equals(reqType)) {
-        	log.debug("validate");
-                
-                TokenValidator validator;
+            if (doDebug) {
+                log.debug("validate");
+            }
+
+            TokenValidator validator;
                 if (tokenType == null ||  tokenType.trim().length() == 0) {
                     validator = config.getDefaultValidatorInstance();
                 } else {
@@ -100,9 +104,11 @@ public class TokenRequestDispatcher {
         	
         } else if((RahasConstants.WST_NS_05_02 + RahasConstants.REQ_TYPE_RENEW).equals(reqType) ||
                 (RahasConstants.WST_NS_05_12 + RahasConstants.REQ_TYPE_RENEW).equals(reqType)) {
-        	log.debug("renew");
-        	
-                TokenRenewer renewer;
+            if (doDebug) {
+                log.debug("renew");
+            }
+
+            TokenRenewer renewer;
                 if (tokenType == null ||  tokenType.trim().length() == 0) {
                     renewer = config.getDefaultRenewerInstance();
                 } else {
@@ -119,7 +125,9 @@ public class TokenRequestDispatcher {
         	         
         } else if((RahasConstants.WST_NS_05_02 + RahasConstants.REQ_TYPE_CANCEL).equals(reqType) ||
                 (RahasConstants.WST_NS_05_12 + RahasConstants.REQ_TYPE_CANCEL).equals(reqType)) {
-        	log.debug("cancel");
+            if (doDebug) {
+                log.debug("cancel");
+            }
             TokenCanceler canceler = config.getDefaultCancelerInstance();
             SOAPEnvelope response = canceler.cancel(data);
 

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java?rev=1072315&r1=1072314&r2=1072315&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/client/STSClient.java Sat Feb 19 11:39:43 2011
@@ -16,19 +16,9 @@
 
 package org.apache.rahas.client;
 
-import java.io.IOException;
-import java.util.*;
-import java.text.DateFormat;
-import java.text.ParseException;
-
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.xml.namespace.QName;
-
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
 import org.apache.axiom.om.util.Base64;
@@ -69,11 +59,25 @@ import org.apache.ws.security.util.WSSec
 import org.apache.ws.security.util.XmlSchemaDateFormat;
 import org.w3c.dom.Element;
 
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
 public class STSClient {
 
     private static final String RAMPART_POLICY = "rampartPolicy";
 
     private static Log log = LogFactory.getLog(STSClient.class);
+    private static boolean doDebug = log.isDebugEnabled();
 
     private String action;
 
@@ -592,7 +596,9 @@ public class STSClient {
         //Assumption: there's only one alternative
 
         if (issuerPolicy != null) {
-            log.debug("Processing Issuer policy");
+            if (doDebug) {
+                log.debug("Processing Issuer policy");
+            }
 
             List issuerAssertions = (List) issuerPolicy.getAlternatives().next();
 
@@ -601,8 +607,10 @@ public class STSClient {
                 //find the AlgorithmSuite assertion
                 if (tempAssertion instanceof Binding) {
 
-                    log.debug("Extracting algo suite from issuer " +
-                              "policy binding");
+                    if (doDebug) {
+                        log.debug("Extracting algo suite from issuer " +
+                                  "policy binding");
+                    }
 
                     this.algorithmSuite = ((Binding) tempAssertion)
                             .getAlgorithmSuite();
@@ -612,7 +620,9 @@ public class STSClient {
 
         if (servicePolicy != null) {
 
-            log.debug("Processing service policy to find Trust10 assertion");
+            if (doDebug) {
+                log.debug("Processing service policy to find Trust10 assertion");
+            }
 
             List assertions = (List) servicePolicy.getAlternatives().next();
 
@@ -620,12 +630,16 @@ public class STSClient {
                 Assertion tempAssertion = (Assertion) iter.next();
                 //find the Trust10 assertion
                 if (tempAssertion instanceof Trust10) {
-                    log.debug("Extracting Trust10 assertion from " +
-                              "service policy");
+                    if (doDebug) {
+                        log.debug("Extracting Trust10 assertion from " +
+                                  "service policy");
+                    }
                     this.trust10 = (Trust10) tempAssertion;
                 } else if (tempAssertion instanceof Trust13) {
-                    log.debug("Extracting Trust13 assertion from " +
-                    "service policy");
+                    if (doDebug) {
+                        log.debug("Extracting Trust13 assertion from " +
+                        "service policy");
+                    }
                     this.trust13 = (Trust13) tempAssertion;
                 }
             }
@@ -643,8 +657,10 @@ public class STSClient {
     private OMElement createIssueRequest(String requestType,
                                          String appliesTo) throws TrustException {
 
-        log.debug("Creating request with request type: " + requestType +
-                  " and applies to: " + appliesTo);
+        if (doDebug) {
+            log.debug("Creating request with request type: " + requestType +
+                      " and applies to: " + appliesTo);
+        }
 
         OMElement rst = TrustUtil.createRequestSecurityTokenElement(version);
 
@@ -657,7 +673,9 @@ public class STSClient {
         //Copy over the elements from the template
         if (this.rstTemplate != null) {
 
-            log.debug("Using RSTTemplate: " + this.rstTemplate.toString());
+            if (doDebug) {
+                log.debug("Using RSTTemplate: " + this.rstTemplate.toString());
+            }
 
             Iterator templateChildren = rstTemplate.getChildElements();
             while (templateChildren.hasNext()) {
@@ -668,13 +686,17 @@ public class STSClient {
                     && ((OMElement) child).getQName().equals(
                         new QName(TrustUtil.getWSTNamespace(this.version),
                                   RahasConstants.IssuanceBindingLocalNames.KEY_SIZE))) {
-                    log.debug("Extracting key size from the RSTTemplate: ");
+                    if (doDebug) {
+                        log.debug("Extracting key size from the RSTTemplate: ");
+                    }
                     OMElement childElem = (OMElement) child;
                     this.keySize =
                             (childElem.getText() != null && !"".equals(childElem.getText())) ?
                             Integer.parseInt(childElem.getText()) :
                             -1;
-                    log.debug("Key size from RSTTemplate: " + this.keySize);
+                    if (doDebug) {
+                        log.debug("Key size from RSTTemplate: " + this.keySize);
+                    }
                 }
             }
         }
@@ -683,11 +705,15 @@ public class STSClient {
             // Handle entropy
             if (this.trust10 != null) {
 
-                log.debug("Processing Trust assertion");
+                if (doDebug) {
+                    log.debug("Processing Trust assertion");
+                }
 
                 if (this.trust10.isRequireClientEntropy()) {
 
-                    log.debug("Requires client entropy");
+                    if (doDebug) {
+                        log.debug("Requires client entropy");
+                    }
 
                     // setup requestor entropy
                     OMElement ent = TrustUtil.createEntropyElement(this.version, rst);
@@ -700,8 +726,9 @@ public class STSClient {
                                     getMaximumSymmetricKeyLength()/8);
                     binSec.setText(Base64.encode(this.requestorEntropy));
 
-                    log.debug("Clien entropy : "
-                              + Base64.encode(this.requestorEntropy));
+                    if (doDebug) {
+                        log.debug("Clien entropy : " + Base64.encode(this.requestorEntropy));
+                    }
 
                     // Add the ComputedKey element
                     TrustUtil.createComputedKeyAlgorithm(this.version, rst,
@@ -712,7 +739,9 @@ public class STSClient {
                 
                 if (this.trust13.isRequireClientEntropy()) {
 
-                    log.debug("Requires client entropy");
+                    if (doDebug) {
+                        log.debug("Requires client entropy");
+                    }
 
                     // setup requestor entropy
                     OMElement ent = TrustUtil.createEntropyElement(this.version, rst);
@@ -725,8 +754,9 @@ public class STSClient {
                                     getMaximumSymmetricKeyLength()/8);
                     binSec.setText(Base64.encode(this.requestorEntropy));
 
-                    log.debug("Clien entropy : "
-                              + Base64.encode(this.requestorEntropy));
+                    if (doDebug) {
+                        log.debug("Clien entropy : " + Base64.encode(this.requestorEntropy));
+                    }
 
                     // Add the ComputedKey element
                     TrustUtil.createComputedKeyAlgorithm(this.version, rst,
@@ -748,9 +778,11 @@ public class STSClient {
     }
     
     private OMElement createValidateRequest(String requestType, String tokenId) throws TrustException {
-        
-        log.debug("Creating request with request type: " + requestType);
-        
+
+        if (doDebug) {
+            log.debug("Creating request with request type: " + requestType);
+        }
+
         OMElement rst = TrustUtil.createRequestSecurityTokenElement(version);
         
         TrustUtil.createRequestTypeElement(this.version, rst, requestType);
@@ -788,9 +820,11 @@ public class STSClient {
         
         String requestType =
             TrustUtil.getWSTNamespace(version) + RahasConstants.REQ_TYPE_RENEW;
-        
-        log.debug("Creating request with request type: " + requestType);
-        
+
+        if (doDebug) {
+            log.debug("Creating request with request type: " + requestType);
+        }
+
         OMElement rst = TrustUtil.createRequestSecurityTokenElement(version);
         
         TrustUtil.createRequestTypeElement(this.version, rst, requestType);

Modified: axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java?rev=1072315&r1=1072314&r2=1072315&view=diff
==============================================================================
--- axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java (original)
+++ axis/axis2/java/rampart/branches/1_6/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java Sat Feb 19 11:39:43 2011
@@ -16,16 +16,6 @@
 
 package org.apache.rahas.impl;
 
-import java.io.FileInputStream;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-import java.security.cert.X509Certificate;
-
-import javax.xml.namespace.QName;
-
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
@@ -36,8 +26,17 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.rahas.TrustException;
 import org.apache.rahas.impl.util.SAMLCallbackHandler;
-import org.apache.ws.security.components.crypto.Crypto;
 import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.components.crypto.Crypto;
+
+import javax.xml.namespace.QName;
+import java.io.FileInputStream;
+import java.security.cert.X509Certificate;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
 
 /**
  * Configuration manager for the <code>SAMLTokenIssuer</code>
@@ -260,13 +259,13 @@ public class SAMLTokenIssuerConfig exten
 					Class handlerClass = Class.forName(value);
 					this.callbackHandler = (SAMLCallbackHandler)handlerClass.newInstance();
 				} catch (ClassNotFoundException e) {
-					log.debug("Error loading class" , e);
+					log.error("Error loading class" , e);
 					throw new TrustException("Error loading class" , e);
 				} catch (InstantiationException e) {
-					log.debug("Error instantiating class" , e);
+					log.error("Error instantiating class" , e);
 					throw new TrustException("Error instantiating class" , e);
 				} catch (IllegalAccessException e) {
-					log.debug("Illegal Access" , e);
+					log.error("Illegal Access" , e);
 					throw new TrustException("Illegal Access" , e);
 				}
 		}