Skip to content

Commit

Permalink
Merge pull request #6119 from ashanthamara/action-properties
Browse files Browse the repository at this point in the history
Refactor ActionManagementDAO to handle action type specific properties
  • Loading branch information
malithie authored Dec 4, 2024
2 parents 78c31ab + b30a89b commit c6d4e92
Show file tree
Hide file tree
Showing 48 changed files with 4,200 additions and 1,693 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.wso2.carbon.identity.action.execution.impl.ActionExecutionRequestBuilderFactory;
import org.wso2.carbon.identity.action.execution.impl.ActionExecutionResponseProcessorFactory;
import org.wso2.carbon.identity.action.execution.impl.ActionExecutorServiceImpl;
import org.wso2.carbon.identity.action.management.ActionManagementService;
import org.wso2.carbon.identity.action.management.service.ActionManagementService;

/**
* OSGI service component for the Action execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.wso2.carbon.identity.action.execution.internal;

import org.wso2.carbon.identity.action.management.ActionManagementService;
import org.wso2.carbon.identity.action.management.service.ActionManagementService;

/**
* This class holds references for dependent services required for Action Execution Service to function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
import org.wso2.carbon.identity.action.execution.util.ActionExecutionDiagnosticLogger;
import org.wso2.carbon.identity.action.execution.util.ActionExecutorConfig;
import org.wso2.carbon.identity.action.execution.util.RequestFilter;
import org.wso2.carbon.identity.action.management.ActionManagementService;
import org.wso2.carbon.identity.action.management.exception.ActionMgtException;
import org.wso2.carbon.identity.action.management.model.Action;
import org.wso2.carbon.identity.action.management.model.Authentication;
import org.wso2.carbon.identity.action.management.model.EndpointConfig;
import org.wso2.carbon.identity.action.management.service.ActionManagementService;
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;

import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.secret.mgt.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.certificate.management</artifactId>
</dependency>
<dependency>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
Expand All @@ -54,6 +58,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
Expand Down Expand Up @@ -84,19 +89,18 @@
</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Private-Package>
org.wso2.carbon.identity.action.management.internal,
org.wso2.carbon.identity.action.management.cache,
org.wso2.carbon.identity.action.management.dao,
org.wso2.carbon.identity.action.management.dao.impl,
org.wso2.carbon.identity.action.management.constant,
org.wso2.carbon.identity.action.management.dao.*,
org.wso2.carbon.identity.action.management.internal,
org.wso2.carbon.identity.action.management.service.impl,
org.wso2.carbon.identity.action.management.util
</Private-Package>
<Export-Package>
!org.wso2.carbon.identity.action.management.internal,
!org.wso2.carbon.identity.action.management.cache,
!org.wso2.carbon.identity.action.management.dao,
!org.wso2.carbon.identity.action.management.dao.impl,
!org.wso2.carbon.identity.action.management.util,
org.wso2.carbon.identity.action.management.*; version="${carbon.identity.package.export.version}"
org.wso2.carbon.identity.action.management.constant.error,
org.wso2.carbon.identity.action.management.exception,
org.wso2.carbon.identity.action.management.model,
org.wso2.carbon.identity.action.management.service; version="${carbon.identity.package.export.version}"
</Export-Package>
<Import-Package>
org.apache.commons.lang; version="${commons-lang.wso2.osgi.version.range}",
Expand Down Expand Up @@ -175,16 +179,11 @@
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<!-- Temporarily decreasing this.
Will be improved upon in a follow-up effort.
Related issue: https://github.com/wso2/product-is/issues/21368 -->
<minimum>0.70</minimum>
<minimum>0.80</minimum>
</limit>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<!-- Temp decreasing this. There is an ongoing effort to improve
the code complexity coverage. -->
<minimum>0.60</minimum>
</limit>
</limits>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
public class ActionMgtConstants {

public static final String URI_ATTRIBUTE = "uri";
public static final String AUTHN_TYPE_ATTRIBUTE = "authnType";
public static final String URI_PROPERTY = "uri";
public static final String AUTHN_TYPE_PROPERTY = "authnType";
public static final String IDN_SECRET_TYPE_ACTION_SECRETS = "ACTION_API_ENDPOINT_AUTH_SECRETS";

public static final String ACTION_NAME_FIELD = "Action name";
Expand All @@ -36,84 +36,6 @@ public class ActionMgtConstants {
public static final String API_KEY_HEADER_FIELD = "API key header name";
public static final String API_KEY_VALUE_FIELD = "API key value";

/**
* Error messages.
*/
public enum ErrorMessages {

// Client errors.
ERROR_INVALID_ACTION_TYPE("60001", "Invalid action type.",
"Invalid action type used for path parameter."),
ERROR_MAXIMUM_ACTIONS_PER_ACTION_TYPE_REACHED("60002", "Unable to create an Action.",
"Maximum number of actions per action type is reached."),
ERROR_NO_ACTION_CONFIGURED_ON_GIVEN_ACTION_TYPE_AND_ID("60003",
"Unable to perform the operation.",
"No Action is configured on the given Action Type and Id."),
ERROR_EMPTY_ACTION_REQUEST_FIELD("60004", "Invalid request.",
"%s is empty."),
ERROR_INVALID_ACTION_REQUEST_FIELD("60005", "Invalid request.",
"%s is invalid."),

// Server errors.
ERROR_WHILE_ADDING_ACTION("65001", "Error while adding Action.",
"Error while persisting Action in the system."),
ERROR_WHILE_ADDING_ENDPOINT_PROPERTIES("65002", "Error while adding Endpoint properties",
"Error while persisting Action Endpoint properties in the system."),
ERROR_WHILE_RETRIEVING_ACTION_ENDPOINT_PROPERTIES("65003",
"Error while retrieving Action Endpoint properties",
"Error while retrieving Action Endpoint properties from the system."),
ERROR_WHILE_RETRIEVING_ACTIONS_BY_ACTION_TYPE("65004",
"Error while retrieving Actions by Action Type",
"Error while retrieving Actions by Action Type from the system."),
ERROR_WHILE_UPDATING_ENDPOINT_PROPERTIES("65005",
"Error while updating Action Endpoint properties",
"Error while updating Action Endpoint properties in the system."),
ERROR_WHILE_UPDATING_ACTION("65006", "Error while updating Action.",
"Error while updating Action in the system."),
ERROR_WHILE_DELETING_ACTION("65007", "Error while deleting Action.",
"Error while deleting Action from the system."),
ERROR_WHILE_UPDATING_ACTION_STATUS("65008", "Error while updating Action status.",
"Error while updating Action status in the system."),
ERROR_WHILE_RETRIEVING_ACTION_BY_ID("65009", "Error while retrieving Action by ID.",
"Error while retrieving Action from the system."),
ERROR_WHILE_RETRIEVING_ACTIONS_COUNT_PER_TYPE("65010",
"Error while retrieving count of Actions per Action Type.",
"Error while retrieving count of Actions per Action Type from the system."),
ERROR_WHILE_RETRIEVING_ACTION_BASIC_INFO("65011", "Error while retrieving Action basic info.",
"Error while retrieving Action basic info from the system."),
ERROR_WHILE_DECRYPTING_ACTION_ENDPOINT_AUTH_PROPERTIES("65012",
"Error while decrypting Action Endpoint Authentication properties",
"Error while decrypting Action Endpoint Authentication properties in the system."),
ERROR_NO_AUTHENTICATION_TYPE("65013",
"Error while retrieving Action Endpoint Authentication configurations",
"Authentication type is not defined for the Action Endpoint."),
ERROR_WHILE_UPDATING_ACTION_BASIC_INFO("65014", "Error while updating basic Action information",
"Error while updating basic Action information in the system.");

private final String code;
private final String message;
private final String description;

ErrorMessages(String code, String message, String description) {

this.code = code;
this.message = message;
this.description = description;
}

public String getCode() {

return code;
}

public String getMessage() {

return message;
}

public String getDescription() {

return description;
}
private ActionMgtConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ private ActionMgtSQLConstants() {

}

public static final String IDN_ACTION_PROPERTIES_TABLE = "IDN_ACTION_PROPERTIES";
public static final String IDN_ACTION_ENDPOINT_TABLE = "IDN_ACTION_ENDPOINT";

/**
* Column Names.
*/
Expand All @@ -38,9 +41,9 @@ public static class Column {
public static final String ACTION_DESCRIPTION = "DESCRIPTION";
public static final String ACTION_STATUS = "STATUS";
public static final String ACTION_COUNT = "COUNT";
public static final String ACTION_ENDPOINT_UUID = "ACTION_UUID";
public static final String ACTION_ENDPOINT_PROPERTY_NAME = "PROPERTY_NAME";
public static final String ACTION_ENDPOINT_PROPERTY_VALUE = "PROPERTY_VALUE";
public static final String ACTION_PROPERTIES_UUID = "ACTION_UUID";
public static final String ACTION_PROPERTIES_PROPERTY_NAME = "PROPERTY_NAME";
public static final String ACTION_PROPERTIES_PROPERTY_VALUE = "PROPERTY_VALUE";
public static final String TENANT_ID = "TENANT_ID";

private Column() {
Expand All @@ -55,29 +58,42 @@ public static class Query {

public static final String ADD_ACTION_TO_ACTION_TYPE = "INSERT INTO IDN_ACTION (UUID, TYPE, NAME, " +
"DESCRIPTION, STATUS, TENANT_ID) VALUES (:UUID;, :TYPE;, :NAME;, :DESCRIPTION;, :STATUS;, :TENANT_ID;)";
public static final String ADD_ACTION_ENDPOINT_PROPERTIES = "INSERT INTO IDN_ACTION_ENDPOINT (ACTION_UUID, " +
public static final String ADD_ACTION_PROPERTIES = "INSERT INTO IDN_ACTION_PROPERTIES (ACTION_UUID, " +
"PROPERTY_NAME, PROPERTY_VALUE, TENANT_ID) VALUES (:ACTION_UUID;, :PROPERTY_NAME;, :PROPERTY_VALUE;, " +
":TENANT_ID;)";
public static final String GET_ACTION_BASIC_INFO_BY_ID = "SELECT TYPE, NAME, DESCRIPTION, STATUS FROM " +
"IDN_ACTION WHERE TYPE = :TYPE; AND UUID = :UUID; AND TENANT_ID = :TENANT_ID;";
public static final String GET_ACTION_ENDPOINT_INFO_BY_ID = "SELECT PROPERTY_NAME, PROPERTY_VALUE FROM " +
"IDN_ACTION_ENDPOINT WHERE ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String GET_ACTION_PROPERTIES_INFO_BY_ID = "SELECT PROPERTY_NAME, PROPERTY_VALUE FROM " +
"IDN_ACTION_PROPERTIES WHERE ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String GET_ACTIONS_BASIC_INFO_BY_ACTION_TYPE = "SELECT UUID, TYPE, NAME, DESCRIPTION," +
" STATUS FROM IDN_ACTION WHERE TYPE = :TYPE; AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_ACTION_BASIC_INFO = "UPDATE IDN_ACTION SET NAME = :NAME;, DESCRIPTION = " +
":DESCRIPTION; WHERE UUID = :UUID; AND TYPE = :TYPE; AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_ACTION_ENDPOINT_PROPERTIES = "DELETE FROM IDN_ACTION_ENDPOINT WHERE " +
"ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_ACTION_PROPERTY = "DELETE FROM IDN_ACTION_PROPERTIES WHERE " +
"PROPERTY_NAME = :PROPERTY_NAME; AND ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_ACTION = "DELETE FROM IDN_ACTION WHERE UUID = :UUID; AND TYPE = :TYPE;" +
" AND TENANT_ID = :TENANT_ID;";
public static final String CHANGE_ACTION_STATUS = "UPDATE IDN_ACTION SET STATUS = :STATUS; WHERE UUID = " +
":UUID; AND TYPE = :TYPE; AND TENANT_ID = :TENANT_ID;";
public static final String GET_ACTIONS_COUNT_PER_ACTION_TYPE = "SELECT TYPE, COUNT(UUID) AS COUNT" +
" FROM IDN_ACTION WHERE TENANT_ID = :TENANT_ID; GROUP BY TYPE";
public static final String UPDATE_ACTION_ENDPOINT_PROPERTIES = "UPDATE IDN_ACTION_ENDPOINT SET " +
public static final String UPDATE_ACTION_PROPERTY = "UPDATE IDN_ACTION_PROPERTIES SET " +
"PROPERTY_VALUE = :PROPERTY_VALUE; WHERE ACTION_UUID = :ACTION_UUID; AND " +
"TENANT_ID = :TENANT_ID; AND PROPERTY_NAME = :PROPERTY_NAME;";

// TODO: Remove this temporary queries once the IDN_ACTION_PROPERTIES table is created.
public static final String ADD_ACTION_ENDPOINT = "INSERT INTO IDN_ACTION_ENDPOINT (ACTION_UUID, " +
"PROPERTY_NAME, PROPERTY_VALUE, TENANT_ID) VALUES (:ACTION_UUID;, :PROPERTY_NAME;, :PROPERTY_VALUE;, " +
":TENANT_ID;)";
public static final String GET_ACTION_ENDPOINT_INFO_BY_ID = "SELECT PROPERTY_NAME, PROPERTY_VALUE FROM " +
"IDN_ACTION_ENDPOINT WHERE ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String DELETE_ACTION_ENDPOINT_PROPERTY = "DELETE FROM IDN_ACTION_ENDPOINT WHERE " +
"PROPERTY_NAME = :PROPERTY_NAME; AND ACTION_UUID = :ACTION_UUID; AND TENANT_ID = :TENANT_ID;";
public static final String UPDATE_ACTION_ENDPOINT_PROPERTY = "UPDATE IDN_ACTION_ENDPOINT SET " +
"PROPERTY_VALUE = :PROPERTY_VALUE; WHERE ACTION_UUID = :ACTION_UUID; AND " +
"TENANT_ID = :TENANT_ID; AND PROPERTY_NAME = :PROPERTY_NAME;";


private Query() {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.management.constant.error;

/**
* Error messages.
*/
public enum ErrorMessage {

// Client errors.
ERROR_INVALID_ACTION_TYPE("60001", "Invalid action type.",
"Invalid action type used for path parameter."),
ERROR_MAXIMUM_ACTIONS_PER_ACTION_TYPE_REACHED("60002", "Unable to create an Action.",
"Maximum number of actions per action type is reached."),
ERROR_NO_ACTION_CONFIGURED_ON_GIVEN_ACTION_TYPE_AND_ID("60003", "Unable to perform the operation.",
"No Action is configured on the given Action Type and Id."),
ERROR_EMPTY_ACTION_REQUEST_FIELD("60004", "Invalid request.", "%s is empty."),
ERROR_INVALID_ACTION_REQUEST_FIELD("60005", "Invalid request.", "%s is invalid."),
ERROR_INVALID_ACTION_PROPERTIES("60006", "Provided Action Properties are invalid.", "%s"),

// Server errors.
ERROR_WHILE_ADDING_ACTION("65001", "Error while adding Action.",
"Error while persisting Action in the system."),
ERROR_WHILE_RETRIEVING_ACTIONS_BY_ACTION_TYPE("65002",
"Error while retrieving Actions by Action Type",
"Error while retrieving Actions by Action Type from the system."),
ERROR_WHILE_RETRIEVING_ACTION_BY_ID("65003", "Error while retrieving Action by ID.",
"Error while retrieving Action from the system."),
ERROR_WHILE_UPDATING_ACTION("65004", "Error while updating Action.",
"Error while updating Action in the system."),
ERROR_WHILE_DELETING_ACTION("65005", "Error while deleting Action.",
"Error while deleting Action from the system."),
ERROR_WHILE_ACTIVATING_ACTION("65006", "Error while activating Action.",
"Error while updating Action status to ACTIVE."),
ERROR_WHILE_DEACTIVATING_ACTION("65007", "Error while deactivating Action.",
"Error while updating Action status to INACTIVE."),
ERROR_WHILE_RETRIEVING_ACTIONS_COUNT_PER_TYPE("65008",
"Error while retrieving count of Actions per Action Type.",
"Error while retrieving count of Actions per Action Type from the system."),
ERROR_WHILE_DECRYPTING_ACTION_ENDPOINT_AUTH_PROPERTIES("65009",
"Error while decrypting Action Endpoint Authentication properties",
"Error while decrypting Action Endpoint Authentication properties in the system.");

private final String code;
private final String message;
private final String description;

ErrorMessage(String code, String message, String description) {

this.code = code;
this.message = message;
this.description = description;
}

public String getCode() {

return code;
}

public String getMessage() {

return message;
}

public String getDescription() {

return description;
}
}
Loading

0 comments on commit c6d4e92

Please sign in to comment.