001/*
002 * (C) Copyright 2006-2013 Nuxeo SA (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 <nelson.silva@inevo.pt> - initial API and implementation
018 *     Nuxeo
019 */
020
021package org.nuxeo.ecm.platform.oauth2.openid;
022
023import java.io.Serializable;
024
025import org.nuxeo.common.xmap.annotation.XNode;
026import org.nuxeo.common.xmap.annotation.XNodeList;
027import org.nuxeo.common.xmap.annotation.XObject;
028import org.nuxeo.ecm.platform.oauth2.openid.auth.DefaultOpenIDUserInfo;
029import org.nuxeo.ecm.platform.oauth2.openid.auth.OpenIDUserInfo;
030import org.nuxeo.ecm.platform.oauth2.openid.auth.UserResolver;
031import org.nuxeo.ecm.platform.oauth2.openid.auth.EmailBasedUserResolver;
032
033@XObject("provider")
034public class OpenIDConnectProviderDescriptor implements Serializable {
035    protected static final long serialVersionUID = 1L;
036
037    public static final String DEFAULT_ACCESS_TOKEN_KEY = "access_token";
038
039    public static final Class<? extends UserResolver> DEFAULT_USER_RESOLVER_CLASS = EmailBasedUserResolver.class;
040
041    public static final Class<? extends RedirectUriResolver> DEFAULT_REDIRECT_URI_RESOLVER_CLASS = RedirectUriResolverHelper.class;
042
043    public static final Class<? extends OpenIDUserInfo> DEFAULT_USER_INFO_CLASS = DefaultOpenIDUserInfo.class;
044
045    @XNode("@enabled")
046    protected boolean enabled = true;
047
048    @XNode("name")
049    protected String name;
050
051    @XNode("tokenServerURL")
052    protected String tokenServerURL;
053
054    @XNode("authorizationServerURL")
055    protected String authorizationServerURL;
056
057    @XNode("userInfoURL")
058    protected String userInfoURL;
059
060    @XNode("accessTokenKey")
061    protected String accessTokenKey = DEFAULT_ACCESS_TOKEN_KEY;
062
063    @XNode("clientId")
064    protected String clientId;
065
066    @XNode("clientSecret")
067    protected String clientSecret;
068
069    @XNodeList(value = "scope", type = String[].class, componentType = String.class)
070    protected String[] scopes;
071
072    @XNode("icon")
073    protected String icon;
074
075    @XNode("label")
076    protected String label;
077
078    @XNode("description")
079    protected String description;
080
081    @XNode("userResolverClass")
082    protected Class<? extends UserResolver> userResolverClass;
083
084    @XNode("userMapperName")
085    protected String userMapper;
086
087    @XNode("redirectUriResolver")
088    protected Class<? extends RedirectUriResolver> redirectUriResolver = DEFAULT_REDIRECT_URI_RESOLVER_CLASS;
089
090    @XNode("userInfoClass")
091    protected Class<? extends OpenIDUserInfo> userInfoClass = DEFAULT_USER_INFO_CLASS;
092
093    public static long getSerialversionuid() {
094        return serialVersionUID;
095    }
096
097    public String getName() {
098        return name;
099    }
100
101    public String getTokenServerURL() {
102        return tokenServerURL;
103    }
104
105    public String getAuthorizationServerURL() {
106        return authorizationServerURL;
107    }
108
109    public String getClientId() {
110        return clientId;
111    }
112
113    public String getClientSecret() {
114        return clientSecret;
115    }
116
117    public String[] getScopes() {
118        return scopes;
119    }
120
121    public String getUserInfoURL() {
122        return userInfoURL;
123    }
124
125    public String getAccessTokenKey() {
126        return accessTokenKey;
127    }
128
129    public String getIcon() {
130        return icon;
131    }
132
133    public boolean isEnabled() {
134        return enabled;
135    }
136
137    public void setEnabled(boolean enabled) {
138        this.enabled = enabled;
139    }
140
141    public String getLabel() {
142        return label;
143    }
144
145    public String getDescription() {
146        return description;
147    }
148
149    public String getUserMapper() {
150        return userMapper;
151    }
152
153    public Class<? extends UserResolver> getUserResolverClass() {
154        if (userResolverClass==null && userMapper==null) {
155            return DEFAULT_USER_RESOLVER_CLASS;
156        }
157        return userResolverClass;
158    }
159
160    public Class<? extends RedirectUriResolver> getRedirectUriResolver() {
161        return redirectUriResolver;
162    }
163
164    public Class<? extends OpenIDUserInfo> getUserInfoClass() {
165        return userInfoClass;
166    }
167
168
169}