From 7de3487a669212f604f1aeaf2d49233e27b8603c Mon Sep 17 00:00:00 2001 From: Lakshman Udayakantha Date: Sat, 22 Dec 2018 18:25:02 +0530 Subject: [PATCH 1/8] Add user mask permission, Retrieve correct permission string for managed application --- .../impl/UserRolePermissionFactory.java | 26 +++++++++---------- .../impl/WSO2PermissionBuilder.java | 2 +- .../src/main/resources/META-INF/component.xml | 4 +++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java index a0ef5103..0bfd47f0 100644 --- a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java +++ b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java @@ -15,8 +15,6 @@ ******************************************************************************/ package com.wso2telco.core.userprofile.permission.impl; -import java.util.HashMap; -import java.util.Map; import com.wso2telco.core.dbutils.exception.BusinessException; import com.wso2telco.core.userprofile.util.UserRolePermissionType; @@ -32,19 +30,19 @@ public static UserRolePermissionFactory getInstance() { } - public UserRolePermission getUserRolePermissionExecuter(UserRolePermissionType userRolePermissionType) throws BusinessException { + public UserRolePermission getUserRolePermissionExecuter(UserRolePermissionType userRolePermissionType) throws BusinessException { - UserRolePermission userRolePermission = null; + UserRolePermission userRolePermission = null; - switch (userRolePermissionType) { - case UI_PERMISSION:{ - userRolePermission = new WSO2PermissionBuilder(); - } - break; - default: - break; - } + switch (userRolePermissionType) { + case UI_PERMISSION: { + userRolePermission = new WSO2PermissionBuilder(); + } + break; + default: + break; + } - return userRolePermission; - } + return userRolePermission; + } } diff --git a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java index fd4b3a82..7aaf3277 100644 --- a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java +++ b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java @@ -200,7 +200,7 @@ public void mergeMapEntry(String resourcePath, RetunEntitiy mergeEntry) { this.returnMap.put(resourcePathSplit[resourcePathSplit.length-1], mergeEntry.returnMap); if(mergeEntry.atLeastOneSelected) { this.atLeastOneSelected = mergeEntry.atLeastOneSelected; - } + } } } diff --git a/components/security/user-profile/src/main/resources/META-INF/component.xml b/components/security/user-profile/src/main/resources/META-INF/component.xml index 9cfb72e2..bf380df1 100644 --- a/components/security/user-profile/src/main/resources/META-INF/component.xml +++ b/components/security/user-profile/src/main/resources/META-INF/component.xml @@ -92,5 +92,9 @@ Whitelist /permission/UIModulePermission/whiteList + + User Mask + /permission/UIModulePermission/user-mask + \ No newline at end of file From 429dc50a15caf49806047351ab63ea4c7b5e32e3 Mon Sep 17 00:00:00 2001 From: Lakshman Udayakantha Date: Fri, 25 Jan 2019 11:16:43 +0530 Subject: [PATCH 2/8] set permissions according to ADFS --- .../impl/UserRolePermissionFactory.java | 31 +- .../impl/WSO2PermissionBuilder.java | 336 +++++++++--------- 2 files changed, 185 insertions(+), 182 deletions(-) diff --git a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java index 0bfd47f0..c407f86b 100644 --- a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java +++ b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/UserRolePermissionFactory.java @@ -15,20 +15,28 @@ ******************************************************************************/ package com.wso2telco.core.userprofile.permission.impl; +import java.util.HashMap; +import java.util.Map; import com.wso2telco.core.dbutils.exception.BusinessException; import com.wso2telco.core.userprofile.util.UserRolePermissionType; public class UserRolePermissionFactory { - private static UserRolePermissionFactory instance; + private static UserRolePermissionFactory instance; + + private Map permissionBuilderMap; + + private UserRolePermissionFactory() { + permissionBuilderMap = new HashMap(); + } + + public static UserRolePermissionFactory getInstance() { + if (instance == null) { + instance = new UserRolePermissionFactory(); + } + return instance; + } - public static UserRolePermissionFactory getInstance() { - if(instance==null) { - instance= new UserRolePermissionFactory(); - } - return instance; - } - public UserRolePermission getUserRolePermissionExecuter(UserRolePermissionType userRolePermissionType) throws BusinessException { @@ -36,7 +44,12 @@ public UserRolePermission getUserRolePermissionExecuter(UserRolePermissionType u switch (userRolePermissionType) { case UI_PERMISSION: { - userRolePermission = new WSO2PermissionBuilder(); + if (permissionBuilderMap.containsKey(userRolePermissionType)) { + userRolePermission = permissionBuilderMap.get(userRolePermissionType); + } else { + userRolePermission = new WSO2PermissionBuilder(); + permissionBuilderMap.put(userRolePermissionType, userRolePermission); + } } break; default: diff --git a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java index 7aaf3277..95184edb 100644 --- a/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java +++ b/components/security/user-profile/src/main/java/com/wso2telco/core/userprofile/permission/impl/WSO2PermissionBuilder.java @@ -15,17 +15,11 @@ ******************************************************************************/ package com.wso2telco.core.userprofile.permission.impl; -import java.rmi.RemoteException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - +import com.wso2telco.core.dbutils.exception.BusinessException; +import com.wso2telco.core.dbutils.exception.GenaralError; +import com.wso2telco.core.userprofile.prosser.UserRoleProsser; +import com.wso2telco.core.userprofile.util.AdminServicePath; +import com.wso2telco.core.userprofile.util.UserRolePermissionType; import org.apache.axis2.AxisFault; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.commons.lang.StringUtils; @@ -39,169 +33,165 @@ import org.wso2.carbon.user.mgt.stub.types.carbon.UIPermissionNode; import org.wso2.carbon.utils.CarbonUtils; -import com.wso2telco.core.dbutils.exception.BusinessException; -import com.wso2telco.core.dbutils.exception.GenaralError; -import com.wso2telco.core.userprofile.prosser.UserRoleProsser; -import com.wso2telco.core.userprofile.util.AdminServicePath; -import com.wso2telco.core.userprofile.util.UserRolePermissionType; +import java.rmi.RemoteException; +import java.util.*; class WSO2PermissionBuilder implements UserRolePermission { - private final Log log = LogFactory.getLog(WSO2PermissionBuilder.class); - private UserAdminStub userAdminStub; - private static final Integer DEFAULT_SO_TIMEOUT=1000*60*2;//2mins as default - private static final Integer DEFAULT_CONNECTION_TIMEOUT= 1000*60*2; - - public WSO2PermissionBuilder() throws BusinessException { - APIManagerConfiguration config = HostObjectComponent.getAPIManagerConfiguration(); - String userAdminServiceEndpoint = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL) - + AdminServicePath.USER_ADMIN.getTObject(); - String adminUsername = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME); - String adminPassword = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD); - try { - userAdminStub = new UserAdminStub(userAdminServiceEndpoint); - userAdminStub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, DEFAULT_SO_TIMEOUT); //set so time out and connection timeout to 2min - userAdminStub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); - } catch (AxisFault e) { - log.error("", e); - throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR); - } - CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient()); - } - - /** - * This will build the permision tree using given users name - */ - public Map build(final String userName) throws BusinessException { - Map permisionTree = Collections.emptyMap(); - RetunEntitiy retunItem = new RetunEntitiy(); - try { - UserRoleProsser userRoleRetriever = new UserRoleProsser(); - UIPermissionNode uiPermissionTree = null; - - - List currentUserRoleList = userRoleRetriever.getRolesByUserName(userName); - /** - * None of the roles are assign for the user - */ - if (currentUserRoleList.isEmpty()) { - throw new BusinessException("No roles assigned for user :" + userName); - } - - for (Iterator iterator = currentUserRoleList.iterator(); iterator.hasNext();) { - - String roleName = iterator.next(); - - UIPermissionNode rolePermissions = userAdminStub.getRolePermissions(roleName); - /** - * if the permission node is empty - */ - if (rolePermissions == null || rolePermissions.getNodeList() == null) { - continue; - } - - /** - * filter out ui permission only - */ - Optional optNode = Arrays.stream(rolePermissions.getNodeList()) - .filter(rowItem -> rowItem.getDisplayName() - .equalsIgnoreCase(UserRolePermissionType.UI_PERMISSION.getTObject())) - .findFirst(); - - /** - * check for existence of node - */ - if (optNode.isPresent()) { - uiPermissionTree = optNode.get(); - - if (uiPermissionTree.getNodeList() != null && uiPermissionTree.getNodeList().length > 0) { - retunItem = popUserRolePermissions(uiPermissionTree.getNodeList()); - if (retunItem.atLeastOneSelected) { - break; - } - } else { - /** - * if the current role does not contain Ui permission then continue - */ - continue; - } - } - - } - - if (retunItem.returnMap.isEmpty()) { - throw new BusinessException( - UserRolePermissionType.UI_PERMISSION.getTObject() + " not assigned for the user :" + userName - + " , assigned roles :[ " + StringUtils.join(currentUserRoleList, ",") + "]"); - } - - } catch (RemoteException | UserAdminUserAdminException e) { - log.error("UIPermission.build", e); - throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR); - } - if (retunItem.returnMap.isEmpty()) { - log.warn(" No ui permission tree found for " + userName); - return Collections.emptyMap(); - } else { - return retunItem.returnMap; - } - - } - - /** - * recuresvly build the permission tree and return as tree of maps - * - * @param rootPermissionTree - * @return - */ - - private RetunEntitiy popUserRolePermissions(UIPermissionNode[] rootPermissionTree) { - RetunEntitiy entity = new RetunEntitiy(); - Arrays.stream(rootPermissionTree).forEach(item -> { - /** - * if node has child elements - */ - UIPermissionNode[] uiPermissionArray = item.getNodeList(); - if (uiPermissionArray != null && uiPermissionArray.length > 0) { - - RetunEntitiy temp = popUserRolePermissions(uiPermissionArray); - entity.mergeMapEntry(item.getResourcePath(), temp); - - } else { - /** - * node don't have children - */ - - entity.mergeMapEntry(item); - } - - }); - - return entity; - } - - class RetunEntitiy { - private boolean atLeastOneSelected = false; - private Map returnMap = new HashMap<>(); - - public void setEntryName(String key,Object value ) { - returnMap.put(key, value); - } - public void mergeMapEntry(UIPermissionNode item) { - String[] resourcePathSplit = item.getResourcePath().split("/"); - this.returnMap.put(resourcePathSplit[resourcePathSplit.length-1],item.getSelected()); - if(item.getSelected()) { - atLeastOneSelected=true; - } - } - - public void mergeMapEntry(String resourcePath, RetunEntitiy mergeEntry) { - String[] resourcePathSplit = resourcePath.split("/"); - this.returnMap.put(resourcePathSplit[resourcePathSplit.length-1], mergeEntry.returnMap); - if(mergeEntry.atLeastOneSelected) { - this.atLeastOneSelected = mergeEntry.atLeastOneSelected; - } - } - - } + private final Log log = LogFactory.getLog(WSO2PermissionBuilder.class); + private UserAdminStub userAdminStub; + private static final Integer DEFAULT_SO_TIMEOUT = 1000 * 60 * 2;//2mins as default + private static final Integer DEFAULT_CONNECTION_TIMEOUT = 1000 * 60 * 2; + + public WSO2PermissionBuilder() throws BusinessException { + APIManagerConfiguration config = HostObjectComponent.getAPIManagerConfiguration(); + String userAdminServiceEndpoint = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL) + + AdminServicePath.USER_ADMIN.getTObject(); + String adminUsername = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME); + String adminPassword = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD); + try { + userAdminStub = new UserAdminStub(userAdminServiceEndpoint); + userAdminStub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, DEFAULT_SO_TIMEOUT); //set so time out and connection timeout to 2min + userAdminStub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); + } catch (AxisFault e) { + log.error("", e); + throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR); + } + CarbonUtils.setBasicAccessSecurityHeaders(adminUsername, adminPassword, userAdminStub._getServiceClient()); + } + + /** + * This will build the permision tree using given users name + */ + public Map build(final String userName) throws BusinessException { + Map permisionTree = Collections.emptyMap(); + RetunEntitiy retunItem = new RetunEntitiy(); + try { + UserRoleProsser userRoleRetriever = new UserRoleProsser(); + UIPermissionNode uiPermissionTree = null; + + + List currentUserRoleList = userRoleRetriever.getRolesByUserName(userName); + /** + * None of the roles are assign for the user + */ + if (currentUserRoleList.isEmpty()) { + throw new BusinessException("No roles assigned for user :" + userName); + } + + for (Iterator iterator = currentUserRoleList.iterator(); iterator.hasNext(); ) { + + String roleName = iterator.next(); + + UIPermissionNode rolePermissions = userAdminStub.getRolePermissions(roleName); + /** + * if the permission node is empty + */ + if (rolePermissions == null || rolePermissions.getNodeList() == null) { + continue; + } + + /** + * filter out ui permission only + */ + Optional optNode = Arrays.stream(rolePermissions.getNodeList()) + .filter(rowItem -> rowItem.getDisplayName() + .equalsIgnoreCase(UserRolePermissionType.UI_PERMISSION.getTObject())) + .findFirst(); + + /** + * check for existence of node + */ + if (optNode.isPresent()) { + uiPermissionTree = optNode.get(); + + if (uiPermissionTree.getNodeList() != null && uiPermissionTree.getNodeList().length > 0) { + retunItem = popUserRolePermissions(uiPermissionTree.getNodeList()); + if (retunItem.atLeastOneSelected) { + break; + } + } else { + /** + * if the current role does not contain Ui permission then continue + */ + continue; + } + } + + } + + if (retunItem.returnMap.isEmpty()) { + throw new BusinessException( + UserRolePermissionType.UI_PERMISSION.getTObject() + " not assigned for the user :" + userName + + " , assigned roles :[ " + StringUtils.join(currentUserRoleList, ",") + "]"); + } + + } catch (RemoteException | UserAdminUserAdminException e) { + log.error("UIPermission.build", e); + throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR); + } + if (retunItem.returnMap.isEmpty()) { + log.warn(" No ui permission tree found for " + userName); + return Collections.emptyMap(); + } else { + return retunItem.returnMap; + } + + } + + /** + * recuresvly build the permission tree and return as tree of maps + * + * @param rootPermissionTree + * @return + */ + + private RetunEntitiy popUserRolePermissions(UIPermissionNode[] rootPermissionTree) { + RetunEntitiy entity = new RetunEntitiy(); + Arrays.stream(rootPermissionTree).forEach(item -> { + /** + * if node has child elements + */ + UIPermissionNode[] uiPermissionArray = item.getNodeList(); + if (uiPermissionArray != null && uiPermissionArray.length > 0) { + + RetunEntitiy temp = popUserRolePermissions(uiPermissionArray); + entity.mergeMapEntry(item.getDisplayName(), temp); + + } else { + /** + * node don't have children + */ + + entity.mergeMapEntry(item); + } + + }); + + return entity; + } + + class RetunEntitiy { + private boolean atLeastOneSelected = false; + private Map returnMap = new HashMap<>(); + + public void setEntryName(String key, Object value) { + returnMap.put(key, value); + } + + public void mergeMapEntry(UIPermissionNode item) { + this.returnMap.put(item.getDisplayName(), item.getSelected()); + if (item.getSelected()) { + atLeastOneSelected = true; + } + } + + public void mergeMapEntry(String entryName, RetunEntitiy mergeEntry) { + this.returnMap.put(entryName, mergeEntry.returnMap); + if (mergeEntry.atLeastOneSelected) { + this.atLeastOneSelected = mergeEntry.atLeastOneSelected; + } + } + + } } From fa7f338eebbb29472e5ad548846e4d6c76d991ac Mon Sep 17 00:00:00 2001 From: azhamn Date: Wed, 6 Mar 2019 15:31:58 +0530 Subject: [PATCH 3/8] Implemented bearer authenticator --- components/security/auth-filter/pom.xml | 22 ++- .../authentication/BearerAuthenticator.java | 84 +++++++++++ .../UserAuthorizationValidator.java | 31 ++++ .../AuthorizationFilterFactory.java | 10 +- .../BasicAuthenticationFilter.java | 141 +++++++++--------- .../BearerAuthenticationFilter.java | 77 ++++++++++ .../core/authfilter/util/AuthFilterParam.java | 1 + 7 files changed, 292 insertions(+), 74 deletions(-) create mode 100644 components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authentication/BearerAuthenticator.java create mode 100644 components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java diff --git a/components/security/auth-filter/pom.xml b/components/security/auth-filter/pom.xml index 3f42a0a7..34fbfdb5 100644 --- a/components/security/auth-filter/pom.xml +++ b/components/security/auth-filter/pom.xml @@ -34,7 +34,27 @@ com.wso2telco.core dbutils - + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.rest.api.util + 6.0.4 + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.impl + 6.0.4 + + + org.springframework + spring-context + 3.0.7.RELEASE + + + org.springframework + spring-context + 3.0.7.RELEASE + + diff --git a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authentication/BearerAuthenticator.java b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authentication/BearerAuthenticator.java new file mode 100644 index 00000000..f56e5c06 --- /dev/null +++ b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authentication/BearerAuthenticator.java @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2016, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + *

+ * WSO2.Telco Inc. licences 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 com.wso2telco.core.authfilter.authentication; + +import com.wso2telco.core.authfilter.util.AuthFilterParam; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.api.APIManagementException; +import org.wso2.carbon.apimgt.api.model.AccessTokenInfo; +import org.wso2.carbon.apimgt.impl.APIConstants; +import org.wso2.carbon.apimgt.impl.factory.KeyManagerHolder; +import org.wso2.carbon.apimgt.impl.utils.APIUtil; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; +import org.wso2.carbon.utils.multitenancy.MultitenantUtils; + +import javax.ws.rs.container.ContainerRequestContext; +import java.lang.reflect.Method; + +public class BearerAuthenticator { + private static final String SUPER_TENANT_SUFFIX = + APIConstants.EMAIL_DOMAIN_SEPARATOR + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; + private static final Log log = LogFactory.getLog(BearerAuthenticator.class); + + /** + * @param authorizationHeader Authorization Header value + * @return boolean + */ + public boolean isAuthenticatedUser(ContainerRequestContext requestContext, Method method, String + authorizationHeader) { + String accessToken = authorizationHeader + .replaceFirst(AuthFilterParam.AUTHENTICATION_SCHEME_BEARER.getTObject() + " ", ""); + AccessTokenInfo tokenInfo = null; + try { + tokenInfo = KeyManagerHolder.getKeyManagerInstance().getTokenMetaData(accessToken); + } catch (APIManagementException e) { + log.error("Error while retrieving token information for token: " + accessToken, e); + } + // if we got valid access token we will proceed with next + if (tokenInfo != null && tokenInfo.isTokenValid()) { + + //If scope validation successful then set tenant name and user name to current context + String tenantDomain = MultitenantUtils.getTenantDomain(tokenInfo.getEndUserName()); + int tenantId; + PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null); + try { + String username = tokenInfo.getEndUserName(); + if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { + if (username.endsWith(SUPER_TENANT_SUFFIX)) { + username = username.substring(0, username.length() - SUPER_TENANT_SUFFIX.length()); + } + } + tenantId = realmService.getTenantManager().getTenantId(tenantDomain); + carbonContext.setTenantDomain(tenantDomain); + carbonContext.setTenantId(tenantId); + carbonContext.setUsername(username); + if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + APIUtil.loadTenantConfigBlockingMode(tenantDomain); + } + return true; + } catch (org.wso2.carbon.user.api.UserStoreException e) { + log.error("Error while retrieving tenant id for tenant domain: " + tenantDomain, e); + } + } else { + log.error("Authentication failed. Please check your token"); + } + return false; + } +} diff --git a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authorization/UserAuthorizationValidator.java b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authorization/UserAuthorizationValidator.java index 5cf5d6e9..ccd89f2f 100644 --- a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authorization/UserAuthorizationValidator.java +++ b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/authorization/UserAuthorizationValidator.java @@ -60,4 +60,35 @@ public boolean isAuthorizedRole(String userName, Set allowedRolesSet) { log.error("authorization failed for user : " + userName); return false; } + + /** + * Checks the list of allowed scopes for a api resource against the scopes + * granted to a token + * + * @param currentTokenScopes Scopes granted to the token being evaluated + * @param allowedScopeSet Scopes allowed to access the APIs resource + * @return Boolean + * + */ + public Boolean isAuthorizedScope(String[] currentTokenScopes, Set allowedScopeSet){ + + List currentTokenScopesList = Arrays.asList(currentTokenScopes); + + Iterator iterator = allowedScopeSet.iterator(); + while (iterator.hasNext()) { + + String allowedScope = iterator.next(); + if (currentTokenScopesList.contains(allowedScope)) { + + return true; + } + } + + if(log.isDebugEnabled()){ + log.debug("Required OAuth Scopes: " + allowedScopeSet); + log.debug("Available OAuth Scopes: " + currentTokenScopesList); + } + + return false; + } } diff --git a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/AuthorizationFilterFactory.java b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/AuthorizationFilterFactory.java index 96ae1e7f..3f4c8c56 100644 --- a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/AuthorizationFilterFactory.java +++ b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/AuthorizationFilterFactory.java @@ -23,14 +23,18 @@ public class AuthorizationFilterFactory extends AuthenticationProsser{ @Override protected AuthenticationFilter loadFilter(String header) { - + AuthenticationFilter authenticationFilter = null; - + if (header.contains(AuthFilterParam.AUTHENTICATION_SCHEME_BASIC.getTObject())) { authenticationFilter = new BasicAuthenticationFilter(); } - + + if (header.contains(AuthFilterParam.AUTHENTICATION_SCHEME_BEARER.getTObject())){ + authenticationFilter = new BearerAuthenticationFilter(); + } + return authenticationFilter; } } diff --git a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BasicAuthenticationFilter.java b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BasicAuthenticationFilter.java index f2d7503f..f551d861 100644 --- a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BasicAuthenticationFilter.java +++ b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BasicAuthenticationFilter.java @@ -15,106 +15,107 @@ ******************************************************************************/ package com.wso2telco.core.authfilter.impl.authorization; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.StringTokenizer; -import javax.annotation.security.RolesAllowed; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.Response; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import com.wso2telco.core.authfilter.authentication.BasicAuthenticator; import com.wso2telco.core.authfilter.authorization.UserAuthorizationValidator; import com.wso2telco.core.authfilter.impl.AuthenticationFilter; import com.wso2telco.core.authfilter.util.AuthFilterParam; import com.wso2telco.core.authfilter.util.HeaderParam; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.annotation.security.RolesAllowed; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.Response; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.StringTokenizer; public class BasicAuthenticationFilter implements AuthenticationFilter { - private final Log log = LogFactory.getLog(BasicAuthenticationFilter.class); + private final Log log = LogFactory.getLog(BasicAuthenticationFilter.class); + + Response accessDenied = Response.status(Response.Status.UNAUTHORIZED).entity("You cannot access this resource") + .build(); + private BasicAuthenticator userAuthentication = new BasicAuthenticator(); + private UserAuthorizationValidator userAuthorizationValidator = new UserAuthorizationValidator(); + + private String userName = null; + + @Override + public boolean isAuthenticated(ContainerRequestContext requestContext, Method method, String authorizationHeader) { - Response accessDenied = Response.status(Response.Status.UNAUTHORIZED).entity("You cannot access this resource") - .build(); - private BasicAuthenticator userAuthentication = new BasicAuthenticator(); - private UserAuthorizationValidator userAuthorizationValidator = new UserAuthorizationValidator(); + String password = null; + boolean isAuthenticated = false; - private String userName = null; + // get base 64 encoded username and password + final String encodedUserPassword = authorizationHeader + .replaceFirst(AuthFilterParam.AUTHENTICATION_SCHEME_BASIC.getTObject() + " ", ""); - @Override - public boolean isAuthenticated(ContainerRequestContext requestContext, Method method, String authorizationHeader) { + log.debug("base64 encoded username and password : " + encodedUserPassword); - String password = null; - boolean isAuthenticated = false; - - // get base 64 encoded username and password - final String encodedUserPassword = authorizationHeader - .replaceFirst(AuthFilterParam.AUTHENTICATION_SCHEME_BASIC.getTObject() + " ", ""); + if (encodedUserPassword != null && encodedUserPassword.trim().length() > 0) { - log.debug("base64 encoded username and password : " + encodedUserPassword); + // decode username and password + String usernameAndPassword = new String(Base64.decodeBase64(encodedUserPassword.getBytes())); - if (encodedUserPassword != null && encodedUserPassword.trim().length() > 0) { + // split username and password by : + final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); - // decode username and password - String usernameAndPassword = new String(Base64.decodeBase64(encodedUserPassword.getBytes())); + if (tokenizer.countTokens() > 1) { - // split username and password by : - final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + userName = tokenizer.nextToken(); + password = tokenizer.nextToken(); - if (tokenizer.countTokens() > 1) { + log.debug("username : " + userName); + log.debug("password : " + password); - userName = tokenizer.nextToken(); - password = tokenizer.nextToken(); + // validate user authentication + isAuthenticated = userAuthentication.isAuthenticatedUser(userName, password); - log.debug("username : " + userName); - log.debug("password : " + password); + if (!isAuthenticated) { - // validate user authentication - isAuthenticated = userAuthentication.isAuthenticatedUser(userName, password); + requestContext.abortWith(accessDenied); + return false; + } + } else { - if (!isAuthenticated) { + requestContext.abortWith(accessDenied); + return false; + } + } else { - requestContext.abortWith(accessDenied); - return false; - } - } else { + requestContext.abortWith(accessDenied); + return false; + } - requestContext.abortWith(accessDenied); - return false; - } - } else { + return true; + } - requestContext.abortWith(accessDenied); - return false; - } + @Override + public boolean isAuthorized(ContainerRequestContext requestContext, Method method) { - return true; - } + boolean isAuthorized = false; - @Override - public boolean isAuthorized(ContainerRequestContext requestContext, Method method) { + requestContext.getHeaders().add(HeaderParam.USER_NAME.getTObject(), userName); - boolean isAuthorized = false; - - requestContext.getHeaders().add(HeaderParam.USER_NAME.getTObject(), userName); - - // validate user authorization by using user roles - if (method.isAnnotationPresent(RolesAllowed.class)) { + // validate user authorization by using user roles + if (method.isAnnotationPresent(RolesAllowed.class)) { - RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class); - Set allowedRolesSet = new HashSet<>(Arrays.asList(rolesAnnotation.value())); + RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class); + Set allowedRolesSet = new HashSet<>(Arrays.asList(rolesAnnotation.value())); - isAuthorized = userAuthorizationValidator.isAuthorizedRole(userName, allowedRolesSet); + isAuthorized = userAuthorizationValidator.isAuthorizedRole(userName, allowedRolesSet); - if (!isAuthorized) { + if (!isAuthorized) { - requestContext.abortWith(accessDenied); - return false; - } - } + requestContext.abortWith(accessDenied); + return false; + } + } - return true; - } + return true; + } } diff --git a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java new file mode 100644 index 00000000..9ac91932 --- /dev/null +++ b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java @@ -0,0 +1,77 @@ +package com.wso2telco.core.authfilter.impl.authorization; + +import com.wso2telco.core.authfilter.authentication.BearerAuthenticator; +import com.wso2telco.core.authfilter.authorization.UserAuthorizationValidator; +import com.wso2telco.core.authfilter.impl.AuthenticationFilter; +import com.wso2telco.core.authfilter.util.AuthFilterParam; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.context.annotation.Scope; +import org.wso2.carbon.apimgt.api.APIManagementException; +import org.wso2.carbon.apimgt.api.model.AccessTokenInfo; +import org.wso2.carbon.apimgt.impl.factory.KeyManagerHolder; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.Response; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Pattern; + +public class BearerAuthenticationFilter implements AuthenticationFilter { + + private static final Log log = LogFactory.getLog(BearerAuthenticationFilter.class); + private static final String REGEX_BEARER_PATTERN = "Bearer\\s"; + private static final Pattern PATTERN = Pattern.compile(REGEX_BEARER_PATTERN); + Response accessDenied = Response.status(Response.Status.UNAUTHORIZED).entity("You cannot access this resource") + .build(); + private UserAuthorizationValidator userAuthorizationValidator = new UserAuthorizationValidator(); + private BearerAuthenticator bearerAuthenticator = new BearerAuthenticator(); + private String authorizationHeader = null; + + @Override + public boolean isAuthenticated(ContainerRequestContext requestContext, Method method, String authorizationHeader) { + Boolean isAuthenticated = false; + this.authorizationHeader = authorizationHeader; + + isAuthenticated = bearerAuthenticator.isAuthenticatedUser(requestContext, method, authorizationHeader); + + if (!isAuthenticated) { + requestContext.abortWith(accessDenied); + return false; + } + + return true; + } + + @Override + public boolean isAuthorized(ContainerRequestContext requestContext, Method method) { + Boolean isAuthorized = false; + if (authorizationHeader != null && method.isAnnotationPresent(Scope.class)) { + + String accessToken = authorizationHeader + .replaceFirst(AuthFilterParam.AUTHENTICATION_SCHEME_BEARER.getTObject() + " ", ""); + AccessTokenInfo tokenInfo = null; + try { + tokenInfo = KeyManagerHolder.getKeyManagerInstance().getTokenMetaData(accessToken); + } catch (APIManagementException e) { + log.error("Error while retrieving token information for token: " + accessToken, e); + } + if (tokenInfo.getScopes() != null) { + Scope scopeAnnotation = method.getAnnotation(Scope.class); + Set allowedScopeSet = new HashSet<>(Arrays.asList(scopeAnnotation.value().split(" "))); + log.debug("Access Token: " + tokenInfo.getAccessToken()); + isAuthorized = userAuthorizationValidator.isAuthorizedScope(tokenInfo.getScopes(), allowedScopeSet); + + if (isAuthorized) { + return true; + } + } + } + log.error("Authorization failed : Invalid OAuth token scope"); + + requestContext.abortWith(accessDenied); + return false; + } +} \ No newline at end of file diff --git a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/util/AuthFilterParam.java b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/util/AuthFilterParam.java index 68f24e02..2a79a9e0 100644 --- a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/util/AuthFilterParam.java +++ b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/util/AuthFilterParam.java @@ -19,6 +19,7 @@ public enum AuthFilterParam { AUTHORIZATION_PROPERTY("Authorization"), AUTHENTICATION_SCHEME_BASIC("Basic"), + AUTHENTICATION_SCHEME_BEARER("Bearer"), COOKIE("Cookie"), JSESSION_ID("JSESSIONID="); From 7d1caa4947607947a5e20d80a5525e17f94c4a10 Mon Sep 17 00:00:00 2001 From: azhamn Date: Wed, 6 Mar 2019 18:04:31 +0530 Subject: [PATCH 4/8] removed duplicate dependency --- components/security/auth-filter/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/security/auth-filter/pom.xml b/components/security/auth-filter/pom.xml index 34fbfdb5..c57d9bef 100644 --- a/components/security/auth-filter/pom.xml +++ b/components/security/auth-filter/pom.xml @@ -49,11 +49,6 @@ spring-context 3.0.7.RELEASE - - org.springframework - spring-context - 3.0.7.RELEASE - From b61b0d5b09814d69d3ba2e81aa9110d8bdd587b2 Mon Sep 17 00:00:00 2001 From: azhamn Date: Wed, 6 Mar 2019 18:05:39 +0530 Subject: [PATCH 5/8] checking debug log is enabled before logging --- .../BearerAuthenticationFilter.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java index 9ac91932..94468614 100644 --- a/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java +++ b/components/security/auth-filter/src/main/java/com/wso2telco/core/authfilter/impl/authorization/BearerAuthenticationFilter.java @@ -1,3 +1,18 @@ +/** + * Copyright (c) 2016, WSO2.Telco Inc. (http://www.wso2telco.com) All Rights Reserved. + *

+ * WSO2.Telco Inc. licences 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 com.wso2telco.core.authfilter.impl.authorization; import com.wso2telco.core.authfilter.authentication.BearerAuthenticator; @@ -61,7 +76,9 @@ public boolean isAuthorized(ContainerRequestContext requestContext, Method metho if (tokenInfo.getScopes() != null) { Scope scopeAnnotation = method.getAnnotation(Scope.class); Set allowedScopeSet = new HashSet<>(Arrays.asList(scopeAnnotation.value().split(" "))); - log.debug("Access Token: " + tokenInfo.getAccessToken()); + if (log.isDebugEnabled()) { + log.debug("Access Token: " + tokenInfo.getAccessToken()); + } isAuthorized = userAuthorizationValidator.isAuthorizedScope(tokenInfo.getScopes(), allowedScopeSet); if (isAuthorized) { From c1a3eaa5ad1a82296b6d01891a700112e8ee662f Mon Sep 17 00:00:00 2001 From: Salinda Date: Fri, 31 May 2019 11:02:21 +0530 Subject: [PATCH 6/8] [EXTGW-362] - introduce new property file reading mechanism and general cache with loading pattern --- components/config-util/pom.xml | 9 - components/framework-axp/pom.xml | 72 +++++ .../main/java/framework/cache/AXPCache.java | 269 ++++++++++++++++++ .../java/framework/cache/AXPCacheBuilder.java | 46 +++ .../java/framework/cache/AXPCacheHandler.java | 172 +++++++++++ .../framework/cache/CachePropertyReader.java | 59 ++++ .../cache/IAXPCacheHandlerService.java | 86 ++++++ .../java/framework/cache/IAXPCacheLoader.java | 23 ++ .../framework/cache/IAXPLoadingCache.java | 71 +++++ .../src/main/java/framework/cache/ICache.java | 59 ++++ .../cache/impl/DefaultAXPLoadingCache.java | 99 +++++++ .../configuration/CarbonUtilsDelegator.java | 41 +++ .../framework/configuration/ConfigFile.java | 41 +++ .../ConfigFileReaderStrategy.java | 51 ++++ .../IConfigFileReaderService.java | 19 ++ .../IConfigFileReaderStrategy.java | 20 ++ .../impl/ConfigFileReaderServiceImpl.java | 82 ++++++ .../impl/JavaPropertyFileReadStrategy.java | 51 ++++ .../impl/XMLPropertyFileReadStrategy.java | 20 ++ .../framework/cache/AXPCacheBuilderTest.java | 29 ++ .../framework/cache/AXPCacheHandlerTest.java | 211 ++++++++++++++ .../java/framework/cache/AXPCacheTest.java | 168 +++++++++++ .../impl/DefaultAXPLoadingCacheTest.java | 264 +++++++++++++++++ .../ConfigFileReaderStrategyTest.java | 31 ++ .../JavaPropertyFileReadStrategyTest.java | 64 +++++ .../test.properties | 25 ++ components/redis-client/pom.xml | 8 - components/sp-config-util/pom.xml | 9 - pom.xml | 88 ++++-- 29 files changed, 2140 insertions(+), 47 deletions(-) create mode 100644 components/framework-axp/pom.xml create mode 100644 components/framework-axp/src/main/java/framework/cache/AXPCache.java create mode 100644 components/framework-axp/src/main/java/framework/cache/AXPCacheBuilder.java create mode 100644 components/framework-axp/src/main/java/framework/cache/AXPCacheHandler.java create mode 100644 components/framework-axp/src/main/java/framework/cache/CachePropertyReader.java create mode 100644 components/framework-axp/src/main/java/framework/cache/IAXPCacheHandlerService.java create mode 100644 components/framework-axp/src/main/java/framework/cache/IAXPCacheLoader.java create mode 100644 components/framework-axp/src/main/java/framework/cache/IAXPLoadingCache.java create mode 100644 components/framework-axp/src/main/java/framework/cache/ICache.java create mode 100644 components/framework-axp/src/main/java/framework/cache/impl/DefaultAXPLoadingCache.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/CarbonUtilsDelegator.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/ConfigFile.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/ConfigFileReaderStrategy.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderService.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderStrategy.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/impl/ConfigFileReaderServiceImpl.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/impl/JavaPropertyFileReadStrategy.java create mode 100644 components/framework-axp/src/main/java/framework/configuration/impl/XMLPropertyFileReadStrategy.java create mode 100644 components/framework-axp/src/test/java/framework/cache/AXPCacheBuilderTest.java create mode 100644 components/framework-axp/src/test/java/framework/cache/AXPCacheHandlerTest.java create mode 100644 components/framework-axp/src/test/java/framework/cache/AXPCacheTest.java create mode 100644 components/framework-axp/src/test/java/framework/cache/impl/DefaultAXPLoadingCacheTest.java create mode 100644 components/framework-axp/src/test/java/framework/configuration/ConfigFileReaderStrategyTest.java create mode 100644 components/framework-axp/src/test/java/framework/configuration/impl/JavaPropertyFileReadStrategyTest.java create mode 100644 components/framework-axp/src/test/resources/com/wso2telco/framework/configuration/impl/JavaPropertyFileReadStrategyTest/test.properties diff --git a/components/config-util/pom.xml b/components/config-util/pom.xml index b42c20bc..07d7d204 100644 --- a/components/config-util/pom.xml +++ b/components/config-util/pom.xml @@ -37,15 +37,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - 1.7 - 1.7 - - org.apache.felix maven-bundle-plugin diff --git a/components/framework-axp/pom.xml b/components/framework-axp/pom.xml new file mode 100644 index 00000000..c5aef8c8 --- /dev/null +++ b/components/framework-axp/pom.xml @@ -0,0 +1,72 @@ + + + + core-parent + com.wso2telco.core + 2.4.5-SNAPSHOT + + 4.0.0 + + framework-axp + + + + org.wso2.carbon + org.wso2.carbon.utils + + + com.google.guava + guava + + + + org.testng + testng + + + org.assertj + assertj-core + + + org.mockito + mockito-all + + + org.easytesting + fest-reflect + + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.groupId}.${project.artifactId} + ${project.artifactId} + + com.wso2telco.framework.* + + + javax.servlet;version="2.4.0", + javax.servlet.http;version="2.4.0", + javax.servlet.resources;version="2.4.0", + org.eclipse.equinox.http.helper, + *;resolution:=optional + + * + + + + + + \ No newline at end of file diff --git a/components/framework-axp/src/main/java/framework/cache/AXPCache.java b/components/framework-axp/src/main/java/framework/cache/AXPCache.java new file mode 100644 index 00000000..cf1526ad --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/AXPCache.java @@ -0,0 +1,269 @@ +package framework.cache; + +import java.io.IOException; +import java.lang.ref.SoftReference; +import java.util.Optional; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Cache implementation for the AXP. + * The cache use a {@link ConcurrentHashMap} for store data in memory. The cache has time-to-live and a purge + * options in side the implementation. Also this has the support for init cache with no time limit. + * This has the capability of the ttl configuration support in object level as well. + *

+ * Note that in the implementation {@link SoftReference} has used to wrap the object. + * softly-reachable objects are guaranteed to have been cleared before the virtual machine throws an OutOfMemoryError. + *

+ * !!! HIGH IMPORTANT !!! + *

+ * All the objects stored in the cache will be return without cloning or deep cloning due to improve the cache performance. + * Because of that user should be responsible of the mutability of the stored object. + */ +public final class AXPCache implements ICache +{ + + private boolean noTimeLimit; + + private long ttl; + + private static Log log = LogFactory.getLog(AXPCache.class); + + private final ConcurrentHashMap> cache = new ConcurrentHashMap<>(); + + private static final long DEFAULT_PURGING_TIME = 5 * 60 * 60 * 1000; + + /** + * Initialize cache with the given time to live value. + * Object will be purged after expiring the ttl. This will overide the configuration value defined in the + * + * @param ttl object time-to-live value in milli seconds + */ + public AXPCache(long ttl) + { + this.ttl = ttl; + initPurgingTask(this.ttl); + } + + /** + * Does not initialize the cache purging thread if the noTimeLimit parameter is true + * If the given boolean value is false, then the cache purge time will be applicable from the the configuration file. + * Even if the noTimeLimit parameter true, + * + * @param noTimeLimit + */ + public AXPCache(boolean noTimeLimit) + { + this.noTimeLimit = noTimeLimit; + if (!noTimeLimit) + { + ttl = getDefaultTTLFromConfiguration(); + initPurgingTask(ttl); + } + else + { + ttl = -1; + /** + * if there are any expired objects available in the cache need to clean them. + */ + initPurgingTask(DEFAULT_PURGING_TIME); + } + } + + /** + * Initialize cache with default purging time. + * Apply the cache object ttl value from the configuration file. + */ + public AXPCache() + { + ttl = getDefaultTTLFromConfiguration(); + initPurgingTask(ttl); + } + + /** + * {@inheritDoc} + * + * @param key + * @param value + * @param + * @param + */ + @Override + public void put(K key, V value) + { + if (key == null) + { + return; + } + if (value == null) + { + cache.remove(key); + } + else + { + long expiryTime = noTimeLimit ? -1 : System.currentTimeMillis() + ttl; + cache.put(key, new SoftReference<>(new CacheObject(value, expiryTime))); + } + } + + /** + * {@inheritDoc} + * + * @param key + * @param value + * @param periodInMillis time-to-live value + * @param + * @param + */ + @Override + public void put(K key, V value, long periodInMillis) + { + if (key == null) + { + return; + } + if (value == null) + { + cache.remove(key); + } + else + { + long expiryTime = System.currentTimeMillis() + periodInMillis; + cache.put(key, new SoftReference<>(new CacheObject(value, expiryTime))); + } + } + + /** + * {@inheritDoc} + * + * @param key + * @param + */ + @Override + public void remove(K key) + { + cache.remove(key); + } + + /** + * {@inheritDoc} + * + * @param key + * @param + * @return + */ + @Override + public Object get(K key) + { + return Optional.ofNullable(cache.get(key)).map(SoftReference::get).filter(cacheObject -> !cacheObject.isExpired()) + .map(CacheObject::getValue).orElse(null); + } + + /** + * {@inheritDoc} + */ + @Override + public void clear() + { + cache.clear(); + } + + /** + * {@inheritDoc} + * + * @return + */ + @Override + public long size() + { + return cache.entrySet().stream().filter(entry -> Optional.ofNullable(entry.getValue()).map(SoftReference::get) + .map(cacheObject -> !cacheObject.isExpired()).orElse(false)).count(); + } + + /** + * Note that if the framework.properties file does not available or entry is not there, -1 will be returned. + * which means cache will not be expired. + * + * @return default ttl configuration in framework.properties file. + */ + private long getDefaultTTLFromConfiguration() + { + long ttl; + try + { + ttl = CachePropertyReader.getInstance().getDefaultTTL() * 1000; + } + catch (IOException e) + { + ttl = -1; + log.error("Error occurred while reading property file configuration for default cache ttl.", e); + } + return ttl; + } + + private void initPurgingTask(final long ttl) + { + if (ttl <= 0) + { + return; + } + TimerTask cleanerTask = new TimerTask() + { + @Override + public void run() + { + purge(); + } + }; + Timer timer = new Timer("Timer"); + timer.scheduleAtFixedRate(cleanerTask, ttl, ttl); + } + + /** + * Purge objects if the time is expired + */ + private void purge() + { + cache.entrySet().removeIf( + entry -> Optional.ofNullable(entry.getValue()).map(SoftReference::get) + .map(CacheObject::isExpired).orElse(false)); + } + + + /** + * Class to hold the cache value and expiration time + */ + private class CacheObject + { + + private Object value; + + private long expiryTime; + + /** + * Set the attributes of the cache object + * + * @param value + * @param expiryTime + */ + public CacheObject(Object value, long expiryTime) + { + this.value = value; + this.expiryTime = expiryTime; + } + + public Object getValue() + { + return value; + } + + boolean isExpired() + { + return expiryTime == -1 ? false : System.currentTimeMillis() > expiryTime; + } + } +} diff --git a/components/framework-axp/src/main/java/framework/cache/AXPCacheBuilder.java b/components/framework-axp/src/main/java/framework/cache/AXPCacheBuilder.java new file mode 100644 index 00000000..4340dc4e --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/AXPCacheBuilder.java @@ -0,0 +1,46 @@ +package framework.cache; + +import framework.cache.impl.DefaultAXPLoadingCache; + +/** + * This builder is responsible for building {@link IAXPLoadingCache} + */ +public class AXPCacheBuilder +{ + + private boolean noTimeLimit = true; + + /** + * @return new {@link AXPCacheBuilder} + */ + public static AXPCacheBuilder newBuilder() + { + return new AXPCacheBuilder(); + } + + /** + * Sets {@code noTimeLimit} flag of {@link AXPCache} + * + * @param noTimeLimit no time limit + * @return current instance of AXPCacheBuilder + */ + public AXPCacheBuilder setNoTimeLimit(final boolean noTimeLimit) + { + this.noTimeLimit = noTimeLimit; + + return this; + } + + /** + * Create and returns new {@link DefaultAXPLoadingCache} by using provided {@code IAXPCacheLoader} + * + * @param cacheLoader cache loader + * @param Type of cache key + * @param Type of cache data + * @return new {@link DefaultAXPLoadingCache} + */ + public IAXPLoadingCache build(final IAXPCacheLoader cacheLoader) + { + return new DefaultAXPLoadingCache<>(cacheLoader, new AXPCache(noTimeLimit)); + } +} diff --git a/components/framework-axp/src/main/java/framework/cache/AXPCacheHandler.java b/components/framework-axp/src/main/java/framework/cache/AXPCacheHandler.java new file mode 100644 index 00000000..22e27500 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/AXPCacheHandler.java @@ -0,0 +1,172 @@ +package framework.cache; + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This handler is responsible for managing {@link AXPCache} by using {@link IAXPCacheLoader} + */ +@SuppressWarnings("unchecked") +public final class AXPCacheHandler implements IAXPCacheHandlerService +{ + + private static final IAXPCacheHandlerService INSTANCE = new AXPCacheHandler(); + + private AXPCacheHandler() + { + } + + public static IAXPCacheHandlerService getInstance() + { + return INSTANCE; + } + + /** + * {@inheritDoc} + * + * @param axpCache client cache + * @param cacheLoader cache loader + * @param cacheKey cache key + * @param + * @param + * @return + * @throws Exception + */ + @Override + public V getData(final AXPCache axpCache, final IAXPCacheLoader cacheLoader, final K cacheKey) throws + Exception + { + final V cachedData = (V) axpCache.get(cacheKey); + if (cachedData != null) + { + return cachedData; + } + else + { + Map missingData = cacheLoader.load(Collections.singletonList(cacheKey)); + for (final Map.Entry loadedDataEntry : missingData.entrySet()) + { + axpCache.put(loadedDataEntry.getKey(), loadedDataEntry.getValue()); + } + } + + return (V) axpCache.get(cacheKey); + } + + /** + * {@inheritDoc} + * + * @param axpCache client cache + * @param cacheLoader cache loader + * @param cacheKeyList cache key list + * @param + * @param + * @return + * @throws Exception + */ + @Override + public Map getDataAsMap(final AXPCache axpCache, final IAXPCacheLoader cacheLoader, + final List cacheKeyList) throws Exception + { + final Map dataMap = new HashMap<>(); + final List missingCacheKeyList = new ArrayList<>(); + + for (final K cacheKey : cacheKeyList) + { + final V cachedData = (V) axpCache.get(cacheKey); + + if (cachedData != null) + { + dataMap.put(cacheKey, cachedData); + } + else + { + missingCacheKeyList.add(cacheKey); + } + } + + if (!missingCacheKeyList.isEmpty()) + { + final Map missingDataMap = cacheLoader.load(missingCacheKeyList); + + for (final Map.Entry loadedDataEntry : missingDataMap.entrySet()) + { + axpCache.put(loadedDataEntry.getKey(), loadedDataEntry.getValue()); + } + + dataMap.putAll(missingDataMap); + } + + return dataMap; + } + + /** + * {@inheritDoc} + * + * @param axpCache client cache + * @param cacheLoader cache loader + * @param cacheKeyList cache key list + * @param + * @param + * @return + * @throws Exception + */ + @Override + public List getDataAsList(final AXPCache axpCache, final IAXPCacheLoader cacheLoader, + final List cacheKeyList) throws Exception + { + final Map dataMap = getDataAsMap(axpCache, cacheLoader, cacheKeyList); + + final List resultDataList = new ArrayList<>(); + + for (final K cacheKey : cacheKeyList) + { + resultDataList.add(dataMap.get(cacheKey)); + } + + return resultDataList; + } + + /** + * {@inheritDoc} + * + * @param axpCache client cache + * @param cacheKey cache key + * @param value value + * @param + * @param + */ + @Override + public void update(final AXPCache axpCache, final K cacheKey, final V value) + { + axpCache.put(cacheKey, value); + } + + /** + * {@inheritDoc} + * + * @param axpCache + */ + @Override + public void clear(final AXPCache axpCache) + { + axpCache.clear(); + } + + /** + * {@inheritDoc} + * + * @param axpCache + * @param cacheKey + * @param + */ + @Override + public void remove(final AXPCache axpCache, K cacheKey) + { + axpCache.remove(cacheKey); + } +} diff --git a/components/framework-axp/src/main/java/framework/cache/CachePropertyReader.java b/components/framework-axp/src/main/java/framework/cache/CachePropertyReader.java new file mode 100644 index 00000000..e5dfab09 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/CachePropertyReader.java @@ -0,0 +1,59 @@ +package framework.cache; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; + +import com.google.common.base.Joiner; +import framework.configuration.CarbonUtilsDelegator; +import framework.configuration.ConfigFile; + +/** + * This class is a dedicated class to read the cache related configurations + */ +class CachePropertyReader +{ + + private static CachePropertyReader instance; + + private String DEFAULT_CACHE_TIMEOUT = "framework.axpcache.timeout"; + + private Properties properties = new Properties(); + + static synchronized CachePropertyReader getInstance() + { + if (instance == null) + { + instance = new CachePropertyReader(); + } + + return instance; + } + + /** + * get default ttl value configured in framework.properties file in conf folder. + * + * @return configured value if available, otherwise -1. + * @throws IOException + */ + long getDefaultTTL() throws IOException + { + if (properties.isEmpty()) + { + String filePath = Joiner.on(File.separator) + .join(CarbonUtilsDelegator.getInstance().getCarbonConfigDirPath(), ConfigFile.FRAMEWORK_CONF.getName()); + Path configPath = Paths.get(filePath); + try (InputStream stream = Files.newInputStream(configPath)) + { + properties.load(stream); + } + } + String property = properties.getProperty(DEFAULT_CACHE_TIMEOUT); + + return property != null && !property.isEmpty() ? Long.parseLong(property) : -1; + } +} diff --git a/components/framework-axp/src/main/java/framework/cache/IAXPCacheHandlerService.java b/components/framework-axp/src/main/java/framework/cache/IAXPCacheHandlerService.java new file mode 100644 index 00000000..9af0c775 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/IAXPCacheHandlerService.java @@ -0,0 +1,86 @@ +package framework.cache; + +import java.util.List; +import java.util.Map; + +/** + * AXP cache handler service. + * This class is responsible of handling axp cache related operations for the loading cache. + */ +public interface IAXPCacheHandlerService +{ + + /** + * Returns the data associated with {@code cacheKey} from provided {@code axpCache}. If the data related to given + * {@code cacheKey} is not in the cache, then the missing data will be loaded according to the logic implemented in + * {@link IAXPCacheLoader#load(List)} and update the provided {@code AXPCache}. + * + * @param axpCache client cache + * @param cacheLoader cache loader + * @param cacheKey cache key + * @param Type of cache key + * @param Type of cached data + * @return data associated with {@code cacheKey} + * @throws Exception + */ + V getData(AXPCache axpCache, IAXPCacheLoader cacheLoader, K cacheKey) + throws Exception; + + /** + * Returns a map of data associated with {@code cacheKeyList} from provided {@code axpCache}. If the data related + * to given {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic + * implemented in {@link IAXPCacheLoader#load(List)} and update the provided {@code axpCache}. + * + * @param axpCache client cache + * @param cacheLoader cache loader + * @param cacheKeyList cache key list + * @param Type of cache key + * @param Type of cached data + * @return a map of data associated with {@code cacheKeyList} + * @throws Exception + */ + Map getDataAsMap(AXPCache axpCache, IAXPCacheLoader cacheLoader, + List cacheKeyList) + throws Exception; + + /** + * Returns a list of data associated with {@code cacheKeyList} from provided {@code axpCache}. If the data related + * to given {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic + * implemented in {@link IAXPCacheLoader#load(List)} and update the provided {@code axpCache}. + *

+ * This always preserve the order of the data list, according to the provided {@code cacheKeyList} + * + * @param axpCache client cache + * @param cacheLoader cache loader + * @param cacheKeyList cache key list + * @param Type of cache key + * @param Type of cached data + * @return a list of data associated with {@code cacheKeyList}, the order will be preserved + * @throws Exception + */ + List getDataAsList(AXPCache axpCache, IAXPCacheLoader cacheLoader, + List cacheKeyList) + throws Exception; + + /** + * Add or update cache entries with provided values in provided client cache + * + * @param axpCache client cache + * @param cacheKey cache key + * @param value value + */ + void update(AXPCache axpCache, K cacheKey, V value); + + /** + * Clear all cached data in provide cache + */ + void clear(AXPCache axpCache); + + /** + * Remove data from the cache associated with the given cache key + * + * @param cacheKey + * @param + */ + void remove(final AXPCache axpCache, K cacheKey); +} diff --git a/components/framework-axp/src/main/java/framework/cache/IAXPCacheLoader.java b/components/framework-axp/src/main/java/framework/cache/IAXPCacheLoader.java new file mode 100644 index 00000000..8cf1d832 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/IAXPCacheLoader.java @@ -0,0 +1,23 @@ +package framework.cache; + +import java.util.List; +import java.util.Map; + +/** + * This defines the contract related to data loading logic of a client side cache + * + * @param Type of cache key + * @param Type of cached data + */ +public interface IAXPCacheLoader +{ + + /** + * Load all the data related to cache key list + * + * @param cacheKeyList cache key list + * @return a map from each key in {@code keys} to the data associated with that key; may not contain null values + * @throws Exception + */ + Map load(List cacheKeyList) throws Exception; +} diff --git a/components/framework-axp/src/main/java/framework/cache/IAXPLoadingCache.java b/components/framework-axp/src/main/java/framework/cache/IAXPLoadingCache.java new file mode 100644 index 00000000..319c1f16 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/IAXPLoadingCache.java @@ -0,0 +1,71 @@ +package framework.cache; + +import java.util.List; +import java.util.Map; + +/** + * This defines the contract related to loading cache. Use {@link AXPCacheBuilder} to define + * and create {@link IAXPLoadingCache} + * + * @param Type of cache key + * @param Type of cached data + */ +public interface IAXPLoadingCache +{ + + /** + * Returns data associated with {@code cacheKey} from the cache. If the data related to given {@code cacheKey} is not + * in the cache, then the missing data will be loaded according to the logic implemented in + * {@link IAXPCacheLoader#load(List)} and update the cache. + * + * @param cacheKey cache key + * @return Returns data associated with {@code cacheKey} from the cache + * @throws Exception + */ + V getData(K cacheKey) throws Exception; + + /** + * Returns a map of data associated with {@code cacheKeyList} from the cache. If the data related to given + * {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic implemented + * in {@link IAXPCacheLoader#load(List)} and update the cache. + * + * @param cacheKeyList cache key list + * @return Returns a map of data associated with {@code cacheKeyList} from the cache + * @throws Exception + */ + Map getDataAsMap(List cacheKeyList) throws Exception; + + /** + * Returns a list of data associated with {@code cacheKeyList} from the cache. If the data related to given + * {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic implemented + * in {@link IAXPCacheLoader#load(List)} and update the cache. + *

+ * This always preserve the order of the data list, according to the provided {@code cacheKeyList} + * + * @param cacheKeyList cache key list + * @return Returns a list of data associated with {@code cacheKeyList} from the cache, the order will be preserved + * @throws Exception + */ + List getDataAsList(List cacheKeyList) throws Exception; + + /** + * Add or update cache entries with provided values + * + * @param cacheKey cache key + * @param value value + */ + void update(K cacheKey, V value); + + /** + * remove data from the cache associated with the given cache key + * + * @param cacheKey + */ + void remove(K cacheKey); + + /** + * Clear all cached data + */ + void clear(); + +} diff --git a/components/framework-axp/src/main/java/framework/cache/ICache.java b/components/framework-axp/src/main/java/framework/cache/ICache.java new file mode 100644 index 00000000..0e7810c7 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/ICache.java @@ -0,0 +1,59 @@ +package framework.cache; + +/** + * The interface for the cache. + * This has the support for all the primary features of a cache + */ +public interface ICache +{ + + /** + * Insert data in to the cache with custom time-to-live value. + * + * @param key + * @param value + * @param periodInMillis time-to-live value + * @param + * @param + */ + void put(K key, V value, long periodInMillis); + + /** + * Remove the data associated with the given key from the cache. + * + * @param key + * @param + */ + void remove(K key); + + /** + * Get the data associated with the the given key. + * + * @param key + * @param + * @return the object associated to the given cache key + */ + Object get(K key); + + /** + * Get the current size of the cache. + * + * @return current size of the cache. + */ + long size(); + + /** + * Insert data into the cache against the given key. + * + * @param key + * @param value + * @param + * @param + */ + void put(K key, V value); + + /** + * Clear all the data in the cache + */ + void clear(); +} diff --git a/components/framework-axp/src/main/java/framework/cache/impl/DefaultAXPLoadingCache.java b/components/framework-axp/src/main/java/framework/cache/impl/DefaultAXPLoadingCache.java new file mode 100644 index 00000000..fcc70b2f --- /dev/null +++ b/components/framework-axp/src/main/java/framework/cache/impl/DefaultAXPLoadingCache.java @@ -0,0 +1,99 @@ +package framework.cache.impl; + + +import java.util.List; +import java.util.Map; + +import framework.cache.AXPCache; +import framework.cache.AXPCacheHandler; +import framework.cache.IAXPCacheLoader; +import framework.cache.IAXPLoadingCache; + +/** + * This implementation uses {@link AXPCache} as the base cache. + */ +public class DefaultAXPLoadingCache implements IAXPLoadingCache +{ + + private final AXPCache axpCache; + + private final IAXPCacheLoader cacheLoader; + + public DefaultAXPLoadingCache(final IAXPCacheLoader cacheLoader, + final AXPCache axpCache) + { + this.axpCache = axpCache; + this.cacheLoader = cacheLoader; + } + + /** + * {@inheritDoc} + * + * @param cacheKey cache key + * @return + * @throws Exception + */ + @Override + public V getData(final K cacheKey) throws Exception + { + return AXPCacheHandler.getInstance().getData(axpCache, cacheLoader, cacheKey); + } + + /** + * {@inheritDoc} + * + * @param cacheKeyList cache key list + * @return + * @throws Exception + */ + @Override + public Map getDataAsMap(final List cacheKeyList) throws Exception + { + return AXPCacheHandler.getInstance().getDataAsMap(axpCache, cacheLoader, cacheKeyList); + } + + /** + * {@inheritDoc} + * + * @param cacheKeyList cache key list + * @return + * @throws Exception + */ + @Override + public List getDataAsList(final List cacheKeyList) throws Exception + { + return AXPCacheHandler.getInstance().getDataAsList(axpCache, cacheLoader, cacheKeyList); + } + + /** + * {@inheritDoc} + * + * @param cacheKey cache key + * @param value value + */ + @Override + public void update(final K cacheKey, final V value) + { + AXPCacheHandler.getInstance().update(axpCache, cacheKey, value); + } + + /** + * {@inheritDoc} + */ + @Override + public void clear() + { + AXPCacheHandler.getInstance().clear(axpCache); + } + + /** + * {@inheritDoc} + * + * @param cacheKey + */ + @Override + public void remove(K cacheKey) + { + AXPCacheHandler.getInstance().remove(axpCache, cacheKey); + } +} diff --git a/components/framework-axp/src/main/java/framework/configuration/CarbonUtilsDelegator.java b/components/framework-axp/src/main/java/framework/configuration/CarbonUtilsDelegator.java new file mode 100644 index 00000000..2a27d620 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/CarbonUtilsDelegator.java @@ -0,0 +1,41 @@ +package framework.configuration; + +import org.wso2.carbon.utils.CarbonUtils; + +/** + * Delegator class for {@link CarbonUtils} + */ +public class CarbonUtilsDelegator +{ + + private static final CarbonUtilsDelegator INSTANCE = new CarbonUtilsDelegator(); + + public static CarbonUtilsDelegator getInstance() + { + return INSTANCE; + } + + private CarbonUtilsDelegator() + { + } + + /** + * Get carbon home directory path as a string + * + * @return + */ + public String getCarbonHome() + { + return CarbonUtils.getCarbonHome(); + } + + /** + * Get Carbon configuration directory path as a string + * + * @return + */ + public String getCarbonConfigDirPath() + { + return CarbonUtils.getCarbonConfigDirPath(); + } +} diff --git a/components/framework-axp/src/main/java/framework/configuration/ConfigFile.java b/components/framework-axp/src/main/java/framework/configuration/ConfigFile.java new file mode 100644 index 00000000..4a6e8752 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/ConfigFile.java @@ -0,0 +1,41 @@ +package framework.configuration; + +/** + * enum to hold the configuration file names which contains in the default config directory. + */ +public enum ConfigFile +{ + + /** + * oneapi-validation-conf.properties + */ + ONEAPI_VALIDATION_CONF("oneapi-validation-conf.properties"), + + /** + * mediator-conf.properties + */ + MEDIATOR_CONF("mediator-conf.properties"), + + /** + * framework.properties + */ + FRAMEWORK_CONF("framework.properties"), + + /** + * MobileCountryConfig.xml + */ + MOBILE_COUNTRY_CONF("MobileCountryConfig.xml"); + + + private final String name; + + ConfigFile(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } +} diff --git a/components/framework-axp/src/main/java/framework/configuration/ConfigFileReaderStrategy.java b/components/framework-axp/src/main/java/framework/configuration/ConfigFileReaderStrategy.java new file mode 100644 index 00000000..477f055b --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/ConfigFileReaderStrategy.java @@ -0,0 +1,51 @@ +package framework.configuration; + +import framework.configuration.impl.JavaPropertyFileReadStrategy; +import framework.configuration.impl.XMLPropertyFileReadStrategy; + +/** + * The class to resolve file reader strategy by extension + */ +public final class ConfigFileReaderStrategy +{ + + private static final ConfigFileReaderStrategy INSTANCE = new ConfigFileReaderStrategy(); + + private static final String EXTENSION_PROPERTIES = "properties"; + + private ConfigFileReaderStrategy() + { + } + + private static final String EXTENSION_XML = "xml"; + + /** + * get singleton instance of {@link ConfigFileReaderStrategy} + * + * @return + */ + public static ConfigFileReaderStrategy getInstance() + { + return INSTANCE; + } + + /** + * Get the file read strategy by file extension + * + * @param extension + * @return + */ + public IConfigFileReaderStrategy getStrategy(String extension) + { + switch (extension) + { + case EXTENSION_PROPERTIES: + return new JavaPropertyFileReadStrategy(CarbonUtilsDelegator.getInstance()); + case EXTENSION_XML: + return new XMLPropertyFileReadStrategy(); + default: + //TODO introduce new runtime exception + throw new RuntimeException("Unsupported file type."); + } + } +} diff --git a/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderService.java b/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderService.java new file mode 100644 index 00000000..e6ed1ea7 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderService.java @@ -0,0 +1,19 @@ +package framework.configuration; + +import java.util.Map; + +/** + * The class for read configuration files in config directory. + */ +public interface IConfigFileReaderService +{ + + /** + * Read the given file in the default config directory. + * + * @param configFile + * @return + * @throws Exception + */ + Map readFile(ConfigFile configFile) throws Exception; +} diff --git a/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderStrategy.java b/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderStrategy.java new file mode 100644 index 00000000..175ca147 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderStrategy.java @@ -0,0 +1,20 @@ +package framework.configuration; + +import java.io.IOException; +import java.util.Map; + +/** + * The class for Configuration files read services. + */ +public interface IConfigFileReaderStrategy +{ + + /** + * Read the given configuration file from the default configuration directory. + * + * @param fileName + * @return a map of properties which contains in the given file + * @throws IOException + */ + Map readFile(String fileName) throws IOException; +} diff --git a/components/framework-axp/src/main/java/framework/configuration/impl/ConfigFileReaderServiceImpl.java b/components/framework-axp/src/main/java/framework/configuration/impl/ConfigFileReaderServiceImpl.java new file mode 100644 index 00000000..8d6aa849 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/impl/ConfigFileReaderServiceImpl.java @@ -0,0 +1,82 @@ +package framework.configuration.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import framework.cache.AXPCacheBuilder; +import framework.cache.IAXPCacheLoader; +import framework.cache.IAXPLoadingCache; +import framework.configuration.ConfigFile; +import framework.configuration.ConfigFileReaderStrategy; +import framework.configuration.IConfigFileReaderService; +import framework.configuration.IConfigFileReaderStrategy; + +/** + * Implementation for the {@link IConfigFileReaderService} + * This file reader class will help to read configuration property files with a caching support. + */ +public class ConfigFileReaderServiceImpl implements IConfigFileReaderService +{ + + private static final ConfigFileReaderServiceImpl INSTANCE = new ConfigFileReaderServiceImpl(); + + private static final String DOT = "."; + + private IAXPLoadingCache> axpLoadingCache = AXPCacheBuilder.newBuilder() + .setNoTimeLimit(true).build(new PropertyFileCacheLoader()); + + private ConfigFileReaderServiceImpl() + { + } + + /** + * Get Singleton instance of {@link ConfigFileReaderServiceImpl} + * + * @return + */ + public static ConfigFileReaderServiceImpl getInstance() + { + return INSTANCE; + } + + /** + * {@inheritDoc} + * + * @param configFile + * @return + * @throws Exception + */ + @Override + public Map readFile(ConfigFile configFile) throws Exception + { + return axpLoadingCache.getData(configFile.getName()); + } + + class PropertyFileCacheLoader implements IAXPCacheLoader> + { + + /** + * {@inheritDoc} + * + * @param cacheKeyList cache key list + * @return + * @throws Exception + */ + @Override + public Map> load(List cacheKeyList) throws Exception + { + ConfigFileReaderStrategy configFileReaderStrategy = ConfigFileReaderStrategy.getInstance(); + Map> filePropertiesMap = new HashMap<>(); + for (String fileName : cacheKeyList) + { + IConfigFileReaderStrategy strategy = configFileReaderStrategy + .getStrategy(fileName.substring(fileName.lastIndexOf(DOT) + 1)); + Map propertiesMap = strategy.readFile(fileName); + filePropertiesMap.put(fileName, propertiesMap); + } + + return filePropertiesMap; + } + } +} diff --git a/components/framework-axp/src/main/java/framework/configuration/impl/JavaPropertyFileReadStrategy.java b/components/framework-axp/src/main/java/framework/configuration/impl/JavaPropertyFileReadStrategy.java new file mode 100644 index 00000000..99c5b7cd --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/impl/JavaPropertyFileReadStrategy.java @@ -0,0 +1,51 @@ +package framework.configuration.impl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Map; +import java.util.Properties; + +import com.google.common.base.Joiner; +import com.google.common.collect.Maps; +import framework.configuration.CarbonUtilsDelegator; +import framework.configuration.IConfigFileReaderStrategy; + +/** + * Java property file reader strategy. + * This supports for the standard java property files. + */ +public final class JavaPropertyFileReadStrategy implements IConfigFileReaderStrategy +{ + + private CarbonUtilsDelegator carbonUtilsDelegator; + + public JavaPropertyFileReadStrategy(CarbonUtilsDelegator carbonUtilsDelegator) + { + this.carbonUtilsDelegator = carbonUtilsDelegator; + } + + /** + * {@inheritDoc} + * + * @param fileName + * @return + * @throws IOException + */ + @Override + public Map readFile(String fileName) throws IOException + { + String filePath = Joiner.on(File.separator).join(carbonUtilsDelegator.getCarbonConfigDirPath(), fileName); + Path configPath = Paths.get(filePath); + try (InputStream stream = Files.newInputStream(configPath)) + { + Properties properties = new Properties(); + properties.load(stream); + + return Maps.fromProperties(properties); + } + } +} \ No newline at end of file diff --git a/components/framework-axp/src/main/java/framework/configuration/impl/XMLPropertyFileReadStrategy.java b/components/framework-axp/src/main/java/framework/configuration/impl/XMLPropertyFileReadStrategy.java new file mode 100644 index 00000000..71022eb4 --- /dev/null +++ b/components/framework-axp/src/main/java/framework/configuration/impl/XMLPropertyFileReadStrategy.java @@ -0,0 +1,20 @@ +package framework.configuration.impl; + +import java.util.Map; + +import framework.configuration.IConfigFileReaderStrategy; + +/** + * XML property file reader strategy + * This supports for the xml property files. + */ +public final class XMLPropertyFileReadStrategy implements IConfigFileReaderStrategy +{ + + @Override + public Map readFile(String fileName) + { + //TODO + return null; + } +} diff --git a/components/framework-axp/src/test/java/framework/cache/AXPCacheBuilderTest.java b/components/framework-axp/src/test/java/framework/cache/AXPCacheBuilderTest.java new file mode 100644 index 00000000..4a13dabc --- /dev/null +++ b/components/framework-axp/src/test/java/framework/cache/AXPCacheBuilderTest.java @@ -0,0 +1,29 @@ +package framework.cache; + +import framework.cache.impl.DefaultAXPLoadingCache; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.testng.Assert.fail; + +public class AXPCacheBuilderTest +{ + + @Test + public void testBuild() + { + try + { + final IAXPLoadingCache clientLoadingCache = AXPCacheBuilder.newBuilder().setNoTimeLimit(true) + .build(cacheKeyList -> null); + + assertThat(clientLoadingCache).isInstanceOf(DefaultAXPLoadingCache.class); + } + catch (Exception e) + { + e.printStackTrace(); + + fail(); + } + } +} diff --git a/components/framework-axp/src/test/java/framework/cache/AXPCacheHandlerTest.java b/components/framework-axp/src/test/java/framework/cache/AXPCacheHandlerTest.java new file mode 100644 index 00000000..ac77a2aa --- /dev/null +++ b/components/framework-axp/src/test/java/framework/cache/AXPCacheHandlerTest.java @@ -0,0 +1,211 @@ +package framework.cache; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.beust.jcommander.internal.Lists; +import org.assertj.core.api.Assertions; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyList; +import static org.mockito.Mockito.*; +import static org.testng.Assert.fail; + +public class AXPCacheHandlerTest +{ + + + private AXPCache axpCache; + + private TestCacheLoader mockCacheLoader; + + @BeforeMethod + public void setUp() + { + axpCache = new AXPCache(true); + axpCache.put(1, "1*"); + axpCache.put(2, "2"); + axpCache.put(3, "3*"); + + mockCacheLoader = mock(TestCacheLoader.class); + } + + @Test + public void testGetDataAsMap() + { + try + { + final List keyList = Lists.newArrayList(); + keyList.add(1); + keyList.add(4); + keyList.add(3); + keyList.add(5); + + when(mockCacheLoader.load(anyList())).thenCallRealMethod(); + + Map dataMap = + AXPCacheHandler.getInstance().getDataAsMap(axpCache, mockCacheLoader, keyList); + + assertThat(dataMap).isNotNull(); + assertThat(dataMap.size()).isEqualTo(4); + assertThat(dataMap.get(1)).isEqualTo("1*"); + assertThat(dataMap.get(4)).isEqualTo("4"); + assertThat(dataMap.get(3)).isEqualTo("3*"); + assertThat(dataMap.get(5)).isEqualTo("5"); + + assertThat(axpCache.size()).isEqualTo(5); + assertThat(axpCache.get(1)).isEqualTo("1*"); + assertThat(axpCache.get(2)).isEqualTo("2"); + assertThat(axpCache.get(3)).isEqualTo("3*"); + assertThat(axpCache.get(4)).isEqualTo("4"); + assertThat(axpCache.get(5)).isEqualTo("5"); + + verify(mockCacheLoader, only()).load(anyList()); + + dataMap = AXPCacheHandler.getInstance().getDataAsMap(axpCache, mockCacheLoader, keyList); + + Assertions.assertThat(dataMap).isNotNull(); + assertThat(dataMap.size()).isEqualTo(4); + assertThat(dataMap.get(1)).isEqualTo("1*"); + assertThat(dataMap.get(4)).isEqualTo("4"); + assertThat(dataMap.get(3)).isEqualTo("3*"); + assertThat(dataMap.get(5)).isEqualTo("5"); + + assertThat(axpCache.size()).isEqualTo(5); + assertThat(axpCache.get(1)).isEqualTo("1*"); + assertThat(axpCache.get(2)).isEqualTo("2"); + assertThat(axpCache.get(3)).isEqualTo("3*"); + assertThat(axpCache.get(4)).isEqualTo("4"); + assertThat(axpCache.get(5)).isEqualTo("5"); + + verify(mockCacheLoader, only()).load(anyList()); + } + catch (Exception e) + { + e.printStackTrace(); + + fail(); + } + } + + @Test + public void testGetDataAsList() + { + try + { + final List keyList = Lists.newArrayList(); + keyList.add(1); + keyList.add(4); + keyList.add(3); + keyList.add(5); + + when(mockCacheLoader.load(anyList())).thenCallRealMethod(); + + List dataList = + AXPCacheHandler.getInstance().getDataAsList(axpCache, mockCacheLoader, keyList); + + assertThat(dataList).isNotNull(); + assertThat(dataList.size()).isEqualTo(4); + assertThat(dataList.get(0)).isEqualTo("1*"); + assertThat(dataList.get(1)).isEqualTo("4"); + assertThat(dataList.get(2)).isEqualTo("3*"); + assertThat(dataList.get(3)).isEqualTo("5"); + + assertThat(axpCache.size()).isEqualTo(5); + assertThat(axpCache.get(1)).isEqualTo("1*"); + assertThat(axpCache.get(2)).isEqualTo("2"); + assertThat(axpCache.get(3)).isEqualTo("3*"); + assertThat(axpCache.get(4)).isEqualTo("4"); + assertThat(axpCache.get(5)).isEqualTo("5"); + + verify(mockCacheLoader, only()).load(anyList()); + + dataList = AXPCacheHandler.getInstance().getDataAsList(axpCache, mockCacheLoader, keyList); + + assertThat(dataList).isNotNull(); + assertThat(dataList.size()).isEqualTo(4); + assertThat(dataList.get(0)).isEqualTo("1*"); + assertThat(dataList.get(1)).isEqualTo("4"); + assertThat(dataList.get(2)).isEqualTo("3*"); + assertThat(dataList.get(3)).isEqualTo("5"); + + assertThat(axpCache.size()).isEqualTo(5); + assertThat(axpCache.get(1)).isEqualTo("1*"); + assertThat(axpCache.get(2)).isEqualTo("2"); + assertThat(axpCache.get(3)).isEqualTo("3*"); + assertThat(axpCache.get(4)).isEqualTo("4"); + assertThat(axpCache.get(5)).isEqualTo("5"); + + verify(mockCacheLoader, only()).load(anyList()); + } + catch (Exception e) + { + e.printStackTrace(); + + fail(); + } + } + + @Test + public void testGetData_cached() throws Exception + { + String result = AXPCacheHandler.getInstance().getData(axpCache, mockCacheLoader, 1); + assertThat(result).isEqualTo("1*"); + } + + @Test + public void testGetData_nonCached() throws Exception + { + List keys = Lists.newArrayList(); + keys.add(7); + when(mockCacheLoader.load(keys)).thenCallRealMethod(); + String result = AXPCacheHandler.getInstance().getData(axpCache, mockCacheLoader, 7); + assertThat(result).isEqualTo("7"); + } + + @Test + public void testUpdate() + { + int key = 2; + AXPCacheHandler.getInstance().update(axpCache, key, "updated value"); + assertThat(axpCache.get(key)).isEqualTo("updated value"); + } + + @Test + public void testClearCache() + { + AXPCache cache = new AXPCache(true); + cache.put(1, 1L); + cache.put(2, 2L); + cache.put(3, 3L); + + AXPCacheHandler.getInstance().clear(cache); + assertThat(cache.get(1l)).isNull(); + assertThat(cache.get(2l)).isNull(); + assertThat(cache.get(3l)).isNull(); + + assertThat(cache.get(1)).isNull(); + assertThat(cache.get(2)).isNull(); + assertThat(cache.get(3)).isNull(); + } + + private static class TestCacheLoader implements IAXPCacheLoader + { + + @Override + public Map load(List cacheKeyList) throws Exception + { + final Map dataMap = new HashMap<>(); + + for (Integer testCacheKey : cacheKeyList) + { + dataMap.put(testCacheKey, testCacheKey + ""); + } + + return dataMap; + } + } +} diff --git a/components/framework-axp/src/test/java/framework/cache/AXPCacheTest.java b/components/framework-axp/src/test/java/framework/cache/AXPCacheTest.java new file mode 100644 index 00000000..1147639e --- /dev/null +++ b/components/framework-axp/src/test/java/framework/cache/AXPCacheTest.java @@ -0,0 +1,168 @@ +package framework.cache; + +import org.assertj.core.api.Assertions; +import org.testng.annotations.Test; + +import static org.testng.Assert.fail; + +public class AXPCacheTest +{ + + private ICache cache; + + @Test + public void testPut() + { + cache = new AXPCache(true); + cache.put("key1", "value1"); + cache.put("key2", "value2"); + cache.put("key3", "value3"); + + Assertions.assertThat((String) cache.get("key1")).isEqualTo("value1"); + Assertions.assertThat((String) cache.get("key2")).isEqualTo("value2"); + Assertions.assertThat((String) cache.get("key3")).isEqualTo("value3"); + } + + @Test + public void testPut_withNullKey() + { + cache = new AXPCache(true); + cache.put(null, "value1"); + cache.put("key2", "value2"); + cache.put("key3", "value3"); + + Assertions.assertThat(cache.size()).isEqualTo(2); + } + + @Test + public void testPut_withNullValue() + { + cache = new AXPCache(true); + cache.put("key1", "value1"); + cache.put("key2", "value2"); + cache.put("key3", "value3"); + + //Remove inserted value + cache.put("key1", null); + + Assertions.assertThat(cache.size()).isEqualTo(2); + Assertions.assertThat((String) cache.get("key1")).isNull(); + Assertions.assertThat((String) cache.get("key2")).isEqualTo("value2"); + Assertions.assertThat((String) cache.get("key3")).isEqualTo("value3"); + } + + @Test + public void testGet_withTTL() + { + try + { + Thread t = new Thread(() -> { + cache = new AXPCache(100); + cache.put("key1", "value1"); + cache.put("key2", "value2"); + cache.put("key3", "value3"); + + try + { + //Sleep until cache get cleared + Thread.sleep(120); + } + catch (InterruptedException e) + { + e.printStackTrace(); + + fail(); + } + Assertions.assertThat(cache.get("key1")).isNull(); + Assertions.assertThat(cache.get("key2")).isNull(); + Assertions.assertThat(cache.get("key3")).isNull(); + }); + t.start(); + t.join(); + } + catch (InterruptedException e) + { + e.printStackTrace(); + + fail(); + } + } + + @Test + public void testPut_withTTL() + { + try + { + Thread t = new Thread(() -> { + cache = new AXPCache(true); + cache.put("key1", "value1", 100); + cache.put("key2", "value2", 100); + cache.put("key3", "value3", 100); + + try + { + //Sleep until cache get cleared + Thread.sleep(120); + } + catch (InterruptedException e) + { + e.printStackTrace(); + + fail(); + } + Assertions.assertThat(cache.get("key1")).isNull(); + Assertions.assertThat(cache.get("key2")).isNull(); + Assertions.assertThat(cache.get("key3")).isNull(); + }); + t.start(); + t.join(); + } + catch (InterruptedException e) + { + e.printStackTrace(); + + fail(); + } + } + + @Test + public void testRemove() + { + cache = new AXPCache(true); + cache.put("key1", "value1", 100); + cache.put("key2", "value2", 100); + cache.put("key3", "value3", 100); + + cache.remove("key1"); + + Assertions.assertThat(cache.get("key1")).isNull(); + Assertions.assertThat(cache.get("key2")).isEqualTo("value2"); + Assertions.assertThat(cache.get("key3")).isEqualTo("value3"); + } + + @Test + public void testClear() + { + cache = new AXPCache(true); + cache.put("key1", "value1", 100); + cache.put("key2", "value2", 100); + cache.put("key3", "value3", 100); + + cache.clear(); + + Assertions.assertThat(cache.get("key1")).isNull(); + Assertions.assertThat(cache.get("key2")).isNull(); + Assertions.assertThat(cache.get("key3")).isNull(); + } + + @Test + public void testSize() + { + cache = new AXPCache(true); + cache.put("key1", "value1", 100); + cache.put("key2", "value2", 100); + cache.put("key3", "value3", 100); + + Assertions.assertThat(cache.size()).isEqualTo(3); + } +} \ No newline at end of file diff --git a/components/framework-axp/src/test/java/framework/cache/impl/DefaultAXPLoadingCacheTest.java b/components/framework-axp/src/test/java/framework/cache/impl/DefaultAXPLoadingCacheTest.java new file mode 100644 index 00000000..28d13529 --- /dev/null +++ b/components/framework-axp/src/test/java/framework/cache/impl/DefaultAXPLoadingCacheTest.java @@ -0,0 +1,264 @@ +package framework.cache.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import com.google.common.collect.Lists; +import framework.cache.AXPCache; +import framework.cache.IAXPCacheLoader; +import framework.cache.IAXPLoadingCache; +import org.fest.reflect.core.Reflection; +import org.mockito.Mockito; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyList; +import static org.mockito.Mockito.*; +import static org.testng.Assert.fail; + + +public class DefaultAXPLoadingCacheTest +{ + private TestCacheLoader mockCacheLoader; + + private DefaultAXPLoadingCache loadingCache; + + private AXPCache axpCache; + + @BeforeMethod + public void setUp() + { + mockCacheLoader = mock(TestCacheLoader.class); + + loadingCache = new DefaultAXPLoadingCache<>(mockCacheLoader, new AXPCache(true)); + + axpCache = Reflection.field("axpCache").ofType(AXPCache.class).in(this.loadingCache).get(); + axpCache.put(getTestCacheKey(1), "1*"); + axpCache.put(getTestCacheKey(2), "2"); + axpCache.put(getTestCacheKey(3), "3*"); + } + + @Test + public void testGetDataAsMap() + { + try + { + final List keyList = Lists.newArrayList(); + keyList.add(getTestCacheKey(1)); + keyList.add(getTestCacheKey(4)); + keyList.add(getTestCacheKey(3)); + keyList.add(getTestCacheKey(5)); + + Mockito.when(mockCacheLoader.load(anyList())).thenCallRealMethod(); + + Map dataMap = loadingCache.getDataAsMap(keyList); + + assertThat(dataMap).isNotNull(); + assertThat(dataMap.size()).isEqualTo(4); + assertThat(dataMap.get(getTestCacheKey(1))).isEqualTo( "1*"); + assertThat(dataMap.get(getTestCacheKey(4))).isEqualTo( "4"); + assertThat(dataMap.get(getTestCacheKey(3))).isEqualTo( "3*"); + assertThat(dataMap.get(getTestCacheKey(5))).isEqualTo( "5"); + + assertThat(axpCache.size()).isEqualTo( 5); + assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo( "1*"); + assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo( "2"); + assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo( "3*"); + assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo( "4"); + assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo( "5"); + + verify(mockCacheLoader, only()).load(anyList()); + + dataMap = loadingCache.getDataAsMap(keyList); + + assertThat(dataMap).isNotNull(); + assertThat(dataMap.size()).isEqualTo( 4); + assertThat(dataMap.get(getTestCacheKey(1))).isEqualTo( "1*"); + assertThat(dataMap.get(getTestCacheKey(4))).isEqualTo( "4"); + assertThat(dataMap.get(getTestCacheKey(3))).isEqualTo( "3*"); + assertThat(dataMap.get(getTestCacheKey(5))).isEqualTo( "5"); + + assertThat(axpCache.size()).isEqualTo( 5); + assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo("1*"); + assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo("2"); + assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo("3*"); + assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo("4"); + assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo("5"); + + verify(mockCacheLoader, only()).load(anyList()); + } + catch (Exception e) + { + e.printStackTrace(); + + fail(); + } + } + + @Test + public void testGetDataAsList() + { + try + { + final List keyList = Lists.newLinkedList(); + keyList.add(getTestCacheKey(1)); + keyList.add(getTestCacheKey(4)); + keyList.add(getTestCacheKey(3)); + keyList.add(getTestCacheKey(5)); + + when(mockCacheLoader.load(anyList())).thenCallRealMethod(); + + List dataList = loadingCache.getDataAsList(keyList); + + assertThat(dataList).isNotNull(); + assertThat(dataList.size()).isEqualTo( 4); + assertThat(dataList.get(0)).isEqualTo( "1*"); + assertThat(dataList.get(1)).isEqualTo( "4"); + assertThat(dataList.get(2)).isEqualTo( "3*"); + assertThat(dataList.get(3)).isEqualTo( "5"); + + assertThat(axpCache.size()).isEqualTo( 5); + assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo( "1*"); + assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo( "2"); + assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo( "3*"); + assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo( "4"); + assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo( "5"); + + verify(mockCacheLoader, only()).load(anyList()); + + dataList = loadingCache.getDataAsList(keyList); + + assertThat(dataList).isNotNull(); + assertThat(dataList.size()).isEqualTo( 4); + assertThat(dataList.get(0)).isEqualTo( "1*"); + assertThat(dataList.get(1)).isEqualTo( "4"); + assertThat(dataList.get(2)).isEqualTo( "3*"); + assertThat(dataList.get(3)).isEqualTo( "5"); + + assertThat(axpCache.size()).isEqualTo( 5); + assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo( "1*"); + assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo( "2"); + assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo( "3*"); + assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo( "4"); + assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo( "5"); + + verify(mockCacheLoader, only()).load(anyList()); + } + catch (Exception e) + { + e.printStackTrace(); + + fail(); + } + } + + @Test + public void testGetData_cached() throws Exception + { + TestCacheKey key = getTestCacheKey(1); + + String result = loadingCache.getData(key); + + assertThat(result).isEqualTo( "1*"); + } + + @Test + public void testGetData_nonCached() throws Exception + { + TestCacheKey key = getTestCacheKey(6); + List keys = Lists.newArrayList(key); + when(mockCacheLoader.load(keys)).thenCallRealMethod(); + + String result = loadingCache.getData(key); + + assertThat(result).isEqualTo("6"); + verify(mockCacheLoader, only()).load(keys); + } + + @Test + public void testUpdate() throws Exception + { + TestCacheKey key = getTestCacheKey(7); + List keys = Lists.newArrayList(key); + + loadingCache.update(key, "7"); + + assertThat(loadingCache.getData(key)).isEqualTo( "7"); + verify(mockCacheLoader, never()).load(keys); + } + + @Test + public void testClear() throws Exception + { + IAXPLoadingCache cache = + new DefaultAXPLoadingCache<>(mockCacheLoader, new AXPCache(true)); + TestCacheKey key = getTestCacheKey(8); + + loadingCache.clear(); + + assertThat(cache.getData(key)).isNull(); + } + + private TestCacheKey getTestCacheKey(int key) + { + return new TestCacheKey(key, String.valueOf(key)); + } + + private static class TestCacheKey + { + + private final int key; + + private final String anotherAttribute; + + TestCacheKey(int key, String anotherAttribute) + { + this.key = key; + this.anotherAttribute = anotherAttribute; + } + + @Override + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + + if (!(o instanceof TestCacheKey)) + { + return false; + } + + TestCacheKey that = (TestCacheKey) o; + + return key == that.key && Objects.equals(anotherAttribute, that.anotherAttribute); + } + + @Override + public int hashCode() + { + return Objects.hash(key, anotherAttribute); + } + } + + private class TestCacheLoader implements IAXPCacheLoader + { + + @Override + public Map load(List cacheKeyList) + { + final Map dataMap = new HashMap<>(); + + for (TestCacheKey testCacheKey : cacheKeyList) + { + dataMap.put(testCacheKey, testCacheKey.anotherAttribute); + } + + return dataMap; + } + } +} diff --git a/components/framework-axp/src/test/java/framework/configuration/ConfigFileReaderStrategyTest.java b/components/framework-axp/src/test/java/framework/configuration/ConfigFileReaderStrategyTest.java new file mode 100644 index 00000000..e6533789 --- /dev/null +++ b/components/framework-axp/src/test/java/framework/configuration/ConfigFileReaderStrategyTest.java @@ -0,0 +1,31 @@ +package framework.configuration; + +import framework.configuration.impl.JavaPropertyFileReadStrategy; +import framework.configuration.impl.XMLPropertyFileReadStrategy; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ConfigFileReaderStrategyTest +{ + + @Test + public void testGetStrategy_extensionProperties() + { + assertThat(ConfigFileReaderStrategy.getInstance().getStrategy("properties")) + .isInstanceOf(JavaPropertyFileReadStrategy.class); + } + + @Test + public void testGetStrategy_extensionXml() + { + assertThat(ConfigFileReaderStrategy.getInstance().getStrategy("xml")) + .isInstanceOf(XMLPropertyFileReadStrategy.class); + } + + @Test(expectedExceptions = RuntimeException.class) + public void testGetStrategy_extensionOther() + { + ConfigFileReaderStrategy.getInstance().getStrategy("abc"); + } +} diff --git a/components/framework-axp/src/test/java/framework/configuration/impl/JavaPropertyFileReadStrategyTest.java b/components/framework-axp/src/test/java/framework/configuration/impl/JavaPropertyFileReadStrategyTest.java new file mode 100644 index 00000000..0a169d59 --- /dev/null +++ b/components/framework-axp/src/test/java/framework/configuration/impl/JavaPropertyFileReadStrategyTest.java @@ -0,0 +1,64 @@ +package framework.configuration.impl; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.Map; + +import com.google.common.base.Joiner; +import framework.configuration.CarbonUtilsDelegator; +import org.mockito.Mockito; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.testng.Assert.fail; + +public class JavaPropertyFileReadStrategyTest +{ + + @Test + public void testReadFile() + { + try + { + CarbonUtilsDelegator mock = mock(CarbonUtilsDelegator.class); + + /** + * This is a dirty fix to resolve resource path. + * When building individual module and the parent, resolving two different resource locations. + */ + String currentPath = Paths.get("").toAbsolutePath().normalize().toString(); + if (currentPath.contains("components")) + + { + String path = Joiner + .on(File.separator) + .join("src", "test", "resources", "com", "wso2telco", "framework", "configuration", "impl", + "JavaPropertyFileReadStrategyTest"); + Mockito.when(mock.getCarbonConfigDirPath()).thenReturn(path); + } + else + { + String path = Joiner + .on(File.separator) + .join("components", "framework-axp", "src", "test", "resources", "com", "wso2telco", "framework", + "configuration", "impl", "JavaPropertyFileReadStrategyTest"); + Mockito.when(mock.getCarbonConfigDirPath()).thenReturn(path); + } + + JavaPropertyFileReadStrategy strategy = new JavaPropertyFileReadStrategy(mock); + Map propertiesMap = strategy.readFile("test.properties"); + + assertThat(propertiesMap).isNotEmpty(); + assertThat(propertiesMap).hasSize(17); + } + catch (IOException e) + { + e.printStackTrace(); + + fail(); + } + } + +} diff --git a/components/framework-axp/src/test/resources/com/wso2telco/framework/configuration/impl/JavaPropertyFileReadStrategyTest/test.properties b/components/framework-axp/src/test/resources/com/wso2telco/framework/configuration/impl/JavaPropertyFileReadStrategyTest/test.properties new file mode 100644 index 00000000..b1adfc91 --- /dev/null +++ b/components/framework-axp/src/test/resources/com/wso2telco/framework/configuration/impl/JavaPropertyFileReadStrategyTest/test.properties @@ -0,0 +1,25 @@ +sendSMSResourceURL=http://example.com/smsmessaging/v1/outbound/ +hubSubsGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/smsmessaging/v1/DeliveryInfoNotification +hubGateway=https://gateway1a.mife.sla-mobile.com.my:8243 +ussdGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/ussd/v1/inbound/ +#requestRouterUrl=http://IDEABIZAPPS/HTTPRequestRouter/route/HUB-USSD/?org= +hub_gateway_id=0001 +hub_gateway_provision_notify_url= + +hubMOSubsGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/smsmessaging/v1/ReceivedInfoNotification +hubDNSubsGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/smsmessaging/v1/DeliveryInfoNotification + +esbEndpoint=http://localhost:8281/payment + +#country code separated by (,) +search.oparatorOnHeaderMCC=94 +search.oparatorOnHeaderName=Operator +search.oparatorOnHeaderRegEx=(?<=XXX=)([a-zA-Z0-9])+ + +retry_on_fail=true +retry_count=3 +numberOfThreads=5 + +#If tokenpoolservice is set to 'true', tokenpoolResourceURL should point to the tokenpool endpoint (incl. trailing slash). +tokenpoolservice=false +tokenpoolResourceURL=http://localhost:8181/tokenservice/ \ No newline at end of file diff --git a/components/redis-client/pom.xml b/components/redis-client/pom.xml index 017355ff..f542b2d2 100644 --- a/components/redis-client/pom.xml +++ b/components/redis-client/pom.xml @@ -37,14 +37,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 1.7 - 1.7 - - org.apache.maven.plugins maven-shade-plugin diff --git a/components/sp-config-util/pom.xml b/components/sp-config-util/pom.xml index cb5eb940..e01dd1bf 100644 --- a/components/sp-config-util/pom.xml +++ b/components/sp-config-util/pom.xml @@ -58,15 +58,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - 1.7 - 1.7 - - org.apache.felix maven-bundle-plugin diff --git a/pom.xml b/pom.xml index 085441e8..77e53030 100644 --- a/pom.xml +++ b/pom.xml @@ -46,8 +46,36 @@ components/security/auth-filter components/security/user-profile features + components/framework-axp + + 1.5.8 + 2.17 + 1.2 + 3.3 + 4.11 + 4.4.3 + 2.1.1.wso2v1 + UTF-8 + 4.4.3 + 7.4.2.wso2v1 + 2.4.0.wso2v1 + 2.4.5-SNAPSHOT + 4.4.9 + 5.2.2 + 2.8.0 + 2.4.2 + 6.0.4 + 11.0.2 + + + 6.14.3 + 3.11.1 + 1.10.19 + 1.4.1 + + @@ -126,6 +154,37 @@ ${com.wso2telco.core.version} provided + + com.google.guava + guava + ${com.google.guava.version} + provided + + + + org.testng + testng + ${org.testng.version} + test + + + org.assertj + assertj-core + ${org.assertj.version} + test + + + org.mockito + mockito-all + ${org.mockito.version} + test + + + org.easytesting + fest-reflect + ${org.easytesting.version} + test + @@ -277,26 +336,6 @@ - - 1.5.8 - 2.17 - 1.2 - 3.3 - 4.11 - 4.4.3 - 2.1.1.wso2v1 - UTF-8 - 4.4.3 - 7.4.2.wso2v1 - 2.4.0.wso2v1 - 2.4.5-SNAPSHOT - 4.4.9 - 5.2.2 - 2.8.0 - 2.4.2 - 6.0.4 - - notify @@ -328,7 +367,14 @@ - + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + - - org.testng - testng - - - org.assertj - assertj-core - - - org.mockito - mockito-all - - - org.easytesting - fest-reflect - - - - - - - org.apache.felix - maven-scr-plugin - - - org.apache.felix - maven-bundle-plugin - true - - - ${project.groupId}.${project.artifactId} - ${project.artifactId} - - com.wso2telco.framework.* - - - javax.servlet;version="2.4.0", - javax.servlet.http;version="2.4.0", - javax.servlet.resources;version="2.4.0", - org.eclipse.equinox.http.helper, - *;resolution:=optional - - * - - - - - - \ No newline at end of file diff --git a/components/framework-axp/src/main/java/framework/cache/AXPCache.java b/components/framework-axp/src/main/java/framework/cache/AXPCache.java deleted file mode 100644 index cf1526ad..00000000 --- a/components/framework-axp/src/main/java/framework/cache/AXPCache.java +++ /dev/null @@ -1,269 +0,0 @@ -package framework.cache; - -import java.io.IOException; -import java.lang.ref.SoftReference; -import java.util.Optional; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Cache implementation for the AXP. - * The cache use a {@link ConcurrentHashMap} for store data in memory. The cache has time-to-live and a purge - * options in side the implementation. Also this has the support for init cache with no time limit. - * This has the capability of the ttl configuration support in object level as well. - *

- * Note that in the implementation {@link SoftReference} has used to wrap the object. - * softly-reachable objects are guaranteed to have been cleared before the virtual machine throws an OutOfMemoryError. - *

- * !!! HIGH IMPORTANT !!! - *

- * All the objects stored in the cache will be return without cloning or deep cloning due to improve the cache performance. - * Because of that user should be responsible of the mutability of the stored object. - */ -public final class AXPCache implements ICache -{ - - private boolean noTimeLimit; - - private long ttl; - - private static Log log = LogFactory.getLog(AXPCache.class); - - private final ConcurrentHashMap> cache = new ConcurrentHashMap<>(); - - private static final long DEFAULT_PURGING_TIME = 5 * 60 * 60 * 1000; - - /** - * Initialize cache with the given time to live value. - * Object will be purged after expiring the ttl. This will overide the configuration value defined in the - * - * @param ttl object time-to-live value in milli seconds - */ - public AXPCache(long ttl) - { - this.ttl = ttl; - initPurgingTask(this.ttl); - } - - /** - * Does not initialize the cache purging thread if the noTimeLimit parameter is true - * If the given boolean value is false, then the cache purge time will be applicable from the the configuration file. - * Even if the noTimeLimit parameter true, - * - * @param noTimeLimit - */ - public AXPCache(boolean noTimeLimit) - { - this.noTimeLimit = noTimeLimit; - if (!noTimeLimit) - { - ttl = getDefaultTTLFromConfiguration(); - initPurgingTask(ttl); - } - else - { - ttl = -1; - /** - * if there are any expired objects available in the cache need to clean them. - */ - initPurgingTask(DEFAULT_PURGING_TIME); - } - } - - /** - * Initialize cache with default purging time. - * Apply the cache object ttl value from the configuration file. - */ - public AXPCache() - { - ttl = getDefaultTTLFromConfiguration(); - initPurgingTask(ttl); - } - - /** - * {@inheritDoc} - * - * @param key - * @param value - * @param - * @param - */ - @Override - public void put(K key, V value) - { - if (key == null) - { - return; - } - if (value == null) - { - cache.remove(key); - } - else - { - long expiryTime = noTimeLimit ? -1 : System.currentTimeMillis() + ttl; - cache.put(key, new SoftReference<>(new CacheObject(value, expiryTime))); - } - } - - /** - * {@inheritDoc} - * - * @param key - * @param value - * @param periodInMillis time-to-live value - * @param - * @param - */ - @Override - public void put(K key, V value, long periodInMillis) - { - if (key == null) - { - return; - } - if (value == null) - { - cache.remove(key); - } - else - { - long expiryTime = System.currentTimeMillis() + periodInMillis; - cache.put(key, new SoftReference<>(new CacheObject(value, expiryTime))); - } - } - - /** - * {@inheritDoc} - * - * @param key - * @param - */ - @Override - public void remove(K key) - { - cache.remove(key); - } - - /** - * {@inheritDoc} - * - * @param key - * @param - * @return - */ - @Override - public Object get(K key) - { - return Optional.ofNullable(cache.get(key)).map(SoftReference::get).filter(cacheObject -> !cacheObject.isExpired()) - .map(CacheObject::getValue).orElse(null); - } - - /** - * {@inheritDoc} - */ - @Override - public void clear() - { - cache.clear(); - } - - /** - * {@inheritDoc} - * - * @return - */ - @Override - public long size() - { - return cache.entrySet().stream().filter(entry -> Optional.ofNullable(entry.getValue()).map(SoftReference::get) - .map(cacheObject -> !cacheObject.isExpired()).orElse(false)).count(); - } - - /** - * Note that if the framework.properties file does not available or entry is not there, -1 will be returned. - * which means cache will not be expired. - * - * @return default ttl configuration in framework.properties file. - */ - private long getDefaultTTLFromConfiguration() - { - long ttl; - try - { - ttl = CachePropertyReader.getInstance().getDefaultTTL() * 1000; - } - catch (IOException e) - { - ttl = -1; - log.error("Error occurred while reading property file configuration for default cache ttl.", e); - } - return ttl; - } - - private void initPurgingTask(final long ttl) - { - if (ttl <= 0) - { - return; - } - TimerTask cleanerTask = new TimerTask() - { - @Override - public void run() - { - purge(); - } - }; - Timer timer = new Timer("Timer"); - timer.scheduleAtFixedRate(cleanerTask, ttl, ttl); - } - - /** - * Purge objects if the time is expired - */ - private void purge() - { - cache.entrySet().removeIf( - entry -> Optional.ofNullable(entry.getValue()).map(SoftReference::get) - .map(CacheObject::isExpired).orElse(false)); - } - - - /** - * Class to hold the cache value and expiration time - */ - private class CacheObject - { - - private Object value; - - private long expiryTime; - - /** - * Set the attributes of the cache object - * - * @param value - * @param expiryTime - */ - public CacheObject(Object value, long expiryTime) - { - this.value = value; - this.expiryTime = expiryTime; - } - - public Object getValue() - { - return value; - } - - boolean isExpired() - { - return expiryTime == -1 ? false : System.currentTimeMillis() > expiryTime; - } - } -} diff --git a/components/framework-axp/src/main/java/framework/cache/AXPCacheBuilder.java b/components/framework-axp/src/main/java/framework/cache/AXPCacheBuilder.java deleted file mode 100644 index 4340dc4e..00000000 --- a/components/framework-axp/src/main/java/framework/cache/AXPCacheBuilder.java +++ /dev/null @@ -1,46 +0,0 @@ -package framework.cache; - -import framework.cache.impl.DefaultAXPLoadingCache; - -/** - * This builder is responsible for building {@link IAXPLoadingCache} - */ -public class AXPCacheBuilder -{ - - private boolean noTimeLimit = true; - - /** - * @return new {@link AXPCacheBuilder} - */ - public static AXPCacheBuilder newBuilder() - { - return new AXPCacheBuilder(); - } - - /** - * Sets {@code noTimeLimit} flag of {@link AXPCache} - * - * @param noTimeLimit no time limit - * @return current instance of AXPCacheBuilder - */ - public AXPCacheBuilder setNoTimeLimit(final boolean noTimeLimit) - { - this.noTimeLimit = noTimeLimit; - - return this; - } - - /** - * Create and returns new {@link DefaultAXPLoadingCache} by using provided {@code IAXPCacheLoader} - * - * @param cacheLoader cache loader - * @param Type of cache key - * @param Type of cache data - * @return new {@link DefaultAXPLoadingCache} - */ - public IAXPLoadingCache build(final IAXPCacheLoader cacheLoader) - { - return new DefaultAXPLoadingCache<>(cacheLoader, new AXPCache(noTimeLimit)); - } -} diff --git a/components/framework-axp/src/main/java/framework/cache/AXPCacheHandler.java b/components/framework-axp/src/main/java/framework/cache/AXPCacheHandler.java deleted file mode 100644 index 22e27500..00000000 --- a/components/framework-axp/src/main/java/framework/cache/AXPCacheHandler.java +++ /dev/null @@ -1,172 +0,0 @@ -package framework.cache; - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * This handler is responsible for managing {@link AXPCache} by using {@link IAXPCacheLoader} - */ -@SuppressWarnings("unchecked") -public final class AXPCacheHandler implements IAXPCacheHandlerService -{ - - private static final IAXPCacheHandlerService INSTANCE = new AXPCacheHandler(); - - private AXPCacheHandler() - { - } - - public static IAXPCacheHandlerService getInstance() - { - return INSTANCE; - } - - /** - * {@inheritDoc} - * - * @param axpCache client cache - * @param cacheLoader cache loader - * @param cacheKey cache key - * @param - * @param - * @return - * @throws Exception - */ - @Override - public V getData(final AXPCache axpCache, final IAXPCacheLoader cacheLoader, final K cacheKey) throws - Exception - { - final V cachedData = (V) axpCache.get(cacheKey); - if (cachedData != null) - { - return cachedData; - } - else - { - Map missingData = cacheLoader.load(Collections.singletonList(cacheKey)); - for (final Map.Entry loadedDataEntry : missingData.entrySet()) - { - axpCache.put(loadedDataEntry.getKey(), loadedDataEntry.getValue()); - } - } - - return (V) axpCache.get(cacheKey); - } - - /** - * {@inheritDoc} - * - * @param axpCache client cache - * @param cacheLoader cache loader - * @param cacheKeyList cache key list - * @param - * @param - * @return - * @throws Exception - */ - @Override - public Map getDataAsMap(final AXPCache axpCache, final IAXPCacheLoader cacheLoader, - final List cacheKeyList) throws Exception - { - final Map dataMap = new HashMap<>(); - final List missingCacheKeyList = new ArrayList<>(); - - for (final K cacheKey : cacheKeyList) - { - final V cachedData = (V) axpCache.get(cacheKey); - - if (cachedData != null) - { - dataMap.put(cacheKey, cachedData); - } - else - { - missingCacheKeyList.add(cacheKey); - } - } - - if (!missingCacheKeyList.isEmpty()) - { - final Map missingDataMap = cacheLoader.load(missingCacheKeyList); - - for (final Map.Entry loadedDataEntry : missingDataMap.entrySet()) - { - axpCache.put(loadedDataEntry.getKey(), loadedDataEntry.getValue()); - } - - dataMap.putAll(missingDataMap); - } - - return dataMap; - } - - /** - * {@inheritDoc} - * - * @param axpCache client cache - * @param cacheLoader cache loader - * @param cacheKeyList cache key list - * @param - * @param - * @return - * @throws Exception - */ - @Override - public List getDataAsList(final AXPCache axpCache, final IAXPCacheLoader cacheLoader, - final List cacheKeyList) throws Exception - { - final Map dataMap = getDataAsMap(axpCache, cacheLoader, cacheKeyList); - - final List resultDataList = new ArrayList<>(); - - for (final K cacheKey : cacheKeyList) - { - resultDataList.add(dataMap.get(cacheKey)); - } - - return resultDataList; - } - - /** - * {@inheritDoc} - * - * @param axpCache client cache - * @param cacheKey cache key - * @param value value - * @param - * @param - */ - @Override - public void update(final AXPCache axpCache, final K cacheKey, final V value) - { - axpCache.put(cacheKey, value); - } - - /** - * {@inheritDoc} - * - * @param axpCache - */ - @Override - public void clear(final AXPCache axpCache) - { - axpCache.clear(); - } - - /** - * {@inheritDoc} - * - * @param axpCache - * @param cacheKey - * @param - */ - @Override - public void remove(final AXPCache axpCache, K cacheKey) - { - axpCache.remove(cacheKey); - } -} diff --git a/components/framework-axp/src/main/java/framework/cache/CachePropertyReader.java b/components/framework-axp/src/main/java/framework/cache/CachePropertyReader.java deleted file mode 100644 index e5dfab09..00000000 --- a/components/framework-axp/src/main/java/framework/cache/CachePropertyReader.java +++ /dev/null @@ -1,59 +0,0 @@ -package framework.cache; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Properties; - -import com.google.common.base.Joiner; -import framework.configuration.CarbonUtilsDelegator; -import framework.configuration.ConfigFile; - -/** - * This class is a dedicated class to read the cache related configurations - */ -class CachePropertyReader -{ - - private static CachePropertyReader instance; - - private String DEFAULT_CACHE_TIMEOUT = "framework.axpcache.timeout"; - - private Properties properties = new Properties(); - - static synchronized CachePropertyReader getInstance() - { - if (instance == null) - { - instance = new CachePropertyReader(); - } - - return instance; - } - - /** - * get default ttl value configured in framework.properties file in conf folder. - * - * @return configured value if available, otherwise -1. - * @throws IOException - */ - long getDefaultTTL() throws IOException - { - if (properties.isEmpty()) - { - String filePath = Joiner.on(File.separator) - .join(CarbonUtilsDelegator.getInstance().getCarbonConfigDirPath(), ConfigFile.FRAMEWORK_CONF.getName()); - Path configPath = Paths.get(filePath); - try (InputStream stream = Files.newInputStream(configPath)) - { - properties.load(stream); - } - } - String property = properties.getProperty(DEFAULT_CACHE_TIMEOUT); - - return property != null && !property.isEmpty() ? Long.parseLong(property) : -1; - } -} diff --git a/components/framework-axp/src/main/java/framework/cache/IAXPCacheHandlerService.java b/components/framework-axp/src/main/java/framework/cache/IAXPCacheHandlerService.java deleted file mode 100644 index 9af0c775..00000000 --- a/components/framework-axp/src/main/java/framework/cache/IAXPCacheHandlerService.java +++ /dev/null @@ -1,86 +0,0 @@ -package framework.cache; - -import java.util.List; -import java.util.Map; - -/** - * AXP cache handler service. - * This class is responsible of handling axp cache related operations for the loading cache. - */ -public interface IAXPCacheHandlerService -{ - - /** - * Returns the data associated with {@code cacheKey} from provided {@code axpCache}. If the data related to given - * {@code cacheKey} is not in the cache, then the missing data will be loaded according to the logic implemented in - * {@link IAXPCacheLoader#load(List)} and update the provided {@code AXPCache}. - * - * @param axpCache client cache - * @param cacheLoader cache loader - * @param cacheKey cache key - * @param Type of cache key - * @param Type of cached data - * @return data associated with {@code cacheKey} - * @throws Exception - */ - V getData(AXPCache axpCache, IAXPCacheLoader cacheLoader, K cacheKey) - throws Exception; - - /** - * Returns a map of data associated with {@code cacheKeyList} from provided {@code axpCache}. If the data related - * to given {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic - * implemented in {@link IAXPCacheLoader#load(List)} and update the provided {@code axpCache}. - * - * @param axpCache client cache - * @param cacheLoader cache loader - * @param cacheKeyList cache key list - * @param Type of cache key - * @param Type of cached data - * @return a map of data associated with {@code cacheKeyList} - * @throws Exception - */ - Map getDataAsMap(AXPCache axpCache, IAXPCacheLoader cacheLoader, - List cacheKeyList) - throws Exception; - - /** - * Returns a list of data associated with {@code cacheKeyList} from provided {@code axpCache}. If the data related - * to given {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic - * implemented in {@link IAXPCacheLoader#load(List)} and update the provided {@code axpCache}. - *

- * This always preserve the order of the data list, according to the provided {@code cacheKeyList} - * - * @param axpCache client cache - * @param cacheLoader cache loader - * @param cacheKeyList cache key list - * @param Type of cache key - * @param Type of cached data - * @return a list of data associated with {@code cacheKeyList}, the order will be preserved - * @throws Exception - */ - List getDataAsList(AXPCache axpCache, IAXPCacheLoader cacheLoader, - List cacheKeyList) - throws Exception; - - /** - * Add or update cache entries with provided values in provided client cache - * - * @param axpCache client cache - * @param cacheKey cache key - * @param value value - */ - void update(AXPCache axpCache, K cacheKey, V value); - - /** - * Clear all cached data in provide cache - */ - void clear(AXPCache axpCache); - - /** - * Remove data from the cache associated with the given cache key - * - * @param cacheKey - * @param - */ - void remove(final AXPCache axpCache, K cacheKey); -} diff --git a/components/framework-axp/src/main/java/framework/cache/IAXPCacheLoader.java b/components/framework-axp/src/main/java/framework/cache/IAXPCacheLoader.java deleted file mode 100644 index 8cf1d832..00000000 --- a/components/framework-axp/src/main/java/framework/cache/IAXPCacheLoader.java +++ /dev/null @@ -1,23 +0,0 @@ -package framework.cache; - -import java.util.List; -import java.util.Map; - -/** - * This defines the contract related to data loading logic of a client side cache - * - * @param Type of cache key - * @param Type of cached data - */ -public interface IAXPCacheLoader -{ - - /** - * Load all the data related to cache key list - * - * @param cacheKeyList cache key list - * @return a map from each key in {@code keys} to the data associated with that key; may not contain null values - * @throws Exception - */ - Map load(List cacheKeyList) throws Exception; -} diff --git a/components/framework-axp/src/main/java/framework/cache/IAXPLoadingCache.java b/components/framework-axp/src/main/java/framework/cache/IAXPLoadingCache.java deleted file mode 100644 index 319c1f16..00000000 --- a/components/framework-axp/src/main/java/framework/cache/IAXPLoadingCache.java +++ /dev/null @@ -1,71 +0,0 @@ -package framework.cache; - -import java.util.List; -import java.util.Map; - -/** - * This defines the contract related to loading cache. Use {@link AXPCacheBuilder} to define - * and create {@link IAXPLoadingCache} - * - * @param Type of cache key - * @param Type of cached data - */ -public interface IAXPLoadingCache -{ - - /** - * Returns data associated with {@code cacheKey} from the cache. If the data related to given {@code cacheKey} is not - * in the cache, then the missing data will be loaded according to the logic implemented in - * {@link IAXPCacheLoader#load(List)} and update the cache. - * - * @param cacheKey cache key - * @return Returns data associated with {@code cacheKey} from the cache - * @throws Exception - */ - V getData(K cacheKey) throws Exception; - - /** - * Returns a map of data associated with {@code cacheKeyList} from the cache. If the data related to given - * {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic implemented - * in {@link IAXPCacheLoader#load(List)} and update the cache. - * - * @param cacheKeyList cache key list - * @return Returns a map of data associated with {@code cacheKeyList} from the cache - * @throws Exception - */ - Map getDataAsMap(List cacheKeyList) throws Exception; - - /** - * Returns a list of data associated with {@code cacheKeyList} from the cache. If the data related to given - * {@code cacheKeyList} are not in the cache, then the missing data will be loaded according to the logic implemented - * in {@link IAXPCacheLoader#load(List)} and update the cache. - *

- * This always preserve the order of the data list, according to the provided {@code cacheKeyList} - * - * @param cacheKeyList cache key list - * @return Returns a list of data associated with {@code cacheKeyList} from the cache, the order will be preserved - * @throws Exception - */ - List getDataAsList(List cacheKeyList) throws Exception; - - /** - * Add or update cache entries with provided values - * - * @param cacheKey cache key - * @param value value - */ - void update(K cacheKey, V value); - - /** - * remove data from the cache associated with the given cache key - * - * @param cacheKey - */ - void remove(K cacheKey); - - /** - * Clear all cached data - */ - void clear(); - -} diff --git a/components/framework-axp/src/main/java/framework/cache/ICache.java b/components/framework-axp/src/main/java/framework/cache/ICache.java deleted file mode 100644 index 0e7810c7..00000000 --- a/components/framework-axp/src/main/java/framework/cache/ICache.java +++ /dev/null @@ -1,59 +0,0 @@ -package framework.cache; - -/** - * The interface for the cache. - * This has the support for all the primary features of a cache - */ -public interface ICache -{ - - /** - * Insert data in to the cache with custom time-to-live value. - * - * @param key - * @param value - * @param periodInMillis time-to-live value - * @param - * @param - */ - void put(K key, V value, long periodInMillis); - - /** - * Remove the data associated with the given key from the cache. - * - * @param key - * @param - */ - void remove(K key); - - /** - * Get the data associated with the the given key. - * - * @param key - * @param - * @return the object associated to the given cache key - */ - Object get(K key); - - /** - * Get the current size of the cache. - * - * @return current size of the cache. - */ - long size(); - - /** - * Insert data into the cache against the given key. - * - * @param key - * @param value - * @param - * @param - */ - void put(K key, V value); - - /** - * Clear all the data in the cache - */ - void clear(); -} diff --git a/components/framework-axp/src/main/java/framework/cache/impl/DefaultAXPLoadingCache.java b/components/framework-axp/src/main/java/framework/cache/impl/DefaultAXPLoadingCache.java deleted file mode 100644 index fcc70b2f..00000000 --- a/components/framework-axp/src/main/java/framework/cache/impl/DefaultAXPLoadingCache.java +++ /dev/null @@ -1,99 +0,0 @@ -package framework.cache.impl; - - -import java.util.List; -import java.util.Map; - -import framework.cache.AXPCache; -import framework.cache.AXPCacheHandler; -import framework.cache.IAXPCacheLoader; -import framework.cache.IAXPLoadingCache; - -/** - * This implementation uses {@link AXPCache} as the base cache. - */ -public class DefaultAXPLoadingCache implements IAXPLoadingCache -{ - - private final AXPCache axpCache; - - private final IAXPCacheLoader cacheLoader; - - public DefaultAXPLoadingCache(final IAXPCacheLoader cacheLoader, - final AXPCache axpCache) - { - this.axpCache = axpCache; - this.cacheLoader = cacheLoader; - } - - /** - * {@inheritDoc} - * - * @param cacheKey cache key - * @return - * @throws Exception - */ - @Override - public V getData(final K cacheKey) throws Exception - { - return AXPCacheHandler.getInstance().getData(axpCache, cacheLoader, cacheKey); - } - - /** - * {@inheritDoc} - * - * @param cacheKeyList cache key list - * @return - * @throws Exception - */ - @Override - public Map getDataAsMap(final List cacheKeyList) throws Exception - { - return AXPCacheHandler.getInstance().getDataAsMap(axpCache, cacheLoader, cacheKeyList); - } - - /** - * {@inheritDoc} - * - * @param cacheKeyList cache key list - * @return - * @throws Exception - */ - @Override - public List getDataAsList(final List cacheKeyList) throws Exception - { - return AXPCacheHandler.getInstance().getDataAsList(axpCache, cacheLoader, cacheKeyList); - } - - /** - * {@inheritDoc} - * - * @param cacheKey cache key - * @param value value - */ - @Override - public void update(final K cacheKey, final V value) - { - AXPCacheHandler.getInstance().update(axpCache, cacheKey, value); - } - - /** - * {@inheritDoc} - */ - @Override - public void clear() - { - AXPCacheHandler.getInstance().clear(axpCache); - } - - /** - * {@inheritDoc} - * - * @param cacheKey - */ - @Override - public void remove(K cacheKey) - { - AXPCacheHandler.getInstance().remove(axpCache, cacheKey); - } -} diff --git a/components/framework-axp/src/main/java/framework/configuration/CarbonUtilsDelegator.java b/components/framework-axp/src/main/java/framework/configuration/CarbonUtilsDelegator.java deleted file mode 100644 index 2a27d620..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/CarbonUtilsDelegator.java +++ /dev/null @@ -1,41 +0,0 @@ -package framework.configuration; - -import org.wso2.carbon.utils.CarbonUtils; - -/** - * Delegator class for {@link CarbonUtils} - */ -public class CarbonUtilsDelegator -{ - - private static final CarbonUtilsDelegator INSTANCE = new CarbonUtilsDelegator(); - - public static CarbonUtilsDelegator getInstance() - { - return INSTANCE; - } - - private CarbonUtilsDelegator() - { - } - - /** - * Get carbon home directory path as a string - * - * @return - */ - public String getCarbonHome() - { - return CarbonUtils.getCarbonHome(); - } - - /** - * Get Carbon configuration directory path as a string - * - * @return - */ - public String getCarbonConfigDirPath() - { - return CarbonUtils.getCarbonConfigDirPath(); - } -} diff --git a/components/framework-axp/src/main/java/framework/configuration/ConfigFile.java b/components/framework-axp/src/main/java/framework/configuration/ConfigFile.java deleted file mode 100644 index 4a6e8752..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/ConfigFile.java +++ /dev/null @@ -1,41 +0,0 @@ -package framework.configuration; - -/** - * enum to hold the configuration file names which contains in the default config directory. - */ -public enum ConfigFile -{ - - /** - * oneapi-validation-conf.properties - */ - ONEAPI_VALIDATION_CONF("oneapi-validation-conf.properties"), - - /** - * mediator-conf.properties - */ - MEDIATOR_CONF("mediator-conf.properties"), - - /** - * framework.properties - */ - FRAMEWORK_CONF("framework.properties"), - - /** - * MobileCountryConfig.xml - */ - MOBILE_COUNTRY_CONF("MobileCountryConfig.xml"); - - - private final String name; - - ConfigFile(String name) - { - this.name = name; - } - - public String getName() - { - return name; - } -} diff --git a/components/framework-axp/src/main/java/framework/configuration/ConfigFileReaderStrategy.java b/components/framework-axp/src/main/java/framework/configuration/ConfigFileReaderStrategy.java deleted file mode 100644 index 477f055b..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/ConfigFileReaderStrategy.java +++ /dev/null @@ -1,51 +0,0 @@ -package framework.configuration; - -import framework.configuration.impl.JavaPropertyFileReadStrategy; -import framework.configuration.impl.XMLPropertyFileReadStrategy; - -/** - * The class to resolve file reader strategy by extension - */ -public final class ConfigFileReaderStrategy -{ - - private static final ConfigFileReaderStrategy INSTANCE = new ConfigFileReaderStrategy(); - - private static final String EXTENSION_PROPERTIES = "properties"; - - private ConfigFileReaderStrategy() - { - } - - private static final String EXTENSION_XML = "xml"; - - /** - * get singleton instance of {@link ConfigFileReaderStrategy} - * - * @return - */ - public static ConfigFileReaderStrategy getInstance() - { - return INSTANCE; - } - - /** - * Get the file read strategy by file extension - * - * @param extension - * @return - */ - public IConfigFileReaderStrategy getStrategy(String extension) - { - switch (extension) - { - case EXTENSION_PROPERTIES: - return new JavaPropertyFileReadStrategy(CarbonUtilsDelegator.getInstance()); - case EXTENSION_XML: - return new XMLPropertyFileReadStrategy(); - default: - //TODO introduce new runtime exception - throw new RuntimeException("Unsupported file type."); - } - } -} diff --git a/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderService.java b/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderService.java deleted file mode 100644 index e6ed1ea7..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderService.java +++ /dev/null @@ -1,19 +0,0 @@ -package framework.configuration; - -import java.util.Map; - -/** - * The class for read configuration files in config directory. - */ -public interface IConfigFileReaderService -{ - - /** - * Read the given file in the default config directory. - * - * @param configFile - * @return - * @throws Exception - */ - Map readFile(ConfigFile configFile) throws Exception; -} diff --git a/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderStrategy.java b/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderStrategy.java deleted file mode 100644 index 175ca147..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/IConfigFileReaderStrategy.java +++ /dev/null @@ -1,20 +0,0 @@ -package framework.configuration; - -import java.io.IOException; -import java.util.Map; - -/** - * The class for Configuration files read services. - */ -public interface IConfigFileReaderStrategy -{ - - /** - * Read the given configuration file from the default configuration directory. - * - * @param fileName - * @return a map of properties which contains in the given file - * @throws IOException - */ - Map readFile(String fileName) throws IOException; -} diff --git a/components/framework-axp/src/main/java/framework/configuration/impl/ConfigFileReaderServiceImpl.java b/components/framework-axp/src/main/java/framework/configuration/impl/ConfigFileReaderServiceImpl.java deleted file mode 100644 index 8d6aa849..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/impl/ConfigFileReaderServiceImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -package framework.configuration.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import framework.cache.AXPCacheBuilder; -import framework.cache.IAXPCacheLoader; -import framework.cache.IAXPLoadingCache; -import framework.configuration.ConfigFile; -import framework.configuration.ConfigFileReaderStrategy; -import framework.configuration.IConfigFileReaderService; -import framework.configuration.IConfigFileReaderStrategy; - -/** - * Implementation for the {@link IConfigFileReaderService} - * This file reader class will help to read configuration property files with a caching support. - */ -public class ConfigFileReaderServiceImpl implements IConfigFileReaderService -{ - - private static final ConfigFileReaderServiceImpl INSTANCE = new ConfigFileReaderServiceImpl(); - - private static final String DOT = "."; - - private IAXPLoadingCache> axpLoadingCache = AXPCacheBuilder.newBuilder() - .setNoTimeLimit(true).build(new PropertyFileCacheLoader()); - - private ConfigFileReaderServiceImpl() - { - } - - /** - * Get Singleton instance of {@link ConfigFileReaderServiceImpl} - * - * @return - */ - public static ConfigFileReaderServiceImpl getInstance() - { - return INSTANCE; - } - - /** - * {@inheritDoc} - * - * @param configFile - * @return - * @throws Exception - */ - @Override - public Map readFile(ConfigFile configFile) throws Exception - { - return axpLoadingCache.getData(configFile.getName()); - } - - class PropertyFileCacheLoader implements IAXPCacheLoader> - { - - /** - * {@inheritDoc} - * - * @param cacheKeyList cache key list - * @return - * @throws Exception - */ - @Override - public Map> load(List cacheKeyList) throws Exception - { - ConfigFileReaderStrategy configFileReaderStrategy = ConfigFileReaderStrategy.getInstance(); - Map> filePropertiesMap = new HashMap<>(); - for (String fileName : cacheKeyList) - { - IConfigFileReaderStrategy strategy = configFileReaderStrategy - .getStrategy(fileName.substring(fileName.lastIndexOf(DOT) + 1)); - Map propertiesMap = strategy.readFile(fileName); - filePropertiesMap.put(fileName, propertiesMap); - } - - return filePropertiesMap; - } - } -} diff --git a/components/framework-axp/src/main/java/framework/configuration/impl/JavaPropertyFileReadStrategy.java b/components/framework-axp/src/main/java/framework/configuration/impl/JavaPropertyFileReadStrategy.java deleted file mode 100644 index 99c5b7cd..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/impl/JavaPropertyFileReadStrategy.java +++ /dev/null @@ -1,51 +0,0 @@ -package framework.configuration.impl; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Map; -import java.util.Properties; - -import com.google.common.base.Joiner; -import com.google.common.collect.Maps; -import framework.configuration.CarbonUtilsDelegator; -import framework.configuration.IConfigFileReaderStrategy; - -/** - * Java property file reader strategy. - * This supports for the standard java property files. - */ -public final class JavaPropertyFileReadStrategy implements IConfigFileReaderStrategy -{ - - private CarbonUtilsDelegator carbonUtilsDelegator; - - public JavaPropertyFileReadStrategy(CarbonUtilsDelegator carbonUtilsDelegator) - { - this.carbonUtilsDelegator = carbonUtilsDelegator; - } - - /** - * {@inheritDoc} - * - * @param fileName - * @return - * @throws IOException - */ - @Override - public Map readFile(String fileName) throws IOException - { - String filePath = Joiner.on(File.separator).join(carbonUtilsDelegator.getCarbonConfigDirPath(), fileName); - Path configPath = Paths.get(filePath); - try (InputStream stream = Files.newInputStream(configPath)) - { - Properties properties = new Properties(); - properties.load(stream); - - return Maps.fromProperties(properties); - } - } -} \ No newline at end of file diff --git a/components/framework-axp/src/main/java/framework/configuration/impl/XMLPropertyFileReadStrategy.java b/components/framework-axp/src/main/java/framework/configuration/impl/XMLPropertyFileReadStrategy.java deleted file mode 100644 index 71022eb4..00000000 --- a/components/framework-axp/src/main/java/framework/configuration/impl/XMLPropertyFileReadStrategy.java +++ /dev/null @@ -1,20 +0,0 @@ -package framework.configuration.impl; - -import java.util.Map; - -import framework.configuration.IConfigFileReaderStrategy; - -/** - * XML property file reader strategy - * This supports for the xml property files. - */ -public final class XMLPropertyFileReadStrategy implements IConfigFileReaderStrategy -{ - - @Override - public Map readFile(String fileName) - { - //TODO - return null; - } -} diff --git a/components/framework-axp/src/test/java/framework/cache/AXPCacheBuilderTest.java b/components/framework-axp/src/test/java/framework/cache/AXPCacheBuilderTest.java deleted file mode 100644 index 4a13dabc..00000000 --- a/components/framework-axp/src/test/java/framework/cache/AXPCacheBuilderTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package framework.cache; - -import framework.cache.impl.DefaultAXPLoadingCache; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.fail; - -public class AXPCacheBuilderTest -{ - - @Test - public void testBuild() - { - try - { - final IAXPLoadingCache clientLoadingCache = AXPCacheBuilder.newBuilder().setNoTimeLimit(true) - .build(cacheKeyList -> null); - - assertThat(clientLoadingCache).isInstanceOf(DefaultAXPLoadingCache.class); - } - catch (Exception e) - { - e.printStackTrace(); - - fail(); - } - } -} diff --git a/components/framework-axp/src/test/java/framework/cache/AXPCacheHandlerTest.java b/components/framework-axp/src/test/java/framework/cache/AXPCacheHandlerTest.java deleted file mode 100644 index ac77a2aa..00000000 --- a/components/framework-axp/src/test/java/framework/cache/AXPCacheHandlerTest.java +++ /dev/null @@ -1,211 +0,0 @@ -package framework.cache; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.beust.jcommander.internal.Lists; -import org.assertj.core.api.Assertions; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyList; -import static org.mockito.Mockito.*; -import static org.testng.Assert.fail; - -public class AXPCacheHandlerTest -{ - - - private AXPCache axpCache; - - private TestCacheLoader mockCacheLoader; - - @BeforeMethod - public void setUp() - { - axpCache = new AXPCache(true); - axpCache.put(1, "1*"); - axpCache.put(2, "2"); - axpCache.put(3, "3*"); - - mockCacheLoader = mock(TestCacheLoader.class); - } - - @Test - public void testGetDataAsMap() - { - try - { - final List keyList = Lists.newArrayList(); - keyList.add(1); - keyList.add(4); - keyList.add(3); - keyList.add(5); - - when(mockCacheLoader.load(anyList())).thenCallRealMethod(); - - Map dataMap = - AXPCacheHandler.getInstance().getDataAsMap(axpCache, mockCacheLoader, keyList); - - assertThat(dataMap).isNotNull(); - assertThat(dataMap.size()).isEqualTo(4); - assertThat(dataMap.get(1)).isEqualTo("1*"); - assertThat(dataMap.get(4)).isEqualTo("4"); - assertThat(dataMap.get(3)).isEqualTo("3*"); - assertThat(dataMap.get(5)).isEqualTo("5"); - - assertThat(axpCache.size()).isEqualTo(5); - assertThat(axpCache.get(1)).isEqualTo("1*"); - assertThat(axpCache.get(2)).isEqualTo("2"); - assertThat(axpCache.get(3)).isEqualTo("3*"); - assertThat(axpCache.get(4)).isEqualTo("4"); - assertThat(axpCache.get(5)).isEqualTo("5"); - - verify(mockCacheLoader, only()).load(anyList()); - - dataMap = AXPCacheHandler.getInstance().getDataAsMap(axpCache, mockCacheLoader, keyList); - - Assertions.assertThat(dataMap).isNotNull(); - assertThat(dataMap.size()).isEqualTo(4); - assertThat(dataMap.get(1)).isEqualTo("1*"); - assertThat(dataMap.get(4)).isEqualTo("4"); - assertThat(dataMap.get(3)).isEqualTo("3*"); - assertThat(dataMap.get(5)).isEqualTo("5"); - - assertThat(axpCache.size()).isEqualTo(5); - assertThat(axpCache.get(1)).isEqualTo("1*"); - assertThat(axpCache.get(2)).isEqualTo("2"); - assertThat(axpCache.get(3)).isEqualTo("3*"); - assertThat(axpCache.get(4)).isEqualTo("4"); - assertThat(axpCache.get(5)).isEqualTo("5"); - - verify(mockCacheLoader, only()).load(anyList()); - } - catch (Exception e) - { - e.printStackTrace(); - - fail(); - } - } - - @Test - public void testGetDataAsList() - { - try - { - final List keyList = Lists.newArrayList(); - keyList.add(1); - keyList.add(4); - keyList.add(3); - keyList.add(5); - - when(mockCacheLoader.load(anyList())).thenCallRealMethod(); - - List dataList = - AXPCacheHandler.getInstance().getDataAsList(axpCache, mockCacheLoader, keyList); - - assertThat(dataList).isNotNull(); - assertThat(dataList.size()).isEqualTo(4); - assertThat(dataList.get(0)).isEqualTo("1*"); - assertThat(dataList.get(1)).isEqualTo("4"); - assertThat(dataList.get(2)).isEqualTo("3*"); - assertThat(dataList.get(3)).isEqualTo("5"); - - assertThat(axpCache.size()).isEqualTo(5); - assertThat(axpCache.get(1)).isEqualTo("1*"); - assertThat(axpCache.get(2)).isEqualTo("2"); - assertThat(axpCache.get(3)).isEqualTo("3*"); - assertThat(axpCache.get(4)).isEqualTo("4"); - assertThat(axpCache.get(5)).isEqualTo("5"); - - verify(mockCacheLoader, only()).load(anyList()); - - dataList = AXPCacheHandler.getInstance().getDataAsList(axpCache, mockCacheLoader, keyList); - - assertThat(dataList).isNotNull(); - assertThat(dataList.size()).isEqualTo(4); - assertThat(dataList.get(0)).isEqualTo("1*"); - assertThat(dataList.get(1)).isEqualTo("4"); - assertThat(dataList.get(2)).isEqualTo("3*"); - assertThat(dataList.get(3)).isEqualTo("5"); - - assertThat(axpCache.size()).isEqualTo(5); - assertThat(axpCache.get(1)).isEqualTo("1*"); - assertThat(axpCache.get(2)).isEqualTo("2"); - assertThat(axpCache.get(3)).isEqualTo("3*"); - assertThat(axpCache.get(4)).isEqualTo("4"); - assertThat(axpCache.get(5)).isEqualTo("5"); - - verify(mockCacheLoader, only()).load(anyList()); - } - catch (Exception e) - { - e.printStackTrace(); - - fail(); - } - } - - @Test - public void testGetData_cached() throws Exception - { - String result = AXPCacheHandler.getInstance().getData(axpCache, mockCacheLoader, 1); - assertThat(result).isEqualTo("1*"); - } - - @Test - public void testGetData_nonCached() throws Exception - { - List keys = Lists.newArrayList(); - keys.add(7); - when(mockCacheLoader.load(keys)).thenCallRealMethod(); - String result = AXPCacheHandler.getInstance().getData(axpCache, mockCacheLoader, 7); - assertThat(result).isEqualTo("7"); - } - - @Test - public void testUpdate() - { - int key = 2; - AXPCacheHandler.getInstance().update(axpCache, key, "updated value"); - assertThat(axpCache.get(key)).isEqualTo("updated value"); - } - - @Test - public void testClearCache() - { - AXPCache cache = new AXPCache(true); - cache.put(1, 1L); - cache.put(2, 2L); - cache.put(3, 3L); - - AXPCacheHandler.getInstance().clear(cache); - assertThat(cache.get(1l)).isNull(); - assertThat(cache.get(2l)).isNull(); - assertThat(cache.get(3l)).isNull(); - - assertThat(cache.get(1)).isNull(); - assertThat(cache.get(2)).isNull(); - assertThat(cache.get(3)).isNull(); - } - - private static class TestCacheLoader implements IAXPCacheLoader - { - - @Override - public Map load(List cacheKeyList) throws Exception - { - final Map dataMap = new HashMap<>(); - - for (Integer testCacheKey : cacheKeyList) - { - dataMap.put(testCacheKey, testCacheKey + ""); - } - - return dataMap; - } - } -} diff --git a/components/framework-axp/src/test/java/framework/cache/AXPCacheTest.java b/components/framework-axp/src/test/java/framework/cache/AXPCacheTest.java deleted file mode 100644 index 1147639e..00000000 --- a/components/framework-axp/src/test/java/framework/cache/AXPCacheTest.java +++ /dev/null @@ -1,168 +0,0 @@ -package framework.cache; - -import org.assertj.core.api.Assertions; -import org.testng.annotations.Test; - -import static org.testng.Assert.fail; - -public class AXPCacheTest -{ - - private ICache cache; - - @Test - public void testPut() - { - cache = new AXPCache(true); - cache.put("key1", "value1"); - cache.put("key2", "value2"); - cache.put("key3", "value3"); - - Assertions.assertThat((String) cache.get("key1")).isEqualTo("value1"); - Assertions.assertThat((String) cache.get("key2")).isEqualTo("value2"); - Assertions.assertThat((String) cache.get("key3")).isEqualTo("value3"); - } - - @Test - public void testPut_withNullKey() - { - cache = new AXPCache(true); - cache.put(null, "value1"); - cache.put("key2", "value2"); - cache.put("key3", "value3"); - - Assertions.assertThat(cache.size()).isEqualTo(2); - } - - @Test - public void testPut_withNullValue() - { - cache = new AXPCache(true); - cache.put("key1", "value1"); - cache.put("key2", "value2"); - cache.put("key3", "value3"); - - //Remove inserted value - cache.put("key1", null); - - Assertions.assertThat(cache.size()).isEqualTo(2); - Assertions.assertThat((String) cache.get("key1")).isNull(); - Assertions.assertThat((String) cache.get("key2")).isEqualTo("value2"); - Assertions.assertThat((String) cache.get("key3")).isEqualTo("value3"); - } - - @Test - public void testGet_withTTL() - { - try - { - Thread t = new Thread(() -> { - cache = new AXPCache(100); - cache.put("key1", "value1"); - cache.put("key2", "value2"); - cache.put("key3", "value3"); - - try - { - //Sleep until cache get cleared - Thread.sleep(120); - } - catch (InterruptedException e) - { - e.printStackTrace(); - - fail(); - } - Assertions.assertThat(cache.get("key1")).isNull(); - Assertions.assertThat(cache.get("key2")).isNull(); - Assertions.assertThat(cache.get("key3")).isNull(); - }); - t.start(); - t.join(); - } - catch (InterruptedException e) - { - e.printStackTrace(); - - fail(); - } - } - - @Test - public void testPut_withTTL() - { - try - { - Thread t = new Thread(() -> { - cache = new AXPCache(true); - cache.put("key1", "value1", 100); - cache.put("key2", "value2", 100); - cache.put("key3", "value3", 100); - - try - { - //Sleep until cache get cleared - Thread.sleep(120); - } - catch (InterruptedException e) - { - e.printStackTrace(); - - fail(); - } - Assertions.assertThat(cache.get("key1")).isNull(); - Assertions.assertThat(cache.get("key2")).isNull(); - Assertions.assertThat(cache.get("key3")).isNull(); - }); - t.start(); - t.join(); - } - catch (InterruptedException e) - { - e.printStackTrace(); - - fail(); - } - } - - @Test - public void testRemove() - { - cache = new AXPCache(true); - cache.put("key1", "value1", 100); - cache.put("key2", "value2", 100); - cache.put("key3", "value3", 100); - - cache.remove("key1"); - - Assertions.assertThat(cache.get("key1")).isNull(); - Assertions.assertThat(cache.get("key2")).isEqualTo("value2"); - Assertions.assertThat(cache.get("key3")).isEqualTo("value3"); - } - - @Test - public void testClear() - { - cache = new AXPCache(true); - cache.put("key1", "value1", 100); - cache.put("key2", "value2", 100); - cache.put("key3", "value3", 100); - - cache.clear(); - - Assertions.assertThat(cache.get("key1")).isNull(); - Assertions.assertThat(cache.get("key2")).isNull(); - Assertions.assertThat(cache.get("key3")).isNull(); - } - - @Test - public void testSize() - { - cache = new AXPCache(true); - cache.put("key1", "value1", 100); - cache.put("key2", "value2", 100); - cache.put("key3", "value3", 100); - - Assertions.assertThat(cache.size()).isEqualTo(3); - } -} \ No newline at end of file diff --git a/components/framework-axp/src/test/java/framework/cache/impl/DefaultAXPLoadingCacheTest.java b/components/framework-axp/src/test/java/framework/cache/impl/DefaultAXPLoadingCacheTest.java deleted file mode 100644 index 28d13529..00000000 --- a/components/framework-axp/src/test/java/framework/cache/impl/DefaultAXPLoadingCacheTest.java +++ /dev/null @@ -1,264 +0,0 @@ -package framework.cache.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import com.google.common.collect.Lists; -import framework.cache.AXPCache; -import framework.cache.IAXPCacheLoader; -import framework.cache.IAXPLoadingCache; -import org.fest.reflect.core.Reflection; -import org.mockito.Mockito; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyList; -import static org.mockito.Mockito.*; -import static org.testng.Assert.fail; - - -public class DefaultAXPLoadingCacheTest -{ - private TestCacheLoader mockCacheLoader; - - private DefaultAXPLoadingCache loadingCache; - - private AXPCache axpCache; - - @BeforeMethod - public void setUp() - { - mockCacheLoader = mock(TestCacheLoader.class); - - loadingCache = new DefaultAXPLoadingCache<>(mockCacheLoader, new AXPCache(true)); - - axpCache = Reflection.field("axpCache").ofType(AXPCache.class).in(this.loadingCache).get(); - axpCache.put(getTestCacheKey(1), "1*"); - axpCache.put(getTestCacheKey(2), "2"); - axpCache.put(getTestCacheKey(3), "3*"); - } - - @Test - public void testGetDataAsMap() - { - try - { - final List keyList = Lists.newArrayList(); - keyList.add(getTestCacheKey(1)); - keyList.add(getTestCacheKey(4)); - keyList.add(getTestCacheKey(3)); - keyList.add(getTestCacheKey(5)); - - Mockito.when(mockCacheLoader.load(anyList())).thenCallRealMethod(); - - Map dataMap = loadingCache.getDataAsMap(keyList); - - assertThat(dataMap).isNotNull(); - assertThat(dataMap.size()).isEqualTo(4); - assertThat(dataMap.get(getTestCacheKey(1))).isEqualTo( "1*"); - assertThat(dataMap.get(getTestCacheKey(4))).isEqualTo( "4"); - assertThat(dataMap.get(getTestCacheKey(3))).isEqualTo( "3*"); - assertThat(dataMap.get(getTestCacheKey(5))).isEqualTo( "5"); - - assertThat(axpCache.size()).isEqualTo( 5); - assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo( "1*"); - assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo( "2"); - assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo( "3*"); - assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo( "4"); - assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo( "5"); - - verify(mockCacheLoader, only()).load(anyList()); - - dataMap = loadingCache.getDataAsMap(keyList); - - assertThat(dataMap).isNotNull(); - assertThat(dataMap.size()).isEqualTo( 4); - assertThat(dataMap.get(getTestCacheKey(1))).isEqualTo( "1*"); - assertThat(dataMap.get(getTestCacheKey(4))).isEqualTo( "4"); - assertThat(dataMap.get(getTestCacheKey(3))).isEqualTo( "3*"); - assertThat(dataMap.get(getTestCacheKey(5))).isEqualTo( "5"); - - assertThat(axpCache.size()).isEqualTo( 5); - assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo("1*"); - assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo("2"); - assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo("3*"); - assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo("4"); - assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo("5"); - - verify(mockCacheLoader, only()).load(anyList()); - } - catch (Exception e) - { - e.printStackTrace(); - - fail(); - } - } - - @Test - public void testGetDataAsList() - { - try - { - final List keyList = Lists.newLinkedList(); - keyList.add(getTestCacheKey(1)); - keyList.add(getTestCacheKey(4)); - keyList.add(getTestCacheKey(3)); - keyList.add(getTestCacheKey(5)); - - when(mockCacheLoader.load(anyList())).thenCallRealMethod(); - - List dataList = loadingCache.getDataAsList(keyList); - - assertThat(dataList).isNotNull(); - assertThat(dataList.size()).isEqualTo( 4); - assertThat(dataList.get(0)).isEqualTo( "1*"); - assertThat(dataList.get(1)).isEqualTo( "4"); - assertThat(dataList.get(2)).isEqualTo( "3*"); - assertThat(dataList.get(3)).isEqualTo( "5"); - - assertThat(axpCache.size()).isEqualTo( 5); - assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo( "1*"); - assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo( "2"); - assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo( "3*"); - assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo( "4"); - assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo( "5"); - - verify(mockCacheLoader, only()).load(anyList()); - - dataList = loadingCache.getDataAsList(keyList); - - assertThat(dataList).isNotNull(); - assertThat(dataList.size()).isEqualTo( 4); - assertThat(dataList.get(0)).isEqualTo( "1*"); - assertThat(dataList.get(1)).isEqualTo( "4"); - assertThat(dataList.get(2)).isEqualTo( "3*"); - assertThat(dataList.get(3)).isEqualTo( "5"); - - assertThat(axpCache.size()).isEqualTo( 5); - assertThat(axpCache.get(getTestCacheKey(1))).isEqualTo( "1*"); - assertThat(axpCache.get(getTestCacheKey(2))).isEqualTo( "2"); - assertThat(axpCache.get(getTestCacheKey(3))).isEqualTo( "3*"); - assertThat(axpCache.get(getTestCacheKey(4))).isEqualTo( "4"); - assertThat(axpCache.get(getTestCacheKey(5))).isEqualTo( "5"); - - verify(mockCacheLoader, only()).load(anyList()); - } - catch (Exception e) - { - e.printStackTrace(); - - fail(); - } - } - - @Test - public void testGetData_cached() throws Exception - { - TestCacheKey key = getTestCacheKey(1); - - String result = loadingCache.getData(key); - - assertThat(result).isEqualTo( "1*"); - } - - @Test - public void testGetData_nonCached() throws Exception - { - TestCacheKey key = getTestCacheKey(6); - List keys = Lists.newArrayList(key); - when(mockCacheLoader.load(keys)).thenCallRealMethod(); - - String result = loadingCache.getData(key); - - assertThat(result).isEqualTo("6"); - verify(mockCacheLoader, only()).load(keys); - } - - @Test - public void testUpdate() throws Exception - { - TestCacheKey key = getTestCacheKey(7); - List keys = Lists.newArrayList(key); - - loadingCache.update(key, "7"); - - assertThat(loadingCache.getData(key)).isEqualTo( "7"); - verify(mockCacheLoader, never()).load(keys); - } - - @Test - public void testClear() throws Exception - { - IAXPLoadingCache cache = - new DefaultAXPLoadingCache<>(mockCacheLoader, new AXPCache(true)); - TestCacheKey key = getTestCacheKey(8); - - loadingCache.clear(); - - assertThat(cache.getData(key)).isNull(); - } - - private TestCacheKey getTestCacheKey(int key) - { - return new TestCacheKey(key, String.valueOf(key)); - } - - private static class TestCacheKey - { - - private final int key; - - private final String anotherAttribute; - - TestCacheKey(int key, String anotherAttribute) - { - this.key = key; - this.anotherAttribute = anotherAttribute; - } - - @Override - public boolean equals(Object o) - { - if (this == o) - { - return true; - } - - if (!(o instanceof TestCacheKey)) - { - return false; - } - - TestCacheKey that = (TestCacheKey) o; - - return key == that.key && Objects.equals(anotherAttribute, that.anotherAttribute); - } - - @Override - public int hashCode() - { - return Objects.hash(key, anotherAttribute); - } - } - - private class TestCacheLoader implements IAXPCacheLoader - { - - @Override - public Map load(List cacheKeyList) - { - final Map dataMap = new HashMap<>(); - - for (TestCacheKey testCacheKey : cacheKeyList) - { - dataMap.put(testCacheKey, testCacheKey.anotherAttribute); - } - - return dataMap; - } - } -} diff --git a/components/framework-axp/src/test/java/framework/configuration/ConfigFileReaderStrategyTest.java b/components/framework-axp/src/test/java/framework/configuration/ConfigFileReaderStrategyTest.java deleted file mode 100644 index e6533789..00000000 --- a/components/framework-axp/src/test/java/framework/configuration/ConfigFileReaderStrategyTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package framework.configuration; - -import framework.configuration.impl.JavaPropertyFileReadStrategy; -import framework.configuration.impl.XMLPropertyFileReadStrategy; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConfigFileReaderStrategyTest -{ - - @Test - public void testGetStrategy_extensionProperties() - { - assertThat(ConfigFileReaderStrategy.getInstance().getStrategy("properties")) - .isInstanceOf(JavaPropertyFileReadStrategy.class); - } - - @Test - public void testGetStrategy_extensionXml() - { - assertThat(ConfigFileReaderStrategy.getInstance().getStrategy("xml")) - .isInstanceOf(XMLPropertyFileReadStrategy.class); - } - - @Test(expectedExceptions = RuntimeException.class) - public void testGetStrategy_extensionOther() - { - ConfigFileReaderStrategy.getInstance().getStrategy("abc"); - } -} diff --git a/components/framework-axp/src/test/java/framework/configuration/impl/JavaPropertyFileReadStrategyTest.java b/components/framework-axp/src/test/java/framework/configuration/impl/JavaPropertyFileReadStrategyTest.java deleted file mode 100644 index 0a169d59..00000000 --- a/components/framework-axp/src/test/java/framework/configuration/impl/JavaPropertyFileReadStrategyTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package framework.configuration.impl; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Paths; -import java.util.Map; - -import com.google.common.base.Joiner; -import framework.configuration.CarbonUtilsDelegator; -import org.mockito.Mockito; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.testng.Assert.fail; - -public class JavaPropertyFileReadStrategyTest -{ - - @Test - public void testReadFile() - { - try - { - CarbonUtilsDelegator mock = mock(CarbonUtilsDelegator.class); - - /** - * This is a dirty fix to resolve resource path. - * When building individual module and the parent, resolving two different resource locations. - */ - String currentPath = Paths.get("").toAbsolutePath().normalize().toString(); - if (currentPath.contains("components")) - - { - String path = Joiner - .on(File.separator) - .join("src", "test", "resources", "com", "wso2telco", "framework", "configuration", "impl", - "JavaPropertyFileReadStrategyTest"); - Mockito.when(mock.getCarbonConfigDirPath()).thenReturn(path); - } - else - { - String path = Joiner - .on(File.separator) - .join("components", "framework-axp", "src", "test", "resources", "com", "wso2telco", "framework", - "configuration", "impl", "JavaPropertyFileReadStrategyTest"); - Mockito.when(mock.getCarbonConfigDirPath()).thenReturn(path); - } - - JavaPropertyFileReadStrategy strategy = new JavaPropertyFileReadStrategy(mock); - Map propertiesMap = strategy.readFile("test.properties"); - - assertThat(propertiesMap).isNotEmpty(); - assertThat(propertiesMap).hasSize(17); - } - catch (IOException e) - { - e.printStackTrace(); - - fail(); - } - } - -} diff --git a/components/framework-axp/src/test/resources/com/wso2telco/framework/configuration/impl/JavaPropertyFileReadStrategyTest/test.properties b/components/framework-axp/src/test/resources/com/wso2telco/framework/configuration/impl/JavaPropertyFileReadStrategyTest/test.properties deleted file mode 100644 index b1adfc91..00000000 --- a/components/framework-axp/src/test/resources/com/wso2telco/framework/configuration/impl/JavaPropertyFileReadStrategyTest/test.properties +++ /dev/null @@ -1,25 +0,0 @@ -sendSMSResourceURL=http://example.com/smsmessaging/v1/outbound/ -hubSubsGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/smsmessaging/v1/DeliveryInfoNotification -hubGateway=https://gateway1a.mife.sla-mobile.com.my:8243 -ussdGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/ussd/v1/inbound/ -#requestRouterUrl=http://IDEABIZAPPS/HTTPRequestRouter/route/HUB-USSD/?org= -hub_gateway_id=0001 -hub_gateway_provision_notify_url= - -hubMOSubsGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/smsmessaging/v1/ReceivedInfoNotification -hubDNSubsGatewayEndpoint=https://gateway1a.mife.sla-mobile.com.my:8243/smsmessaging/v1/DeliveryInfoNotification - -esbEndpoint=http://localhost:8281/payment - -#country code separated by (,) -search.oparatorOnHeaderMCC=94 -search.oparatorOnHeaderName=Operator -search.oparatorOnHeaderRegEx=(?<=XXX=)([a-zA-Z0-9])+ - -retry_on_fail=true -retry_count=3 -numberOfThreads=5 - -#If tokenpoolservice is set to 'true', tokenpoolResourceURL should point to the tokenpool endpoint (incl. trailing slash). -tokenpoolservice=false -tokenpoolResourceURL=http://localhost:8181/tokenservice/ \ No newline at end of file diff --git a/components/redis-client/pom.xml b/components/redis-client/pom.xml index f542b2d2..017355ff 100644 --- a/components/redis-client/pom.xml +++ b/components/redis-client/pom.xml @@ -37,6 +37,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + org.apache.maven.plugins maven-shade-plugin diff --git a/components/sp-config-util/pom.xml b/components/sp-config-util/pom.xml index e01dd1bf..cb5eb940 100644 --- a/components/sp-config-util/pom.xml +++ b/components/sp-config-util/pom.xml @@ -58,6 +58,15 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.7 + 1.7 + + org.apache.felix maven-bundle-plugin diff --git a/pom.xml b/pom.xml index 77e53030..085441e8 100644 --- a/pom.xml +++ b/pom.xml @@ -46,36 +46,8 @@ components/security/auth-filter components/security/user-profile features - components/framework-axp - - 1.5.8 - 2.17 - 1.2 - 3.3 - 4.11 - 4.4.3 - 2.1.1.wso2v1 - UTF-8 - 4.4.3 - 7.4.2.wso2v1 - 2.4.0.wso2v1 - 2.4.5-SNAPSHOT - 4.4.9 - 5.2.2 - 2.8.0 - 2.4.2 - 6.0.4 - 11.0.2 - - - 6.14.3 - 3.11.1 - 1.10.19 - 1.4.1 - - @@ -154,37 +126,6 @@ ${com.wso2telco.core.version} provided - - com.google.guava - guava - ${com.google.guava.version} - provided - - - - org.testng - testng - ${org.testng.version} - test - - - org.assertj - assertj-core - ${org.assertj.version} - test - - - org.mockito - mockito-all - ${org.mockito.version} - test - - - org.easytesting - fest-reflect - ${org.easytesting.version} - test - @@ -336,6 +277,26 @@ + + 1.5.8 + 2.17 + 1.2 + 3.3 + 4.11 + 4.4.3 + 2.1.1.wso2v1 + UTF-8 + 4.4.3 + 7.4.2.wso2v1 + 2.4.0.wso2v1 + 2.4.5-SNAPSHOT + 4.4.9 + 5.2.2 + 2.8.0 + 2.4.2 + 6.0.4 + + notify @@ -367,14 +328,7 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - +