001/* 002 * (C) Copyright 2017 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 * Gabriel Barata <[email protected]> 018 */ 019package org.nuxeo.ecm.platform.oauth2.providers; 020 021import static org.nuxeo.ecm.core.io.registry.reflect.Instantiations.SINGLETON; 022import static org.nuxeo.ecm.core.io.registry.reflect.Priorities.REFERENCE; 023 024import java.io.IOException; 025import java.util.List; 026 027import org.nuxeo.ecm.core.io.marshallers.json.EntityJsonReader; 028import org.nuxeo.ecm.core.io.registry.reflect.Setup; 029 030import com.fasterxml.jackson.databind.JsonNode; 031 032/** 033 * @since 9.2 034 */ 035@Setup(mode = SINGLETON, priority = REFERENCE) 036public class NuxeoOAuth2ServiceProviderReader extends EntityJsonReader<NuxeoOAuth2ServiceProvider> { 037 038 public NuxeoOAuth2ServiceProviderReader() { 039 super(NuxeoOAuth2ServiceProviderWriter.ENTITY_TYPE); 040 } 041 042 @Override 043 protected NuxeoOAuth2ServiceProvider readEntity(JsonNode jn) throws IOException { 044 NuxeoOAuth2ServiceProvider provider = new NuxeoOAuth2ServiceProvider(); 045 provider.setServiceName(getStringField(jn, "serviceName")); 046 provider.setDescription(getStringField(jn, "description")); 047 provider.setClientId(getStringField(jn, "clientId")); 048 provider.setClientSecret(getStringField(jn, "clientSecret")); 049 provider.setAuthorizationServerURL(getStringField(jn, "authorizationServerURL")); 050 provider.setTokenServerURL(getStringField(jn, "tokenServerURL")); 051 provider.setUserAuthorizationURL(getStringField(jn, "userAuthorizationURL")); 052 List<String> scopes = getStringListField(jn, "scopes"); 053 provider.setScopes(scopes == null ? new String[0] : scopes.toArray(new String[0])); 054 Boolean enabled = getBooleanField(jn, "isEnabled"); 055 provider.setEnabled(enabled == null ? false : enabled); 056 return provider; 057 } 058 059}