summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-item-permissions-manager
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-item-permissions-manager')
-rw-r--r--openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManager.java18
-rw-r--r--openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManagerFactory.java9
-rw-r--r--openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerFactoryImpl.java9
-rw-r--r--openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerImpl.java243
4 files changed, 127 insertions, 152 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManager.java b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManager.java
index a7e8ca549d..d5e8ce0342 100644
--- a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManager.java
+++ b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManager.java
@@ -15,29 +15,25 @@
*/
package org.openecomp.sdc.itempermissions;
-import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
-
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
/**
* Created by ayalaben on 6/18/2017.
*/
public interface PermissionsManager {
- Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
-
- Set<String> listUserPermittedItems(String userId, String permission);
-
- void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds);
+ Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
- boolean isAllowed(String itemId, String userId, String action);
+ Set<String> listUserPermittedItems(String userId, String permission);
- Optional<String> getUserItemPermission(String itemId, String userId);
+ void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds);
- void deleteItemPermissions(String itemId);
+ boolean isAllowed(String itemId, String userId, String action);
+ Optional<String> getUserItemPermission(String itemId, String userId);
+ void deleteItemPermissions(String itemId);
}
diff --git a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManagerFactory.java b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManagerFactory.java
index 0353e5ce03..f37ccf9214 100644
--- a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManagerFactory.java
+++ b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/PermissionsManagerFactory.java
@@ -21,10 +21,9 @@ import org.openecomp.core.factory.api.AbstractFactory;
/**
* Created by ayalaben on 6/18/2017.
*/
-public abstract class PermissionsManagerFactory extends
- AbstractComponentFactory<PermissionsManager> {
+public abstract class PermissionsManagerFactory extends AbstractComponentFactory<PermissionsManager> {
- public static PermissionsManagerFactory getInstance() {
- return AbstractFactory.getInstance(PermissionsManagerFactory.class);
- }
+ public static PermissionsManagerFactory getInstance() {
+ return AbstractFactory.getInstance(PermissionsManagerFactory.class);
+ }
}
diff --git a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerFactoryImpl.java
index 14539b0fa1..3848b7c9a4 100644
--- a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerFactoryImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerFactoryImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao.impl;
import org.openecomp.sdc.itempermissions.PermissionsManager;
@@ -28,11 +27,9 @@ import org.openecomp.sdc.versioning.AsdcItemManagerFactory;
*/
public class PermissionsManagerFactoryImpl extends PermissionsManagerFactory {
- private static final PermissionsManager INSTANCE =
- new PermissionsManagerImpl(PermissionsServicesFactory.getInstance().createInterface(),
- AsdcItemManagerFactory.getInstance().createInterface(),
- NotificationPropagationManagerFactory.getInstance().createInterface(),
- SubscriptionServiceFactory.getInstance().createInterface());
+ private static final PermissionsManager INSTANCE = new PermissionsManagerImpl(PermissionsServicesFactory.getInstance().createInterface(),
+ AsdcItemManagerFactory.getInstance().createInterface(), NotificationPropagationManagerFactory.getInstance().createInterface(),
+ SubscriptionServiceFactory.getInstance().createInterface());
@Override
public PermissionsManager createInterface() {
diff --git a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerImpl.java b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerImpl.java
index 90b39bea6f..68edb21fd8 100644
--- a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsManagerImpl.java
@@ -13,9 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao.impl;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.ITEM_ID_PROP;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.ITEM_NAME_PROP;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_CHANGED;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_GRANTED;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_ITEM;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
@@ -33,158 +44,130 @@ import org.openecomp.sdc.notification.services.SubscriptionService;
import org.openecomp.sdc.versioning.AsdcItemManager;
import org.openecomp.sdc.versioning.types.Item;
-import java.util.*;
-
-import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.*;
-
/**
* Created by ayalaben on 6/18/2017.
*/
public class PermissionsManagerImpl implements PermissionsManager {
- private static final Logger LOGGER = LoggerFactory.getLogger(PermissionsManagerImpl.class);
- private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
-
- private PermissionsServices permissionsServices;
- private AsdcItemManager asdcItemManager;
- private NotificationPropagationManager notifier;
- private SubscriptionService subscriptionService;
-
- public PermissionsManagerImpl(PermissionsServices permissionsServices,
- AsdcItemManager asdcItemManager,
- NotificationPropagationManager notificationPropagationManager,
- SubscriptionService subscriptionService) {
- this.permissionsServices = permissionsServices;
- this.asdcItemManager = asdcItemManager;
- this.notifier = notificationPropagationManager;
- this.subscriptionService = subscriptionService;
- }
-
- @Override
- public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) {
-
- return permissionsServices.listItemPermissions(itemId);
- }
-
- @Override
- public Set<String> listUserPermittedItems(String userId, String permission) {
- return permissionsServices.listUserPermittedItems(userId,permission);
- }
-
- @Override
- public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds) {
-
- String currentUser =
- SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
-
- if (!permissionsServices.isAllowed(itemId, currentUser, CHANGE_PERMISSIONS)) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage(Messages.PERMISSIONS_ERROR.getErrorMessage())
- .withId(Messages.PERMISSIONS_ERROR.name())
- .withCategory(ErrorCategory.SECURITY).build());
+ private static final Logger LOGGER = LoggerFactory.getLogger(PermissionsManagerImpl.class);
+ private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
+ private PermissionsServices permissionsServices;
+ private AsdcItemManager asdcItemManager;
+ private NotificationPropagationManager notifier;
+ private SubscriptionService subscriptionService;
+
+ public PermissionsManagerImpl(PermissionsServices permissionsServices, AsdcItemManager asdcItemManager,
+ NotificationPropagationManager notificationPropagationManager, SubscriptionService subscriptionService) {
+ this.permissionsServices = permissionsServices;
+ this.asdcItemManager = asdcItemManager;
+ this.notifier = notificationPropagationManager;
+ this.subscriptionService = subscriptionService;
}
- if (permission.equals(PermissionTypes.Owner.name()) ){
- if (addedUsersIds.size() == 1){
- asdcItemManager.updateOwner(itemId,addedUsersIds.iterator().next());
- } else {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage(Messages.PERMISSIONS_OWNER_ERROR.getErrorMessage())
- .withId(Messages.PERMISSIONS_OWNER_ERROR.name())
- .withCategory(ErrorCategory.SECURITY).build());
- }
+ @Override
+ public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) {
+ return permissionsServices.listItemPermissions(itemId);
}
- permissionsServices
- .updateItemPermissions(itemId, permission, addedUsersIds, removedUsersIds);
-
- sendNotifications(itemId, permission, addedUsersIds, removedUsersIds, currentUser);
- }
-
- private void sendNotifications(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds, String userName) {
-
- Item item = asdcItemManager.get(itemId);
- addedUsersIds.forEach(affectedUser -> {
- notifyUser(userName, true, item.getName(), itemId, affectedUser, permission);
- subscriptionService.subscribe(affectedUser, itemId);
- });
- removedUsersIds.forEach(affectedUser -> {
- notifyUser(userName, false, item.getName(), itemId, affectedUser, permission);
- subscriptionService.unsubscribe(affectedUser, itemId);
- });
-
- }
-
- private void notifyUser(String userName, boolean granted, String itemName, String itemId,
- String affectedUser, String permission) {
- Map<String, Object> details = new HashMap<>();
- details.put(PERMISSION_ITEM, permission);
- details.put(ITEM_ID_PROP, itemId);
- details.put(ITEM_NAME_PROP, itemName);
- details.put(PERMISSION_GRANTED, granted);
- details.put(PERMISSION_USER, userName);
- PermissionEvent permissionEvent = new PermissionEvent(PERMISSION_CHANGED, affectedUser,
- details, affectedUser);
-
- try {
- notifier.directNotification(permissionEvent, affectedUser);
- } catch (Exception e) {
- LOGGER.error("Failed to send notification on permission changed for user '" +
- affectedUser + "'");
+ @Override
+ public Set<String> listUserPermittedItems(String userId, String permission) {
+ return permissionsServices.listUserPermittedItems(userId, permission);
}
- }
-
- @Override
- public boolean isAllowed(String itemId, String userId, String action) {
- return permissionsServices.isAllowed(itemId, userId, action);
- }
-
- @Override
- public Optional<String> getUserItemPermission(String itemId, String userId) {
- return permissionsServices.getUserItemPermission(itemId, userId);
- }
-
- @Override
- public void deleteItemPermissions(String itemId) {
- permissionsServices.deleteItemPermissions(itemId);
- }
-
- private class PermissionEvent implements Event {
+ @Override
+ public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds) {
+ String currentUser = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
+ if (!permissionsServices.isAllowed(itemId, currentUser, CHANGE_PERMISSIONS)) {
+ throw new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withMessage(Messages.PERMISSIONS_ERROR.getErrorMessage()).withId(Messages.PERMISSIONS_ERROR.name())
+ .withCategory(ErrorCategory.SECURITY).build());
+ }
+ if (permission.equals(PermissionTypes.Owner.name())) {
+ if (addedUsersIds.size() == 1) {
+ asdcItemManager.updateOwner(itemId, addedUsersIds.iterator().next());
+ } else {
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(Messages.PERMISSIONS_OWNER_ERROR.getErrorMessage())
+ .withId(Messages.PERMISSIONS_OWNER_ERROR.name()).withCategory(ErrorCategory.SECURITY).build());
+ }
+ }
+ permissionsServices.updateItemPermissions(itemId, permission, addedUsersIds, removedUsersIds);
+ sendNotifications(itemId, permission, addedUsersIds, removedUsersIds, currentUser);
+ }
- private String eventType;
- private String originatorId;
- private Map<String, Object> attributes;
- private String entityId;
+ private void sendNotifications(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds, String userName) {
+ Item item = asdcItemManager.get(itemId);
+ addedUsersIds.forEach(affectedUser -> {
+ notifyUser(userName, true, item.getName(), itemId, affectedUser, permission);
+ subscriptionService.subscribe(affectedUser, itemId);
+ });
+ removedUsersIds.forEach(affectedUser -> {
+ notifyUser(userName, false, item.getName(), itemId, affectedUser, permission);
+ subscriptionService.unsubscribe(affectedUser, itemId);
+ });
+ }
- private PermissionEvent(String eventType, String originatorId,
- Map<String, Object> attributes, String entityId) {
- this.eventType = eventType;
- this.originatorId = originatorId;
- this.attributes = attributes;
- this.entityId = entityId;
+ private void notifyUser(String userName, boolean granted, String itemName, String itemId, String affectedUser, String permission) {
+ Map<String, Object> details = new HashMap<>();
+ details.put(PERMISSION_ITEM, permission);
+ details.put(ITEM_ID_PROP, itemId);
+ details.put(ITEM_NAME_PROP, itemName);
+ details.put(PERMISSION_GRANTED, granted);
+ details.put(PERMISSION_USER, userName);
+ PermissionEvent permissionEvent = new PermissionEvent(PERMISSION_CHANGED, affectedUser, details, affectedUser);
+ try {
+ notifier.directNotification(permissionEvent, affectedUser);
+ } catch (Exception e) {
+ LOGGER.error("Failed to send notification on permission changed for user '" + affectedUser + "'");
+ }
}
@Override
- public String getEventType() {
- return eventType;
+ public boolean isAllowed(String itemId, String userId, String action) {
+ return permissionsServices.isAllowed(itemId, userId, action);
}
@Override
- public String getOriginatorId() {
- return originatorId;
+ public Optional<String> getUserItemPermission(String itemId, String userId) {
+ return permissionsServices.getUserItemPermission(itemId, userId);
}
@Override
- public Map<String, Object> getAttributes() {
- return attributes;
+ public void deleteItemPermissions(String itemId) {
+ permissionsServices.deleteItemPermissions(itemId);
}
- @Override
- public String getEntityId() {
- return entityId;
+ private class PermissionEvent implements Event {
+
+ private String eventType;
+ private String originatorId;
+ private Map<String, Object> attributes;
+ private String entityId;
+
+ private PermissionEvent(String eventType, String originatorId, Map<String, Object> attributes, String entityId) {
+ this.eventType = eventType;
+ this.originatorId = originatorId;
+ this.attributes = attributes;
+ this.entityId = entityId;
+ }
+
+ @Override
+ public String getEventType() {
+ return eventType;
+ }
+
+ @Override
+ public String getOriginatorId() {
+ return originatorId;
+ }
+
+ @Override
+ public Map<String, Object> getAttributes() {
+ return attributes;
+ }
+
+ @Override
+ public String getEntityId() {
+ return entityId;
+ }
}
- }
}