use of java.util.Collections in project CzechIdMng by bcvsolutions.
the class DefaultIdmAuthorizationPolicyService method getDefaultAuthorities.
@Override
@Transactional(readOnly = true)
public Set<GrantedAuthority> getDefaultAuthorities(UUID identityId) {
IdmRoleDto defaultRole = roleService.getDefaultRole();
if (defaultRole == null) {
LOG.debug("Default role not found, no default authorities will be added. Change configuration [{}].", IdmRoleService.PROPERTY_DEFAULT_ROLE);
return Collections.<GrantedAuthority>emptySet();
}
if (defaultRole.isDisabled()) {
LOG.debug("Default role [{}] is disabled, no default authorities will be added.", defaultRole.getCode());
return Collections.<GrantedAuthority>emptySet();
}
//
UUID defaultRoleId = defaultRole.getId();
Set<GrantedAuthority> defaultAuthorities = new HashSet<>();
// default role authorities
defaultAuthorities.addAll(getEnabledRoleAuthorities(identityId, defaultRoleId));
// all sub roles authorities
roleCompositionService.findAllSubRoles(defaultRoleId).stream().filter(roleComposition -> {
IdmRoleDto subRole = DtoUtils.getEmbedded(roleComposition, IdmRoleComposition_.sub);
return !subRole.isDisabled();
}).forEach(roleComposition -> {
defaultAuthorities.addAll(getEnabledRoleAuthorities(identityId, roleComposition.getSub()));
});
//
LOG.debug("Found [{}] default authorities", defaultAuthorities.size());
return defaultAuthorities;
}
use of java.util.Collections in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method changePassword.
@Override
public List<OperationResult> changePassword(DTO dto, PasswordChangeDto passwordChange) {
Assert.notNull(dto, "DTO is required.");
Assert.notNull(dto.getId(), "Password can be changed, when dto is already persisted.");
Assert.notNull(passwordChange, "Password change dto is required.");
List<SysProvisioningOperationDto> preparedOperations = new ArrayList<>();
//
EntityAccountFilter filter = this.createEntityAccountFilter();
filter.setEntityId(dto.getId());
List<? extends EntityAccountDto> entityAccountList = getEntityAccountService().find(filter, null).getContent();
if (entityAccountList == null) {
return Collections.<OperationResult>emptyList();
}
// Distinct by accounts
List<UUID> accountIds = new ArrayList<>();
entityAccountList.stream().filter(entityAccount -> {
if (!entityAccount.isOwnership()) {
return false;
}
if (passwordChange.isAll()) {
// Add all account supports change password
if (entityAccount.getAccount() == null) {
return false;
}
// Check if system for this account support change password
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setSupportChangePassword(Boolean.TRUE);
accountFilter.setId(entityAccount.getAccount());
List<AccAccountDto> accountsChecked = accountService.find(accountFilter, null).getContent();
if (accountsChecked.size() == 1) {
return true;
}
return false;
} else {
return passwordChange.getAccounts().contains(entityAccount.getAccount().toString());
}
}).forEach(entityAccount -> {
if (!accountIds.contains(entityAccount.getAccount())) {
accountIds.add(entityAccount.getAccount());
}
});
//
// Is possible that some account has disabled password attributes
List<OperationResult> notExecutedPasswordChanged = new ArrayList<>();
//
List<AccAccountDto> accounts = new ArrayList<>();
accountIds.forEach(accountId -> {
AccAccountDto account = accountService.get(accountId);
// Skip account in protection
if (account.isInProtection()) {
// Skip this iteration
return;
}
//
accounts.add(account);
// find UID from system entity or from account
SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system);
if (account.getSystemEntity() == null) {
throw new SystemEntityNotFoundException(AccResultCode.PROVISIONING_PASSWORD_SYSTEM_ENTITY_NOT_FOUND, String.valueOf(account.getUid()), system.getCode());
}
SysSystemEntityDto systemEntity = systemEntityService.get(account.getSystemEntity());
//
// Find mapped attributes (include overloaded attributes)
List<AttributeMapping> finalAttributes = resolveMappedAttributes(account, dto, system, systemEntity.getEntityType());
if (CollectionUtils.isEmpty(finalAttributes)) {
return;
}
// We try find __PASSWORD__ attribute in mapped attributes
AttributeMapping mappedAttribute = finalAttributes.stream().filter((attribute) -> {
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attribute);
return ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME.equals(schemaAttributeDto.getName());
}).findFirst().orElse(null);
//
// get all another passwords, list with all passwords (included primary password marked as __PASSWORD__)
SysSystemMappingDto systemMappingDto = getMapping(system, systemEntity.getEntityType());
List<SysSystemAttributeMappingDto> passwordAttributes = attributeMappingService.getAllPasswordAttributes(system.getId(), systemMappingDto.getId());
//
// create account object with all another password
Map<ProvisioningAttributeDto, Object> accountObjectWithAnotherPassword = new HashMap<>(passwordAttributes.size());
for (AttributeMapping passwordAttribute : passwordAttributes) {
// all password attributes contains also main __PASSWORD__ the attribute must be skipped
if (mappedAttribute != null && mappedAttribute.equals(passwordAttribute)) {
continue;
}
GuardedString transformPassword = transformPassword(passwordChange.getNewPassword(), passwordAttribute, systemEntity.getUid(), dto);
SysSchemaAttributeDto schemaAttribute = schemaAttributeService.get(passwordAttribute.getSchemaAttribute());
ProvisioningAttributeDto passwordProvisiongAttributeDto = ProvisioningAttributeDto.createProvisioningAttributeKey(passwordAttribute, schemaAttribute.getName(), schemaAttribute.getClassType());
accountObjectWithAnotherPassword.put(passwordProvisiongAttributeDto, transformPassword);
}
// for this account doesn't exist mapped attribute as password
if (accountObjectWithAnotherPassword.isEmpty() && mappedAttribute == null) {
// Beware we cant use AccAccountDto from acc module, in core is checked by this
notExecutedPasswordChanged.add(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_FAILED, ImmutableMap.of(IdmAccountDto.PARAMETER_NAME, createResultAccount(account, system)))).build());
// for this account is this failed password change
return;
}
//
// add all account attributes => standard provisioning
SysProvisioningOperationDto additionalProvisioningOperation = null;
// resolve another attributes that must be sent together with password
List<AttributeMapping> additionalPasswordChangeAttributes = resolveAdditionalPasswordChangeAttributes(account, dto, system, systemEntity.getEntityType());
if (!additionalPasswordChangeAttributes.isEmpty()) {
additionalProvisioningOperation = prepareProvisioning(systemEntity, dto, dto.getId(), ProvisioningOperationType.UPDATE, additionalPasswordChangeAttributes);
}
// add another password
if (!accountObjectWithAnotherPassword.isEmpty()) {
if (additionalProvisioningOperation == null) {
// if additional operation is null create one
additionalProvisioningOperation = prepareProvisioningOperationForAdditionalPassword(systemEntity, dto, dto.getId(), ProvisioningOperationType.UPDATE, systemMappingDto, accountObjectWithAnotherPassword);
} else {
// if additional operation exists just add all account object with additional passwords
additionalProvisioningOperation.getProvisioningContext().getAccountObject().putAll(accountObjectWithAnotherPassword);
}
}
//
// password change operation
SysProvisioningOperationDto operation;
if (provisioningExecutor.getConfiguration().isSendPasswordAttributesTogether() && additionalProvisioningOperation != null) {
// all attributes including another password attributes will be sent with password one provisioning operation
operation = additionalProvisioningOperation;
//
if (mappedAttribute != null) {
// Main password attribute isn't mapped
// transform password value trough transformation
GuardedString transformPassword = transformPassword(passwordChange.getNewPassword(), mappedAttribute, systemEntity.getUid(), dto);
//
// add wish for password
SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.get(mappedAttribute.getSchemaAttribute());
ProvisioningAttributeDto passwordAttribute = ProvisioningAttributeDto.createProvisioningAttributeKey(mappedAttribute, schemaAttributeDto.getName(), schemaAttributeDto.getClassType());
//
// newly isn't needed check if password is constant or etc.
//
operation.getProvisioningContext().getAccountObject().put(passwordAttribute, transformPassword);
}
//
// do provisioning for additional attributes and password
// together
preparedOperations.add(operation);
} else {
//
if (mappedAttribute != null) {
// Main password attribute isn't mapped
// transform password value trough transformation
GuardedString transformPassword = transformPassword(passwordChange.getNewPassword(), mappedAttribute, systemEntity.getUid(), dto);
//
operation = prepareProvisioningForAttribute(systemEntity, mappedAttribute, transformPassword, ProvisioningOperationType.UPDATE, dto);
preparedOperations.add(operation);
}
// do provisioning for additional attributes and passwords in second
if (additionalProvisioningOperation != null) {
preparedOperations.add(additionalProvisioningOperation);
}
}
});
//
// execute prepared operations
List<OperationResult> results = preparedOperations.stream().map(operation -> {
SysProvisioningOperationDto result = provisioningExecutor.executeSync(operation);
Map<String, Object> parameters = new LinkedHashMap<String, Object>();
AccAccountDto account = accounts.stream().filter(a -> {
return a.getRealUid().equals(result.getSystemEntityUid()) && a.getSystem().equals(operation.getSystem());
}).findFirst().get();
SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system);
//
parameters.put(IdmAccountDto.PARAMETER_NAME, createResultAccount(account, system));
//
if (result.getResult().getState() == OperationState.EXECUTED) {
// Add success changed password account
return new OperationResult.Builder(OperationState.EXECUTED).setModel(new DefaultResultModel(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS, parameters)).build();
}
OperationResult changeResult = new OperationResult.Builder(result.getResult().getState()).setModel(new DefaultResultModel(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_FAILED, parameters)).build();
changeResult.setCause(result.getResult().getCause());
changeResult.setCode(result.getResult().getCode());
return changeResult;
}).collect(Collectors.toList());
//
// add not executed changed from prepare stage
results.addAll(notExecutedPasswordChanged);
return results;
}
use of java.util.Collections in project beam by apache.
the class BaseFirestoreIT method listCollections.
@Test
@TestDataLayoutHint(DataLayout.Deep)
public final void listCollections() throws Exception {
// verification and cleanup of nested collections is much slower because each document
// requires an rpc to find its collections, instead of using the usual size, use 20
// to keep the test quick
List<String> collectionIds = IntStream.rangeClosed(1, 20).mapToObj(i -> helper.colId()).collect(Collectors.toList());
ApiFutures.transform(ApiFutures.allAsList(chunkUpDocIds(collectionIds).map(chunk -> {
WriteBatch batch = helper.getFs().batch();
chunk.stream().map(col -> helper.getBaseDocument().collection(col).document()).forEach(ref -> batch.set(ref, ImmutableMap.of("foo", "bar")));
return batch.commit();
}).collect(Collectors.toList())), FirestoreTestingHelper.flattenListList(), MoreExecutors.directExecutor()).get(10, TimeUnit.SECONDS);
PCollection<String> actualCollectionIds = testPipeline.apply(Create.of("")).apply(getListCollectionIdsPTransform(testName.getMethodName())).apply(FirestoreIO.v1().read().listCollectionIds().withRpcQosOptions(rpcQosOptions).build());
PAssert.that(actualCollectionIds).containsInAnyOrder(collectionIds);
testPipeline.run(options);
}
use of java.util.Collections in project drools-wb by kiegroup.
the class AbstractDataManagementStrategy method storeData.
/**
* Store data in required target objects
*/
public void storeData(final FactModelTuple factModelTuple, final TestToolsView.Presenter testToolsPresenter, final ScenarioSimulationContext context, final GridWidget gridWidget) {
// Instantiate a map of already assigned properties
final Map<String, List<List<String>>> propertiesToHide = getPropertiesToHide(context.getAbstractScesimGridModelByGridWidget(gridWidget));
final SortedMap<String, FactModelTree> visibleFacts = factModelTuple.getVisibleFacts();
final Map<Boolean, List<Map.Entry<String, FactModelTree>>> partitionBy = visibleFacts.entrySet().stream().collect(Collectors.partitioningBy(stringFactModelTreeEntry -> stringFactModelTreeEntry.getValue().isSimple()));
final SortedMap<String, FactModelTree> complexDataObjects = new TreeMap<>(partitionBy.get(false).stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
final SortedMap<String, FactModelTree> simpleDataObjects = new TreeMap<>(partitionBy.get(true).stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
// Update context
SortedMap<String, FactModelTree> dataObjectFieldsMap = new TreeMap<>();
dataObjectFieldsMap.putAll(visibleFacts);
dataObjectFieldsMap.putAll(factModelTuple.getHiddenFacts());
context.setDataObjectFieldsMap(dataObjectFieldsMap);
// Update model
// Avoid Collections.emptySortedMap() due to "The method emptySortedMap() is undefined for the type Collections" error
SortedMap<String, FactModelTree> instanceFieldsMap = new TreeMap<>();
SortedMap<String, FactModelTree> simpleJavaTypeInstanceFieldsMap = new TreeMap<>();
if (GridWidget.SIMULATION.equals(gridWidget)) {
instanceFieldsMap = getInstanceMap(complexDataObjects);
simpleJavaTypeInstanceFieldsMap = getInstanceMap(simpleDataObjects);
Set<String> dataObjectsInstancesName = new HashSet<>(visibleFacts.keySet());
dataObjectsInstancesName.addAll(instanceFieldsMap.keySet());
context.setDataObjectsInstancesName(dataObjectsInstancesName);
Set<String> simpleJavaTypeInstancesName = new HashSet<>(simpleDataObjects.keySet());
simpleJavaTypeInstancesName.addAll(simpleJavaTypeInstanceFieldsMap.keySet());
context.getAbstractScesimGridModelByGridWidget(gridWidget).setSimpleJavaTypeInstancesName(simpleJavaTypeInstancesName);
}
// Update right panel
TestToolsPresenterData testToolsPresenterData = new TestToolsPresenterData(complexDataObjects, simpleDataObjects, instanceFieldsMap, simpleJavaTypeInstanceFieldsMap, factModelTuple.getHiddenFacts(), propertiesToHide, gridWidget);
testToolsPresenter.populateTestTools(testToolsPresenterData);
}
use of java.util.Collections in project flow by vaadin.
the class UidlWriterTest method checkAllTypesOfDependencies_npmMode.
@Test
public void checkAllTypesOfDependencies_npmMode() throws Exception {
UI ui = initializeUIForDependenciesTest(new TestUI());
UidlWriter uidlWriter = new UidlWriter();
addInitialComponentDependencies(ui, uidlWriter);
ui.add(new ComponentWithAllDependencyTypes());
JsonObject response = uidlWriter.createUidl(ui, false);
Map<LoadMode, List<JsonObject>> dependenciesMap = Stream.of(LoadMode.values()).map(mode -> response.getArray(mode.name())).flatMap(JsonUtils::<JsonObject>stream).collect(Collectors.toMap(jsonObject -> LoadMode.valueOf(jsonObject.getString(Dependency.KEY_LOAD_MODE)), Collections::singletonList, (list1, list2) -> {
List<JsonObject> result = new ArrayList<>(list1);
result.addAll(list2);
return result;
}));
assertThat("Dependencies with all types of load mode should be present in this response", dependenciesMap.size(), is(LoadMode.values().length));
List<JsonObject> eagerDependencies = dependenciesMap.get(LoadMode.EAGER);
assertThat("Should have an eager dependency", eagerDependencies, hasSize(1));
assertThat("Eager dependencies should not have inline contents", eagerDependencies.stream().filter(json -> json.hasKey(Dependency.KEY_CONTENTS)).collect(Collectors.toList()), hasSize(0));
JsonObject eagerDependency = eagerDependencies.get(0);
assertEquals("eager.css", eagerDependency.getString(Dependency.KEY_URL));
assertEquals(Dependency.Type.STYLESHEET, Dependency.Type.valueOf(eagerDependency.getString(Dependency.KEY_TYPE)));
List<JsonObject> lazyDependencies = dependenciesMap.get(LoadMode.LAZY);
JsonObject lazyDependency = lazyDependencies.get(0);
assertEquals("lazy.css", lazyDependency.getString(Dependency.KEY_URL));
assertEquals(Dependency.Type.STYLESHEET, Dependency.Type.valueOf(lazyDependency.getString(Dependency.KEY_TYPE)));
List<JsonObject> inlineDependencies = dependenciesMap.get(LoadMode.INLINE);
assertInlineDependencies(inlineDependencies);
}
Aggregations