Example usage for org.springframework.util StringUtils collectionToCommaDelimitedString

List of usage examples for org.springframework.util StringUtils collectionToCommaDelimitedString

Introduction

In this page you can find the example usage for org.springframework.util StringUtils collectionToCommaDelimitedString.

Prototype

public static String collectionToCommaDelimitedString(@Nullable Collection<?> coll) 

Source Link

Document

Convert a Collection into a delimited String (e.g., CSV).

Usage

From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenServices.java

@Override
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException {
    Map<String, Object> claims = getClaimsForToken(accessToken);

    // Check token expiry
    Integer expiration = (Integer) claims.get(EXP);
    if (expiration != null && new Date(expiration * 1000l).before(new Date())) {
        throw new InvalidTokenException("Invalid access token (expired): " + accessToken + " expired at "
                + new Date(expiration * 1000l));
    }/*ww  w . j ava  2 s. co  m*/

    // Check client ID is valid
    validateClient((String) claims.get(CLIENT_ID));
    validateClient((String) claims.get(CID));

    @SuppressWarnings("unchecked")
    ArrayList<String> scopes = (ArrayList<String>) claims.get(SCOPE);

    AuthorizationRequest authorizationRequest = new AuthorizationRequest((String) claims.get(CLIENT_ID),
            scopes);

    ArrayList<String> rids = (ArrayList<String>) claims.get(AUD);
    //TODO - Fix null resource IDs for a client_credentials request to /oauth/token
    Set<String> resourceIds = Collections
            .unmodifiableSet(rids == null ? new HashSet<String>() : new HashSet<>(rids));
    authorizationRequest.setResourceIds(resourceIds);

    authorizationRequest.setApproved(true);

    Collection<? extends GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(
            StringUtils.collectionToCommaDelimitedString(defaultUserAuthorities));
    if (claims.containsKey("authorities")) {
        Object authoritiesFromClaims = claims.get("authorities");
        if (authoritiesFromClaims instanceof String) {
            authorities = AuthorityUtils.commaSeparatedStringToAuthorityList((String) authoritiesFromClaims);
        }
        if (authoritiesFromClaims instanceof Collection) {
            authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(
                    StringUtils.collectionToCommaDelimitedString((Collection<?>) authoritiesFromClaims));
        }
    }

    Authentication userAuthentication = null;
    // Is this a user token?
    if (claims.containsKey(EMAIL)) {
        UaaUser user = new UaaUser((String) claims.get(USER_ID), (String) claims.get(USER_NAME), null,
                (String) claims.get(EMAIL), UaaAuthority.USER_AUTHORITIES, null, null, null, null, null, null,
                false);

        UaaPrincipal principal = new UaaPrincipal(user);
        userAuthentication = new UaaAuthentication(principal, UaaAuthority.USER_AUTHORITIES, null);
    } else {
        authorizationRequest.setAuthorities(authorities);
    }

    OAuth2Authentication authentication = new OAuth2Authentication(authorizationRequest.createOAuth2Request(),
            userAuthentication);
    authentication.setAuthenticated(true);
    return authentication;
}

From source file:org.cloudfoundry.identity.uaa.oauth.UaaTokenServices.java

@Override
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException {
    if (StringUtils.isEmpty(accessToken)) {
        throw new InvalidTokenException(
                "Invalid access token value, must be at least 30 characters:" + accessToken);
    }//www. j a  va  2 s .  c  o  m

    TokenValidation tokenValidation = validateToken(accessToken);
    Map<String, Object> claims = tokenValidation.getClaims();
    accessToken = tokenValidation.getJwt().getEncoded();

    // Check token expiry
    Integer expiration = (Integer) claims.get(EXP);
    if (expiration != null && new Date(expiration * 1000l).before(new Date())) {
        throw new InvalidTokenException("Invalid access token (expired): " + accessToken + " expired at "
                + new Date(expiration * 1000l));
    }

    @SuppressWarnings("unchecked")
    ArrayList<String> scopes = (ArrayList<String>) claims.get(SCOPE);

    AuthorizationRequest authorizationRequest = new AuthorizationRequest((String) claims.get(CLIENT_ID),
            scopes);

    ArrayList<String> rids = (ArrayList<String>) claims.get(AUD);
    //TODO - Fix null resource IDs for a client_credentials request to /oauth/token
    Set<String> resourceIds = Collections
            .unmodifiableSet(rids == null ? new HashSet<String>() : new HashSet<>(rids));
    authorizationRequest.setResourceIds(resourceIds);

    authorizationRequest.setApproved(true);

    Collection<? extends GrantedAuthority> authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(
            StringUtils.collectionToCommaDelimitedString(defaultUserAuthorities));
    if (claims.containsKey("authorities")) {
        Object authoritiesFromClaims = claims.get("authorities");
        if (authoritiesFromClaims instanceof String) {
            authorities = AuthorityUtils.commaSeparatedStringToAuthorityList((String) authoritiesFromClaims);
        }
        if (authoritiesFromClaims instanceof Collection) {
            authorities = AuthorityUtils.commaSeparatedStringToAuthorityList(
                    StringUtils.collectionToCommaDelimitedString((Collection<?>) authoritiesFromClaims));
        }
    }

    Authentication userAuthentication = null;
    // Is this a user token - minimum info is user_id
    if (claims.containsKey(USER_ID)) {
        UaaUser user = userDatabase.retrieveUserById((String) claims.get(USER_ID));
        UaaPrincipal principal = new UaaPrincipal(user);
        userAuthentication = new UaaAuthentication(principal, UaaAuthority.USER_AUTHORITIES, null);
    } else {
        authorizationRequest.setAuthorities(authorities);
    }

    OAuth2Authentication authentication = new UaaOauth2Authentication(accessToken,
            IdentityZoneHolder.get().getId(), authorizationRequest.createOAuth2Request(), userAuthentication);
    authentication.setAuthenticated(true);
    return authentication;
}

