Example usage for org.apache.commons.collections ListUtils EMPTY_LIST

List of usage examples for org.apache.commons.collections ListUtils EMPTY_LIST

Introduction

In this page you can find the example usage for org.apache.commons.collections ListUtils EMPTY_LIST.

Prototype

List EMPTY_LIST

To view the source code for org.apache.commons.collections ListUtils EMPTY_LIST.

Click Source Link

Document

An empty unmodifiable list.

Usage

From source file:org.codice.ddf.admin.application.service.impl.ApplicationServiceBeanTest.java

/**
 * Tests the {@link ApplicationServiceBean#getServices(String)} method
 * for the case where the services do not have the "configurations" key
 *
 * @throws Exception//from w w w  . j  a va 2s  .  co m
 */
@Test
public void testGetServicesNotContainsKey() throws Exception {
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt,
            mBeanServer) {
        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    Bundle testBundle = mock(Bundle.class);
    Bundle[] bundles = { testBundle };
    when(bundleContext.getBundles()).thenReturn(bundles);

    List<Map<String, Object>> services = new ArrayList<>();
    Map<String, Object> testService2 = mock(HashMap.class);
    Map<String, Object> testService1 = mock(HashMap.class);
    services.add(testService1);
    services.add(testService2);
    when(testService1.get("factory")).thenReturn(true);
    when(testService2.get("factory")).thenReturn(false);

    BundleInfo testBundle1 = mock(BundleInfo.class);
    Set<BundleInfo> testBundles = new HashSet<>();
    testBundles.add(testBundle1);

    when(testApp.getBundles()).thenReturn(testBundles);
    when(testBundle1.getLocation()).thenReturn(TEST_LOCATION);
    when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
    when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class)))
            .thenReturn(services);

    assertThat("Should not find any services.", serviceBean.getServices(TEST_APP_NAME),
            is(ListUtils.EMPTY_LIST));
}

From source file:org.dspace.authenticate.IPAuthentication.java

@Override
public List<Group> getSpecialGroups(Context context, HttpServletRequest request) throws SQLException {
    if (request == null) {
        return ListUtils.EMPTY_LIST;
    }/*  w  ww . j a v  a  2  s.  c  o m*/
    List<Group> groups = new ArrayList<Group>();

    // Get the user's IP address
    String addr = request.getRemoteAddr();
    if (useProxies == null) {
        useProxies = ConfigurationManager.getBooleanProperty("useProxies", false);
    }
    if (useProxies && request.getHeader("X-Forwarded-For") != null) {
        /* This header is a comma delimited list */
        for (String xfip : request.getHeader("X-Forwarded-For").split(",")) {
            if (!request.getHeader("X-Forwarded-For").contains(addr)) {
                addr = xfip.trim();
            }
        }
    }

    for (IPMatcher ipm : ipMatchers) {
        try {
            if (ipm.match(addr)) {
                // Do we know group ID?
                UUID g = ipMatcherGroupIDs.get(ipm);
                if (g != null) {
                    groups.add(groupService.find(context, g));
                } else {
                    // See if we have a group name
                    String groupName = ipMatcherGroupNames.get(ipm);

                    if (groupName != null) {
                        Group group = groupService.findByName(context, groupName);
                        if (group != null) {
                            // Add ID so we won't have to do lookup again
                            ipMatcherGroupIDs.put(ipm, (group.getID()));
                            ipMatcherGroupNames.remove(ipm);

                            groups.add(group);
                        } else {
                            log.warn(LogManager.getHeader(context, "configuration_error",
                                    "unknown_group=" + groupName));
                        }
                    }
                }
            }
        } catch (IPMatcherException ipme) {
            log.warn(LogManager.getHeader(context, "configuration_error", "bad_ip=" + addr), ipme);
        }
    }

    // Now remove any negative matches
    for (IPMatcher ipm : ipNegativeMatchers) {
        try {
            if (ipm.match(addr)) {
                // Do we know group ID?
                UUID g = ipMatcherGroupIDs.get(ipm);
                if (g != null) {
                    groups.remove(groupService.find(context, g));
                } else {
                    // See if we have a group name
                    String groupName = ipMatcherGroupNames.get(ipm);

                    if (groupName != null) {
                        Group group = groupService.findByName(context, groupName);
                        if (group != null) {
                            // Add ID so we won't have to do lookup again
                            ipMatcherGroupIDs.put(ipm, group.getID());
                            ipMatcherGroupNames.remove(ipm);

                            groups.remove(group);
                        } else {
                            log.warn(LogManager.getHeader(context, "configuration_error",
                                    "unknown_group=" + groupName));
                        }
                    }
                }
            }
        } catch (IPMatcherException ipme) {
            log.warn(LogManager.getHeader(context, "configuration_error", "bad_ip=" + addr), ipme);
        }
    }

    if (log.isDebugEnabled()) {
        StringBuilder gsb = new StringBuilder();
        for (Group group : groups) {
            gsb.append(group.getID()).append(", ");
        }

        log.debug(LogManager.getHeader(context, "authenticated", "special_groups=" + gsb.toString()));
    }

    return groups;
}

