diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/pom.xml b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/pom.xml index 8c64972ed9..aea3420d7c 100644 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/pom.xml @@ -44,11 +44,6 @@ - - org.springframework - spring-web - provided - javax.ws.rs javax.ws.rs-api diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/src/main/java/org/wso2/carbon/identity/api/server/action/management/common/ActionManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/src/main/java/org/wso2/carbon/identity/api/server/action/management/common/ActionManagementServiceHolder.java index 29b0acfadf..8c5f89a6e7 100644 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/src/main/java/org/wso2/carbon/identity/api/server/action/management/common/ActionManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/src/main/java/org/wso2/carbon/identity/api/server/action/management/common/ActionManagementServiceHolder.java @@ -18,6 +18,7 @@ package org.wso2.carbon.identity.api.server.action.management.common; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.action.management.service.ActionManagementService; /** @@ -25,25 +26,21 @@ */ public class ActionManagementServiceHolder { - private static ActionManagementService actionManagementService; + private ActionManagementServiceHolder() {} - /** - * Get ActionManagementService osgi service. - * - * @return ActionManagementService. - */ - public static ActionManagementService getActionManagementService() { + private static class ServiceHolder { - return actionManagementService; + static final ActionManagementService SERVICE = (ActionManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(ActionManagementService.class, null); } /** - * Set ActionManagementService osgi service. + * Get ActionManagementService osgi service. * - * @param actionManagementService ActionManagementService. + * @return ActionManagementService. */ - public static void setActionManagementService(ActionManagementService actionManagementService) { + public static ActionManagementService getActionManagementService() { - ActionManagementServiceHolder.actionManagementService = actionManagementService; + return ServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/src/main/java/org/wso2/carbon/identity/api/server/action/management/common/factory/ActionMgtOSGiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/src/main/java/org/wso2/carbon/identity/api/server/action/management/common/factory/ActionMgtOSGiServiceFactory.java deleted file mode 100644 index 0b9059d145..0000000000 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.common/src/main/java/org/wso2/carbon/identity/api/server/action/management/common/factory/ActionMgtOSGiServiceFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.api.server.action.management.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.action.management.service.ActionManagementService; - -/** - * Factory class for ActionManagementOSGiService. - */ -public class ActionMgtOSGiServiceFactory extends AbstractFactoryBean { - - private ActionManagementService actionManagementService; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected ActionManagementService createInstance() throws Exception { - - if (this.actionManagementService == null) { - actionManagementService = (ActionManagementService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(ActionManagementService.class, null); - if (actionManagementService == null) { - throw new Exception("Action Management Service is not available."); - } - } - return this.actionManagementService; - } -} diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/pom.xml index 4c68c06ed2..fb140c983b 100644 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/pom.xml @@ -88,11 +88,6 @@ - - org.springframework - spring-web - provided - org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.common diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/ActionsApi.java b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/ActionsApi.java index 84d0e7cecd..6c6cc843a0 100644 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/ActionsApi.java +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/ActionsApi.java @@ -18,7 +18,6 @@ package org.wso2.carbon.identity.api.server.action.management.v1; -import org.springframework.beans.factory.annotation.Autowired; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import java.io.InputStream; @@ -36,16 +35,19 @@ import javax.ws.rs.*; import javax.ws.rs.core.Response; import io.swagger.annotations.*; - -import javax.validation.constraints.*; +import org.wso2.carbon.identity.api.server.action.management.v1.factories.ActionsApiServiceFactory; @Path("/actions") @Api(description = "The actions API") public class ActionsApi { - @Autowired - private ActionsApiService delegate; + private final ActionsApiService delegate; + + public ActionsApi() { + + this.delegate = ActionsApiServiceFactory.getActionsApi(); + } @Valid @POST diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/factories/ActionsApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/factories/ActionsApiServiceFactory.java index a004542f2d..7635c3e7ac 100644 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/factories/ActionsApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/action/management/v1/factories/ActionsApiServiceFactory.java @@ -21,12 +21,20 @@ import org.wso2.carbon.identity.api.server.action.management.v1.ActionsApiService; import org.wso2.carbon.identity.api.server.action.management.v1.impl.ActionsApiServiceImpl; +/** + * Factory class for Actions API Service. + */ public class ActionsApiServiceFactory { - private final static ActionsApiService service = new ActionsApiServiceImpl(); + private static final ActionsApiService SERVICE = new ActionsApiServiceImpl(); + + /** + * Get Actions API Service. + * + * @return ActionsApiService. + */ + public static ActionsApiService getActionsApi() { - public static ActionsApiService getActionsApi() - { - return service; + return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/core/ServerActionManagementService.java b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/core/ServerActionManagementService.java index a2011a9f80..60d2edd722 100644 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/core/ServerActionManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/core/ServerActionManagementService.java @@ -27,7 +27,7 @@ import org.wso2.carbon.identity.action.management.model.ActionRule; import org.wso2.carbon.identity.action.management.model.Authentication; import org.wso2.carbon.identity.action.management.model.EndpointConfig; -import org.wso2.carbon.identity.api.server.action.management.common.ActionManagementServiceHolder; +import org.wso2.carbon.identity.action.management.service.ActionManagementService; import org.wso2.carbon.identity.api.server.action.management.v1.ActionBasicResponse; import org.wso2.carbon.identity.api.server.action.management.v1.ActionModel; import org.wso2.carbon.identity.api.server.action.management.v1.ActionResponse; @@ -61,9 +61,15 @@ */ public class ServerActionManagementService { + private final ActionManagementService actionManagementService; private static final Log LOG = LogFactory.getLog(ServerActionManagementService.class); private static final Set NOT_IMPLEMENTED_ACTION_TYPES = new HashSet<>(); + public ServerActionManagementService(ActionManagementService actionManagementService) { + + this.actionManagementService = actionManagementService; + } + static { NOT_IMPLEMENTED_ACTION_TYPES.add(Action.ActionTypes.PRE_UPDATE_PASSWORD.getPathParam()); NOT_IMPLEMENTED_ACTION_TYPES.add(Action.ActionTypes.PRE_UPDATE_PROFILE.getPathParam()); @@ -76,8 +82,8 @@ public ActionResponse createAction(String actionType, ActionModel actionModel) { try { Action.ActionTypes validatedActionType = validateActionType(actionType); String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); - return buildActionResponse(ActionManagementServiceHolder.getActionManagementService() - .addAction(actionType, buildAction(validatedActionType, actionModel, tenantDomain), tenantDomain)); + return buildActionResponse(actionManagementService.addAction(actionType, buildAction(validatedActionType, + actionModel, tenantDomain), tenantDomain)); } catch (ActionMgtException e) { throw ActionMgtEndpointUtil.handleActionMgtException(e); } @@ -87,9 +93,8 @@ public List getActionsByActionType(String actionType) { try { validateActionType(actionType); - List actions = ActionManagementServiceHolder.getActionManagementService() - .getActionsByActionType(actionType, - CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + List actions = actionManagementService.getActionsByActionType(actionType, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); List actionBasicResponses = new ArrayList<>(); for (Action action : actions) { @@ -105,16 +110,14 @@ public ActionResponse getActionByActionId(String actionType, String actionId) { try { validateActionType(actionType); - Action action = ActionManagementServiceHolder.getActionManagementService() - .getActionByActionId(actionType, actionId, + Action action = actionManagementService.getActionByActionId(actionType, actionId, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); if (action == null) { throw ActionMgtEndpointUtil.handleException(Response.Status.NOT_FOUND, ERROR_NO_ACTION_FOUND_ON_GIVEN_ACTION_TYPE_AND_ID); } - return buildActionResponse(ActionManagementServiceHolder.getActionManagementService() - .getActionByActionId(actionType, actionId, - CarbonContext.getThreadLocalCarbonContext().getTenantDomain())); + return buildActionResponse(actionManagementService.getActionByActionId(actionType, actionId, + CarbonContext.getThreadLocalCarbonContext().getTenantDomain())); } catch (ActionMgtException e) { throw ActionMgtEndpointUtil.handleActionMgtException(e); } @@ -125,8 +128,7 @@ public ActionResponse updateAction(String actionType, String actionId, ActionUpd try { Action.ActionTypes validatedActionType = validateActionType(actionType); String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); - return buildActionResponse(ActionManagementServiceHolder.getActionManagementService() - .updateAction(actionType, actionId, + return buildActionResponse(actionManagementService.updateAction(actionType, actionId, buildUpdatingAction(validatedActionType, actionUpdateModel, tenantDomain), tenantDomain)); } catch (ActionMgtException e) { throw ActionMgtEndpointUtil.handleActionMgtException(e); @@ -137,8 +139,8 @@ public void deleteAction(String actionType, String actionId) { try { validateActionType(actionType); - ActionManagementServiceHolder.getActionManagementService().deleteAction(actionType, actionId, - CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + actionManagementService.deleteAction(actionType, actionId, CarbonContext.getThreadLocalCarbonContext() + .getTenantDomain()); } catch (ActionMgtException e) { throw ActionMgtEndpointUtil.handleActionMgtException(e); } @@ -148,8 +150,7 @@ public ActionBasicResponse activateAction(String actionType, String actionId) { try { validateActionType(actionType); - return buildActionBasicResponse(ActionManagementServiceHolder.getActionManagementService() - .activateAction(actionType, actionId, + return buildActionBasicResponse(actionManagementService.activateAction(actionType, actionId, CarbonContext.getThreadLocalCarbonContext().getTenantDomain())); } catch (ActionMgtException e) { throw ActionMgtEndpointUtil.handleActionMgtException(e); @@ -160,8 +161,7 @@ public ActionBasicResponse deactivateAction(String actionType, String actionId) try { validateActionType(actionType); - return buildActionBasicResponse(ActionManagementServiceHolder.getActionManagementService() - .deactivateAction(actionType, actionId, + return buildActionBasicResponse(actionManagementService.deactivateAction(actionType, actionId, CarbonContext.getThreadLocalCarbonContext().getTenantDomain())); } catch (ActionMgtException e) { throw ActionMgtEndpointUtil.handleActionMgtException(e); @@ -174,8 +174,8 @@ public List getActionTypes() { LOG.debug("Retrieving Action Types."); } try { - Map actionsCountPerType = ActionManagementServiceHolder.getActionManagementService() - .getActionsCountPerType(CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + Map actionsCountPerType = actionManagementService.getActionsCountPerType(CarbonContext + .getThreadLocalCarbonContext().getTenantDomain()); List actionTypesResponseItems = new ArrayList<>(); for (Action.ActionTypes actionType : Action.ActionTypes.filterByCategory( diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/factories/ActionManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/factories/ActionManagementServiceFactory.java new file mode 100644 index 0000000000..5de118d8fa --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/factories/ActionManagementServiceFactory.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025, 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.api.server.action.management.v1.factories; + +import org.wso2.carbon.identity.action.management.service.ActionManagementService; +import org.wso2.carbon.identity.api.server.action.management.common.ActionManagementServiceHolder; +import org.wso2.carbon.identity.api.server.action.management.v1.core.ServerActionManagementService; + +/** + * Factory class for Action Management Service. + */ +public class ActionManagementServiceFactory { + + private static final ServerActionManagementService SERVICE; + + static { + ActionManagementService actionManagementService = ActionManagementServiceHolder.getActionManagementService(); + + if (actionManagementService == null) { + throw new IllegalStateException("ActionManagementService is not available from OSGi context."); + } + + SERVICE = new ServerActionManagementService(actionManagementService); + } + + /** + * Get Action Management Service. + * + * @return ServerActionManagementService. + */ + public static ServerActionManagementService getActionManagementService() { + + return SERVICE; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/impl/ActionsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/impl/ActionsApiServiceImpl.java index ab6960b45b..89b6f1390b 100644 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/impl/ActionsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/java/org/wso2/carbon/identity/api/server/action/management/v1/impl/ActionsApiServiceImpl.java @@ -18,13 +18,13 @@ package org.wso2.carbon.identity.api.server.action.management.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.server.action.management.v1.ActionModel; import org.wso2.carbon.identity.api.server.action.management.v1.ActionResponse; import org.wso2.carbon.identity.api.server.action.management.v1.ActionUpdateModel; import org.wso2.carbon.identity.api.server.action.management.v1.ActionsApiService; import org.wso2.carbon.identity.api.server.action.management.v1.constants.ActionMgtEndpointConstants; import org.wso2.carbon.identity.api.server.action.management.v1.core.ServerActionManagementService; +import org.wso2.carbon.identity.api.server.action.management.v1.factories.ActionManagementServiceFactory; import org.wso2.carbon.identity.api.server.common.ContextLoader; import java.net.URI; @@ -38,8 +38,16 @@ */ public class ActionsApiServiceImpl implements ActionsApiService { - @Autowired - ServerActionManagementService serverActionManagementService; + private final ServerActionManagementService serverActionManagementService; + + public ActionsApiServiceImpl() { + + try { + this.serverActionManagementService = ActionManagementServiceFactory.getActionManagementService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating server action management service.", e); + } + } @Override public Response activateAction(String actionType, String actionId) { diff --git a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/resources/META-INF/cxf/action-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/resources/META-INF/cxf/action-server-v1-cxf.xml deleted file mode 100644 index e7afa6af90..0000000000 --- a/components/org.wso2.carbon.identity.api.server.action.management/org.wso2.carbon.identity.api.server.action.management.v1/src/main/resources/META-INF/cxf/action-server-v1-cxf.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - -