cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [3/3] cxf git commit: Some code cleanup + fixes
Date Mon, 18 May 2015 17:05:56 GMT
Some code cleanup + fixes

Conflicts:
	rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
	services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
	services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java


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

Branch: refs/heads/3.0.x-fixes
Commit: 761d06a3be6a7cdac0a1794d63ba9419bd91dfad
Parents: a9c4ec3
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Mon May 18 13:19:09 2015 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Mon May 18 18:05:50 2015 +0100

----------------------------------------------------------------------
 .../jose/jws/NoneJwsSignatureVerifier.java      |   2 +-
 ...AbstractRequestAssertionConsumerHandler.java |   2 +-
 .../server/NettyHttpServerEngineFactory.java    |   2 +-
 .../apache/cxf/transport/http/ProxyFactory.java |   2 +-
 .../SecureConversationInInterceptor.java        |   7 +
 .../cxf/ws/security/trust/STSLoginModule.java   |   8 +-
 .../security/trust/STSStaxTokenValidator.java   |   4 +-
 .../cxf/sts/cache/AbstractIdentityCache.java    | 137 +++++++++++++++++++
 .../cxf/sts/cache/EHCacheIdentityCache.java     |  50 +++----
 .../cxf/sts/cache/MemoryIdentityCache.java      |  39 ++----
 .../apache/cxf/testutil/common/TestUtil.java    |  10 +-
 11 files changed, 190 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/NoneJwsSignatureVerifier.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/NoneJwsSignatureVerifier.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/NoneJwsSignatureVerifier.java
