cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: More refactoring
Date Tue, 24 Mar 2015 17:40:33 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 4534b2955 -> 40c9bfd5e


More refactoring


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/40c9bfd5
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/40c9bfd5
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/40c9bfd5

Branch: refs/heads/master
Commit: 40c9bfd5ee0ba7cccd7abc7e7d19db531e212c97
Parents: 4534b29
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Tue Mar 24 17:40:20 2015 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Tue Mar 24 17:40:20 2015 +0000

----------------------------------------------------------------------
 .../security/saml/sso/AbstractSSOSpHandler.java | 76 +++-----------------
 .../saml/sso/SAMLProtocolResponseValidator.java | 14 ++--
 .../cxf/rs/security/saml/sso/SSOConstants.java  |  6 +-
 .../saml/sso/SamlpRequestComponentBuilder.java  |  4 +-
 .../saml/sso/state/MemorySPStateManager.java    |  6 +-
 .../cxf/rs/security/common/CryptoLoader.java    |  2 +-
 .../cxf/rt/security/utils/SecurityUtils.java    | 53 +++++++++++++-
 .../org/apache/cxf/sts/StaticSTSProperties.java | 62 ++++------------
 .../apache/cxf/sts/token/realm/SAMLRealm.java   | 50 +------------
 9 files changed, 92 insertions(+), 181 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
index f839620..548ea6e 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractSSOSpHandler.java
@@ -19,22 +19,18 @@
 package org.apache.cxf.rs.security.saml.sso;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
 import java.util.Date;
 import java.util.Properties;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.annotation.PreDestroy;
 import javax.security.auth.callback.CallbackHandler;
 
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.rs.security.saml.sso.state.SPStateManager;
+import org.apache.cxf.rt.security.utils.SecurityUtils;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.crypto.CryptoFactory;
 import org.apache.wss4j.common.ext.WSSecurityException;
@@ -160,49 +156,9 @@ public class AbstractSSOSpHandler {
         return stateTimeToLive;
     }
     
