Skip to content

Commit

Permalink
Merge pull request #4758 from madurangasiriwardena/registry-remove
Browse files Browse the repository at this point in the history
Remove unnecessary registry usages
  • Loading branch information
hwupathum authored Jul 3, 2023
2 parents 5cc3792 + 8bbdd74 commit 63165a5
Show file tree
Hide file tree
Showing 33 changed files with 90 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.RegistryType;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException;
Expand Down Expand Up @@ -81,8 +80,6 @@
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.idp.mgt.model.ConnectedAppsResult;
import org.wso2.carbon.idp.mgt.util.IdPManagementConstants;
import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.core.RegistryConstants;
import org.wso2.carbon.user.api.ClaimMapping;
import org.wso2.carbon.user.api.Tenant;
import org.wso2.carbon.user.api.UserRealm;
Expand Down Expand Up @@ -2580,10 +2577,6 @@ public void updateApplicationByResourceId(String resourceId, ServiceProvider upd
}

updateApplicationPermissions(updatedApp, updatedAppName, storedAppName);
} catch (RegistryException e) {
String message = "Error while updating application with resourceId: " + resourceId + " in tenantDomain: "
+ tenantDomain;
throw buildServerException(message, e);
} finally {
endTenantFlow();
}
Expand Down Expand Up @@ -2649,17 +2642,9 @@ private void doPreUpdateChecks(String storedAppName, ServiceProvider updatedApp,
}

