Example usage for org.apache.commons.collections4 Transformer Transformer

List of usage examples for org.apache.commons.collections4 Transformer Transformer

Introduction

In this page you can find the example usage for org.apache.commons.collections4 Transformer Transformer.

Prototype

Transformer

Source Link

Usage

From source file:org.apache.syncope.core.logic.LoggerLogic.java

@PreAuthorize("hasRole('" + StandardEntitlement.AUDIT_LIST + "')")
@Transactional(readOnly = true)//w w w  .  jav  a  2 s.  com
public List<AuditLoggerName> listAudits() {
    return CollectionUtils.collect(IteratorUtils.filteredIterator(list(LoggerType.AUDIT).iterator(),
            PredicateUtils.notNullPredicate()), new Transformer<LoggerTO, AuditLoggerName>() {

                @Override
                public AuditLoggerName transform(final LoggerTO logger) {
                    AuditLoggerName result = null;
                    try {
                        result = AuditLoggerName.fromLoggerName(logger.getKey());
                    } catch (Exception e) {
                        LOG.warn("Unexpected audit logger name: {}", logger.getKey(), e);
                    }

                    return result;
                }
            }, new ArrayList<AuditLoggerName>());
}

From source file:org.apache.syncope.core.logic.NotificationTest.java

@Before
public void setupSecurity() {
    List<GrantedAuthority> authorities = CollectionUtils.collect(Entitlement.values(),
            new Transformer<String, GrantedAuthority>() {

                @Override/*from   w w  w  .  j a v a  2s  .c  om*/
                public GrantedAuthority transform(final String entitlement) {
                    return new SyncopeGrantedAuthority(entitlement, SyncopeConstants.ROOT_REALM);
                }
            }, new ArrayList<GrantedAuthority>());

    UserDetails userDetails = new User(adminUser, "FAKE_PASSWORD", authorities);
    Authentication authentication = new TestingAuthenticationToken(userDetails, "FAKE_PASSWORD", authorities);
    SecurityContextHolder.getContext().setAuthentication(authentication);
}

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// w  w  w.j  a  v a2s. co 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.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//from  w w w  .  jav a  2 s  .c o  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.misc.utils.EntityUtils.java

public static <KEY, E extends Entity<KEY>> Transformer<E, KEY> keyTransformer() {
    return new Transformer<E, KEY>() {

        @Override/*from ww w  .  j ava  2  s .c  om*/
        public KEY transform(final E input) {
            return input.getKey();
        }
    };
}

From source file:org.apache.syncope.core.persistence.jpa.entity.AbstractPlainAttr.java

@Override
public List<String> getValuesAsStrings() {
    List<String> result;
    if (getUniqueValue() == null) {
        result = CollectionUtils.collect(getValues(), new Transformer<PlainAttrValue, String>() {

            @Override//from   w  w w . j a va 2  s  .c o m
            public String transform(final PlainAttrValue input) {
                return input.getValueAsString();
            }
        }, new ArrayList<String>());
    } else {
        result = Collections.singletonList(getUniqueValue().getValueAsString());
    }

    return Collections.unmodifiableList(result);
}

From source file:org.apache.syncope.core.persistence.jpa.entity.JPAAccountPolicy.java

@Override
public Set<String> getResourceNames() {
    return CollectionUtils.collect(getResources(), new Transformer<ExternalResource, String>() {

        @Override/* w ww.j  a va  2  s. c o  m*/
        public String transform(final ExternalResource input) {
            return input.getKey();
        }
    }, new HashSet<String>());
}

From source file:org.apache.syncope.core.persistence.jpa.entity.JPAReport.java

@Override
public List<ReportletConf> getReportletConfs() {
    return CollectionUtils.collect(reportletConfs, new Transformer<JPAReportletConfInstance, ReportletConf>() {

        @Override/*  ww  w .jav a 2s.c o m*/
        public ReportletConf transform(final JPAReportletConfInstance input) {
            return input.getInstance();
        }
    }, new ArrayList<ReportletConf>());
}

From source file:org.apache.syncope.core.persistence.jpa.entity.policy.JPAAccountPolicy.java

@Override
public List<AccountRuleConf> getRuleConfs() {
    return CollectionUtils.collect(ruleConfs, new Transformer<JPAAccountRuleConfInstance, AccountRuleConf>() {

        @Override//  w w  w . j av  a2 s. com
        public AccountRuleConf transform(final JPAAccountRuleConfInstance input) {
            return input.getInstance();
        }
    }, new ArrayList<AccountRuleConf>());
}

From source file:org.apache.syncope.core.persistence.jpa.entity.policy.JPAPasswordPolicy.java

@Override
public List<PasswordRuleConf> getRuleConfs() {
    return CollectionUtils.collect(ruleConfs, new Transformer<JPAPasswordRuleConfInstance, PasswordRuleConf>() {

        @Override//from  ww  w .j av  a  2  s .  com
        public PasswordRuleConf transform(final JPAPasswordRuleConfInstance input) {
            return input.getInstance();
        }
    }, new ArrayList<PasswordRuleConf>());
}