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 <gbarata@nuxeo.com> 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.codehaus.jackson.JsonNode; 028import org.nuxeo.ecm.core.io.marshallers.json.EntityJsonReader; 029import org.nuxeo.ecm.core.io.registry.reflect.Setup; 030 031/** 032 * @since 9.2 033 */ 034@Setup(mode = SINGLETON, priority = REFERENCE) 035public class NuxeoOAuth2ServiceProviderReader extends EntityJsonReader<NuxeoOAuth2ServiceProvider> { 036 037 public NuxeoOAuth2ServiceProviderReader() { 038 super(NuxeoOAuth2ServiceProviderWriter.ENTITY_TYPE); 039 } 040 041 @Override 042 protected NuxeoOAuth2ServiceProvider readEntity(JsonNode jn) throws IOException { 043 NuxeoOAuth2ServiceProvider provider = new NuxeoOAuth2ServiceProvider(); 044 provider.setServiceName(getStringField(jn, "serviceName")); 045 provider.setDescription(getStringField(jn, "description")); 046 provider.setClientId(getStringField(jn, "clientId")); 047 provider.setClientSecret(getStringField(jn, "clientSecret")); 048 provider.setAuthorizationServerURL(getStringField(jn, "authorizationServerURL")); 049 provider.setTokenServerURL(getStringField(jn, "tokenServerURL")); 050 provider.setUserAuthorizationURL(getStringField(jn, "userAuthorizationURL")); 051 List<String> scopes = getStringListField(jn, "scopes"); 052 provider.setScopes(scopes == null ? new String[0] : scopes.toArray(new String[0])); 053 Boolean enabled = getBooleanField(jn, "isEnabled"); 054 provider.setEnabled(enabled == null ? false : enabled); 055 return provider; 056 } 057 058}