-    protected static Properties getProps(Object o) {
-        Properties properties = null;
-        if (o instanceof Properties) {
-            properties = (Properties)o;
-        } else if (o instanceof String) {
-            URL url = null;
-            Bus bus = PhaseInterceptorChain.getCurrentMessage().getExchange().getBus();
-            ResourceManager rm = bus.getExtension(ResourceManager.class);
-            url = rm.resolveResource((String)o, URL.class);
-            try {
-                if (url == null) {
-                    url = ClassLoaderUtils.getResource((String)o, AbstractSSOSpHandler.class);
-                }
-                if (url == null) {
-                    url = new URL((String)o);
-                }
-                if (url != null) {
-                    properties = new Properties();
-                    InputStream ins = url.openStream();
-                    properties.load(ins);
-                    ins.close();
-                }
-            } catch (IOException e) {
-                LOG.fine(e.getMessage());
-                properties = null;
-            }
-        } else if (o instanceof URL) {
-            properties = new Properties();
-            try {
-                InputStream ins = ((URL)o).openStream();
-                properties.load(ins);
-                ins.close();
-            } catch (IOException e) {
-                LOG.fine(e.getMessage());
-                properties = null;
-            }            
-        }
-        return properties;
-    }
-    
     protected Crypto getSignatureCrypto() {
         if (signatureCrypto == null && signaturePropertiesFile != null) {
-            Properties sigProperties = getProps(signaturePropertiesFile);
+            Properties sigProperties = SecurityUtils.loadProperties(signaturePropertiesFile);
             if (sigProperties == null) {
                 LOG.fine("Cannot load signature properties using: " + signaturePropertiesFile);
                 return null;
@@ -219,28 +175,18 @@ public class AbstractSSOSpHandler {
     
     protected CallbackHandler getCallbackHandler() {
         if (callbackHandler == null && callbackHandlerClass != null) {
-            callbackHandler = getCallbackHandler(callbackHandlerClass);
-            if (callbackHandler == null) {
-                LOG.fine("Cannot load CallbackHandler using: " + callbackHandlerClass);
+            try {
+                callbackHandler = SecurityUtils.getCallbackHandler(callbackHandlerClass);
+                if (callbackHandler == null) {
+                    LOG.fine("Cannot load CallbackHandler using: " + callbackHandlerClass);
+                    return null;
+                }
+            } catch (WSSecurityException ex) {
+                LOG.log(Level.FINE, "Error in loading callback handler", ex);
                 return null;
             }
         }
         return callbackHandler;
     }
     
-    private CallbackHandler getCallbackHandler(Object o) {
-        CallbackHandler handler = null;
-        if (o instanceof CallbackHandler) {
-            handler = (CallbackHandler)o;
-        } else if (o instanceof String) {
-            try {
-                handler = 
-                    (CallbackHandler)ClassLoaderUtils.loadClass((String)o, this.getClass()).newInstance();
-            } catch (Exception e) {
-                LOG.fine(e.getMessage());
-                handler = null;
-            }
-        }
-        return handler;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SAMLProtocolResponseValidator.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SAMLProtocolResponseValidator.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SAMLProtocolResponseValidator.java
index 2ec8aa0..c1be9f5 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SAMLProtocolResponseValidator.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SAMLProtocolResponseValidator.java
@@ -38,13 +38,13 @@ import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.rs.security.common.SecurityUtils;
 import org.apache.cxf.rs.security.xml.EncryptionUtils;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.wss4j.common.WSS4JConstants;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.ext.WSSecurityException;
 import org.apache.wss4j.common.saml.SAMLKeyInfo;
 import org.apache.wss4j.common.saml.SAMLUtil;
 import org.apache.wss4j.common.saml.SamlAssertionWrapper;
 import org.apache.wss4j.common.util.KeyUtils;
-import org.apache.wss4j.dom.WSConstants;
 import org.apache.wss4j.dom.WSDocInfo;
 import org.apache.wss4j.dom.WSSConfig;
 import org.apache.wss4j.dom.handler.RequestData;
@@ -417,9 +417,9 @@ public class SAMLProtocolResponseValidator {
         EncryptedData encryptedData = assertion.getEncryptedData();
         Element encryptedDataDOM = encryptedData.getDOM();
                 
-        Element encKeyElement = getNode(assertion.getDOM(), WSConstants.ENC_NS, "EncryptedKey",
0);
+        Element encKeyElement = getNode(assertion.getDOM(), WSS4JConstants.ENC_NS, "EncryptedKey",
0);
         if (encKeyElement == null) {
-            encKeyElement = getNode(encryptedDataDOM, WSConstants.ENC_NS, "EncryptedKey",
0);
+            encKeyElement = getNode(encryptedDataDOM, WSS4JConstants.ENC_NS, "EncryptedKey",
0);
         }
         if (encKeyElement == null) {
             LOG.log(Level.FINE, "EncryptedKey element is not available");
@@ -436,7 +436,7 @@ public class SAMLProtocolResponseValidator {
         String keyEncAlgo = getEncodingMethodAlgorithm(encKeyElement);
         String digestAlgo = getDigestMethodAlgorithm(encKeyElement);
         
-        Element cipherValue = getNode(encKeyElement, WSConstants.ENC_NS, "CipherValue", 0);
+        Element cipherValue = getNode(encKeyElement, WSS4JConstants.ENC_NS, "CipherValue",
0);
         if (cipherValue == null) {
             LOG.fine("CipherValue element is not available");
             throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
@@ -524,7 +524,7 @@ public class SAMLProtocolResponseValidator {
     }
     
     private String getEncodingMethodAlgorithm(Element parent) throws WSSecurityException
{
-        Element encMethod = getNode(parent, WSConstants.ENC_NS, "EncryptionMethod", 0);
+        Element encMethod = getNode(parent, WSS4JConstants.ENC_NS, "EncryptionMethod", 0);
         if (encMethod == null) {
             LOG.fine("EncryptionMethod element is not available");
             throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
@@ -533,9 +533,9 @@ public class SAMLProtocolResponseValidator {
     }
     
     private String getDigestMethodAlgorithm(Element parent) {
-        Element encMethod = getNode(parent, WSConstants.ENC_NS, "EncryptionMethod", 0);
+        Element encMethod = getNode(parent, WSS4JConstants.ENC_NS, "EncryptionMethod", 0);
         if (encMethod != null) {
-            Element digestMethod = getNode(encMethod, WSConstants.SIG_NS, "DigestMethod",
0);
+            Element digestMethod = getNode(encMethod, WSS4JConstants.SIG_NS, "DigestMethod",
0);
             if (digestMethod != null) {
                 return digestMethod.getAttributeNS(null, "Algorithm");
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SSOConstants.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SSOConstants.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SSOConstants.java
index fde2ddd..340f375 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SSOConstants.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SSOConstants.java
@@ -18,7 +18,7 @@
  */
 package org.apache.cxf.rs.security.saml.sso;
 
-import org.apache.wss4j.dom.WSConstants;
+import org.apache.wss4j.common.WSS4JConstants;
 
 public final class SSOConstants {
     public static final String SAML_REQUEST = "SAMLRequest";
@@ -28,8 +28,8 @@ public final class SSOConstants {
     public static final String SIGNATURE = "Signature";
     public static final long DEFAULT_STATE_TIME = 2L * 60L * 1000L;
     
-    public static final String RSA_SHA1 = WSConstants.RSA_SHA1;
-    public static final String DSA_SHA1 = WSConstants.DSA;
+    public static final String RSA_SHA1 = WSS4JConstants.RSA_SHA1;
+    public static final String DSA_SHA1 = WSS4JConstants.DSA;
     
     
     public static final String SECURITY_CONTEXT_TOKEN = "org.apache.cxf.websso.context";

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SamlpRequestComponentBuilder.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SamlpRequestComponentBuilder.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SamlpRequestComponentBuilder.java
index 74f9b27..1125c27 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SamlpRequestComponentBuilder.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/SamlpRequestComponentBuilder.java
@@ -139,7 +139,7 @@ public final class SamlpRequestComponentBuilder {
         if (authnCtxClassRefList != null) {
             List<AuthnContextClassRef> classRefList = authnCtx.getAuthnContextClassRefs();
             if (classRefList == null) {
-                classRefList = new ArrayList<AuthnContextClassRef>();
+                classRefList = new ArrayList<>();
             }
             classRefList.addAll(authnCtxClassRefList);
         }
@@ -147,7 +147,7 @@ public final class SamlpRequestComponentBuilder {
         if (authnCtxDeclRefList != null) {
             List<AuthnContextDeclRef> declRefList = authnCtx.getAuthnContextDeclRefs();
             if (declRefList == null) {
-                declRefList = new ArrayList<AuthnContextDeclRef>();
+                declRefList = new ArrayList<>();
             }
             declRefList.addAll(authnCtxDeclRefList);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/MemorySPStateManager.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/MemorySPStateManager.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/MemorySPStateManager.java
index de9092b..dd549c6 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/MemorySPStateManager.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/state/MemorySPStateManager.java
@@ -24,11 +24,9 @@ import java.util.concurrent.ConcurrentHashMap;
 
 public class MemorySPStateManager implements SPStateManager {
 
-    private final Map<String, RequestState> requestStateMap = 
-        new ConcurrentHashMap<String, RequestState>(16, 0.75f, 4);
+    private final Map<String, RequestState> requestStateMap = new ConcurrentHashMap<>(16,
0.75f, 4);
     
-    private final Map<String, ResponseState> responseStateMap = 
-        new ConcurrentHashMap<String, ResponseState>(16, 0.75f, 4);
+    private final Map<String, ResponseState> responseStateMap = new ConcurrentHashMap<>(16,
0.75f, 4);
     
     public ResponseState getResponseState(String securityContextKey) {
         return responseStateMap.get(securityContextKey);

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java
index 8d1474e..62dae7b 100644
--- a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java
+++ b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/common/CryptoLoader.java
@@ -40,7 +40,7 @@ public class CryptoLoader {
 
     public Crypto loadCrypto(String cryptoResource) throws IOException, WSSecurityException
{
         URL url = 
-            org.apache.cxf.rt.security.utils.SecurityUtils.loadResource(null, cryptoResource);
+            org.apache.cxf.rt.security.utils.SecurityUtils.loadResource(cryptoResource);
         if (url != null) {
             return loadCryptoFromURL(url);
         } else {

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java
----------------------------------------------------------------------
diff --git a/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java
b/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java
index c62acf8..1f918f7 100644
--- a/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java
+++ b/rt/security/src/main/java/org/apache/cxf/rt/security/utils/SecurityUtils.java
@@ -20,15 +20,20 @@ package org.apache.cxf.rt.security.utils;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.net.URL;
+import java.util.Properties;
+import java.util.logging.Logger;
 
 import javax.security.auth.callback.CallbackHandler;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.resource.ResourceManager;
 import org.apache.wss4j.common.ext.WSSecurityException;
 
@@ -37,6 +42,8 @@ import org.apache.wss4j.common.ext.WSSecurityException;
  */
 public final class SecurityUtils {
     
+    private static final Logger LOG = LogUtils.getL7dLogger(SecurityUtils.class);
+    
     private SecurityUtils() {
         // complete
     }
@@ -65,7 +72,23 @@ public final class SecurityUtils {
         return loadResource(message, o);
     }
     
+    public static URL loadResource(Object o) {
+        return loadResource((Message)null, o);
+    }
+    
     public static URL loadResource(Message message, Object o) {
+        Message msg = message;
+        if (msg == null) {
+            msg = PhaseInterceptorChain.getCurrentMessage();
+        }
+        ResourceManager manager = null;
+        if (msg != null && msg.getExchange() != null && msg.getExchange().get(Bus.class)
!= null) {
+            manager = msg.getExchange().get(Bus.class).getExtension(ResourceManager.class);
+        }
+        return loadResource(manager, o);
+    }
+    
+    public static URL loadResource(ResourceManager manager, Object o) {
         
         if (o instanceof String) {
             URL url = ClassLoaderUtils.getResource((String)o, SecurityUtils.class);
@@ -74,8 +97,7 @@ public final class SecurityUtils {
             }
             ClassLoaderHolder orig = null;
             try {
-                if (message != null) {
-                    ResourceManager manager = message.getExchange().get(Bus.class).getExtension(ResourceManager.class);
+                if (manager != null) {
                     ClassLoader loader = manager.resolveResource((String)o, ClassLoader.class);
                     if (loader != null) {
                         orig = ClassLoaderUtils.setThreadContextClassloader(loader);
@@ -116,4 +138,31 @@ public final class SecurityUtils {
         return null;
     }
     
+    public static Properties loadProperties(Object o) {
+        if (o instanceof Properties) {
+            return (Properties)o;
+        } 
+        
+        URL url = null;
+        if (o instanceof String) {
+            url = SecurityUtils.loadResource(o);
+        } else if (o instanceof URL) {
+            url = (URL)o;
+        }
+        
+        if (url != null) {
+            Properties properties = new Properties();
+            try {
+                InputStream ins = ((URL)o).openStream();
+                properties.load(ins);
+                ins.close();
+            } catch (IOException e) {
+                LOG.fine(e.getMessage());
+                properties = null;
+            }
+            return properties;
+        }
+        
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/services/sts/sts-core/src/main/java/org/apache/cxf/sts/StaticSTSProperties.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/StaticSTSProperties.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/StaticSTSProperties.java
index 9a04be5..fa92bad 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/StaticSTSProperties.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/StaticSTSProperties.java
@@ -18,8 +18,6 @@
  */
 package org.apache.cxf.sts;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 import java.util.List;
 import java.util.Properties;
@@ -29,7 +27,6 @@ import javax.security.auth.callback.CallbackHandler;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.rt.security.utils.SecurityUtils;
@@ -74,7 +71,9 @@ public class StaticSTSProperties implements STSPropertiesMBean {
      */
     public void configureProperties() throws STSException {
         if (signatureCrypto == null && signatureCryptoProperties != null) {
-            Properties sigProperties = getProps(signatureCryptoProperties, bus);
+            ResourceManager resourceManager = getResourceManager();
+            URL url = SecurityUtils.loadResource(resourceManager, signatureCryptoProperties);
+            Properties sigProperties = SecurityUtils.loadProperties(url);
             if (sigProperties == null) {
                 LOG.fine("Cannot load signature properties using: " + signatureCryptoProperties);
                 throw new STSException("Configuration error: cannot load signature properties");
@@ -88,7 +87,9 @@ public class StaticSTSProperties implements STSPropertiesMBean {
         }
         
         if (encryptionCrypto == null && encryptionCryptoProperties != null) {
-            Properties encrProperties = getProps(encryptionCryptoProperties, bus);
+            ResourceManager resourceManager = getResourceManager();
+            URL url = SecurityUtils.loadResource(resourceManager, encryptionCryptoProperties);
+            Properties encrProperties = SecurityUtils.loadProperties(url);
             if (encrProperties == null) {
                 LOG.fine("Cannot load encryption properties using: " + encryptionCryptoProperties);
                 throw new STSException("Configuration error: cannot load encryption properties");
@@ -115,6 +116,14 @@ public class StaticSTSProperties implements STSPropertiesMBean {
         }
         WSSConfig.init();
     }
+    
+    private ResourceManager getResourceManager() {
+        Bus b = bus;
+        if (b == null) {
+            b = BusFactory.getThreadDefaultBus();
+        }
+        return b.getExtension(ResourceManager.class);
+    }
 
     /**
      * Set the CallbackHandler object. 
@@ -329,49 +338,6 @@ public class StaticSTSProperties implements STSPropertiesMBean {
         return identityMapper;
     }
     
-    private static Properties getProps(Object o, Bus bus) {
-        Properties properties = null;
-        if (o instanceof Properties) {
-            properties = (Properties)o;
-        } else if (o instanceof String) {
-            URL url = null;
-            Bus b = bus;
-            if (b == null) {
-                b = BusFactory.getThreadDefaultBus();
-            }
-            ResourceManager rm = b.getExtension(ResourceManager.class);
-            url = rm.resolveResource((String)o, URL.class);
-            try {
-                if (url == null) {
-                    url = ClassLoaderUtils.getResource((String)o, StaticSTSProperties.class);
-                }
-                if (url == null) {
-                    url = new URL((String)o);
-                }
-                if (url != null) {
-                    properties = new Properties();
-                    InputStream ins = url.openStream();
-                    properties.load(ins);
-                    ins.close();
-                }
-            } catch (IOException e) {
-                LOG.fine(e.getMessage());
-                properties = null;
-            }
-        } else if (o instanceof URL) {
-            properties = new Properties();
-            try {
-                InputStream ins = ((URL)o).openStream();
-                properties.load(ins);
-                ins.close();
-            } catch (IOException e) {
-                LOG.fine(e.getMessage());
-                properties = null;
-            }            
-        }
-        return properties;
-    }
-    
     public void setRelationships(List<Relationship> relationships) {
         this.relationships = relationships;
         this.relationshipResolver = new RelationshipResolver(this.relationships);

http://git-wip-us.apache.org/repos/asf/cxf/blob/40c9bfd5/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/realm/SAMLRealm.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/realm/SAMLRealm.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/realm/SAMLRealm.java
index 9c7e973..01aaf6f 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/realm/SAMLRealm.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/realm/SAMLRealm.java
@@ -19,22 +19,14 @@
 
 package org.apache.cxf.sts.token.realm;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
 import java.util.Properties;
 import java.util.logging.Logger;
 
 import javax.security.auth.callback.CallbackHandler;
 
-import org.apache.cxf.Bus;
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.rt.security.utils.SecurityUtils;
 import org.apache.cxf.sts.SignatureProperties;
-import org.apache.cxf.sts.StaticSTSProperties;
 import org.apache.cxf.ws.security.sts.provider.STSException;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.crypto.CryptoFactory;
@@ -129,7 +121,7 @@ public class SAMLRealm {
      */
     public Crypto getSignatureCrypto() {
         if (signatureCrypto == null && signaturePropertiesFile != null) {
-            Properties sigProperties = getProps(signaturePropertiesFile);
+            Properties sigProperties = SecurityUtils.loadProperties(signaturePropertiesFile);
             if (sigProperties == null) {
                 LOG.fine("Cannot load signature properties using: " + signaturePropertiesFile);
                 throw new STSException("Configuration error: cannot load signature properties");
@@ -184,44 +176,4 @@ public class SAMLRealm {
         return callbackHandler;
     }
     
-    private static Properties getProps(Object o) {
-        Properties properties = null;
-        if (o instanceof Properties) {
-            properties = (Properties)o;
-        } else if (o instanceof String) {
-            URL url = null;
-            Bus bus = PhaseInterceptorChain.getCurrentMessage().getExchange().getBus();
-            ResourceManager rm = bus.getExtension(ResourceManager.class);
-            url = rm.resolveResource((String)o, URL.class);
-            try {
-                if (url == null) {
-                    url = ClassLoaderUtils.getResource((String)o, StaticSTSProperties.class);
-                }
-                if (url == null) {
-                    url = new URL((String)o);
-                }
-                if (url != null) {
-                    properties = new Properties();
-                    InputStream ins = url.openStream();
-                    properties.load(ins);
-                    ins.close();
-                }
-            } catch (IOException e) {
-                LOG.fine(e.getMessage());
-                properties = null;
-            }
-        } else if (o instanceof URL) {
-            properties = new Properties();
-            try {
-                InputStream ins = ((URL)o).openStream();
-                properties.load(ins);
-                ins.close();
-            } catch (IOException e) {
-                LOG.fine(e.getMessage());
-                properties = null;
-            }            
-        }
-        return properties;
-    }
-    
 }


Mime
View raw message