use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel 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.UserRoleModel in project hub-alert by blackducksoftware.
the class DefaultUserAccessor method createModel.
private UserModel createModel(UserEntity user) {
List<UserRoleRelation> roleRelations = userRoleRepository.findAllByUserId(user.getId());
List<Long> roleIdsForUser = roleRelations.stream().map(UserRoleRelation::getRoleId).collect(Collectors.toList());
Set<UserRoleModel> roles = roleAccessor.getRoles(roleIdsForUser);
AuthenticationType authenticationType = authenticationTypeAccessor.getAuthenticationType(user.getAuthenticationType()).orElse(null);
return UserModel.existingUser(user.getId(), user.getUserName(), user.getPassword(), user.getEmailAddress(), authenticationType, roles, user.isEnabled());
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class MockRoleAccessor method updatePermissionsForRole.
@Override
public PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix) throws AlertConfigurationException {
Long roleId = roleMap.entrySet().stream().filter(entry -> entry.getValue().getName().equals(roleName)).map(Map.Entry::getKey).findFirst().orElseThrow(() -> new AlertConfigurationException(String.format("role with name %s not found", roleName)));
roleMap.computeIfPresent(roleId, (ignored, role) -> new UserRoleModel(role.getId(), role.getName(), role.isCustom(), permissionMatrix));
return permissionMatrix;
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel 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);
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class UserDetailsServiceTest method initializeAuthoritiesPopulator.
@BeforeEach
public void initializeAuthoritiesPopulator() {
Set<UserRoleModel> roles = Arrays.stream(VALID_DB_ROLES).map(UserRoleModel::of).collect(Collectors.toSet());
UserModel userModel = UserModel.newUser(USER_NAME, "password", EMAIL, AuthenticationType.SAML, roles, true);
AuthenticationDescriptorKey key = new AuthenticationDescriptorKey();
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ConfigurationModel configuration = Mockito.mock(ConfigurationModel.class);
UserAccessor userAccessor = Mockito.mock(UserAccessor.class);
Mockito.when(configuration.getField(Mockito.anyString())).thenReturn(Optional.empty());
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.eq(key))).thenReturn(List.of(configuration));
Mockito.when(userAccessor.getUser(Mockito.anyString())).thenReturn(Optional.of(userModel));
authoritiesPopulator = new UserManagementAuthoritiesPopulator(key, configurationModelConfigurationAccessor, userAccessor);
}
Aggregations