List of usage examples for org.apache.commons.collections4 Transformer Transformer
Transformer
From source file:org.apache.syncope.core.persistence.jpa.inner.MultitenancyTest.java
@BeforeClass public static void setAuthContext() { List<GrantedAuthority> authorities = CollectionUtils.collect(StandardEntitlement.values(), new Transformer<String, GrantedAuthority>() { @Override//from w w w . j a va 2s . c om public GrantedAuthority transform(final String entitlement) { return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM); } }, new ArrayList<GrantedAuthority>()); UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken( new org.springframework.security.core.userdetails.User("admin", "FAKE_PASSWORD", authorities), "FAKE_PASSWORD", authorities); auth.setDetails(new SyncopeAuthenticationDetails("Two")); SecurityContextHolder.getContext().setAuthentication(auth); }
From source file:org.apache.syncope.core.persistence.jpa.validation.entity.AnyValidator.java
@Override public boolean isValid(final Any any, final ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (!(any instanceof Conf)) { Collection<String> allowedPlainSchemas = CollectionUtils.collect(new JPAAnyUtilsFactory() .getInstance(any.getType().getKind()).getAllowedSchemas(any, PlainSchema.class), new Transformer<PlainSchema, String>() { @Override//www .ja va2 s .c o m public String transform(final PlainSchema schema) { return schema.getKey(); } }); for (PlainAttr<?> attr : ((Any<?>) any).getPlainAttrs()) { if (attr != null && !allowedPlainSchemas.contains(attr.getSchema().getKey())) { context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidPlainSchema, attr.getSchema().getKey() + " not allowed for this instance")) .addPropertyNode("plainAttrs").addConstraintViolation(); return false; } } } return true; }
From source file:org.apache.syncope.core.persistence.jpa.validation.entity.ReportValidator.java
@Override @SuppressWarnings("ResultOfObjectAllocationIgnored") public boolean isValid(final Report object, final ConstraintValidatorContext context) { boolean isValid = true; if (object.getCronExpression() != null) { try {//from w w w .j a v a 2 s .co m new CronExpression(object.getCronExpression()); } catch (ParseException e) { LOG.error("Invalid cron expression '" + object.getCronExpression() + "'", e); isValid = false; context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( getTemplate(EntityViolationType.InvalidReport, "Invalid cron expression")) .addPropertyNode("cronExpression").addConstraintViolation(); } } Set<String> reportletNames = CollectionUtils.collect(object.getReportletConfs(), new Transformer<ReportletConf, String>() { @Override public String transform(final ReportletConf input) { return input.getName(); } }, new HashSet<String>()); if (reportletNames.size() != object.getReportletConfs().size()) { LOG.error("Reportlet name must be unique"); isValid = false; context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( getTemplate(EntityViolationType.InvalidReport, "Reportlet name must be unique")) .addPropertyNode("reportletConfs").addConstraintViolation(); } return isValid; }
From source file:org.apache.syncope.core.provisioning.api.utils.EntityUtils.java
public static <E extends Entity> Transformer<E, String> keyTransformer() { return new Transformer<E, String>() { @Override/* w ww . j av a 2 s. com*/ public String transform(final E input) { return input.getKey(); } }; }
From source file:org.apache.syncope.core.provisioning.camel.processor.UserProvisionProcessor.java
@Override public void process(final Exchange exchange) { Long key = exchange.getIn().getBody(Long.class); Boolean changePwd = exchange.getProperty("changePwd", Boolean.class); String password = exchange.getProperty("password", String.class); @SuppressWarnings("unchecked") List<String> resources = exchange.getProperty("resources", List.class); Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class); UserPatch userPatch = new UserPatch(); userPatch.setKey(key);/*from w ww .j a v a 2 s .co m*/ userPatch.getResources() .addAll(CollectionUtils.collect(resources, new Transformer<String, StringPatchItem>() { @Override public StringPatchItem transform(final String resource) { return new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource) .build(); } })); if (changePwd) { userPatch.setPassword( new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build()); } PropagationByResource propByRes = new PropagationByResource(); for (String resource : resources) { propByRes.add(ResourceOperation.UPDATE, resource); } WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<Pair<UserPatch, Boolean>>( ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update"); List<PropagationTask> tasks = propagationManager.getUserUpdateTasks(wfResult, changePwd, null); PropagationReporter propagationReporter = ApplicationContextProvider.getBeanFactory() .getBean(PropagationReporter.class); taskExecutor.execute(tasks, propagationReporter, nullPriorityAsync); exchange.getOut().setBody(propagationReporter.getStatuses()); }
From source file:org.apache.syncope.core.provisioning.java.ConnectorFacadeProxy.java
@Override public void search(final ObjectClass objectClass, final Filter filter, final ResultsHandler handler, final int pageSize, final String pagedResultsCookie, final List<OrderByClause> orderBy, final Iterator<? extends MappingItem> mapItems) { OperationOptionsBuilder builder = new OperationOptionsBuilder().setPageSize(pageSize); if (pagedResultsCookie != null) { builder.setPagedResultsCookie(pagedResultsCookie); }/*from w w w . j a v a2 s . co m*/ builder.setSortKeys(CollectionUtils.collect(orderBy, new Transformer<OrderByClause, SortKey>() { @Override public SortKey transform(final OrderByClause clause) { return new SortKey(clause.getField(), clause.getDirection() == OrderByClause.Direction.ASC); } }, new ArrayList<SortKey>(orderBy.size()))); builder.setAttributesToGet(MappingUtils.buildOperationOptions(mapItems).getAttributesToGet()); search(objectClass, filter, handler, builder.build()); }
From source file:org.apache.syncope.core.provisioning.java.data.RoleDataBinderImpl.java
@Override public RoleTO getRoleTO(final Role role) { RoleTO roleTO = new RoleTO(); roleTO.setKey(role.getKey());//from w ww . j ava 2 s .c o m roleTO.getEntitlements().addAll(role.getEntitlements()); CollectionUtils.collect(role.getRealms(), new Transformer<Realm, String>() { @Override public String transform(final Realm input) { return input.getFullPath(); } }, roleTO.getRealms()); if (role.getDynMembership() != null) { roleTO.setDynMembershipCond(role.getDynMembership().getFIQLCond()); } return roleTO; }
From source file:org.apache.syncope.core.provisioning.java.sync.AbstractProvisioningJob.java
@Override protected String doExecute(final boolean dryRun) throws JobExecutionException { // PRE: grant all authorities (i.e. setup the SecurityContextHolder) List<GrantedAuthority> authorities = CollectionUtils.collect(Entitlement.values(), new Transformer<String, GrantedAuthority>() { @Override/*from www. ja va 2 s .c om*/ public GrantedAuthority transform(final String entitlement) { return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM); } }, new ArrayList<GrantedAuthority>()); UserDetails userDetails = new User("admin", "FAKE_PASSWORD", authorities); SecurityContextHolder.getContext().setAuthentication( new UsernamePasswordAuthenticationToken(userDetails, "FAKE_PASSWORD", authorities)); try { Class<T> clazz = getTaskClassReference(); if (!clazz.isAssignableFrom(task.getClass())) { throw new JobExecutionException("Task " + taskId + " isn't a SyncTask"); } T provisioningTask = clazz.cast(this.task); Connector connector; try { connector = connFactory.getConnector(provisioningTask.getResource()); } catch (Exception e) { final String msg = String.format( "Connector instance bean for resource %s and connInstance %s not found", provisioningTask.getResource(), provisioningTask.getResource().getConnector()); throw new JobExecutionException(msg, e); } boolean noMapping = true; for (Provision provision : provisioningTask.getResource().getProvisions()) { Mapping mapping = provision.getMapping(); if (mapping != null) { noMapping = false; if (mapping.getConnObjectKeyItem() == null) { throw new JobExecutionException("Invalid ConnObjectKey mapping for provision " + provision); } } } if (noMapping) { return "No mapping configured for both users and groups: aborting..."; } return executeWithSecurityContext(provisioningTask, connector, dryRun); } catch (Throwable t) { LOG.error("While executing provisioning job {}", getClass().getName(), t); throw t; } finally { // POST: clean up the SecurityContextHolder SecurityContextHolder.clearContext(); } }
From source file:org.apache.syncope.core.rest.cxf.service.ConnectorServiceImpl.java
@Override public List<PlainSchemaTO> getSchemaNames(final Long key, final ConnInstanceTO connInstanceTO, final boolean includeSpecial) { connInstanceTO.setKey(key);//from w w w . j av a2 s . c o m return CollectionUtils.collect(logic.getSchemaNames(connInstanceTO, includeSpecial), new Transformer<String, PlainSchemaTO>() { @Override public PlainSchemaTO transform(final String name) { PlainSchemaTO schemaTO = new PlainSchemaTO(); schemaTO.setKey(name); return schemaTO; } }, new ArrayList<PlainSchemaTO>()); }
From source file:org.apache.syncope.core.workflow.activiti.SyncopeGroupQueryImpl.java
private void execute() { if (groupId != null) { org.apache.syncope.core.persistence.api.entity.group.Group syncopeGroup = groupDAO.findByName(groupId); if (syncopeGroup == null) { result = Collections.emptyList(); } else {/*from w w w .j a v a 2 s .c om*/ result = Collections.singletonList(fromSyncopeGroup(syncopeGroup)); } } if (result == null) { result = CollectionUtils.collect(groupDAO.findAll(), new Transformer<org.apache.syncope.core.persistence.api.entity.group.Group, Group>() { @Override public Group transform( final org.apache.syncope.core.persistence.api.entity.group.Group user) { return fromSyncopeGroup(user); } }, new ArrayList<Group>()); } }