use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigAccessor method createConfiguration.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public JiraServerGlobalConfigModel createConfiguration(JiraServerGlobalConfigModel configuration) throws AlertConfigurationException {
if (jiraServerConfigurationRepository.existsByName(configuration.getName())) {
throw new AlertConfigurationException(String.format("A config with the name '%s' already exists.", configuration.getName()));
}
UUID configurationId = UUID.randomUUID();
configuration.setId(configurationId.toString());
return populateConfiguration(configurationId, configuration, DateUtils.createCurrentDateTimestamp());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class AuthenticationActionsTestIT method testAuthenticationLDAPExceptionIT.
@Test
public void testAuthenticationLDAPExceptionIT() throws Exception {
HttpServletRequest servletRequest = new MockHttpServletRequest();
HttpServletResponse servletResponse = new MockHttpServletResponse();
Authentication authentication = Mockito.mock(Authentication.class);
Mockito.when(authentication.isAuthenticated()).thenReturn(true);
LdapAuthenticationProvider ldapAuthenticationProvider = Mockito.mock(LdapAuthenticationProvider.class);
Mockito.when(ldapAuthenticationProvider.authenticate(Mockito.any(Authentication.class))).thenReturn(authentication);
LdapManager mockLdapManager = Mockito.mock(LdapManager.class);
Mockito.when(mockLdapManager.isLdapEnabled()).thenReturn(true);
Mockito.when(mockLdapManager.getAuthenticationProvider()).thenThrow(new AlertConfigurationException("LDAP CONFIG EXCEPTION"));
DaoAuthenticationProvider databaseProvider = Mockito.mock(DaoAuthenticationProvider.class);
Mockito.when(databaseProvider.authenticate(Mockito.any(Authentication.class))).thenReturn(authentication);
AuthenticationEventManager authenticationEventManager = Mockito.mock(AuthenticationEventManager.class);
Mockito.doNothing().when(authenticationEventManager).sendAuthenticationEvent(Mockito.any(), Mockito.eq(AuthenticationType.LDAP));
RoleAccessor roleAccessor = Mockito.mock(RoleAccessor.class);
AlertDatabaseAuthenticationPerformer alertDatabaseAuthenticationPerformer = new AlertDatabaseAuthenticationPerformer(authenticationEventManager, roleAccessor, databaseProvider);
LdapAuthenticationPerformer ldapAuthenticationPerformer = new LdapAuthenticationPerformer(authenticationEventManager, roleAccessor, mockLdapManager);
AlertAuthenticationProvider authenticationProvider = new AlertAuthenticationProvider(List.of(ldapAuthenticationPerformer, alertDatabaseAuthenticationPerformer));
AuthenticationActions authenticationActions = new AuthenticationActions(authenticationProvider, csrfTokenRepository);
ActionResponse<Void> response = authenticationActions.authenticateUser(servletRequest, servletResponse, mockLoginRestModel.createRestModel());
assertTrue(response.isError());
Mockito.verify(databaseProvider).authenticate(Mockito.any(Authentication.class));
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class RoleActionsTest method updateErrorTest.
@Test
public void updateErrorTest() throws Exception {
String newRoleName = "newRoleName";
Long longId = 1L;
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, newRoleName, Set.of(permissionModel));
UserRoleModel userRoleModel = new UserRoleModel(longId, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
Mockito.when(roleAccessor.getRoles()).thenReturn(Set.of());
Mockito.doThrow(new AlertConfigurationException("Exception for test")).when(authorizationManager).updatePermissionsForRole(Mockito.anyString(), Mockito.any());
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.update(1L, rolePermissionModel);
Mockito.verify(authorizationManager).updateRoleName(Mockito.eq(longId), Mockito.eq(newRoleName));
assertTrue(rolePermissionModelActionResponse.isError());
assertFalse(rolePermissionModelActionResponse.hasContent());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, rolePermissionModelActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class UserActionsTest method testUpdateWithoutChecksDatabaseError.
@Test
public void testUpdateWithoutChecksDatabaseError() throws Exception {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
Mockito.when(userAccessor.getUser(id)).thenReturn(Optional.of(userModel));
Mockito.when(userAccessor.updateUser(Mockito.any(), Mockito.anyBoolean())).thenThrow(new AlertConfigurationException("Exception for test"));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", "newEmailAddress", roleNames, false, false, false, true, false, authenticationType.name(), false);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<UserConfig> userConfigActionResponse = userActions.updateWithoutChecks(id, userConfig);
assertTrue(userConfigActionResponse.isError());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, userConfigActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class DefaultUserAccessor method updateUser.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserModel updateUser(UserModel user, boolean passwordEncoded) throws AlertConfigurationException, AlertForbiddenOperationException {
Long userId = user.getId();
UserEntity existingUser = userRepository.findById(userId).orElseThrow(() -> new AlertConfigurationException(String.format("No user found with id '%s'", userId)));
Long existingUserId = existingUser.getId();
UserEntity savedEntity = existingUser;
// if it isn't an external user then update username, password, and email.
Optional<AuthenticationType> authenticationType = authenticationTypeAccessor.getAuthenticationType(existingUser.getAuthenticationType());
if (authenticationType.isEmpty()) {
throw new AlertRuntimeException("Unknown Authentication Type, user not updated.");
} else if (AuthenticationType.DATABASE != authenticationType.get()) {
boolean isUserNameInvalid = !StringUtils.equals(existingUser.getUserName(), user.getName());
boolean isEmailInvalid = !StringUtils.equals(existingUser.getEmailAddress(), user.getEmailAddress());
boolean isPasswordSet = StringUtils.isNotBlank(user.getPassword());
if (isUserNameInvalid || isEmailInvalid || isPasswordSet) {
throw new AlertForbiddenOperationException("An external user cannot change its credentials.");
}
} else {
String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword());
UserEntity newEntity = new UserEntity(user.getName(), password, user.getEmailAddress(), user.isExpired(), user.isLocked(), user.isPasswordExpired(), user.isEnabled(), existingUser.getAuthenticationType());
newEntity.setId(existingUserId);
savedEntity = userRepository.save(newEntity);
}
roleAccessor.updateUserRoles(existingUserId, user.getRoles());
return createModel(savedEntity);
}
Aggregations