001/*
002 * (C) Copyright 2015-2018 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *      Nelson Silva
018 */
019package org.nuxeo.ecm.admin.oauth2;
020
021import java.util.ArrayList;
022import java.util.Arrays;
023import java.util.List;
024
025import org.apache.commons.lang3.StringUtils;
026import org.jboss.seam.ScopeType;
027import org.jboss.seam.annotations.Name;
028import org.jboss.seam.annotations.Scope;
029import org.nuxeo.ecm.admin.oauth.DirectoryBasedEditor;
030import org.nuxeo.ecm.platform.oauth2.tokens.OAuth2TokenStore;
031
032@Name("oauth2ProvidersTokensActions")
033@Scope(ScopeType.CONVERSATION)
034public class OAuth2ProvidersTokensActionBean extends DirectoryBasedEditor {
035
036    private static final long serialVersionUID = 1L;
037
038    @Override
039    protected String getDirectoryName() {
040        return OAuth2TokenStore.DIRECTORY_NAME;
041    }
042
043    @Override
044    protected String getSchemaName() {
045        return "oauth2Token";
046    }
047
048    public List<String> getSharedWith() {
049        List<String> sharedWith = new ArrayList<>();
050        String sharedWithProperty = (String) editableEntry.getProperty(getSchemaName(), "sharedWith");
051        if (sharedWithProperty != null) {
052            sharedWith = Arrays.asList(sharedWithProperty.split(","));
053        }
054        return sharedWith;
055    }
056
057    public void setSharedWith(List<String> sharedWith) {
058        String list = StringUtils.join(sharedWith, ",");
059        editableEntry.setProperty(getSchemaName(), "sharedWith", list);
060    }
061}