use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testUpdateNotFound.
@Test
public void testUpdateNotFound() {
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.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
UUID configId = UUID.randomUUID();
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(emailGlobalConfigAccessor.getConfiguration()).thenReturn(Optional.empty());
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.NOT_FOUND, response.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testGetOne.
@Test
public void testGetOne() {
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.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
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");
Mockito.when(emailGlobalConfigAccessor.getConfiguration()).thenReturn(Optional.of(model));
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.getOne();
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.hasContent());
assertEquals(model.obfuscate(), response.getContent().get());
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testCreate.
@Test
public void testCreate() throws AlertConfigurationException {
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.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
Mockito.when(emailGlobalConfigAccessor.createConfiguration(Mockito.eq(model))).thenReturn(model);
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.create(model);
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.hasContent());
assertEquals(model.obfuscate(), response.getContent().get());
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelSaveActionsTest method createAuthorizationManager.
private AuthorizationManager createAuthorizationManager() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), settingsDescriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
return 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 PermissionModelUtil method convertToPermissionMatrixModel.
public static PermissionMatrixModel convertToPermissionMatrixModel(Set<PermissionModel> permissionModels) {
Map<PermissionKey, Integer> permissionMatrix = new HashMap<>();
for (PermissionModel permissionModel : permissionModels) {
String descriptorKey = permissionModel.getDescriptorName();
String context = permissionModel.getContext();
PermissionKey permissionKey = new PermissionKey(context, descriptorKey);
int accessOperationsBits = 0;
if (permissionModel.isCreate()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.CREATE.getBit());
}
if (permissionModel.isRead()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.READ.getBit());
}
if (permissionModel.isDelete()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.DELETE.getBit());
}
if (permissionModel.isExecute()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.EXECUTE.getBit());
}
if (permissionModel.isWrite()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.WRITE.getBit());
}
if (permissionModel.isUploadDelete()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.UPLOAD_FILE_DELETE.getBit());
}
if (permissionModel.isUploadRead()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.UPLOAD_FILE_READ.getBit());
}
if (permissionModel.isUploadWrite()) {
accessOperationsBits = BitwiseUtil.combineBits(accessOperationsBits, AccessOperation.UPLOAD_FILE_WRITE.getBit());
}
permissionMatrix.put(permissionKey, accessOperationsBits);
}
return new PermissionMatrixModel(permissionMatrix);
}
Aggregations