Search in sources :

Example 26 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserAccessorTestIT method testChangeUserEmailAddress.

@Test
public void testChangeUserEmailAddress() throws AlertForbiddenOperationException, AlertConfigurationException {
    String userName = "testUser";
    String password = "testPassword";
    String email = "testEmail";
    UserModel userModel = userAccessor.addUser(userName, password, email);
    assertNotNull(userModel);
    assertEquals(userName, userModel.getName());
    assertEquals(email, userModel.getEmailAddress());
    assertTrue(userModel.getRoles().isEmpty());
    assertTrue(userAccessor.changeUserEmailAddress(userModel.getName(), "new_test_email"));
    Optional<UserModel> foundModel = userAccessor.getUser(userName);
    assertTrue(foundModel.isPresent());
    UserModel updatedModel = foundModel.get();
    assertEquals(userModel.getName(), updatedModel.getName());
    assertNotEquals(userModel.getEmailAddress(), updatedModel.getEmailAddress());
    userAccessor.deleteUser(userName);
    assertFalse(userAccessor.changeUserEmailAddress("bad_user_name", "new_test_email"));
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 27 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserAccessorTestIT method testExternalUserUpdateRoles.

@Test
public void testExternalUserUpdateRoles() throws AlertForbiddenOperationException, AlertConfigurationException {
    String userName = "testUser";
    String password = "testPassword";
    String email = "testEmail";
    UserModel userModel = UserModel.newUser(userName, password, email, AuthenticationType.LDAP, Collections.emptySet(), true);
    userModel = userAccessor.addUser(userModel, false);
    UserRoleModel userRole = UserRoleModel.of(DefaultUserRole.ALERT_ADMIN.name());
    Set<UserRoleModel> roles = Set.of(userRole);
    UserModel existingUser = UserModel.existingUser(userModel.getId(), userName, null, email, AuthenticationType.LDAP, roles, true);
    UserModel updatedUser = userAccessor.updateUser(existingUser, true);
    assertEquals(roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet()), updatedUser.getRoles().stream().map(UserRoleModel::getName).collect(Collectors.toSet()));
    userAccessor.deleteUser(userName);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 28 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserAccessorTestIT method testExternalUserUpdateNameException.

@Test
public void testExternalUserUpdateNameException() throws AlertForbiddenOperationException, AlertConfigurationException {
    String userName = "testUser";
    String password = "testPassword";
    String email = "testEmail";
    UserModel userModel = UserModel.newUser(userName, password, email, AuthenticationType.LDAP, Collections.emptySet(), true);
    userModel = userAccessor.addUser(userModel, false);
    UserModel updatedUser = UserModel.existingUser(userModel.getId(), userName + "_updated", null, email, AuthenticationType.LDAP, Collections.emptySet(), true);
    testUserUpdateException(updatedUser);
    userAccessor.deleteUser(userName);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 29 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserAccessorTestIT method testAddUser.

@Test
public void testAddUser() throws AlertForbiddenOperationException, AlertConfigurationException {
    String userName = "testUser";
    String password = "testPassword";
    String email = "testEmail";
    UserModel userModel = userAccessor.addUser(userName, password, email);
    assertNotNull(userModel);
    assertEquals(userName, userModel.getName());
    assertEquals(email, userModel.getEmailAddress());
    assertTrue(userModel.getRoles().isEmpty());
    userAccessor.deleteUser(userName);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 30 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserAccessorTestIT method testExternalUserUpdatePasswordException.

@Test
public void testExternalUserUpdatePasswordException() throws AlertForbiddenOperationException, AlertConfigurationException {
    String userName = "testUser";
    String password = "testPassword";
    String email = "testEmail";
    UserModel userModel = UserModel.newUser(userName, password, email, AuthenticationType.LDAP, Collections.emptySet(), true);
    userModel = userAccessor.addUser(userModel, false);
    UserModel updatedUser = UserModel.existingUser(userModel.getId(), userName, password, email, AuthenticationType.LDAP, Collections.emptySet(), true);
    testUserUpdateException(updatedUser);
    userAccessor.deleteUser(userName);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)42 Test (org.junit.jupiter.api.Test)32 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)17 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)12 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)8 UserRoleRelation (com.synopsys.integration.alert.database.user.UserRoleRelation)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)6 UserManagementDescriptorKey (com.synopsys.integration.alert.component.users.UserManagementDescriptorKey)6 AuthenticationTypeDetails (com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)4 AuthenticationType (com.synopsys.integration.alert.common.enumeration.AuthenticationType)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 DefaultUserRole (com.synopsys.integration.alert.common.enumeration.DefaultUserRole)3 UserAccessor (com.synopsys.integration.alert.common.persistence.accessor.UserAccessor)3 LoginConfig (com.synopsys.integration.alert.component.authentication.web.LoginConfig)3