From source file:org.dspace.authenticate.PasswordAuthentication.java

/**
 * Add authenticated users to the group defined in authentication-password.cfg by
 * the login.specialgroup key.//from   w w  w  .j av a2  s  . c  o  m
 */
@Override
public List<Group> getSpecialGroups(Context context, HttpServletRequest request) {
    // Prevents anonymous users from being added to this group, and the second check
    // ensures they are password users
    try {
        if (context.getCurrentUser() != null && StringUtils.isNotBlank(EPersonServiceFactory.getInstance()
                .getEPersonService().getPasswordHash(context.getCurrentUser()).toString())) {
            String groupName = DSpaceServicesFactory.getInstance().getConfigurationService()
                    .getProperty("authentication-password.login.specialgroup");
            if ((groupName != null) && (!groupName.trim().equals(""))) {
                Group specialGroup = EPersonServiceFactory.getInstance().getGroupService().findByName(context,
                        groupName);
                if (specialGroup == null) {
                    // Oops - the group isn't there.
                    log.warn(LogManager.getHeader(context, "password_specialgroup",
                            "Group defined in modules/authentication-password.cfg login.specialgroup does not exist"));
                    return ListUtils.EMPTY_LIST;
                } else {
                    return Arrays.asList(specialGroup);
                }
            }
        }
    } catch (Exception e) {
        log.error(LogManager.getHeader(context, "getSpecialGroups", ""), e);
    }
    return ListUtils.EMPTY_LIST;
}

From source file:org.dspace.authenticate.ShibAuthentication.java

/**
 * Get list of extra groups that user implicitly belongs to. Note that this
 * method will be invoked regardless of the authentication status of the
 * user (logged-in or not) e.g. a group that depends on the client
 * network-address./*from ww w  .  j a v  a 2 s.c o  m*/
 * 
 * DSpace is able to place users into pre-defined groups based upon values
 * received from Shibboleth. Using this option you can place all faculty members
 * into a DSpace group when the correct affiliation's attribute is provided.
 * When DSpace does this they are considered 'special groups', these are really
 * groups but the user's membership within these groups is not recorded in the
 * database. Each time a user authenticates they are automatically placed within
 * the pre-defined DSpace group, so if the user loses their affiliation then the
 * next time they login they will no longer be in the group.
 * 
 * Depending upon the shibboleth attributed use in the role-header, it may be
 * scoped. Scoped is shibboleth terminology for identifying where an attribute
 * originated from. For example a students affiliation may be encoded as
 * "student@tamu.edu". The part after the @ sign is the scope, and the preceding
 * value is the value. You may use the whole value or only the value or scope.
 * Using this you could generate a role for students and one institution
 * different than students at another institution. Or if you turn on
 * ignore-scope you could ignore the institution and place all students into
 * one group.
 * 
 * The values extracted (a user may have multiple roles) will be used to look
 * up which groups to place the user into. The groups are defined as
 * {@code authentication.shib.role.<role-name>} which is a comma separated list of
 * DSpace groups. 
 * 
 * @param context
 *            A valid DSpace context.
 * 
 * @param request
 *            The request that started this operation, or null if not
 *            applicable.
 * 
 * @return array of EPerson-group IDs, possibly 0-length, but never
 *         <code>null</code>.
 */
