-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5864 from malithie/actions-core
Remove unnecessary dependency to Identity Util to read action execution configs
- Loading branch information
Showing
7 changed files
with
145 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...on/src/main/java/org/wso2/carbon/identity/action/execution/util/ActionExecutorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.identity.action.execution.util; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.wso2.carbon.identity.action.execution.model.ActionType; | ||
import org.wso2.carbon.identity.core.util.IdentityUtil; | ||
|
||
/** | ||
* This class holds the system configurations for the Action Executor Service. | ||
*/ | ||
public class ActionExecutorConfig { | ||
|
||
private static final ActionExecutorConfig INSTANCE = new ActionExecutorConfig(); | ||
|
||
private static final String PRE_ISSUE_ACCESS_TOKEN_ACTION_TYPE_ENABLE_PROPERTY = | ||
"Actions.Types.PreIssueAccessToken.Enable"; | ||
|
||
private ActionExecutorConfig() { | ||
|
||
} | ||
|
||
public static ActionExecutorConfig getInstance() { | ||
|
||
return INSTANCE; | ||
} | ||
|
||
public boolean isExecutionForActionTypeEnabled(ActionType actionType) { | ||
|
||
switch (actionType) { | ||
case PRE_ISSUE_ACCESS_TOKEN: | ||
return isActionTypeEnabled(PRE_ISSUE_ACCESS_TOKEN_ACTION_TYPE_ENABLE_PROPERTY); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
private boolean isActionTypeEnabled(String actionTypePropertyName) { | ||
|
||
boolean isActionTypeEnabled = false; | ||
String actionTypeEnabledPropertyValue = IdentityUtil.getProperty(actionTypePropertyName); | ||
if (StringUtils.isNotBlank(actionTypeEnabledPropertyValue)) { | ||
return Boolean.parseBoolean(actionTypeEnabledPropertyValue); | ||
} | ||
return isActionTypeEnabled; | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...rc/test/java/org/wso2/carbon/identity/action/execution/util/ActionExecutorConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.identity.action.execution.util; | ||
|
||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import org.wso2.carbon.identity.action.execution.model.ActionType; | ||
import org.wso2.carbon.identity.core.util.IdentityUtil; | ||
|
||
import static org.testng.Assert.assertFalse; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class ActionExecutorConfigTest { | ||
|
||
private ActionExecutorConfig actionExecutorConfig; | ||
|
||
private MockedStatic<IdentityUtil> identityUtil; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
|
||
MockitoAnnotations.openMocks(this); | ||
actionExecutorConfig = ActionExecutorConfig.getInstance(); | ||
identityUtil = Mockito.mockStatic(IdentityUtil.class); | ||
} | ||
|
||
@AfterMethod | ||
public void tearDown() { | ||
|
||
identityUtil.close(); | ||
} | ||
|
||
@Test | ||
public void testIsExecutionForActionTypeEnabled_PreIssueAccessToken_Enabled() { | ||
|
||
identityUtil.when(() -> IdentityUtil.getProperty("Actions.Types.PreIssueAccessToken.Enable")) | ||
.thenReturn("true"); | ||
assertTrue(actionExecutorConfig.isExecutionForActionTypeEnabled(ActionType.PRE_ISSUE_ACCESS_TOKEN)); | ||
} | ||
|
||
@Test | ||
public void testIsExecutionForActionTypeEnabled_PreIssueAccessToken_Disabled() { | ||
|
||
identityUtil.when(() -> IdentityUtil.getProperty("Actions.Types.PreIssueAccessToken.Enable")) | ||
.thenReturn("false"); | ||
assertFalse(actionExecutorConfig.isExecutionForActionTypeEnabled(ActionType.PRE_ISSUE_ACCESS_TOKEN)); | ||
} | ||
|
||
@Test | ||
public void testIsExecutionForActionTypeEnabled_PreIssueAccessToken_InvalidValue() { | ||
|
||
identityUtil.when(() -> IdentityUtil.getProperty("Actions.Types.PreIssueAccessToken.Enable")) | ||
.thenReturn("invalid"); | ||
assertFalse(actionExecutorConfig.isExecutionForActionTypeEnabled(ActionType.PRE_ISSUE_ACCESS_TOKEN)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters