List of usage examples for org.apache.commons.collections4 Closure Closure
Closure
From source file:com.vrem.wifianalyzer.wifi.channelgraph.ChannelGraphNavigationTest.java
@Test public void testUpdateGHZ5WithJapan() throws Exception { // setup//from w w w . j a v a 2s . co m when(settings.getCountryCode()).thenReturn(Locale.JAPAN.getCountry()); when(settings.getWiFiBand()).thenReturn(WiFiBand.GHZ5); when(settings.getSortBy()).thenReturn(SortBy.CHANNEL); // execute fixture.update(WiFiData.EMPTY); // validate verify(layout).setVisibility(View.VISIBLE); IterableUtils.forEach(views.keySet(), new Closure<Pair<WiFiChannel, WiFiChannel>>() { @Override public void execute(Pair<WiFiChannel, WiFiChannel> key) { verify(views.get(key)).setVisibility(WiFiChannelsGHZ5.SET3.equals(key) ? View.GONE : View.VISIBLE); } }); verify(settings).getCountryCode(); verify(settings, times(2)).getWiFiBand(); verify(settings).getSortBy(); }
From source file:org.apache.syncope.core.logic.report.ReconciliationReportlet.java
private void doExtract(final ContentHandler handler, final List<? extends Any<?>> anys) throws SAXException, ReportException { final Set<Missing> missing = new HashSet<>(); final Set<Misaligned> misaligned = new HashSet<>(); for (Any<?> any : anys) { missing.clear();/*w w w. j a va 2 s . co m*/ misaligned.clear(); AnyUtils anyUtils = anyUtilsFactory.getInstance(any); for (final ExternalResource resource : anyUtils.getAllResources(any)) { Provision provision = resource.getProvision(any.getType()); MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); final String connObjectKeyValue = connObjectKeyItem == null ? StringUtils.EMPTY : mappingManager.getConnObjectKeyValue(any, provision); if (provision != null && connObjectKeyItem != null && StringUtils.isNotBlank(connObjectKeyValue)) { // 1. read from the underlying connector Connector connector = connFactory.getConnector(resource); ConnectorObject connectorObject = connector.getObject(provision.getObjectClass(), new Uid(connObjectKeyValue), MappingUtils.buildOperationOptions(provision.getMapping().getItems().iterator())); if (connectorObject == null) { // 2. not found on resource? LOG.error("Object {} with class {} not found on resource {}", connObjectKeyValue, provision.getObjectClass(), resource); missing.add(new Missing(resource.getKey(), connObjectKeyValue)); } else { // 3. found but misaligned? Pair<String, Set<Attribute>> preparedAttrs = mappingManager.prepareAttrs(any, null, false, null, provision); preparedAttrs.getRight().add(AttributeBuilder.build(Uid.NAME, preparedAttrs.getLeft())); preparedAttrs.getRight().add(AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), preparedAttrs.getLeft())); final Map<String, Set<Object>> syncopeAttrs = new HashMap<>(); for (Attribute attr : preparedAttrs.getRight()) { syncopeAttrs.put(attr.getName(), attr.getValue() == null ? null : new HashSet<>(attr.getValue())); } final Map<String, Set<Object>> resourceAttrs = new HashMap<>(); for (Attribute attr : connectorObject.getAttributes()) { if (!OperationalAttributes.PASSWORD_NAME.equals(attr.getName()) && !OperationalAttributes.ENABLE_NAME.equals(attr.getName())) { resourceAttrs.put(attr.getName(), attr.getValue() == null ? null : new HashSet<>(attr.getValue())); } } IterableUtils.forEach( CollectionUtils.subtract(syncopeAttrs.keySet(), resourceAttrs.keySet()), new Closure<String>() { @Override public void execute(final String name) { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, name, syncopeAttrs.get(name), Collections.emptySet())); } }); for (Map.Entry<String, Set<Object>> entry : resourceAttrs.entrySet()) { if (syncopeAttrs.containsKey(entry.getKey())) { if (!Objects.equals(syncopeAttrs.get(entry.getKey()), entry.getValue())) { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), syncopeAttrs.get(entry.getKey()), entry.getValue())); } } else { misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, entry.getKey(), Collections.emptySet(), entry.getValue())); } } } } } if (!missing.isEmpty() || !misaligned.isEmpty()) { doExtract(handler, any, missing, misaligned); } } }
From source file:org.apache.syncope.core.misc.security.AuthDataAccessor.java
@Transactional public Set<SyncopeGrantedAuthority> load(final String username) { final Set<SyncopeGrantedAuthority> authorities = new HashSet<>(); if (anonymousUser.equals(username)) { authorities.add(new SyncopeGrantedAuthority(StandardEntitlement.ANONYMOUS)); } else if (adminUser.equals(username)) { CollectionUtils.collect(EntitlementsHolder.getInstance().getValues(), new Transformer<String, SyncopeGrantedAuthority>() { @Override//from w ww. j av a 2 s. c o m public SyncopeGrantedAuthority transform(final String entitlement) { return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM); } }, authorities); } else { User user = userDAO.find(username); if (user == null) { throw new UsernameNotFoundException("Could not find any user with id " + username); } if (user.isMustChangePassword()) { authorities.add(new SyncopeGrantedAuthority(StandardEntitlement.MUST_CHANGE_PASSWORD)); } else { final Map<String, Set<String>> entForRealms = new HashMap<>(); // Give entitlements as assigned by roles (with realms, where applicable) - assigned either // statically and dynamically for (final Role role : userDAO.findAllRoles(user)) { IterableUtils.forEach(role.getEntitlements(), new Closure<String>() { @Override public void execute(final String entitlement) { Set<String> realms = entForRealms.get(entitlement); if (realms == null) { realms = new HashSet<>(); entForRealms.put(entitlement, realms); } CollectionUtils.collect(role.getRealms(), new Transformer<Realm, String>() { @Override public String transform(final Realm realm) { return realm.getFullPath(); } }, realms); } }); } // Give group entitlements for owned groups for (Group group : groupDAO.findOwnedByUser(user.getKey())) { for (String entitlement : Arrays.asList(StandardEntitlement.GROUP_READ, StandardEntitlement.GROUP_UPDATE, StandardEntitlement.GROUP_DELETE)) { Set<String> realms = entForRealms.get(entitlement); if (realms == null) { realms = new HashSet<>(); entForRealms.put(entitlement, realms); } realms.add(RealmUtils.getGroupOwnerRealm(group.getRealm().getFullPath(), group.getKey())); } } // Finally normalize realms for each given entitlement and generate authorities for (Map.Entry<String, Set<String>> entry : entForRealms.entrySet()) { SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entry.getKey()); authority.addRealms(RealmUtils.normalize(entry.getValue())); authorities.add(authority); } } } return authorities; }
From source file:org.apache.syncope.core.misc.security.SyncopeGrantedAuthority.java
public void addRealms(final List<String> newRealms) { CollectionUtils.forAllDo(newRealms, new Closure<String>() { @Override/*from ww w . j a v a2s . c o m*/ public void execute(final String newRealm) { addRealm(newRealm); } }); }
From source file:org.apache.syncope.core.misc.security.SyncopeUserDetailsService.java
@Override public UserDetails loadUserByUsername(final String username) { final Set<SyncopeGrantedAuthority> authorities = new HashSet<>(); if (anonymousUser.equals(username)) { authorities.add(new SyncopeGrantedAuthority(Entitlement.ANONYMOUS)); } else if (adminUser.equals(username)) { CollectionUtils/* ww w . j a v a 2s .co m*/ .collect( IteratorUtils.filteredIterator(Entitlement.values().iterator(), PredicateUtils .notPredicate(PredicateUtils.equalPredicate(Entitlement.ANONYMOUS))), new Transformer<String, SyncopeGrantedAuthority>() { @Override public SyncopeGrantedAuthority transform(final String entitlement) { return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM); } }, authorities); } else { org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.find(username); if (user == null) { throw new UsernameNotFoundException("Could not find any user with id " + username); } // Give entitlements as assigned by roles (with realms, where applicable) - assigned either // statically and dynamically for (final Role role : userDAO.findAllRoles(user)) { CollectionUtils.forAllDo(role.getEntitlements(), new Closure<String>() { @Override public void execute(final String entitlement) { SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entitlement); authorities.add(authority); List<String> realmFullPahs = new ArrayList<>(); CollectionUtils.collect(role.getRealms(), new Transformer<Realm, String>() { @Override public String transform(final Realm realm) { return realm.getFullPath(); } }, realmFullPahs); authority.addRealms(realmFullPahs); } }); } // Give group entitlements for owned groups for (Group group : groupDAO.findOwnedByUser(user.getKey())) { for (String entitlement : Arrays.asList(Entitlement.GROUP_READ, Entitlement.GROUP_UPDATE, Entitlement.GROUP_DELETE)) { SyncopeGrantedAuthority authority = new SyncopeGrantedAuthority(entitlement); authority.addRealm( RealmUtils.getGroupOwnerRealm(group.getRealm().getFullPath(), group.getKey())); authorities.add(authority); } } } return new User(username, "<PASSWORD_PLACEHOLDER>", authorities); }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAConnInstanceDAO.java
@Override public void delete(final String key) { ConnInstance connInstance = find(key); if (connInstance == null) { return;/*w w w . j a va2 s . c om*/ } IterableUtils.forEach(new CopyOnWriteArrayList<>(connInstance.getResources()), new Closure<ExternalResource>() { @Override public void execute(final ExternalResource input) { resourceDAO.delete(input.getKey()); } }); entityManager().remove(connInstance); connRegistry.unregisterConnector(key.toString()); }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPANotificationDAO.java
@Override public void delete(final String key) { Notification notification = find(key); if (notification == null) { return;//from w ww. jav a 2s.c om } IterableUtils.forEach(taskDAO.findAll(TaskType.NOTIFICATION, null, notification, null, null, -1, -1, Collections.<OrderByClause>emptyList()), new Closure<Task>() { @Override public void execute(final Task input) { delete(input.getKey()); } }); entityManager().remove(notification); }