Skip to content

Commit

Permalink
Making all registry references, method local
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanasbg committed Dec 20, 2024
1 parent 7bcb134 commit 35e06e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public boolean addServiceProvider(SAMLSSOServiceProviderDO serviceProviderDO, in
return false;
}

Resource resource = createResource(serviceProviderDO);
Resource resource = createResource(serviceProviderDO, registry);
if (!isTransactionStarted) {
registry.beginTransaction();
}
Expand Down Expand Up @@ -315,13 +315,14 @@ public boolean addServiceProvider(SAMLSSOServiceProviderDO serviceProviderDO, in
log.error(msg, e);
throw IdentityException.error(msg, e);
} finally {
commitOrRollbackTransaction(isErrorOccurred);
commitOrRollbackTransaction(isErrorOccurred, registry);
}
}

private Resource createResource(SAMLSSOServiceProviderDO serviceProviderDO) throws RegistryException {
Resource resource;
resource = registry.newResource();
private Resource createResource(SAMLSSOServiceProviderDO serviceProviderDO, Registry registry)
throws RegistryException {

Resource resource = registry.newResource();
resource.addProperty(IdentityRegistryResources.PROP_SAML_SSO_ISSUER,
serviceProviderDO.getIssuer());
resource.setProperty(IdentityRegistryResources.PROP_SAML_SSO_ASSERTION_CONS_URLS,
Expand Down Expand Up @@ -514,7 +515,7 @@ public boolean updateServiceProvider(SAMLSSOServiceProviderDO serviceProviderDO,
return false;
}

Resource resource = createResource(serviceProviderDO);
Resource resource = createResource(serviceProviderDO, registry);
if (!isTransactionStarted) {
registry.beginTransaction();
}
Expand Down Expand Up @@ -549,7 +550,7 @@ public boolean updateServiceProvider(SAMLSSOServiceProviderDO serviceProviderDO,
log.error(msg, e);
throw new IdentityException(msg, e);
} finally {
commitOrRollbackTransaction(isErrorOccurred);
commitOrRollbackTransaction(isErrorOccurred, registry);
}
}

Expand All @@ -566,7 +567,7 @@ public SAMLSSOServiceProviderDO[] getServiceProviders(int tenantId) throws Ident
Collection samlSSOServiceProvidersCollection = (Collection) samlSSOServiceProvidersResource;
String[] resources = samlSSOServiceProvidersCollection.getChildren();
for (String resource : resources) {
getChildResources(resource, serviceProvidersList);
getChildResources(resource, serviceProvidersList, registry);
}
}
}
Expand Down Expand Up @@ -609,7 +610,7 @@ public boolean removeServiceProvider(String issuer, int tenantId) throws Identit
log.error(msg, e);
throw IdentityException.error(msg, e);
} finally {
commitOrRollbackTransaction(isErrorOccurred);
commitOrRollbackTransaction(isErrorOccurred, registry);
}
}

Expand Down Expand Up @@ -779,7 +780,7 @@ public SAMLSSOServiceProviderDO uploadServiceProvider(SAMLSSOServiceProviderDO s
registry.beginTransaction();
}

Resource resource = createResource(serviceProviderDO);
Resource resource = createResource(serviceProviderDO, registry);
registry.put(path, resource);
if (log.isDebugEnabled()) {
if (StringUtils.isNotBlank(serviceProviderDO.getIssuerQualifier())) {
Expand All @@ -795,7 +796,7 @@ public SAMLSSOServiceProviderDO uploadServiceProvider(SAMLSSOServiceProviderDO s
isErrorOccurred = true;
throw IdentityException.error("Error while adding Service Provider.", e);
} finally {
commitOrRollbackTransaction(isErrorOccurred);
commitOrRollbackTransaction(isErrorOccurred, registry);
}
}

Expand All @@ -804,7 +805,7 @@ public SAMLSSOServiceProviderDO uploadServiceProvider(SAMLSSOServiceProviderDO s
* @param isErrorOccurred Identifier for error transactions.
* @throws IdentityException Error while committing or running rollback on the transaction.
*/
private void commitOrRollbackTransaction(boolean isErrorOccurred) throws IdentityException {
private void commitOrRollbackTransaction(boolean isErrorOccurred, Registry registry) throws IdentityException {

try {
// Rollback the transaction if there is an error, Otherwise try to commit.
Expand All @@ -825,16 +826,16 @@ private void commitOrRollbackTransaction(boolean isErrorOccurred) throws Identit
* @param serviceProviderList child resource list.
* @throws RegistryException
*/
private void getChildResources(String parentResource, List<SAMLSSOServiceProviderDO>
serviceProviderList) throws RegistryException {
private void getChildResources(String parentResource, List<SAMLSSOServiceProviderDO> serviceProviderList,
Registry registry) throws RegistryException {

if (registry.resourceExists(parentResource)) {
Resource resource = registry.get(parentResource);
if (resource instanceof Collection) {
Collection collection = (Collection) resource;
String[] resources = collection.getChildren();
for (String res : resources) {
getChildResources(res, serviceProviderList);
getChildResources(res, serviceProviderList, registry);
}
} else {
serviceProviderList.add(resourceToObject(resource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<classes>
<class name="org.wso2.carbon.identity.core.util.IdentityUtilTest"/>
<class name="org.wso2.carbon.identity.core.util.IdentityConfigParserTest"/>
<!-- <class name="org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderDAOTest"/>-->
<class name="org.wso2.carbon.identity.core.dao.SAMLSSOServiceProviderDAOTest"/>
<class name="org.wso2.carbon.identity.core.internal.DefaultServiceURLBuilderTest"/>
<class name="org.wso2.carbon.identity.core.cache.BaseCacheTest"/>
<class name="org.wso2.carbon.identity.core.ThreadLocalAwareThreadPoolExecutorTest"/>
Expand Down

0 comments on commit 35e06e5

Please sign in to comment.