001/*
002 * (C) Copyright 2006-2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nelson Silva <nelson.silva@inevo.pt> - initial API and implementation
016 *     Nuxeo
017 */
018
019package org.nuxeo.ecm.platform.oauth2.openid;
020
021import java.io.Serializable;
022
023import org.nuxeo.common.xmap.annotation.XNode;
024import org.nuxeo.common.xmap.annotation.XNodeList;
025import org.nuxeo.common.xmap.annotation.XObject;
026import org.nuxeo.ecm.platform.oauth2.openid.auth.DefaultOpenIDUserInfo;
027import org.nuxeo.ecm.platform.oauth2.openid.auth.OpenIDUserInfo;
028import org.nuxeo.ecm.platform.oauth2.openid.auth.UserResolver;
029import org.nuxeo.ecm.platform.oauth2.openid.auth.EmailBasedUserResolver;
030
031@XObject("provider")
032public class OpenIDConnectProviderDescriptor implements Serializable {
033    protected static final long serialVersionUID = 1L;
034
035    public static final String DEFAULT_ACCESS_TOKEN_KEY = "access_token";
036
037    public static final Class<? extends UserResolver> DEFAULT_USER_RESOLVER_CLASS = EmailBasedUserResolver.class;
038
039    public static final Class<? extends RedirectUriResolver> DEFAULT_REDIRECT_URI_RESOLVER_CLASS = RedirectUriResolverHelper.class;
040
041    public static final Class<? extends OpenIDUserInfo> DEFAULT_USER_INFO_CLASS = DefaultOpenIDUserInfo.class;
042
043    @XNode("@enabled")
044    protected boolean enabled = true;
045
046    @XNode("name")
047    protected String name;
048
049    @XNode("tokenServerURL")
050    protected String tokenServerURL;
051
052    @XNode("authorizationServerURL")
053    protected String authorizationServerURL;
054
055    @XNode("userInfoURL")
056    protected String userInfoURL;
057
058    @XNode("accessTokenKey")
059    protected String accessTokenKey = DEFAULT_ACCESS_TOKEN_KEY;
060
061    @XNode("clientId")
062    protected String clientId;
063
064    @XNode("clientSecret")
065    protected String clientSecret;
066
067    @XNodeList(value = "scope", type = String[].class, componentType = String.class)
068    protected String[] scopes;
069
070    @XNode("icon")
071    protected String icon;
072
073    @XNode("label")
074    protected String label;
075
076    @XNode("description")
077    protected String description;
078
079    @XNode("userResolverClass")
080    protected Class<? extends UserResolver> userResolverClass;
081
082    @XNode("userMapperName")
083    protected String userMapper;
084
085    @XNode("redirectUriResolver")
086    protected Class<? extends RedirectUriResolver> redirectUriResolver = DEFAULT_REDIRECT_URI_RESOLVER_CLASS;
087
088    @XNode("userInfoClass")
089    protected Class<? extends OpenIDUserInfo> userInfoClass = DEFAULT_USER_INFO_CLASS;
090
091    public static long getSerialversionuid() {
092        return serialVersionUID;
093    }
094
095    public String getName() {
096        return name;
097    }
098
099    public String getTokenServerURL() {
100        return tokenServerURL;
101    }
102
103    public String getAuthorizationServerURL() {
104        return authorizationServerURL;
105    }
106
107    public String getClientId() {
108        return clientId;
109    }
110
111    public String getClientSecret() {
112        return clientSecret;
113    }
114
115    public String[] getScopes() {
116        return scopes;
117    }
118
119    public String getUserInfoURL() {
120        return userInfoURL;
121    }
122
123    public String getAccessTokenKey() {
124        return accessTokenKey;
125    }
126
127    public String getIcon() {
128        return icon;
129    }
130
131    public boolean isEnabled() {
132        return enabled;
133    }
134
135    public void setEnabled(boolean enabled) {
136        this.enabled = enabled;
137    }
138
139    public String getLabel() {
140        return label;
141    }
142
143    public String getDescription() {
144        return description;
145    }
146
147    public String getUserMapper() {
148        return userMapper;
149    }
150
151    public Class<? extends UserResolver> getUserResolverClass() {
152        if (userResolverClass==null && userMapper==null) {
153            return DEFAULT_USER_RESOLVER_CLASS;
154        }
155        return userResolverClass;
156    }
157
158    public Class<? extends RedirectUriResolver> getRedirectUriResolver() {
159        return redirectUriResolver;
160    }
161
162    public Class<? extends OpenIDUserInfo> getUserInfoClass() {
163        return userInfoClass;
164    }
165
166
167}