From 5ee8c0f0654ffee90282f2c66e912884249f8a17 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Wed, 2 Sep 2015 14:47:36 +0530 Subject: [PATCH 1/3] Fixing the cache manager issues --- .../operation/mgt/OperationManagerImpl.java | 2 +- .../org.wso2.carbon.policy.mgt.core/pom.xml | 3 +- .../cache/impl/PolicyCacheManagerImpl.java | 233 ++++++++++++++---- .../core/util/PolicyManagementConstants.java | 1 + .../mgt/core/util/PolicyManagerUtil.java | 30 ++- 5 files changed, 212 insertions(+), 57 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 0315ded100..c26eea0de4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -184,7 +184,7 @@ public class OperationManagerImpl implements OperationManager { } finally { DeviceManagementDAOFactory.closeConnection(); } - + OperationManagementDAOFactory.openConnection(); if (enrolmentId < 0) { throw new OperationManagementException("Device not found for the given device Identifier:" + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index a2333b475d..7e7a50ecd8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -71,7 +71,8 @@ org.wso2.carbon.user.api.*, org.wso2.carbon.device.mgt.core.*, org.wso2.carbon.device.mgt.common.*, - org.wso2.carbon.ntask.* + org.wso2.carbon.ntask.*, + org.wso2.carbon.caching.* !org.wso2.carbon.policy.mgt.core.internal, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java index 677b30920d..28096de9c1 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java @@ -27,11 +27,13 @@ import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager; import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager; import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl; +import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants; +import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; -import java.util.ArrayList; +import javax.cache.Cache; import java.util.HashMap; +import java.util.Iterator; import java.util.List; -import java.util.Set; public class PolicyCacheManagerImpl implements PolicyCacheManager { @@ -41,6 +43,14 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { private static PolicyCacheManagerImpl policyCacheManager; +// private static Cache getPolicyCache() { +// return PolicyManagerUtil.getPolicyCache(PolicyManagementConstants.DM_CACHE); +// } + + private static Cache> getPolicyListCache() { + return PolicyManagerUtil.getPolicyListCache(PolicyManagementConstants.DM_CACHE_LIST); + } + private PolicyCacheManagerImpl() { } @@ -57,43 +67,87 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void addAllPolicies(List policies) { - HashMap map = this.getTenantRelatedMap(); - if (map.isEmpty()) { - for (Policy policy : policies) { - map.put(policy.getId(), policy); - } - } + // HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// if (cache.isEmpty()) { + +// for (Policy policy : policies) { +// cache.put(policy.getId(), policy); +// } +// } + + Cache> lCache = getPolicyListCache(); + lCache.put(1, policies); } @Override public void updateAllPolicies(List policies) { - HashMap map = this.getTenantRelatedMap(); - map.clear(); - if (map.isEmpty()) { - for (Policy policy : policies) { - map.put(policy.getId(), policy); - } - } +//// HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// cache.removeAll(); +//// map.clear(); +//// if (map.isEmpty()) { +// for (Policy policy : policies) { +//// map.put(policy.getId(), policy); +// cache.put(policy.getId(), policy); +// } +//// } + + Cache> lCache = getPolicyListCache(); + lCache.removeAll(); + lCache.put(1, policies); } @Override public List getAllPolicies() throws PolicyManagementException { - HashMap map = this.getTenantRelatedMap(); - if (map.isEmpty()) { +// // HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// Iterator iterator = cache.iterator(); +//// iterator.hasNext() +// if (!iterator.hasNext()) { +// PolicyManager policyManager = new PolicyManagerImpl(); +// this.addAllPolicies(policyManager.getPolicies()); +// } +// if (log.isDebugEnabled()) { +// //log.debug("No of policies stored in the cache .. : " + map.size()); +// +// //Set keySet = map.keySet(); +// Iterator iterator2 = cache.iterator(); +// while (iterator2.hasNext()) { +// org.wso2.carbon.caching.impl.CacheEntry thisEntry = (org.wso2.carbon.caching.impl.CacheEntry) +// iterator2.next(); +// log.debug("Policy id in maps .. : " + thisEntry.getKey() + " policy name : " + ((Policy) thisEntry +// .getValue()). +// getPolicyName() + " Activated : " + ((Policy) thisEntry.getValue()).isActive()); +// } +// } +// +// List policies = new ArrayList<>(); +// while (iterator.hasNext()){ +// CacheEntry thisEntry = (CacheEntry) iterator.next(); +// policies.add((Policy) thisEntry.getValue()); +// } +// +// return policies; +//// return new ArrayList<>(map.values()); + + Cache> lCache = getPolicyListCache(); + if (!lCache.containsKey(1)) { PolicyManager policyManager = new PolicyManagerImpl(); this.addAllPolicies(policyManager.getPolicies()); } - if (log.isDebugEnabled()) { - log.debug("No of policies stored in the cache .. : " + map.size()); - Set keySet = map.keySet(); - for (Integer x : keySet) { - log.debug("Policy id in maps .. : " + map.get(x).getId() + " policy name : " + map.get(x). - getPolicyName() + " Activated : " + map.get(x).isActive()); + if (log.isDebugEnabled()) { + List cachedPolicy = lCache.get(1); + for (Policy policy : cachedPolicy) { + log.debug("Policy id in cache .. : " + policy.getId() + " policy name : " + policy. + getPolicyName() + " Activated : " + policy.isActive()); } } - return new ArrayList<>(map.values()); + + return lCache.get(1); + } @Override @@ -105,59 +159,136 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void removeAllPolicies() { - HashMap map = this.getTenantRelatedMap(); - map.clear(); +// Cache cache = getPolicyCache(); +// cache.removeAll(); + //HashMap map = this.getTenantRelatedMap(); + //map.clear(); + + Cache> lCache = getPolicyListCache(); + lCache.removeAll(); } @Override public void addPolicy(Policy policy) { - HashMap map = this.getTenantRelatedMap(); - if (!map.containsKey(policy.getId())) { - map.put(policy.getId(), policy); - } else { - log.warn("Policy id (" + policy.getId() + ") already exist in the map. hence not attempted to store."); + //HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// if (!cache.containsKey(policy.getId())) { +// cache.put(policy.getId(), policy); +// } else { +// log.warn("Policy id (" + policy.getId() + ") already exist in the map. hence not attempted to store."); +// } + + Cache> lCache = getPolicyListCache(); + if (lCache.containsKey(1)) { + List cachedPolicy = lCache.get(1); + + for (Policy pol : cachedPolicy) { + if (pol.getId() == policy.getId()) { + return; + } + } + cachedPolicy.add(policy); } + } @Override public void updatePolicy(Policy policy) { - HashMap map = this.getTenantRelatedMap(); - if (map.containsKey(policy.getId())) { - map.remove(policy.getId()); - map.put(policy.getId(), policy); + // HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// if (cache.containsKey(policy.getId())) { +// cache.remove(policy.getId()); +// cache.put(policy.getId(), policy); +// } + + Cache> lCache = getPolicyListCache(); + if (lCache.containsKey(1)) { + List cachedPolicy = lCache.get(1); + Iterator iterator = cachedPolicy.iterator(); + while (iterator.hasNext()) { + Policy pol = (Policy) iterator.next(); + if (pol.getId() == policy.getId()) { + iterator.remove(); + break; + } + } + cachedPolicy.add(policy); + lCache.replace(1, cachedPolicy); } + } @Override public void updatePolicy(int policyId) throws PolicyManagementException { - HashMap map = this.getTenantRelatedMap(); - if (map.containsKey(policyId)) { - this.removePolicy(policyId); + // HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// if (cache.containsKey(policyId)) { +// this.removePolicy(policyId); +// } +// PolicyManager policyManager = new PolicyManagerImpl(); +// Policy policy = policyManager.getPolicy(policyId); +// cache.put(policyId, policy); + + Cache> lCache = getPolicyListCache(); + if (lCache.containsKey(1)) { + PolicyManager policyManager = new PolicyManagerImpl(); + Policy policy = policyManager.getPolicy(policyId); + this.updatePolicy(policy); } - PolicyManager policyManager = new PolicyManagerImpl(); - Policy policy = policyManager.getPolicy(policyId); - map.put(policyId, policy); + } @Override public void removePolicy(int policyId) { - HashMap map = this.getTenantRelatedMap(); - if (map.containsKey(policyId)) { - map.remove(policyId); - } else { - log.warn("Policy id (" + policyId + ") does not exist in the cache. Hence not removed."); + // HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// if (cache.containsKey(policyId)) { +// cache.remove(policyId); +// } else { +// log.warn("Policy id (" + policyId + ") does not exist in the cache. Hence not removed."); +// } + + Cache> lCache = getPolicyListCache(); + if (lCache.containsKey(1)) { + List cachedPolicy = lCache.get(1); + Iterator iterator = cachedPolicy.iterator(); + while (iterator.hasNext()) { + Policy pol = (Policy) iterator.next(); + if (pol.getId() == policyId) { + iterator.remove(); + break; + } + } + lCache.replace(1, cachedPolicy); } } @Override public Policy getPolicy(int policyId) throws PolicyManagementException { - HashMap map = this.getTenantRelatedMap(); - if (!map.containsKey(policyId)) { + //HashMap map = this.getTenantRelatedMap(); +// Cache cache = getPolicyCache(); +// if (!cache.containsKey(policyId)) { +// this.removeAllPolicies(); +// this.getAllPolicies(); +// } +// return cache.get(policyId); + + Cache> lCache = getPolicyListCache(); + if (!lCache.containsKey(1)) { this.removeAllPolicies(); this.getAllPolicies(); } - return map.get(policyId); + Policy policy = null; + List cachedPolicy = lCache.get(1); + Iterator iterator = cachedPolicy.iterator(); + while (iterator.hasNext()) { + Policy pol = (Policy) iterator.next(); + if (pol.getId() == policyId) { + policy = pol; + } + } + return policy; } @Override @@ -175,10 +306,10 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { return 0; } - private HashMap getTenantRelatedMap(){ + private HashMap getTenantRelatedMap() { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - if(!tenantedPolicyMap.containsKey(tenantId)){ + if (!tenantedPolicyMap.containsKey(tenantId)) { HashMap policyMap = new HashMap<>(); tenantedPolicyMap.put(tenantId, policyMap); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java index e8354b3e99..13a2df3442 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java @@ -39,6 +39,7 @@ public final class PolicyManagementConstants { public static final String DM_CACHE_MANAGER = "DM_CACHE_MANAGER"; public static final String DM_CACHE = "DM_CACHE"; + public static final String DM_CACHE_LIST = "DM_CACHE_LIST"; public static final String DELEGATION_TASK_TYPE = "DELEGATION__TASK"; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index 198913c055..ed14a3c6ea 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -31,6 +31,10 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; +import org.wso2.carbon.registry.api.GhostResource; +import org.wso2.carbon.registry.core.RegistryConstants; +import org.wso2.carbon.registry.core.caching.RegistryCacheEntry; +import org.wso2.carbon.registry.core.caching.RegistryCacheKey; import javax.cache.Cache; import javax.cache.CacheManager; @@ -152,10 +156,28 @@ public class PolicyManagerUtil { } - public static Cache getCacheManagerImpl() { - return Caching.getCacheManagerFactory() - .getCacheManager(PolicyManagementConstants.DM_CACHE_MANAGER).getCache(PolicyManagementConstants - .DM_CACHE); +// public static Cache getCacheManagerImpl() { +// return Caching.getCacheManagerFactory() +// .getCacheManager(PolicyManagementConstants.DM_CACHE_MANAGER).getCache(PolicyManagementConstants +// .DM_CACHE); +// } + + + public static Cache getPolicyCache(String name){ + CacheManager manager = getCacheManager(); + return (manager != null) ? manager.getCache(name) : + Caching.getCacheManager().getCache(name); + } + + public static Cache> getPolicyListCache(String name){ + CacheManager manager = getCacheManager(); + return (manager != null) ? manager.>getCache(name) : + Caching.getCacheManager().>getCache(name); + } + + private static CacheManager getCacheManager() { + return Caching.getCacheManagerFactory().getCacheManager( + PolicyManagementConstants.DM_CACHE_MANAGER); } From dff526b27237cf52d1a9f70f75bd6664c2c8b4b9 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Wed, 2 Sep 2015 15:02:33 +0530 Subject: [PATCH 2/3] Removing the unnessary commets and imports --- .../cache/impl/PolicyCacheManagerImpl.java | 107 ------------------ .../mgt/core/util/PolicyManagerUtil.java | 4 - 2 files changed, 111 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java index 28096de9c1..624b5ac9d4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/cache/impl/PolicyCacheManagerImpl.java @@ -21,7 +21,6 @@ package org.wso2.carbon.policy.mgt.core.cache.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.core.cache.PolicyCacheManager; @@ -31,7 +30,6 @@ import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; import javax.cache.Cache; -import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -39,14 +37,8 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { private static final Log log = LogFactory.getLog(PolicyCacheManagerImpl.class); - private static HashMap> tenantedPolicyMap = new HashMap<>(); - private static PolicyCacheManagerImpl policyCacheManager; -// private static Cache getPolicyCache() { -// return PolicyManagerUtil.getPolicyCache(PolicyManagementConstants.DM_CACHE); -// } - private static Cache> getPolicyListCache() { return PolicyManagerUtil.getPolicyListCache(PolicyManagementConstants.DM_CACHE_LIST); } @@ -67,15 +59,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void addAllPolicies(List policies) { - // HashMap map = this.getTenantRelatedMap(); - -// Cache cache = getPolicyCache(); -// if (cache.isEmpty()) { - -// for (Policy policy : policies) { -// cache.put(policy.getId(), policy); -// } -// } Cache> lCache = getPolicyListCache(); lCache.put(1, policies); @@ -83,16 +66,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void updateAllPolicies(List policies) { -//// HashMap map = this.getTenantRelatedMap(); -// Cache cache = getPolicyCache(); -// cache.removeAll(); -//// map.clear(); -//// if (map.isEmpty()) { -// for (Policy policy : policies) { -//// map.put(policy.getId(), policy); -// cache.put(policy.getId(), policy); -// } -//// } Cache> lCache = getPolicyListCache(); lCache.removeAll(); @@ -101,43 +74,12 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public List getAllPolicies() throws PolicyManagementException { -// // HashMap map = this.getTenantRelatedMap(); -// Cache cache = getPolicyCache(); -// Iterator iterator = cache.iterator(); -//// iterator.hasNext() -// if (!iterator.hasNext()) { -// PolicyManager policyManager = new PolicyManagerImpl(); -// this.addAllPolicies(policyManager.getPolicies()); -// } -// if (log.isDebugEnabled()) { -// //log.debug("No of policies stored in the cache .. : " + map.size()); -// -// //Set keySet = map.keySet(); -// Iterator iterator2 = cache.iterator(); -// while (iterator2.hasNext()) { -// org.wso2.carbon.caching.impl.CacheEntry thisEntry = (org.wso2.carbon.caching.impl.CacheEntry) -// iterator2.next(); -// log.debug("Policy id in maps .. : " + thisEntry.getKey() + " policy name : " + ((Policy) thisEntry -// .getValue()). -// getPolicyName() + " Activated : " + ((Policy) thisEntry.getValue()).isActive()); -// } -// } -// -// List policies = new ArrayList<>(); -// while (iterator.hasNext()){ -// CacheEntry thisEntry = (CacheEntry) iterator.next(); -// policies.add((Policy) thisEntry.getValue()); -// } -// -// return policies; -//// return new ArrayList<>(map.values()); Cache> lCache = getPolicyListCache(); if (!lCache.containsKey(1)) { PolicyManager policyManager = new PolicyManagerImpl(); this.addAllPolicies(policyManager.getPolicies()); } - if (log.isDebugEnabled()) { List cachedPolicy = lCache.get(1); for (Policy policy : cachedPolicy) { @@ -145,7 +87,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { getPolicyName() + " Activated : " + policy.isActive()); } } - return lCache.get(1); } @@ -159,10 +100,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void removeAllPolicies() { -// Cache cache = getPolicyCache(); -// cache.removeAll(); - //HashMap map = this.getTenantRelatedMap(); - //map.clear(); Cache> lCache = getPolicyListCache(); lCache.removeAll(); @@ -170,13 +107,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void addPolicy(Policy policy) { - //HashMap map = this.getTenantRelatedMap(); -// Cache cache = getPolicyCache(); -// if (!cache.containsKey(policy.getId())) { -// cache.put(policy.getId(), policy); -// } else { -// log.warn("Policy id (" + policy.getId() + ") already exist in the map. hence not attempted to store."); -// } Cache> lCache = getPolicyListCache(); if (lCache.containsKey(1)) { @@ -194,12 +124,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void updatePolicy(Policy policy) { - // HashMap map = this.getTenantRelatedMap(); -// Cache cache = getPolicyCache(); -// if (cache.containsKey(policy.getId())) { -// cache.remove(policy.getId()); -// cache.put(policy.getId(), policy); -// } Cache> lCache = getPolicyListCache(); if (lCache.containsKey(1)) { @@ -220,14 +144,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void updatePolicy(int policyId) throws PolicyManagementException { - // HashMap map = this.getTenantRelatedMap(); -// Cache cache = getPolicyCache(); -// if (cache.containsKey(policyId)) { -// this.removePolicy(policyId); -// } -// PolicyManager policyManager = new PolicyManagerImpl(); -// Policy policy = policyManager.getPolicy(policyId); -// cache.put(policyId, policy); Cache> lCache = getPolicyListCache(); if (lCache.containsKey(1)) { @@ -240,13 +156,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public void removePolicy(int policyId) { - // HashMap map = this.getTenantRelatedMap(); -// Cache cache = getPolicyCache(); -// if (cache.containsKey(policyId)) { -// cache.remove(policyId); -// } else { -// log.warn("Policy id (" + policyId + ") does not exist in the cache. Hence not removed."); -// } Cache> lCache = getPolicyListCache(); if (lCache.containsKey(1)) { @@ -265,13 +174,6 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { @Override public Policy getPolicy(int policyId) throws PolicyManagementException { - //HashMap map = this.getTenantRelatedMap(); -// Cache cache = getPolicyCache(); -// if (!cache.containsKey(policyId)) { -// this.removeAllPolicies(); -// this.getAllPolicies(); -// } -// return cache.get(policyId); Cache> lCache = getPolicyListCache(); if (!lCache.containsKey(1)) { @@ -306,13 +208,4 @@ public class PolicyCacheManagerImpl implements PolicyCacheManager { return 0; } - private HashMap getTenantRelatedMap() { - - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - if (!tenantedPolicyMap.containsKey(tenantId)) { - HashMap policyMap = new HashMap<>(); - tenantedPolicyMap.put(tenantId, policyMap); - } - return tenantedPolicyMap.get(tenantId); - } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index ed14a3c6ea..982b3859a7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -31,10 +31,6 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; -import org.wso2.carbon.registry.api.GhostResource; -import org.wso2.carbon.registry.core.RegistryConstants; -import org.wso2.carbon.registry.core.caching.RegistryCacheEntry; -import org.wso2.carbon.registry.core.caching.RegistryCacheKey; import javax.cache.Cache; import javax.cache.CacheManager; From 46c5dba5c5e1eb4d85031d780063f47f07c974e8 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 2 Sep 2015 15:24:53 +0530 Subject: [PATCH 3/3] Improving web-app authenticator framework --- .../authenticator/framework/APIInfo.java | 24 ----- .../framework/APIMapperContextListener.java | 33 ------- .../WebappAuthenticationHandler.java | 87 +++++++++++++++++++ .../framework/WebappAuthenticatorFactory.java | 17 ++++ .../WebappAuthenticatorFrameworkValve.java | 1 + .../WebappAuthenticatorRepository.java | 9 +- .../authenticator/BasicAuthAuthenticator.java | 19 +++- .../authenticator/JWTAuthenticator.java | 11 ++- .../authenticator/OAuthAuthenticator.java | 26 ++++-- .../WebappAuthenticator.java | 4 +- ...uthenticatorFrameworkServiceComponent.java | 5 +- .../conf/webapp-authenticator-config.xml | 8 ++ 12 files changed, 164 insertions(+), 80 deletions(-) delete mode 100644 components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIInfo.java delete mode 100644 components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIMapperContextListener.java create mode 100644 components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java rename components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/{ => authenticator}/WebappAuthenticator.java (89%) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIInfo.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIInfo.java deleted file mode 100644 index 20252f8f5a..0000000000 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIInfo.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.wso2.carbon.webapp.authenticator.framework; - -public class APIInfo { - - -} diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIMapperContextListener.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIMapperContextListener.java deleted file mode 100644 index 21069b6710..0000000000 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/APIMapperContextListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.wso2.carbon.webapp.authenticator.framework; - -import org.apache.catalina.Lifecycle; -import org.apache.catalina.LifecycleEvent; -import org.apache.catalina.LifecycleListener; - -public class APIMapperContextListener implements LifecycleListener { - - @Override - public void lifecycleEvent(LifecycleEvent lifecycleEvent) { - if (Lifecycle.AFTER_INIT_EVENT.equals(lifecycleEvent.getType())) { - } - } - -} diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java new file mode 100644 index 0000000000..26e0e76d74 --- /dev/null +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationHandler.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.wso2.carbon.webapp.authenticator.framework; + +import org.apache.catalina.connector.Request; +import org.apache.catalina.connector.Response; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve; +import org.wso2.carbon.tomcat.ext.valves.CompositeValve; +import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; + +import javax.servlet.http.HttpServletResponse; + +public class WebappAuthenticationHandler extends CarbonTomcatValve { + + private static final Log log = LogFactory.getLog(WebappAuthenticationHandler.class); + + @Override + public void invoke(Request request, Response response, CompositeValve compositeValve) { + if (this.isNonAdminService(request) || this.skipAuthentication(request) || this.isContextSkipped(request)) { + this.getNext().invoke(request, response, compositeValve); + return; + } + WebappAuthenticator authenticator = WebappAuthenticatorFactory.getAuthenticator(request); + if (authenticator == null) { + String msg = "Failed to load an appropriate authenticator to authenticate the request"; + AuthenticationFrameworkUtil.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, msg); + return; + } + WebappAuthenticator.Status status = authenticator.authenticate(request, response); + this.processResponse(request, response, compositeValve, status); + } + + private boolean isNonAdminService(Request request) { + String param = request.getContext().findParameter("isAdminService"); + return !(param != null && Boolean.parseBoolean(param)); + } + + private boolean skipAuthentication(Request request) { + String param = request.getContext().findParameter("doAuthentication"); + return (param == null || !Boolean.parseBoolean(param)); + } + + private boolean isContextSkipped(Request request) { + String ctx = request.getContext().getPath(); + if (ctx == null) { + ctx = request.getContextPath(); + if (ctx == null) { + return false; + } + } + return ctx.equals("/Carbon") || ctx.equals("/Services"); + } + + private void processResponse(Request request, Response response, CompositeValve compositeValve, + WebappAuthenticator.Status status) { + switch (status) { + case SUCCESS: + case CONTINUE: + this.getNext().invoke(request, response, compositeValve); + break; + case FAILURE: + String msg = "Failed to authorize incoming request"; + log.error(msg); + AuthenticationFrameworkUtil.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, msg); + break; + } + } + +} diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java index 18758a468b..c0e0e68a49 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFactory.java @@ -18,9 +18,26 @@ */ package org.wso2.carbon.webapp.authenticator.framework; +import org.apache.catalina.connector.Request; +import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; + +import java.util.Map; + public class WebappAuthenticatorFactory { public static WebappAuthenticator getAuthenticator(String authScheme) { return DataHolder.getInstance().getWebappAuthenticatorRepository().getAuthenticator(authScheme); } + + public static WebappAuthenticator getAuthenticator(Request request) { + Map authenticators = + DataHolder.getInstance().getWebappAuthenticatorRepository().getAuthenticators(); + for (WebappAuthenticator authenticator : authenticators.values()) { + if (authenticator.canHandle(request)) { + return authenticator; + } + } + return null; + } + } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java index d27116b8fe..3501c9e594 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorFrameworkValve.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve; import org.wso2.carbon.tomcat.ext.valves.CompositeValve; +import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; import javax.servlet.http.HttpServletResponse; diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java index 02a86ce9cc..bb805c8c76 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticatorRepository.java @@ -18,15 +18,18 @@ */ package org.wso2.carbon.webapp.authenticator.framework; +import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; + import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class WebappAuthenticatorRepository { private Map authenticators; public WebappAuthenticatorRepository() { - this.authenticators = new HashMap(); + this.authenticators = new ConcurrentHashMap<>(); } public void addAuthenticator(WebappAuthenticator authenticator) { @@ -37,4 +40,8 @@ public class WebappAuthenticatorRepository { return authenticators.get(name); } + public Map getAuthenticators() { + return authenticators; + } + } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java index d17827bd99..7227bdf471 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java @@ -24,15 +24,25 @@ import org.apache.catalina.util.Base64; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.tomcat.util.buf.CharChunk; import org.apache.tomcat.util.buf.MessageBytes; -import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticator; +import org.wso2.carbon.webapp.authenticator.framework.Constants; public class BasicAuthAuthenticator implements WebappAuthenticator { private static final String BASIC_AUTH_AUTHENTICATOR = "BasicAuth"; + private static final String HEADER_BASIC_AUTH = "authorization"; @Override - public boolean isAuthenticated(Request request) { - return false; + public boolean canHandle(Request request) { + MessageBytes authorization = + request.getCoyoteRequest().getMimeHeaders().getValue(Constants.HTTPHeaders.HEADER_HTTP_AUTHORIZATION); + if (authorization != null) { + authorization.toBytes(); + ByteChunk authBC = authorization.getByteChunk(); + if (authBC.startsWithIgnoreCase("basic ", 0)) { + return true; + } + } + return false; } @Override @@ -47,7 +57,8 @@ public class BasicAuthAuthenticator implements WebappAuthenticator { private Credentials getCredentials(Request request) { Credentials credentials = null; - MessageBytes authorization = request.getCoyoteRequest().getMimeHeaders().getValue("authorization"); + MessageBytes authorization = + request.getCoyoteRequest().getMimeHeaders().getValue(Constants.HTTPHeaders.HEADER_HTTP_AUTHORIZATION); if (authorization != null) { authorization.toBytes(); ByteChunk authBC = authorization.getByteChunk(); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java index 20651681f9..974480fd5a 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/JWTAuthenticator.java @@ -36,7 +36,6 @@ import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.webapp.authenticator.framework.DataHolder; -import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticator; import java.security.interfaces.RSAPublicKey; import java.text.ParseException; @@ -51,12 +50,12 @@ public class JWTAuthenticator implements WebappAuthenticator { public static final String SIGNED_JWT_AUTH_USERNAME = "Username"; private static final String JWT_AUTHENTICATOR = "JWT"; - @Override - public boolean isAuthenticated(Request request) { - return false; - } + @Override + public boolean canHandle(Request request) { + return false; + } - @Override + @Override public Status authenticate(Request request, Response response) { String requestUri = request.getRequestURI(); if (requestUri == null || "".equals(requestUri)) { diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java index cf5a177167..3413cf1b0c 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/OAuthAuthenticator.java @@ -30,7 +30,6 @@ import org.wso2.carbon.apimgt.core.gateway.APITokenAuthenticator; import org.wso2.carbon.webapp.authenticator.framework.AuthenticationException; import org.wso2.carbon.webapp.authenticator.framework.AuthenticationFrameworkUtil; import org.wso2.carbon.webapp.authenticator.framework.Constants; -import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticator; import java.util.StringTokenizer; import java.util.regex.Matcher; @@ -39,13 +38,28 @@ import java.util.regex.Pattern; public class OAuthAuthenticator implements WebappAuthenticator { private static final String OAUTH_AUTHENTICATOR = "OAuth"; - private static APITokenAuthenticator authenticator = new APITokenAuthenticator(); private static final String REGEX_BEARER_PATTERN = "[B|b]earer\\s"; + private static final Pattern PATTERN = Pattern.compile(REGEX_BEARER_PATTERN); + + private static APITokenAuthenticator authenticator = new APITokenAuthenticator(); private static final Log log = LogFactory.getLog(OAuthAuthenticator.class); @Override - public boolean isAuthenticated(Request request) { + public boolean canHandle(Request request) { + MessageBytes authorization = + request.getCoyoteRequest().getMimeHeaders(). + getValue(Constants.HTTPHeaders.HEADER_HTTP_AUTHORIZATION); + String tokenValue = null; + if (authorization != null) { + authorization.toBytes(); + ByteChunk authBC = authorization.getByteChunk(); + tokenValue = authBC.toString(); + Matcher matcher = PATTERN.matcher(tokenValue); + if (matcher.find()) { + return true; + } + } return false; } @@ -93,19 +107,15 @@ public class OAuthAuthenticator implements WebappAuthenticator { } private String getBearerToken(Request request) { - MessageBytes authorization = request.getCoyoteRequest().getMimeHeaders(). getValue(Constants.HTTPHeaders.HEADER_HTTP_AUTHORIZATION); String tokenValue = null; - if (authorization != null) { - authorization.toBytes(); ByteChunk authBC = authorization.getByteChunk(); tokenValue = authBC.toString(); - Pattern pattern = Pattern.compile(REGEX_BEARER_PATTERN); - Matcher matcher = pattern.matcher(tokenValue); + Matcher matcher = PATTERN.matcher(tokenValue); if (matcher.find()) { tokenValue = tokenValue.substring(matcher.end()); } diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/WebappAuthenticator.java similarity index 89% rename from components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticator.java rename to components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/WebappAuthenticator.java index 5f2eecf8d1..18e49cb212 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/WebappAuthenticator.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.webapp.authenticator.framework; +package org.wso2.carbon.webapp.authenticator.framework.authenticator; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; @@ -27,7 +27,7 @@ public interface WebappAuthenticator { SUCCESS, FAILURE, CONTINUE } - boolean isAuthenticated(Request request); + boolean canHandle(Request request); Status authenticate(Request request, Response response); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java index 6dad1613d3..e30d9ce680 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/internal/WebappAuthenticatorFrameworkServiceComponent.java @@ -25,7 +25,8 @@ import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve; import org.wso2.carbon.tomcat.ext.valves.TomcatValveContainer; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.webapp.authenticator.framework.DataHolder; -import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticator; +import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticationHandler; +import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorFrameworkValve; import org.wso2.carbon.webapp.authenticator.framework.WebappAuthenticatorRepository; import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig; @@ -64,7 +65,7 @@ public class WebappAuthenticatorFrameworkServiceComponent { DataHolder.getInstance().setWebappAuthenticatorRepository(repository); List valves = new ArrayList(); - valves.add(new WebappAuthenticatorFrameworkValve()); + valves.add(new WebappAuthenticationHandler()); TomcatValveContainer.addValves(valves); if (log.isDebugEnabled()) { diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml index d4c9638d49..f42dde6271 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml @@ -4,5 +4,13 @@ OAuth org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthenticator + + BasicAuth + org.wso2.carbon.webapp.authenticator.framework.authenticator.BasicAuthAuthenticator + + + JWT + org.wso2.carbon.webapp.authenticator.framework.authenticator.JWTAuthenticator +