Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use createJsGraphBuilderFactoryFromConfig function from FrameworkUtils #147

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
<groupId>org.wso2.orbit.org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.mockito.Mockito;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO;
Expand Down Expand Up @@ -75,6 +76,7 @@ protected void setUp() throws Exception {

super.setUp();

CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("callAnalytics", new CallAnalyticsFunctionImpl());
UserRealm userRealm = realmService.getTenantUserRealm(-1234);
userRealm.getUserStoreManager().addRole("admin", new String[]{"admin", "test_user"}, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
<artifactId>jsr311-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO;
Expand Down Expand Up @@ -110,6 +111,7 @@ protected void setUp() throws Exception {

super.setUp();

CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("callChoreo", new CallChoreoFunctionImpl());
UserRealm userRealm = realmService.getTenantUserRealm(-1234);
userRealm.getUserStoreManager().addRole("admin", new String[]{"admin", "test_user"}, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
<artifactId>org.wso2.carbon.identity.conditional.auth.functions.test.utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.mockito.Mockito;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class CallElasticFunctionImplTest extends JsSequenceHandlerAbstractTest {
protected void initClass() throws Exception {

super.setUp();
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("callElastic", new CallElasticFunctionImpl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
<artifactId>org.wso2.carbon.crypto.impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.core.internal.CarbonCoreDataHolder;
import org.wso2.carbon.crypto.impl.DefaultCryptoService;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class CookieFunctionImplTest extends JsSequenceHandlerAbstractTest {
protected void setUp() throws Exception {

super.setUp();
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("setCookie", (SetCookieFunction) new CookieFunctionImpl()::setCookie);
sequenceHandlerRunner.registerJsFunction("getCookieValue", (GetCookieFunction) new CookieFunctionImpl()
::getCookieValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class HTTPGetFunctionImplTest extends JsSequenceHandlerAbstractTest {
protected void initClass() throws Exception {

super.setUp();
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
int connectionTimeout = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class HTTPPostFunctionImplTest extends JsSequenceHandlerAbstractTest {
protected void initClass() throws Exception {

super.setUp();
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
int connectionTimeout = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
Expand Down Expand Up @@ -58,6 +59,7 @@ protected void setUp() throws Exception {

super.setUp();

CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the usecase behind this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in the pre test set ups. However there is no default value provided for this in CarbonConstants. Therefore this gives a NullPointerException when tests are run. Therefore the value was initialised here before tests run.

sequenceHandlerRunner.registerJsFunction("sendEmail", new SendEmailFunctionImpl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<classifier>runtime</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@
<artifactId>nashorn-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we adding these new dependencies/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were build issues due to this dependency not being present. There are multiple usages of this in the codebase however the dependency was missing. Therefore there were compilation issues.

</dependency>
<dependency>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private Map<String, Object> getIdTokenClaims(String idToken) {
byte[] decoded = Base64.decodeBase64(base64Body.getBytes());
Set<Map.Entry<String, Object>> jwtAttributeSet = new HashSet<>();
try {
jwtAttributeSet = JSONObjectUtils.parseJSONObject(new String(decoded)).entrySet();
jwtAttributeSet = JSONObjectUtils.parse(new String(decoded)).entrySet();
} catch (ParseException e) {
LOG.error("Error occurred while parsing JWT provided by federated IDP: ", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.wso2.carbon.identity.conditional.auth.functions.user.model;

import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.openjdk.nashorn.JsOpenJdkNashornGraphBuilderFactory;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;

/**
* Singleton to get the appropriate Javascript Proxy Object Wrapper Factory.
Expand All @@ -32,8 +32,7 @@ public class JsWrapperFactoryProvider {

private JsWrapperFactoryProvider() {

if (FrameworkServiceDataHolder.getInstance().
getJsGraphBuilderFactory() instanceof JsOpenJdkNashornGraphBuilderFactory) {
if (FrameworkUtils.createJsGraphBuilderFactoryFromConfig() instanceof JsOpenJdkNashornGraphBuilderFactory) {
jsWrapperBaseFactory = new JsOpenJdkNashornWrapperFactory();
} else {
jsWrapperBaseFactory = new JsWrapperFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
Expand Down Expand Up @@ -56,6 +57,7 @@ protected void setUp() throws Exception {

super.setUp();

CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("hasAnyOfTheRoles", new HasAnyOfTheRolesFunctionImpl());
UserRealm userRealm = realmService.getTenantUserRealm(-1234);
userRealm.getUserStoreManager().addRole("admin", new String[]{"test_user1", "test_user2"}, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException;
Expand Down Expand Up @@ -58,6 +59,7 @@ protected void setUp() throws Exception {

super.setUp();

CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("hasRole", new HasRoleFunctionImpl());
UserRealm userRealm = realmService.getTenantUserRealm(-1234);
userRealm.getUserStoreManager().addRole("admin", new String[]{"test_user1", "test_user2"}, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class IsMemberOfAnyOfGroupsFunctionImplTest extends JsSequenceHandlerAbst
protected void setUp() throws Exception {

super.setUp();
CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = true;
sequenceHandlerRunner.registerJsFunction("isMemberOfAnyOfGroups",
new IsMemberOfAnyOfGroupsFunctionImpl());
UserRealm userRealm = realmService.getTenantUserRealm(-1234);
Expand Down
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@
<artifactId>org.wso2.carbon.crypto.impl</artifactId>
<version>${carbon.crypto.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<version>${identity.organization.management.core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -468,10 +474,11 @@
</plugins>
</build>
<properties>
<carbon.kernel.version>4.6.3-m5</carbon.kernel.version>
<carbon.kernel.version>4.9.17</carbon.kernel.version>
<carbon.kernel.package.import.version.range>[4.6.0, 5.0.0)</carbon.kernel.package.import.version.range>
<carbon.user.package.import.version.range>[1.0.1, 2.0.0)</carbon.user.package.import.version.range>
<carbon.identity.framework.version>5.22.0</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.509</carbon.identity.framework.version>
<identity.organization.management.core.version>1.0.89</identity.organization.management.core.version>
<carbon.identity.framework.testutils.version>5.20.447</carbon.identity.framework.testutils.version>
<carbon.identity.package.import.version.range>[5.14.0, 7.0.0)</carbon.identity.package.import.version.range>
<identity.governance.version>1.1.17</identity.governance.version>
Expand Down