From source file:org.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimGroupMembershipManager.java

private String getGroupAuthorities(ScimGroupMemberInterface member) {
    if (member.getRoles() != null && !member.getRoles().isEmpty()) {
        return StringUtils.collectionToCommaDelimitedString(member.getRoles());
    } else {/* ww  w .j a  va2s.co m*/
        return StringUtils.collectionToCommaDelimitedString(ScimGroupMemberInterface.GROUP_MEMBER);
    }
}

From source file:org.cloudfoundry.identity.uaa.scim.jdbc.JdbcScimGroupMembershipManager.java

private String getGroupAuthorities(ScimGroupMember member) {
    if (member.getRoles() != null && !member.getRoles().isEmpty()) {
        return StringUtils.collectionToCommaDelimitedString(member.getRoles());
    } else {//from www .  j a  v a  2  s . c o m
        return StringUtils.collectionToCommaDelimitedString(ScimGroupMember.GROUP_MEMBER);
    }
}

From source file:org.cloudfoundry.identity.uaa.test.UaaTestAccounts.java

public ClientDetails getClientDetails(String prefix, BaseClientDetails defaults) {
    String clientId = environment.getProperty(prefix + ".id", defaults.getClientId());
    String clientSecret = environment.getProperty(prefix + ".secret", defaults.getClientSecret());
    String resourceIds = environment.getProperty(prefix + ".resource-ids",
            StringUtils.collectionToCommaDelimitedString(defaults.getResourceIds()));
    String scopes = environment.getProperty(prefix + ".scope",
            StringUtils.collectionToCommaDelimitedString(defaults.getScope()));
    String grantTypes = environment.getProperty(prefix + ".authorized-grant-types",
            StringUtils.collectionToCommaDelimitedString(defaults.getAuthorizedGrantTypes()));
    String authorities = environment.getProperty(prefix + ".authorities",
            StringUtils.collectionToCommaDelimitedString(defaults.getAuthorities()));
    String redirectUris = environment.getProperty(prefix + ".redirect-uri",
            StringUtils.collectionToCommaDelimitedString(defaults.getRegisteredRedirectUri()));
    BaseClientDetails result = new BaseClientDetails(clientId, resourceIds, scopes, grantTypes, authorities,
            redirectUris);//from w ww .j av a 2 s .  co m
    result.setClientSecret(clientSecret);
    return result;
}

From source file:org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService.java

private Object[] getFieldsForUpdate(ClientDetails clientDetails) {
    String json = null;//w w w  .  j av  a2 s.co  m
    try {
        json = JsonUtils.writeValueAsString(clientDetails.getAdditionalInformation());
    } catch (Exception e) {
        logger.warn("Could not serialize additional information: " + clientDetails, e);
        throw new InvalidDataAccessResourceUsageException(
                "Could not serialize additional information:" + clientDetails.getClientId(), e);
    }
    return new Object[] {
            clientDetails.getResourceIds() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getResourceIds())
                    : null,
            clientDetails.getScope() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getScope())
                    : null,
            clientDetails.getAuthorizedGrantTypes() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorizedGrantTypes())
                    : null,
            clientDetails.getRegisteredRedirectUri() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getRegisteredRedirectUri())
                    : null,
            clientDetails.getAuthorities() != null
                    ? StringUtils.collectionToCommaDelimitedString(clientDetails.getAuthorities())
                    : null,
            clientDetails.getAccessTokenValiditySeconds(), clientDetails.getRefreshTokenValiditySeconds(), json,
            getAutoApproveScopes(clientDetails), new Timestamp(System.currentTimeMillis()),
            clientDetails.getClientId(), IdentityZoneHolder.get().getId() };
}