index ba1fad6..0373bf8 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/NoneJwsSignatureVerifier.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/NoneJwsSignatureVerifier.java
@@ -24,7 +24,7 @@ public class NoneJwsSignatureVerifier implements JwsSignatureVerifier {
 
     @Override
     public boolean verify(JwsHeaders headers, String unsignedText, byte[] signature) {
-        return headers.getAlgorithm().equals(getAlgorithm()) && signature.length
== 0;
+        return headers.getAlgorithm().equals(getAlgorithm().getJwaName()) && signature.length
== 0;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractRequestAssertionConsumerHandler.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractRequestAssertionConsumerHandler.java
b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractRequestAssertionConsumerHandler.java
index e20c84f..83dd499 100644
--- a/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractRequestAssertionConsumerHandler.java
+++ b/rt/rs/security/sso/saml/src/main/java/org/apache/cxf/rs/security/saml/sso/AbstractRequestAssertionConsumerHandler.java
@@ -205,7 +205,7 @@ public abstract class AbstractRequestAssertionConsumerHandler extends
AbstractSS
             reportError("MISSING_RELAY_STATE");
             throw ExceptionUtils.toBadRequestException(null, null);
         }
-        if (relayState.getBytes().length < 0 || relayState.getBytes().length > 80)
{
+        if (relayState.getBytes().length == 0 || relayState.getBytes().length > 80) {
             reportError("INVALID_RELAY_STATE");
             throw ExceptionUtils.toBadRequestException(null, null);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java
b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java
index 43fcb5d..a0da30e 100644
--- a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java
+++ b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java
@@ -175,7 +175,7 @@ public class NettyHttpServerEngineFactory implements BusLifeCycleListener
{
         LOG.log(Level.FINE, "CREATING_NETTY_SERVER_ENGINE",  port);
         TLSServerParameters tlsServerParameters = null;
         if (protocol.equals("https") && tlsServerParametersMap != null) {
-            tlsServerParameters = tlsServerParametersMap.get(port);
+            tlsServerParameters = tlsServerParametersMap.get(Integer.toString(port));
         }
         NettyHttpServerEngine ref = getOrCreate(this, host, port, tlsServerParameters);
         // checking the protocol

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
index a97286c..22779db 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
@@ -76,7 +76,7 @@ public class ProxyFactory {
             // 8080 is the default proxy port value as per some documentation
             String proxyPort = SystemPropertyAction.getProperty(HTTP_PROXY_PORT, "8080");
             if (StringUtils.isEmpty(proxyPort)) {
-                proxyPort = null;
+                proxyPort = "8080";
             }
             
             systemProxyConfiguration.setProxyServerPort(Integer.valueOf(proxyPort));

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
index ef97425..1b08acc 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SecureConversationInInterceptor.java
@@ -547,7 +547,14 @@ class SecureConversationInInterceptor extends AbstractPhaseInterceptor<SoapMessa
                     }
                     
                     client.cancelSecurityToken(tok);
+<<<<<<< HEAD
                     NegotiationUtils.getTokenStore(m2).remove(tok.getId());
+=======
+                    TokenStore tokenStore = TokenStoreUtils.getTokenStore(m2);
+                    if (tokenStore != null) {
+                        tokenStore.remove(tok.getId());
+                    }
+>>>>>>> 591e5d9... Some code cleanup + fixes
                     m2.put(SecurityConstants.TOKEN, null);
                 } catch (RuntimeException e) {
                     throw e;

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
index 465a4c9..60b0248 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
@@ -257,7 +257,7 @@ public class STSLoginModule implements LoginModule {
                 message.put(SecurityConstants.STS_CLIENT, stsClient);
                 data.setMsgContext(message);
             } else {
-                TokenStore tokenStore = configureTokenStore(message);
+                TokenStore tokenStore = configureTokenStore();
                 validator.setStsClient(stsClient);
                 validator.setTokenStore(tokenStore);
             }
@@ -325,11 +325,7 @@ public class STSLoginModule implements LoginModule {
         return c;
     }
     
-    private TokenStore configureTokenStore(Message msg) throws MalformedURLException {
-        if (msg != null) {
-            return STSTokenValidator.getTokenStore(msg);
-        }
-        
+    private TokenStore configureTokenStore() throws MalformedURLException {
         if (TokenStoreFactory.isEhCacheInstalled()) {
             String cfg = "cxf-ehcache.xml";
             URL url = null;

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
index f144182..b2d3844 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
@@ -533,7 +533,7 @@ public class STSStaxTokenValidator
         private Element convertToDOM(
             BinarySecurityTokenType binarySecurityTokenType,
             byte[] securityTokenData
-        ) {
+        ) throws WSSecurityException {
             Document doc = DOMUtils.newDocument();
             BinarySecurity binarySecurity = null;
             if (WSSConstants.NS_X509_V3_TYPE.equals(binarySecurityTokenType.getValueType()))
{
@@ -542,6 +542,8 @@ public class STSStaxTokenValidator
                 binarySecurity = new PKIPathSecurity(doc);
             } else if (WSSConstants.NS_GSS_Kerberos5_AP_REQ.equals(binarySecurityTokenType.getValueType()))
{
                 binarySecurity = new KerberosSecurity(doc);
+            } else {
+                throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN);
             }
             
             binarySecurity.addWSSENamespace();

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/AbstractIdentityCache.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/AbstractIdentityCache.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/AbstractIdentityCache.java
new file mode 100644
index 0000000..4c3ef25
--- /dev/null
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/AbstractIdentityCache.java
@@ -0,0 +1,137 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.sts.cache;
+
+import java.security.Principal;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.management.ManagedComponent;
+import org.apache.cxf.sts.IdentityMapper;
+import org.apache.wss4j.common.principal.CustomTokenPrincipal;
+
+public abstract class AbstractIdentityCache implements IdentityCache, IdentityMapper, ManagedComponent
{
+    
+    private static final Logger LOG = LogUtils.getL7dLogger(AbstractIdentityCache.class);
+    
+    private final IdentityMapper identityMapper;
+    private final Bus bus;
+    private MemoryIdentityCacheStatistics statistics;
+    
+    public AbstractIdentityCache(IdentityMapper identityMapper) {
+        this(null, identityMapper);
+    }
+    
+    public AbstractIdentityCache(Bus bus, IdentityMapper identityMapper) {
+        this.identityMapper = identityMapper;
+        this.bus = bus;
+    }
+    
+    public Principal mapPrincipal(String sourceRealm,
+            Principal sourcePrincipal, String targetRealm) {
+        
+        Principal targetPrincipal = null;
+        Map<String, String> identities = this.get(sourcePrincipal.getName(), sourceRealm);
+        if (identities != null) {
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Identities found for '" + sourcePrincipal.getName() + "@" + sourceRealm
+ "'");
+            }
+            // Identities object found for key sourceUser@sourceRealm
+            String targetUser = identities.get(targetRealm);
+            if (targetUser == null) {
+                getStatistics().increaseCacheMiss();
+                if (LOG.isLoggable(Level.FINE)) {
+                    LOG.fine("No mapping found for realm " + targetRealm + " of user '"
+                             + sourcePrincipal.getName() + "@" + sourceRealm + "'");
+                }
+                // User identity of target realm not cached yet
+                targetPrincipal = this.identityMapper.mapPrincipal(
+                        sourceRealm, sourcePrincipal, targetRealm);
+                // Add the identity for target realm to the cached entry 
+                identities.put(targetRealm, targetPrincipal.getName());
+                
+                // Verify whether target user has cached some identities already
+                Map<String, String> cachedItem = this.get(targetPrincipal.getName(),
targetRealm);
+                if (cachedItem != null) {
+                    if (LOG.isLoggable(Level.FINE)) {
+                        LOG.fine("Merging mappings for '" + sourcePrincipal.getName() + "@"
+ sourceRealm + "'");
+                    }
+                    //Identities already cached for targetUser@targetRealm key pair
+                    //Merge into identities object
+                    this.mergeMap(identities, cachedItem);
+                }
+                this.add(targetPrincipal.getName(), targetRealm, identities);
+            } else {
+                getStatistics().increaseCacheHit();
+                if (LOG.isLoggable(Level.INFO)) {
+                    LOG.info("Mapping '" + sourcePrincipal.getName() + "@" + sourceRealm
+ "' to '"
+                             + targetUser + "@" + targetRealm + "' cached");
+                }
+                targetPrincipal = new CustomTokenPrincipal(targetUser);
+            }
+            
+        } else {
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("No mapping found for realm " + targetRealm + " of user '"
+                        + sourcePrincipal.getName() + "@" + sourceRealm + "'");
+            }
+            getStatistics().increaseCacheMiss();
+            
+            // Identities object NOT found for key sourceUser@sourceRealm
+            targetPrincipal = this.identityMapper.mapPrincipal(
+                    sourceRealm, sourcePrincipal, targetRealm);
+            identities = new HashMap<>();
+            identities.put(sourceRealm, sourcePrincipal.getName());
+            identities.put(targetRealm, targetPrincipal.getName());
+            this.add(targetPrincipal.getName(), targetRealm, identities);
+            this.add(sourcePrincipal.getName(), sourceRealm, identities);
+        }
+        return targetPrincipal;
+    }
+    
+    public MemoryIdentityCacheStatistics getStatistics() {
+        if (statistics == null) {
+            this.statistics = new MemoryIdentityCacheStatistics(bus, this);
+        }
+        return statistics;
+    }
+
+    public void setStatistics(MemoryIdentityCacheStatistics stats) {
+        this.statistics = stats;
+    }
+
+    private void mergeMap(Map<String, String> to, Map<String, String> from) {
+        for (Map.Entry<String, String> entry : from.entrySet()) {
+            to.put(entry.getKey(), entry.getValue());
+        }
+        for (Map.Entry<String, String> entry : to.entrySet()) {
+            from.put(entry.getKey(), entry.getValue());
+        }
+    }
+    
+    protected Bus getBus() {
+        return bus;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
index fea5c09..256ac54 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
@@ -22,8 +22,6 @@ package org.apache.cxf.sts.cache;
 import java.io.Closeable;
 import java.io.IOException;
 import java.net.URL;
-import java.security.Principal;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -43,7 +41,6 @@ import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.management.InstrumentationManager;
-import org.apache.cxf.management.ManagedComponent;
 import org.apache.cxf.management.ManagementConstants;
 import org.apache.cxf.management.annotation.ManagedOperation;
 import org.apache.cxf.management.annotation.ManagedResource;
@@ -52,22 +49,18 @@ import org.apache.cxf.sts.IdentityMapper;
 import org.apache.cxf.ws.security.cache.EHCacheUtils;
 import org.apache.cxf.ws.security.tokenstore.TokenStoreFactory;
 import org.apache.wss4j.common.cache.EHCacheManagerHolder;
-import org.apache.wss4j.common.principal.CustomTokenPrincipal;
 
 /**
  * A EH-Cache based cache to cache identities in different realms where
  * the relationship is of type FederateIdentity.
  */
 @ManagedResource()
-public class EHCacheIdentityCache 
-    implements IdentityCache, IdentityMapper, Closeable, BusLifeCycleListener, ManagedComponent
{
+public class EHCacheIdentityCache extends AbstractIdentityCache 
+    implements Closeable, BusLifeCycleListener {
     
     private static final Logger LOG = LogUtils.getL7dLogger(EHCacheIdentityCache.class);
     
-    private IdentityMapper identityMapper;
-    private MemoryIdentityCacheStatistics statistics;
     private Ehcache cache;
-    private Bus bus;
     private CacheManager cacheManager;
     
     
@@ -80,10 +73,8 @@ public class EHCacheIdentityCache
     public EHCacheIdentityCache(
         IdentityMapper identityMapper, String key, Bus b, URL configFileURL
     ) {
-        this.identityMapper = identityMapper;
-        
-        bus = b;
-        if (bus != null) {
+        super(b, identityMapper);
+        if (b != null) {
             b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this);
             InstrumentationManager im = b.getExtension(InstrumentationManager.class);
             if (im != null) {
@@ -96,9 +87,9 @@ public class EHCacheIdentityCache
         }
 
         if (configFileURL != null) {
-            cacheManager = EHCacheUtils.getCacheManager(bus, configFileURL);
+            cacheManager = EHCacheUtils.getCacheManager(b, configFileURL);
         } else {
-            cacheManager = EHCacheUtils.getCacheManager(bus, getDefaultConfigFileURL());
+            cacheManager = EHCacheUtils.getCacheManager(b, getDefaultConfigFileURL());
         }
         CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager);
         
@@ -106,17 +97,6 @@ public class EHCacheIdentityCache
         cache = cacheManager.addCacheIfAbsent(newCache);
     }
     
-    public MemoryIdentityCacheStatistics getStatistics() {
-        if (statistics == null) {
-            this.statistics = new MemoryIdentityCacheStatistics(bus, this);
-        }
-        return statistics;
-    }
-
-    public void setStatistics(MemoryIdentityCacheStatistics stats) {
-        this.statistics = stats;
-    }
-
     @Override
     public void add(String user, String realm, Map<String, String> identities) {
         cache.put(new Element(user + "@" + realm, identities));
@@ -155,6 +135,7 @@ public class EHCacheIdentityCache
         return this.cache.toString();
     }
 
+<<<<<<< HEAD
     @Override
     public Principal mapPrincipal(String sourceRealm,
             Principal sourcePrincipal, String targetRealm) {
@@ -229,6 +210,8 @@ public class EHCacheIdentityCache
         }
     }
     
+=======
+>>>>>>> 591e5d9... Some code cleanup + fixes
     public void close() {
         if (cacheManager != null) {
             // this step is especially important for global shared cache manager
@@ -239,8 +222,8 @@ public class EHCacheIdentityCache
             EHCacheManagerHolder.releaseCacheManger(cacheManager);
             cacheManager = null;
             cache = null;
-            if (bus != null) {
-                bus.getExtension(BusLifeCycleManager.class).unregisterLifeCycleListener(this);
+            if (super.getBus() != null) {
+                super.getBus().getExtension(BusLifeCycleManager.class).unregisterLifeCycleListener(this);
             }
         }
     }
@@ -258,8 +241,10 @@ public class EHCacheIdentityCache
     
     private URL getDefaultConfigFileURL() {
         URL url = null;
-        ResourceManager rm = bus.getExtension(ResourceManager.class);
-        url = rm.resolveResource("sts-ehcache.xml", URL.class);
+        if (super.getBus() != null) {
+            ResourceManager rm = super.getBus().getExtension(ResourceManager.class);
+            url = rm.resolveResource("sts-ehcache.xml", URL.class);
+        }
         try {
             if (url == null) {
                 url = ClassLoaderUtils.getResource("sts-ehcache.xml", TokenStoreFactory.class);
@@ -277,7 +262,10 @@ public class EHCacheIdentityCache
     public ObjectName getObjectName() throws JMException {
         StringBuilder buffer = new StringBuilder();
         buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME).append(':');
-        buffer.append(ManagementConstants.BUS_ID_PROP).append('=').append(bus.getId()).append(',');
+        if (super.getBus() != null) {
+            buffer.append(
+                ManagementConstants.BUS_ID_PROP).append('=').append(super.getBus().getId()).append(',');
+        }
         buffer.append(ManagementConstants.TYPE_PROP).append('=').append("EHCacheIdentityCache").append(',');
         buffer.append(ManagementConstants.NAME_PROP).append('=')
             .append("EHCacheIdentityCache-" + System.identityHashCode(this));

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java
index 58862ec..b084a51 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java
@@ -19,7 +19,6 @@
 
 package org.apache.cxf.sts.cache;
 
-import java.security.Principal;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -32,19 +31,17 @@ import javax.management.ObjectName;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.management.InstrumentationManager;
-import org.apache.cxf.management.ManagedComponent;
 import org.apache.cxf.management.ManagementConstants;
 import org.apache.cxf.management.annotation.ManagedOperation;
 import org.apache.cxf.management.annotation.ManagedResource;
 import org.apache.cxf.sts.IdentityMapper;
-import org.apache.wss4j.common.principal.CustomTokenPrincipal;
 
 /**
  * A simple in-memory HashMap based cache to cache identities in different realms where
  * the relationship is of type FederateIdentity.
  */
 @ManagedResource()
-public class MemoryIdentityCache implements IdentityCache, IdentityMapper, ManagedComponent
{
+public class MemoryIdentityCache extends AbstractIdentityCache {
     
     private static final Logger LOG = LogUtils.getL7dLogger(MemoryIdentityCache.class);
     
@@ -53,23 +50,16 @@ public class MemoryIdentityCache implements IdentityCache, IdentityMapper,
Manag
     
     private long maxCacheItems = 10000L;
     
-    private IdentityMapper identityMapper;
-    private final Bus bus;
-    
-    private MemoryIdentityCacheStatistics statistics;
-    
-
     protected MemoryIdentityCache() {
-        this.bus = null;
+        super(null, null);
     }
     
     public MemoryIdentityCache(IdentityMapper identityMapper) {
-        this.identityMapper = identityMapper;
-        this.bus = null;
+        super(null, identityMapper);
     }
+    
     public MemoryIdentityCache(Bus bus, IdentityMapper identityMapper) {
-        this.identityMapper = identityMapper;
-        this.bus = bus;
+        super(bus, identityMapper);
         if (bus != null) {
             InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
             if (im != null) {
@@ -82,17 +72,6 @@ public class MemoryIdentityCache implements IdentityCache, IdentityMapper,
Manag
         }
     }
     
-    public MemoryIdentityCacheStatistics getStatistics() {
-        if (statistics == null) {
-            this.statistics = new MemoryIdentityCacheStatistics(bus, this);
-        }
-        return statistics;
-    }
-
-    public void setStatistics(MemoryIdentityCacheStatistics stats) {
-        this.statistics = stats;
-    }
-
     public long getMaxCacheItems() {
         return maxCacheItems;
     }
@@ -137,6 +116,7 @@ public class MemoryIdentityCache implements IdentityCache, IdentityMapper,
Manag
         return this.cache.toString();
     }
 
+<<<<<<< HEAD
     @Override
     public Principal mapPrincipal(String sourceRealm,
             Principal sourcePrincipal, String targetRealm) {
@@ -211,10 +191,15 @@ public class MemoryIdentityCache implements IdentityCache, IdentityMapper,
Manag
         }
     }
     
+=======
+>>>>>>> 591e5d9... Some code cleanup + fixes
     public ObjectName getObjectName() throws JMException {
         StringBuilder buffer = new StringBuilder();
         buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME).append(':');
-        buffer.append(ManagementConstants.BUS_ID_PROP).append('=').append(bus.getId()).append(',');
+        if (super.getBus() != null) {
+            buffer.append(
+                ManagementConstants.BUS_ID_PROP).append('=').append(super.getBus().getId()).append(',');
+        }
         buffer.append(ManagementConstants.TYPE_PROP).append('=').append("MemoryIdentityCache").append(',');
         buffer.append(ManagementConstants.NAME_PROP).append('=')
             .append("MemoryIdentityCache-" + System.identityHashCode(this));

http://git-wip-us.apache.org/repos/asf/cxf/blob/761d06a3/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
----------------------------------------------------------------------
diff --git a/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java b/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
index 472ef07..2cb3703 100644
--- a/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
+++ b/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
@@ -79,10 +79,12 @@ public final class TestUtil {
     public static boolean deleteDir(File dir) {
         if (dir.isDirectory()) {
             String[] children = dir.list();
-            for (int i = 0; i < children.length; i++) {
-                boolean success = deleteDir(new File(dir, children[i]));
-                if (!success) {
-                    return false;
+            if (children != null) {
+                for (int i = 0; i < children.length; i++) {
+                    boolean success = deleteDir(new File(dir, children[i]));
+                    if (!success) {
+                        return false;
+                    }
                 }
             }
         }


Mime
View raw message