private void updateApplicationPermissions(ServiceProvider updatedApp, String updatedAppName, String storedAppName)
throws RegistryException, IdentityApplicationManagementException {

String applicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + RegistryConstants
.PATH_SEPARATOR + storedAppName;
org.wso2.carbon.registry.api.Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext()
.getRegistry(RegistryType.USER_GOVERNANCE);
throws IdentityApplicationManagementException {

boolean exist = tenantGovReg.resourceExists(applicationNode);
if (exist && !StringUtils.equals(storedAppName, updatedAppName)) {
ApplicationMgtUtil.renameAppPermissionPathNode(storedAppName, updatedAppName);
}
ApplicationMgtUtil.renameAppPermissionPathNode(storedAppName, updatedAppName);

if (updatedApp.getPermissionAndRoleConfig() != null) {
ApplicationMgtUtil.updatePermissions(updatedAppName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.registry.core.RegistryConstants;
import org.wso2.carbon.user.api.Tenant;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
Expand Down Expand Up @@ -74,7 +73,7 @@
public class ApplicationMgtUtil {

public static final String APPLICATION_ROOT_PERMISSION = "applications";
public static final String PATH_CONSTANT = RegistryConstants.PATH_SEPARATOR;
public static final String PATH_CONSTANT = "/";
// Default regex for validating application name.
// This regex allows alphanumeric characters, dot, underscore, hyphen and spaces in the name.
// Does not allow leading and trailing whitespaces.
Expand Down Expand Up @@ -487,7 +486,7 @@ public static Property[] concatArrays(Property[] o1, Property[] o2) {

public static String getApplicationPermissionPath() {

return CarbonConstants.UI_PERMISSION_NAME + RegistryConstants.PATH_SEPARATOR + APPLICATION_ROOT_PERMISSION;
return CarbonConstants.UI_PERMISSION_NAME + PATH_CONSTANT + APPLICATION_ROOT_PERMISSION;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.wso2.carbon.identity.organization.management.service.OrganizationManagementInitialize;
import org.wso2.carbon.identity.organization.management.service.OrganizationUserResidentResolverService;
import org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService;
Expand Down Expand Up @@ -147,27 +146,6 @@ protected void deactivate(ComponentContext context) {
}
}

@Reference(
name = "registry.service",
service = RegistryService.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetRegistryService"
)
protected void setRegistryService(RegistryService registryService) {
if (log.isDebugEnabled()) {
log.debug("RegistryService set in Identity ApplicationManagementComponent bundle");
}
ApplicationManagementServiceComponentHolder.getInstance().setRegistryService(registryService);
}

protected void unsetRegistryService(RegistryService registryService) {
if (log.isDebugEnabled()) {
log.debug("RegistryService unset in Identity ApplicationManagementComponent bundle");
}
ApplicationManagementServiceComponentHolder.getInstance().setRegistryService(null);
}

@Reference(
name = "user.realmservice.default",
service = RealmService.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager;
import org.wso2.carbon.identity.organization.management.service.OrganizationManagementInitialize;
import org.wso2.carbon.identity.organization.management.service.OrganizationUserResidentResolverService;
import org.wso2.carbon.registry.api.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.ConfigurationContextService;

Expand All @@ -43,8 +42,6 @@ public class ApplicationManagementServiceComponentHolder {

private String authnTemplatesJson;

private RegistryService registryService;

private RealmService realmService;

private SAMLSSOServiceProviderManager samlSSOServiceProviderManager;
Expand Down Expand Up @@ -114,16 +111,6 @@ public static void removeInboundAuthenticatorConfig(String type) {
inboundAuthenticatorConfigs.remove(type);
}

public RegistryService getRegistryService() {

return registryService;
}

public void setRegistryService(RegistryService registryService) {

this.registryService = registryService;
}

public RealmService getRealmService() {

return realmService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.wso2.carbon.identity.application.mgt.provider;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
Expand Down Expand Up @@ -61,11 +62,22 @@ public class RegistryBasedApplicationPermissionProvider implements ApplicationPe
public void renameAppPermissionName(String oldName, String newName)
throws IdentityApplicationManagementException {

List<ApplicationPermission> loadPermissions = loadPermissions(oldName);
String newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + oldName;
if (StringUtils.equals(oldName, newName)) {
return;
}

Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.USER_GOVERNANCE);
// Creating new application node.
String oldApplicationNode = getApplicationPermissionPath() + PATH_CONSTANT + oldName;

try {
if (!tenantGovReg.resourceExists(oldApplicationNode)) {
return;
}

List<ApplicationPermission> loadPermissions = loadPermissions(oldName);
String newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + oldName;

// Creating new application node.
for (ApplicationPermission applicationPermission : loadPermissions) {
tenantGovReg.delete(newApplicationNode + PATH_CONSTANT + applicationPermission.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonException;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.core.util.AnonymousSessionUtil;
import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator;
import org.wso2.carbon.identity.application.authentication.framework.config.builder.FileBasedConfigurationBuilder;
import org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig;
Expand All @@ -37,7 +35,6 @@
import org.wso2.carbon.identity.application.authentication.framework.handler.approles.ApplicationRolesResolver;
import org.wso2.carbon.identity.application.authentication.framework.handler.approles.exception.ApplicationRolesException;
import org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
Expand All @@ -59,6 +56,7 @@
import org.wso2.carbon.user.core.UserRealm;
import org.wso2.carbon.user.core.UserStoreManager;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
import org.wso2.carbon.user.core.service.RealmService;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -779,10 +777,11 @@ private ClaimManager getClaimManager(String tenantDomain, UserRealm realm) throw
private UserRealm getUserRealm(String tenantDomain) throws FrameworkException {
UserRealm realm;
try {
realm = AnonymousSessionUtil.getRealmByTenantDomain(
FrameworkServiceComponent.getRegistryService(),
FrameworkServiceComponent.getRealmService(), tenantDomain);
} catch (CarbonException e) {
RealmService realmService = FrameworkServiceDataHolder.getInstance().getRealmService();
int tenantId = realmService.getTenantManager().getTenantId(tenantDomain);

realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
} catch (UserStoreException e) {
throw new FrameworkException("Error occurred while retrieving the Realm for " +
tenantDomain + " to handle local claims", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.CarbonException;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.AnonymousSessionUtil;
import org.wso2.carbon.core.util.PermissionUpdateUtil;
import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException;
import org.wso2.carbon.identity.application.authentication.framework.handler.provisioning.ProvisioningHandler;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
import org.wso2.carbon.identity.application.common.model.User;
Expand All @@ -44,7 +42,6 @@
import org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException;
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.idp.mgt.IdentityProviderManager;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.UserCoreConstants;
import org.wso2.carbon.user.core.UserRealm;
import org.wso2.carbon.user.core.UserStoreException;
Expand Down Expand Up @@ -110,14 +107,12 @@ public void handle(List<String> roles, String subject, Map<String, String> attri
String provisioningUserStoreId, String tenantDomain, List<String> idpToLocalRoleMapping)
throws FrameworkException {

RegistryService registryService = FrameworkServiceComponent.getRegistryService();
RealmService realmService = FrameworkServiceComponent.getRealmService();
RealmService realmService = FrameworkServiceDataHolder.getInstance().getRealmService();
String attributeSyncMethod = IdentityUtil.threadLocalProperties.get()
.get(FrameworkConstants.ATTRIBUTE_SYNC_METHOD).toString();
try {
int tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService,
realmService, tenantDomain);
UserRealm realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
String username = MultitenantUtils.getTenantAwareUsername(subject);

String userStoreDomain;
Expand Down Expand Up @@ -340,8 +335,7 @@ tobeDeleted claims (claims came from federated idp as null). If there is a match

PermissionUpdateUtil.updatePermissionTree(tenantId);

} catch (org.wso2.carbon.user.api.UserStoreException | CarbonException |
FederatedAssociationManagerException e) {
} catch (org.wso2.carbon.user.api.UserStoreException | FederatedAssociationManagerException e) {
throw new FrameworkException("Error while provisioning user : " + subject, e);
} finally {
IdentityUtil.clearIdentityErrorMsg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.idp.mgt.IdentityProviderManager;
import org.wso2.carbon.idp.mgt.util.IdPManagementUtil;
import org.wso2.carbon.registry.core.utils.UUIDGenerator;
import org.wso2.carbon.user.core.config.UserStorePreferenceOrderSupplier;
import org.wso2.carbon.user.core.model.UserMgtContext;
import org.wso2.carbon.user.core.util.UserCoreUtil;
Expand All @@ -75,6 +74,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
Expand Down Expand Up @@ -540,7 +540,7 @@ protected void concludeFlow(HttpServletRequest request, HttpServletResponse resp
sessionContext.addProperty(FrameworkConstants.AUTHENTICATION_CONTEXT_PROPERTIES,
context.getProperty(FrameworkConstants.AUTHENTICATION_CONTEXT_PROPERTIES));
}
String sessionKey = UUIDGenerator.generateUUID();
String sessionKey = UUID.randomUUID().toString();
sessionContextKey = DigestUtils.sha256Hex(sessionKey);
sessionContext.addProperty(FrameworkConstants.AUTHENTICATED_USER, authenticationResult.getSubject());
sessionContext.addProperty(FrameworkUtils.TENANT_DOMAIN, context.getLoginTenantDomain());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.registry.core.utils.UUIDGenerator;
import org.wso2.carbon.user.api.Tenant;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.UserCoreConstants;
Expand All @@ -80,6 +79,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import javax.servlet.ServletException;
Expand Down Expand Up @@ -632,7 +632,7 @@ protected AuthenticationContext initializeFlow(HttpServletRequest request, HttpS
context.setCallerPath(callerPath);

// generate a new key to hold the context data object
String contextId = UUIDGenerator.generateUUID();
String contextId = UUID.randomUUID().toString();
context.setContextIdentifier(contextId);

if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.utils.URIBuilder;
import org.wso2.carbon.CarbonException;
import org.wso2.carbon.core.util.AnonymousSessionUtil;
import org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade;
import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
Expand All @@ -33,7 +31,6 @@
import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException;
import org.wso2.carbon.identity.application.authentication.framework.handler.request.AbstractPostAuthnHandler;
import org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
Expand All @@ -54,6 +51,7 @@
import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
import org.wso2.carbon.user.core.constants.UserCoreErrorConstants.ErrorMessages;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.util.UserCoreUtil;

import java.io.IOException;
Expand Down Expand Up @@ -466,10 +464,11 @@ protected UserRealm getUserRealm(String tenantDomain) throws PostAuthenticationF

UserRealm realm;
try {
realm = AnonymousSessionUtil.getRealmByTenantDomain(
FrameworkServiceComponent.getRegistryService(),
FrameworkServiceComponent.getRealmService(), tenantDomain);
} catch (CarbonException e) {
RealmService realmService = FrameworkServiceDataHolder.getInstance().getRealmService();
int tenantId = realmService.getTenantManager().getTenantId(tenantDomain);

realm = (UserRealm) realmService.getTenantUserRealm(tenantId);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new PostAuthenticationFailedException("Error while handling missing mandatory claims. " +
"Error in realm.", "Error occurred while retrieving the Realm for " + tenantDomain +
" to handle local claims", e);
Expand Down
Loading

0 comments on commit 63165a5

Please sign in to comment.