@Override
public List<Group> getSpecialGroups(Context context, HttpServletRequest request) {
    try {
        // User has not successfuly authenticated via shibboleth.
        if (request == null || context.getCurrentUser() == null
                || request.getSession().getAttribute("shib.authenticated") == null) {
            return ListUtils.EMPTY_LIST;
        }

        // If we have already calculated the special groups then return them.
        if (request.getSession().getAttribute("shib.specialgroup") != null) {
            log.debug("Returning cached special groups.");
            List<UUID> sessionGroupIds = (List<UUID>) request.getSession().getAttribute("shib.specialgroup");
            List<Group> result = new ArrayList<>();
            for (UUID uuid : sessionGroupIds) {
                result.add(groupService.find(context, uuid));
            }
            return result;
        }

        log.debug("Starting to determine special groups");
        String[] defaultRoles = configurationService
                .getArrayProperty("authentication-shibboleth.default-roles");
        String roleHeader = configurationService.getProperty("authentication-shibboleth.role-header");
        boolean ignoreScope = configurationService
                .getBooleanProperty("authentication-shibboleth.role-header.ignore-scope", true);
        boolean ignoreValue = configurationService
                .getBooleanProperty("authentication-shibboleth.role-header.ignore-value", false);

        if (ignoreScope && ignoreValue) {
            throw new IllegalStateException(
                    "Both config parameters for ignoring an roll attributes scope and value are turned on, this is not a permissable configuration. (Note: ignore-scope defaults to true) The configuration parameters are: 'authentication.shib.role-header.ignore-scope' and 'authentication.shib.role-header.ignore-value'");
        }

        // Get the Shib supplied affiliation or use the default affiliation
        List<String> affiliations = findMultipleAttributes(request, roleHeader);
        if (affiliations == null) {
            if (defaultRoles != null)
                affiliations = Arrays.asList(defaultRoles);
            log.debug("Failed to find Shibboleth role header, '" + roleHeader
                    + "', falling back to the default roles: '" + StringUtils.join(defaultRoles, ",") + "'");
        } else {
            log.debug("Found Shibboleth role header: '" + roleHeader + "' = '" + affiliations + "'");
        }

        // Loop through each affiliation
        Set<Group> groups = new HashSet<>();
        if (affiliations != null) {
            for (String affiliation : affiliations) {
                // If we ignore the affiliation's scope then strip the scope if it exists.
                if (ignoreScope) {
                    int index = affiliation.indexOf('@');
                    if (index != -1) {
                        affiliation = affiliation.substring(0, index);
                    }
                }
                // If we ignore the value, then strip it out so only the scope remains.
                if (ignoreValue) {
                    int index = affiliation.indexOf('@');
                    if (index != -1) {
                        affiliation = affiliation.substring(index + 1, affiliation.length());
                    }
                }

                // Get the group names
                String[] groupNames = configurationService
                        .getArrayProperty("authentication-shibboleth.role." + affiliation);
                if (groupNames == null || groupNames.length == 0) {
                    groupNames = configurationService
                            .getArrayProperty("authentication-shibboleth.role." + affiliation.toLowerCase());
                }

                if (groupNames == null) {
                    log.debug("Unable to find role mapping for the value, '" + affiliation
                            + "', there should be a mapping in config/modules/authentication-shibboleth.cfg:  role."
                            + affiliation + " = <some group name>");
                    continue;
                } else {
                    log.debug("Mapping role affiliation to DSpace group: '" + StringUtils.join(groupNames, ",")
                            + "'");
                }

                // Add each group to the list.
                for (int i = 0; i < groupNames.length; i++) {
                    try {
                        Group group = groupService.findByName(context, groupNames[i].trim());
                        if (group != null)
                            groups.add(group);
                        else
                            log.debug("Unable to find group: '" + groupNames[i].trim() + "'");
                    } catch (SQLException sqle) {
                        log.error("Exception thrown while trying to lookup affiliation role for group name: '"
                                + groupNames[i].trim() + "'", sqle);
                    }
                } // for each groupNames
            } // foreach affiliations
        } // if affiliations

        log.info("Added current EPerson to special groups: " + groups);

        List<UUID> groupIds = new ArrayList<>();
        for (Group group : groups) {
            groupIds.add(group.getID());
        }

        // Cache the special groups, so we don't have to recalculate them again
        // for this session.
        request.getSession().setAttribute("shib.specialgroup", groupIds);

        return new ArrayList<>(groups);
    } catch (Throwable t) {
        log.error("Unable to validate any sepcial groups this user may belong too because of an exception.", t);
        return ListUtils.EMPTY_LIST;
    }
}

From source file:org.dspace.authenticate.X509Authentication.java

/**
 * Return special groups configured in dspace.cfg for X509 certificate
 * authentication.// ww w . j a  v  a 2  s.  c o  m
 * 
 * @param context context
 * @param request
 *            object potentially containing the cert
 * 
 * @return An int array of group IDs
 * @throws SQLException if database error
 * 
 */
