use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserModelTest method testUserModelNullRoles.
@Test
public void testUserModelNullRoles() {
String expectedUserName = "expectedUser";
String expectedPassword = "expectedPassword";
String expectedEmail = "expectedEmail";
Set<String> roleNames = null;
Set<UserRoleModel> expectedRoles = null;
UserModel userModel = UserModel.newUser(expectedUserName, expectedPassword, expectedEmail, AuthenticationType.DATABASE, expectedRoles, true);
assertEquals(expectedUserName, userModel.getName());
assertEquals(expectedPassword, userModel.getPassword());
assertEquals(expectedEmail, userModel.getEmailAddress());
assertNull(userModel.getRoles());
assertFalse(userModel.hasRole(DefaultUserRole.ALERT_ADMIN.name()));
assertFalse(userModel.hasRole("UNKNOWN_ROLE"));
assertFalse(userModel.isExpired());
assertFalse(userModel.isLocked());
assertFalse(userModel.isPasswordExpired());
assertTrue(userModel.isEnabled());
assertFalse(userModel.isExternal());
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserModelTest method testUserModelEmptyRoles.
@Test
public void testUserModelEmptyRoles() {
String expectedUserName = "expectedUser";
String expectedPassword = "expectedPassword";
String expectedEmail = "expectedEmail";
Set<UserRoleModel> expectedRoles = new LinkedHashSet<>();
UserModel userModel = UserModel.newUser(expectedUserName, expectedPassword, expectedEmail, AuthenticationType.DATABASE, expectedRoles, true);
assertEquals(expectedUserName, userModel.getName());
assertEquals(expectedPassword, userModel.getPassword());
assertEquals(expectedEmail, userModel.getEmailAddress());
assertTrue(userModel.getRoles().isEmpty());
assertFalse(userModel.hasRole(DefaultUserRole.ALERT_ADMIN.name()));
assertFalse(userModel.hasRole("UNKNOWN_ROLE"));
assertFalse(userModel.isExpired());
assertFalse(userModel.isLocked());
assertFalse(userModel.isPasswordExpired());
assertTrue(userModel.isEnabled());
assertFalse(userModel.isExternal());
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class AuthenticationTestUtils method createAuthentication.
public Authentication createAuthentication(Long id, String username, Set<UserRoleModel> roles) {
UserModel userModel = UserModel.existingUser(id, username, "", "", AuthenticationType.DATABASE, roles, true);
UserPrincipal userPrincipal = new UserPrincipal(userModel);
return new UsernamePasswordAuthenticationToken(userPrincipal, null, userPrincipal.getAuthorities());
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class ConfigurationOverridesStartupComponentTest method testInitializeResetPasswordDifferentUsername.
@Test
public void testInitializeResetPasswordDifferentUsername() throws AlertException {
Environment environment = Mockito.mock(Environment.class);
Mockito.when(environment.getProperty(ConfigurationOverridesStartupComponent.ENV_VAR_ADMIN_USER_PASSWORD_RESET)).thenReturn("true");
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
ConfigurationOverridesStartupComponent configurationOverridesStartupComponent = new ConfigurationOverridesStartupComponent(environmentVariableUtility, userAccessor, descriptorKey, configurationModelConfigurationAccessor, apiAction, configurationFieldModelConverter);
String newUsername = "UpdatedAdmin";
// Update the sysadmin username and password
Optional<UserModel> sysadminOptional = userAccessor.getUser(UserAccessor.DEFAULT_ADMIN_USER_ID);
assertTrue(sysadminOptional.isPresent());
UserModel sysadmin = sysadminOptional.get();
assertEquals(DEFAULT_PASSWORD_ENCODED, sysadmin.getPassword());
UserModel updatedSysadmin = changeUserNameAndPassword(sysadmin, newUsername, UPDATED_PASSWORD);
userAccessor.updateUser(updatedSysadmin, false);
// Run the initialize method
configurationOverridesStartupComponent.initialize();
// Verify the sysadmin password is the default password
sysadminOptional = userAccessor.getUser(UserAccessor.DEFAULT_ADMIN_USER_ID);
assertTrue(sysadminOptional.isPresent());
sysadmin = sysadminOptional.get();
assertEquals(DEFAULT_PASSWORD_ENCODED, sysadmin.getPassword());
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
HttpSession session = Mockito.mock(HttpSession.class);
Mockito.when(servletRequest.getSession()).thenReturn(session);
HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
// Try to login with the updated password
LoginConfig updatedLoginConfig = new LoginConfig(newUsername, UPDATED_PASSWORD);
ActionResponse<Void> actionResponse = authenticationActions.authenticateUser(servletRequest, servletResponse, updatedLoginConfig);
assertEquals(HttpStatus.UNAUTHORIZED, actionResponse.getHttpStatus());
// Try to login with the default password
LoginConfig defaultLoginConfig = new LoginConfig(newUsername, DEFAULT_PASSWORD);
actionResponse = authenticationActions.authenticateUser(servletRequest, servletResponse, defaultLoginConfig);
assertEquals(HttpStatus.NO_CONTENT, actionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserDetailsService method loadUserBySAML.
@Override
public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException {
String userName = credential.getNameID().getValue();
String emailAddress = StringUtils.contains(userName, "@") ? userName : null;
String[] alertRoles = credential.getAttributeAsStringArray(authoritiesPopulator.getSAMLRoleAttributeName("AlertRoles"));
Set<String> existingRoles = Set.of();
if (alertRoles != null) {
existingRoles = Arrays.stream(alertRoles).collect(Collectors.toSet());
}
Set<String> roleNames = authoritiesPopulator.addAdditionalRoleNames(userName, existingRoles, false);
Set<UserRoleModel> roles = roleNames.stream().map(UserRoleModel::of).collect(Collectors.toSet());
UserModel userModel = UserModel.newUser(userName, "", emailAddress, AuthenticationType.SAML, roles, true);
return new UserPrincipal(userModel);
}
Aggregations