use of com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails in project hub-alert by blackducksoftware.
the class DefaultUserAccessor method addUser.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserModel addUser(UserModel user, boolean passwordEncoded) throws AlertConfigurationException {
String username = user.getName();
Optional<UserEntity> userWithSameUsername = userRepository.findByUserName(username);
if (userWithSameUsername.isPresent()) {
throw new AlertConfigurationException(String.format("A user with username '%s' is already present", username));
}
String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword());
AuthenticationTypeDetails authenticationType = authenticationTypeAccessor.getAuthenticationTypeDetails(user.getAuthenticationType()).orElseThrow(() -> new AlertRuntimeException("Cannot find Authentication Type."));
UserEntity newEntity = new UserEntity(username, password, user.getEmailAddress(), authenticationType.getId());
UserEntity savedEntity = userRepository.save(newEntity);
UserModel model = createModel(savedEntity);
roleAccessor.updateUserRoles(model.getId(), user.getRoles());
return model;
}
use of com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails in project hub-alert by blackducksoftware.
the class UserActionsTest method testReadAllWithoutChecks.
@Test
public void testReadAllWithoutChecks() {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
AuthenticationTypeDetails authenticationTypeDetails = new AuthenticationTypeDetails(1L, authenticationType.name());
Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUsers()).thenReturn(List.of(userModel));
Mockito.when(authenticationTypeAccessor.getAuthenticationTypeDetails(Mockito.any())).thenReturn(Optional.of(authenticationTypeDetails));
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<MultiUserConfigResponseModel> actionResponse = userActions.getAll();
assertTrue(actionResponse.hasContent());
List<UserConfig> userModels = actionResponse.getContent().get().getUsers();
assertEquals(1, userModels.size());
UserConfig userConfig = userModels.get(0);
assertUserConfig(userConfig);
assertEquals(authenticationType.name(), userConfig.getAuthenticationType());
assertNull(userConfig.getPassword());
}
use of com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method addUserTest.
@Test
public void addUserTest() throws Exception {
final String roleName = "userName";
UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L);
userEntity.setId(1L);
AuthenticationTypeDetails authenticationTypeDetails = new AuthenticationTypeDetails(2L, "authentication-name");
UserRoleRelation userRoleRelation = new UserRoleRelation(1L, 2L);
UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true);
Mockito.when(userRepository.findByUserName(Mockito.any())).thenReturn(Optional.empty());
Mockito.when(authenticationTypeAccessor.getAuthenticationTypeDetails(Mockito.any())).thenReturn(Optional.of(authenticationTypeDetails));
Mockito.when(userRepository.save(Mockito.any())).thenReturn(userEntity);
createModelMocks(userRoleRelation, userRoleModel, AuthenticationType.DATABASE);
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
UserModel userModel = defaultUserAccessor.addUser(username, password, emailAddress);
testUserModel(userEntity.getId(), username, emailAddress, roleName, userModel);
}
use of com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails in project hub-alert by blackducksoftware.
the class DefaultAuthenticationTypeAccessorTest method getAuthenticationTypeDetailsNullTest.
@Test
public void getAuthenticationTypeDetailsNullTest() {
AuthenticationTypeRepository authenticationTypeRepository = Mockito.mock(AuthenticationTypeRepository.class);
DefaultAuthenticationTypeAccessor authenticationTypeAccessor = new DefaultAuthenticationTypeAccessor(authenticationTypeRepository);
Mockito.when(authenticationTypeRepository.findById(Mockito.any())).thenReturn(Optional.empty());
Optional<AuthenticationTypeDetails> testAuthenticationTypeDetails = authenticationTypeAccessor.getAuthenticationTypeDetails(AuthenticationType.DATABASE);
assertFalse(testAuthenticationTypeDetails.isPresent());
}
use of com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails in project hub-alert by blackducksoftware.
the class DefaultAuthenticationTypeAccessorTest method getAuthenticationTypeDetailsTest.
@Test
public void getAuthenticationTypeDetailsTest() {
AuthenticationTypeRepository authenticationTypeRepository = Mockito.mock(AuthenticationTypeRepository.class);
DefaultAuthenticationTypeAccessor authenticationTypeAccessor = new DefaultAuthenticationTypeAccessor(authenticationTypeRepository);
AuthenticationTypeEntity authenticationTypeEntity = new AuthenticationTypeEntity("name-test");
Mockito.when(authenticationTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(authenticationTypeEntity));
Optional<AuthenticationTypeDetails> testAuthenticationTypeDetails = authenticationTypeAccessor.getAuthenticationTypeDetails(AuthenticationType.DATABASE);
assertTrue(testAuthenticationTypeDetails.isPresent());
AuthenticationTypeDetails authenticationTypeDetails = testAuthenticationTypeDetails.get();
assertEquals(authenticationTypeEntity.getName(), authenticationTypeDetails.getName());
assertEquals(authenticationTypeEntity.getId(), authenticationTypeDetails.getId());
}
Aggregations