@Override
public List<Group> getSpecialGroups(Context context, HttpServletRequest request) throws SQLException {
    if (request == null) {
        return ListUtils.EMPTY_LIST;
    }

    Boolean authenticated = false;
    HttpSession session = request.getSession(false);
    authenticated = (Boolean) session.getAttribute("x509Auth");
    authenticated = (null == authenticated) ? false : authenticated;

    if (authenticated) {
        List<String> groupNames = getX509Groups();
        List<Group> groups = new ArrayList<>();

        if (groupNames != null) {
            for (String groupName : groupNames) {
                if (groupName != null) {
                    Group group = groupService.findByName(context, groupName);
                    if (group != null) {
                        groups.add(group);
                    } else {
                        log.warn(LogManager.getHeader(context, "configuration_error",
                                "unknown_group=" + groupName));
                    }
                }
            }
        }

        return groups;
    }

    return ListUtils.EMPTY_LIST;
}

From source file:org.dspace.content.BitstreamFormatTest.java

/**
 * Test of setExtensions method, of class BitstreamFormat.
 *///from w  ww. j a  v  a 2  s  .c o  m
@Test
public void setExtensions() {
    List<String> backupExtensions = bf.getExtensions();
    assertThat("setExtensions 0", bf.getExtensions().get(0), equalTo("xml"));
    String[] values = { "1", "2", "3" };
    bf.setExtensions(Arrays.asList(values));
    assertThat("setExtensions 1", bf.getExtensions(), notNullValue());
    assertTrue("setExtensions 2", bf.getExtensions().size() == 3);
    assertThat("setExtensions 3", bf.getExtensions().get(0), equalTo("1"));
    assertThat("setExtensions 4", bf.getExtensions().get(1), equalTo("2"));
    assertThat("setExtensions 5", bf.getExtensions().get(2), equalTo("3"));

    bf.setExtensions(ListUtils.EMPTY_LIST);
    assertThat("setExtensions 6", bf.getExtensions(), notNullValue());
    assertTrue("setExtensions 7", bf.getExtensions().size() == 0);
    bf.setExtensions(backupExtensions);
}

From source file:org.dspace.content.dao.impl.CommunityDAOImpl.java

@Override
public List<Community> findAll(Context context, MetadataField sortField, Integer limit, Integer offset)
        throws SQLException {
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("SELECT ").append(Community.class.getSimpleName()).append(" FROM Community as ")
            .append(Community.class.getSimpleName()).append(" ");
    addMetadataLeftJoin(queryBuilder, Community.class.getSimpleName(), Arrays.asList(sortField));
    addMetadataSortQuery(queryBuilder, Arrays.asList(sortField), ListUtils.EMPTY_LIST);

    Query query = createQuery(context, queryBuilder.toString());
    if (offset != null) {
        query.setFirstResult(offset);//  w  ww .j a v a 2s.  c  o m
    }
    if (limit != null) {
        query.setMaxResults(limit);
    }
    query.setParameter(sortField.toString(), sortField.getID());
    return list(query);
}

From source file:org.dspace.content.dao.impl.CommunityDAOImpl.java

@Override
public List<Community> findAllNoParent(Context context, MetadataField sortField) throws SQLException {
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("SELECT community FROM Community as community ");
    addMetadataLeftJoin(queryBuilder, Community.class.getSimpleName().toLowerCase(), Arrays.asList(sortField));
    addMetadataValueWhereQuery(queryBuilder, ListUtils.EMPTY_LIST, null,
            " community.parentCommunities IS EMPTY");
    addMetadataSortQuery(queryBuilder, Arrays.asList(sortField), ListUtils.EMPTY_LIST);

    Query query = createQuery(context, queryBuilder.toString());
    query.setParameter(sortField.toString(), sortField.getID());
    query.setCacheable(true);//from  w ww.j  a va  2s. com

    return findMany(context, query);
}

From source file:org.dspace.core.AbstractHibernateDSODAO.java

protected void addMetadataSortQuery(StringBuilder query, List<MetadataField> metadataSortFields,
        List<String> columnSortFields) {
    addMetadataSortQuery(query, metadataSortFields, columnSortFields, ListUtils.EMPTY_LIST);
}

From source file:org.dspace.eperson.dao.impl.EPersonDAOImpl.java

@Override
public int searchResultCount(Context context, String query, List<MetadataField> queryFields)
        throws SQLException {
    String queryString = "SELECT count(*) FROM EPerson as " + EPerson.class.getSimpleName().toLowerCase();
    Query hibernateQuery = getSearchQuery(context, queryString, query, queryFields, ListUtils.EMPTY_LIST, null);

    return count(hibernateQuery);
}