use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testUpdateForbidden.
@Test
public void testUpdateForbidden() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.NO_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
UUID configId = UUID.randomUUID();
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.update(model);
assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalCrudActionsTestIT method init.
@BeforeEach
public void init() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.JIRA_SERVER;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class RoleActions method updateWithoutChecks.
@Override
protected ActionResponse<RolePermissionModel> updateWithoutChecks(Long id, RolePermissionModel resource) {
try {
String roleName = resource.getRoleName();
Optional<UserRoleModel> existingRole = roleAccessor.getRoles(List.of(id)).stream().findFirst();
if (existingRole.isPresent()) {
logger.debug(actionMessageCreator.updateStartMessage("role", existingRole.get().getName()));
if (!existingRole.get().getName().equals(roleName)) {
authorizationManager.updateRoleName(id, roleName);
}
Set<PermissionModel> permissions = resource.getPermissions();
PermissionMatrixModel permissionMatrixModel = PermissionModelUtil.convertToPermissionMatrixModel(permissions);
authorizationManager.updatePermissionsForRole(roleName, permissionMatrixModel);
logger.debug(actionMessageCreator.updateSuccessMessage("Role", roleName));
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
logger.warn(actionMessageCreator.updateNotFoundMessage("Role", id));
return new ActionResponse<>(HttpStatus.NOT_FOUND, "Role not found.");
} catch (AlertException ex) {
logger.error(actionMessageCreator.updateErrorMessage("role", resource.getRoleName()));
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
Aggregations