Skip to content

Commit

Permalink
Provide support for authentication action type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Aug 12, 2024
1 parent 8f81737 commit 2994e4e
Show file tree
Hide file tree
Showing 258 changed files with 28,565 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>action-mgt</artifactId>
<version>7.3.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.identity.action.execution</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Identity - Action Executor Component</name>
<description>Action execution backend component</description>
<url>http://wso2.org</url>

<dependencies>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.action.management</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>
${project.artifactId}
</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Private-Package>
org.wso2.carbon.identity.action.execution.internal,
</Private-Package>
<Export-Package>
!org.wso2.carbon.identity.action.execution.internal,
org.wso2.carbon.identity.action.execution.*;
version="${carbon.identity.package.export.version}"
</Export-Package>
<Import-Package>
org.wso2.carbon.identity.action.management.*;
version="${carbon.identity.package.import.version.range}",
org.apache.commons.lang; version="${commons-lang.wso2.osgi.version.range}",
org.apache.commons.logging; version="${import.package.version.commons.logging}",
org.apache.commons.collections; version="${commons-collections.wso2.osgi.version.range}",
org.apache.http; version="${httpcore.version.osgi.import.range}",
org.apache.http.client.config; version="${httpcore.version.osgi.import.range}",
org.apache.http.client.methods; version="${httpcore.version.osgi.import.range}",
org.apache.http.concurrent; version="${httpcore.version.osgi.import.range}",
org.apache.http.conn; version="${httpcore.version.osgi.import.range}",
org.apache.http.entity; version="${httpcore.version.osgi.import.range}",
org.apache.http.util; version="${httpcore.version.osgi.import.range}",
org.apache.http.impl.client; version="${httpcomponents-httpclient.imp.pkg.version.range}",
org.apache.http.impl.conn; version="${httpcomponents-httpclient.imp.pkg.version.range}",
org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}",
org.osgi.service.component; version="${osgi.service.component.imp.pkg.version.range}",
org.wso2.carbon.utils; version="${carbon.kernel.package.import.version.range}",
com.fasterxml.jackson.core.*; version="${com.fasterxml.jackson.annotation.version.range}",
com.fasterxml.jackson.databind.*; version="${com.fasterxml.jackson.annotation.version.range}",
com.fasterxml.jackson.annotation.*; version="${com.fasterxml.jackson.annotation.version.range}",
</Import-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>
--add-opens java.xml/jdk.xml.internal=ALL-UNNAMED
--add-exports java.base/jdk.internal.loader=ALL-UNNAMED
</argLine>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.90</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<configuration>
<excludeFilterFile>../../../spotbugs-exclude.xml</excludeFilterFile>
<effort>Max</effort>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static ActionExecutionResponseProcessor getActionExecutionResponseProcess
switch (actionType) {
case PRE_ISSUE_ACCESS_TOKEN:
return actionInvocationResponseProcessors.get(ActionType.PRE_ISSUE_ACCESS_TOKEN);
case AUTHENTICATION:
return actionInvocationResponseProcessors.get(ActionType.AUTHENTICATION);
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.action.execution.exception.ActionExecutionException;
Expand Down Expand Up @@ -90,13 +91,26 @@ public boolean isExecutionEnabled(ActionType actionType) {
public ActionExecutionStatus execute(ActionType actionType, Map<String, Object> eventContext, String tenantDomain)
throws ActionExecutionException {

return execute(actionType, null, eventContext, tenantDomain);
}

public ActionExecutionStatus execute(ActionType actionType, String actionId, Map<String, Object> eventContext,
String tenantDomain) throws ActionExecutionException {

try {
List<Action> actions = getActionsByActionType(actionType, tenantDomain);
validateActions(actions, actionType);
Action action;
if (StringUtils.isNotBlank(actionId)) {
List<Action> actions = getActionsByActionType(actionType, tenantDomain);
validateActions(actions, actionType);
// As of now only one action is allowed.
action = actions.get(0);
} else {
action = getActionsByActionId(actionId, tenantDomain);
}

ActionExecutionRequest actionRequest = buildActionExecutionRequest(actionType, eventContext);
ActionExecutionResponseProcessor actionExecutionResponseProcessor = getResponseProcessor(actionType);

Action action = actions.get(0); // As of now only one action is allowed.
return Optional.ofNullable(action)
.filter(activeAction -> activeAction.getStatus() == Action.Status.ACTIVE)
.map(activeAction -> executeAction(activeAction, actionRequest, eventContext,
Expand All @@ -121,6 +135,16 @@ private List<Action> getActionsByActionType(ActionType actionType, String tenant
}
}

private Action getActionsByActionId(String actionId, String tenantDomain) throws ActionExecutionRuntimeException {

try {
return ActionExecutionServiceComponentHolder.getInstance().getActionManagementService()
.getActionByActionId(actionId, tenantDomain);
} catch (ActionMgtException e) {
throw new ActionExecutionRuntimeException("Error occurred while retrieving actions.", e);
}
}

private void validateActions(List<Action> actions, ActionType actionType) throws ActionExecutionException {

if (CollectionUtils.isEmpty(actions)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
*/
public enum ActionType {
PRE_ISSUE_ACCESS_TOKEN,
AUTHENTICATION
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
public enum Operation {
ADD("add"),
REMOVE("remove"),
REPLACE("replace");
REPLACE("replace"),
REDIRECT("redirect");

private final String value;

Expand Down
Loading

0 comments on commit 2994e4e

Please sign in to comment.