From source file:org.cloudfoundry.identity.uaa.zone.MultitenantJdbcClientDetailsService.java

private String getAutoApproveScopes(ClientDetails clientDetails) {
    if (clientDetails.isAutoApprove("true")) {
        return "true"; // all scopes autoapproved
    }/*  w  ww . j  ava2 s  .  c o m*/
    Set<String> scopes = new HashSet<String>();
    for (String scope : clientDetails.getScope()) {
        if (clientDetails.isAutoApprove(scope)) {
            scopes.add(scope);
        }
    }
    return StringUtils.collectionToCommaDelimitedString(scopes);
}

From source file:org.eclipse.hawkbit.ui.artifacts.upload.UploadLayout.java

private String getDuplicateFileValidationMessage() {
    final StringBuilder message = new StringBuilder();
    if (!duplicateFileNamesList.isEmpty()) {
        final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList);
        if (duplicateFileNamesList.size() == 1) {
            message.append(i18n.getMessage("message.no.duplicateFile") + fileNames);

        } else if (duplicateFileNamesList.size() > 1) {
            message.append(i18n.getMessage("message.no.duplicateFiles"));
        }/*from   w  w w.ja va2  s. co  m*/
    }
    return message.toString();
}

From source file:org.genedb.jogra.plugins.TermRationaliser.java

private void setSelectedTaxonsAndScopeLabel(List<String> organismNames) {
    if (this.selectedTaxons != null && this.selectedTaxons.size() > 0) {
        this.selectedTaxons.clear(); //clear anything that already is in the list
    }//from  w ww.  ja  v  a 2 s .com

    if (organismNames != null && organismNames.size() != 0 && !organismNames.contains("root")) { // 'root' with a simple r causes problems 
        scopeLabel.setText("Organism(s): " + StringUtils.collectionToCommaDelimitedString(organismNames));
        for (String s : organismNames) {
            this.selectedTaxons.add(taxonNodeManager.getTaxonNodeForLabel(s));
        }
    } else { //If there are no selections, get all terms
        scopeLabel.setText("Organism(s): All organisms");
        this.selectedTaxons.add(taxonNodeManager.getTaxonNodeForLabel("Root"));
    }
}

From source file:org.genedb.jogra.plugins.TermRationaliser.java

private Box createRationaliserPanel(final String name, final RationaliserJList rjlist) {

    int preferredHeight = 500; //change accordingly
    int preferredWidth = 500;

    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension size = tk.getScreenSize();
    int textboxHeight = 10; //change accordingly
    int textboxWidth = size.width;

    Box box = Box.createVerticalBox();
    box.add(new JLabel(name));

    JTextField searchField = new JTextField(20); //Search field on top
    /* We don't want this textfield's height to expand when
     * the Rationaliser is dragged to exapnd. So we set it's
     * height to what we want and the width to the width of
     * the screen  /*w w  w . java  2s.c o  m*/
     */
    searchField.setMaximumSize(new Dimension(textboxWidth, textboxHeight));
    rjlist.installJTextField(searchField);
    box.add(searchField);

    JScrollPane scrollPane = new JScrollPane(); //scroll pane
    scrollPane.setViewportView(rjlist);
    scrollPane.setPreferredSize(new Dimension(preferredWidth, preferredHeight));
    box.add(scrollPane);

    TitledBorder sysidBorder = BorderFactory.createTitledBorder("Systematic IDs"); //systematic ID box
    sysidBorder.setTitleColor(Color.DARK_GRAY);

    final JTextArea idField = new JTextArea(1, 1);
    idField.setMaximumSize(new Dimension(textboxWidth, textboxHeight));
    idField.setEditable(false);
    idField.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
    idField.setForeground(Color.DARK_GRAY);
    JScrollPane scroll = new JScrollPane(idField);
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    Box sysidBox = Box.createVerticalBox();
    sysidBox.add(scroll /*idField*/);
    sysidBox.setBorder(sysidBorder);
    box.add(sysidBox);

    rjlist.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            Term highlightedTerm = (Term) rjlist.getSelectedValue();
            if (highlightedTerm != null) {
                /* For each list, call the relevant methods
                 * to get the systematic IDs. Then for the
                 * right list, add the term name in the
                 * text box below
                 */
                if (name.equals(FROM_LIST_NAME)) {
                    idField.setText(StringUtils.collectionToCommaDelimitedString(
                            termService.getSystematicIDs(highlightedTerm, selectedTaxons)));
                } else if (name.equals(TO_LIST_NAME)) {
                    idField.setText(StringUtils.collectionToCommaDelimitedString(
                            termService.getSystematicIDs(highlightedTerm, null)));
                    /* We allow the user to edit the term name */
                    textField.setText(highlightedTerm.getName());
                }

            }
        }
    });

    return box;

}