Skip to content

Commit

Permalink
[Spring Cleanup] Remove Spring dependencies in action management API (#…
Browse files Browse the repository at this point in the history
…684)

* Remove Spring dependencies in action management API

* Resolve PR comments
  • Loading branch information
NipuniBhagya authored Dec 9, 2024
1 parent ebd5681 commit 948fe0b
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
</build>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@

package org.wso2.carbon.identity.api.server.action.management.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.action.management.ActionManagementService;

/**
* Service holder class for action management.
*/
public class ActionManagementServiceHolder {

private static ActionManagementService actionManagementService;
private ActionManagementServiceHolder() {}

private static class ActionServiceHolder {
static final ActionManagementService SERVICE = (ActionManagementService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(ActionManagementService.class, null);
}

/**
* Get ActionManagementService osgi service.
Expand All @@ -34,16 +40,6 @@ public class ActionManagementServiceHolder {
*/
public static ActionManagementService getActionManagementService() {

return actionManagementService;
}

/**
* Set ActionManagementService osgi service.
*
* @param actionManagementService ActionManagementService.
*/
public static void setActionManagementService(ActionManagementService actionManagementService) {

ActionManagementServiceHolder.actionManagementService = actionManagementService;
return ActionServiceHolder.SERVICE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.server.api</groupId>
<artifactId>org.wso2.carbon.identity.api.server.common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,23 @@

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;
import java.util.List;

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;
import org.wso2.carbon.identity.api.server.action.management.v1.ActionTypesResponseItem;
import org.wso2.carbon.identity.api.server.action.management.v1.ActionUpdateModel;
import org.wso2.carbon.identity.api.server.action.management.v1.AuthenticationTypeProperties;
import org.wso2.carbon.identity.api.server.action.management.v1.Error;
import org.wso2.carbon.identity.api.server.action.management.v1.ActionsApiService;

import javax.validation.Valid;
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 final static ActionsApiService SERVICE = new ActionsApiServiceImpl();

/**
* Get Actions API Service.
*
* @return ActionsApiService.
*/
public static ActionsApiService getActionsApi()
{
return service;
return SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
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.api.server.action.management.common.ActionManagementServiceHolder;
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;
Expand Down Expand Up @@ -58,9 +58,15 @@
*/
public class ServerActionManagementService {

private final ActionManagementService actionManagementService;
private static final Log LOG = LogFactory.getLog(ServerActionManagementService.class);
private static final Set<String> 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());
Expand All @@ -72,9 +78,8 @@ public ActionResponse createAction(String actionType, ActionModel actionModel) {

try {
handleNotImplementedActionTypes(actionType);
return buildActionResponse(ActionManagementServiceHolder.getActionManagementService()
.addAction(actionType, buildAction(actionModel),
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
return buildActionResponse(actionManagementService.addAction(actionType, buildAction(actionModel),
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
} catch (ActionMgtException e) {
throw ActionMgtEndpointUtil.handleActionMgtException(e);
}
Expand All @@ -84,9 +89,8 @@ public List<ActionResponse> getActionsByActionType(String actionType) {

try {
handleNotImplementedActionTypes(actionType);
List<Action> actions = ActionManagementServiceHolder.getActionManagementService()
.getActionsByActionType(actionType,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
List<Action> actions = actionManagementService.getActionsByActionType(actionType,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());

List<ActionResponse> actionResponses = new ArrayList<>();
for (Action action : actions) {
Expand All @@ -102,16 +106,14 @@ public ActionResponse getActionByActionId(String actionType, String actionId) {

try {
handleNotImplementedActionTypes(actionType);
Action action = ActionManagementServiceHolder.getActionManagementService()
.getActionByActionId(actionType, actionId,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
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);
}
Expand All @@ -121,9 +123,9 @@ public ActionResponse updateAction(String actionType, String actionId, ActionUpd

try {
handleNotImplementedActionTypes(actionType);
return buildActionResponse(ActionManagementServiceHolder.getActionManagementService()
.updateAction(actionType, actionId, buildUpdatingAction(actionUpdateModel),
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
return buildActionResponse(actionManagementService.updateAction(actionType, actionId,
buildUpdatingAction(actionUpdateModel),
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
} catch (ActionMgtException e) {
throw ActionMgtEndpointUtil.handleActionMgtException(e);
}
Expand All @@ -133,7 +135,7 @@ public void deleteAction(String actionType, String actionId) {

try {
handleNotImplementedActionTypes(actionType);
ActionManagementServiceHolder.getActionManagementService().deleteAction(actionType, actionId,
actionManagementService.deleteAction(actionType, actionId,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
} catch (ActionMgtException e) {
throw ActionMgtEndpointUtil.handleActionMgtException(e);
Expand All @@ -144,9 +146,8 @@ public ActionBasicResponse activateAction(String actionType, String actionId) {

try {
handleNotImplementedActionTypes(actionType);
return buildActionBasicResponse(ActionManagementServiceHolder.getActionManagementService()
.activateAction(actionType, actionId,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
return buildActionBasicResponse(actionManagementService.activateAction(actionType, actionId,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
} catch (ActionMgtException e) {
throw ActionMgtEndpointUtil.handleActionMgtException(e);
}
Expand All @@ -156,9 +157,8 @@ public ActionBasicResponse deactivateAction(String actionType, String actionId)

try {
handleNotImplementedActionTypes(actionType);
return buildActionBasicResponse(ActionManagementServiceHolder.getActionManagementService()
.deactivateAction(actionType, actionId,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
return buildActionBasicResponse(actionManagementService.deactivateAction(actionType, actionId,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
} catch (ActionMgtException e) {
throw ActionMgtEndpointUtil.handleActionMgtException(e);
}
Expand All @@ -170,8 +170,8 @@ public List<ActionTypesResponseItem> getActionTypes() {
LOG.debug("Retrieving Action Types.");
}
try {
Map<String, Integer> actionsCountPerType = ActionManagementServiceHolder.getActionManagementService()
.getActionsCountPerType(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
Map<String, Integer> actionsCountPerType = actionManagementService.getActionsCountPerType(CarbonContext
.getThreadLocalCarbonContext().getTenantDomain());

List<ActionTypesResponseItem> actionTypesResponseItems = new ArrayList<>();
for (Action.ActionTypes actionType : Action.ActionTypes.values()) {
Expand All @@ -193,15 +193,15 @@ public List<ActionTypesResponseItem> getActionTypes() {
}

public ActionResponse updateActionEndpointAuthentication(String actionType, String actionId, String authType,
AuthenticationTypeProperties authenticationTypeProperties) {
AuthenticationTypeProperties authenticationTypeProperties) {

try {
handleNotImplementedActionTypes(actionType);
Authentication authentication = buildAuthentication(getAuthTypeFromPath(authType),
authenticationTypeProperties.getProperties());
return buildActionResponse(ActionManagementServiceHolder.getActionManagementService()
.updateActionEndpointAuthentication(actionType, actionId, authentication,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
return buildActionResponse(actionManagementService.updateActionEndpointAuthentication(actionType,
actionId, authentication,
CarbonContext.getThreadLocalCarbonContext().getTenantDomain()));
} catch (ActionMgtException e) {
throw ActionMgtEndpointUtil.handleActionMgtException(e);
}
Expand Down Expand Up @@ -299,7 +299,7 @@ private Action buildUpdatingAction(ActionUpdateModel actionUpdateModel) {
/**
* Get Authentication object from the Authentication Type and Authentication properties.
*
* @param authType Authentication Type.
* @param authType Authentication Type.
* @param authPropertiesMap Authentication properties.
* @return Authentication object.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.v1.factories;

import org.wso2.carbon.identity.action.management.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;
}
}
Loading

0 comments on commit 948fe0b

Please sign in to comment.