001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.users;
019
020import io.stallion.dataAccess.ModelBase;
021import io.stallion.dataAccess.UniqueKey;
022import io.stallion.dataAccess.db.Converter;
023
024import javax.persistence.Column;
025
026import java.util.*;
027
028import static io.stallion.utils.Literals.*;
029
030
031public class OAuthClient extends ModelBase {
032    private String name = "";
033    private String publicName = "";
034    private String publicAuthor = "";
035    private String publicDescription = "";
036    private String logoUrl = "";
037    private String fullClientId = "";
038    private String clientSecret = "";
039    private boolean requiresSecret = true;
040    private boolean allowProvidedCode = false;
041    private Set<String> allowedRedirectUris = set();
042    private Long creatorId = 0L;
043    private Set<Long> ownerIds = set();
044    private Set<String> scopes = set();
045    private boolean scoped = false;
046    private Long accessTokenValiditySeconds = 0L;
047    private Long refreshTokenValiditySeconds = 0L;
048    private Set<String> authorizedGrantTypes = new HashSet<>();
049    private String defaultRedirectUri = "";
050    private Boolean autoApprove = false;
051    private Map additionalInformation = new HashMap<>();
052    private boolean disabled = false;
053    private boolean pendingApproval = false;
054
055    @Column
056    public String getName() {
057        return name;
058    }
059
060    public OAuthClient setName(String name) {
061        this.name = name;
062        return this;
063    }
064
065    public String getPublicAuthor() {
066        return publicAuthor;
067    }
068
069    public OAuthClient setPublicAuthor(String publicAuthor) {
070        this.publicAuthor = publicAuthor;
071        return this;
072    }
073
074    @UniqueKey
075    @Column
076    public String getFullClientId() {
077        return fullClientId;
078    }
079
080    public OAuthClient setFullClientId(String fullClientId) {
081        this.fullClientId = fullClientId;
082        return this;
083    }
084
085    @Column
086    public String getClientSecret() {
087        return clientSecret;
088    }
089
090    public OAuthClient setClientSecret(String clientSecret) {
091        this.clientSecret = clientSecret;
092        return this;
093    }
094
095    @Column
096    @Converter(name="io.stallion.dataAccess.db.converters.JsonSetConverter")
097    public Set<String> getAllowedRedirectUris() {
098        return allowedRedirectUris;
099    }
100
101    public OAuthClient setAllowedRedirectUris(Set<String> allowedRedirectUris) {
102        this.allowedRedirectUris = allowedRedirectUris;
103        return this;
104    }
105
106    @Column
107    public Long getCreatorId() {
108        return creatorId;
109    }
110
111    public OAuthClient setCreatorId(Long creatorId) {
112        this.creatorId = creatorId;
113        return this;
114    }
115
116    @Column
117    @Converter(name="io.stallion.dataAccess.db.converters.JsonSetConverter")
118    public Set<Long> getOwnerIds() {
119        return ownerIds;
120    }
121
122    public OAuthClient setOwnerIds(Set<Long> ownerIds) {
123        this.ownerIds = ownerIds;
124        return this;
125    }
126
127    @Column
128    public Set<String> getScopes() {
129        return scopes;
130    }
131
132    public OAuthClient setScopes(Set<String> scopes) {
133        this.scopes = scopes;
134        return this;
135    }
136
137    @Column
138    public boolean isScoped() {
139        return scoped;
140    }
141
142    public OAuthClient setScoped(boolean scoped) {
143        this.scoped = scoped;
144        return this;
145    }
146
147    @Column
148    public Long getAccessTokenValiditySeconds() {
149        return accessTokenValiditySeconds;
150    }
151
152    public OAuthClient setAccessTokenValiditySeconds(Long accessTokenValiditySeconds) {
153        this.accessTokenValiditySeconds = accessTokenValiditySeconds;
154        return this;
155    }
156
157    @Column
158    public Long getRefreshTokenValiditySeconds() {
159        return refreshTokenValiditySeconds;
160    }
161
162    public OAuthClient setRefreshTokenValiditySeconds(Long refreshTokenValiditySeconds) {
163        this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
164        return this;
165    }
166
167    @Column
168    public Set<String> getAuthorizedGrantTypes() {
169        return authorizedGrantTypes;
170    }
171
172    public OAuthClient setAuthorizedGrantTypes(Set<String> authorizedGrantTypes) {
173        this.authorizedGrantTypes = authorizedGrantTypes;
174        return this;
175    }
176
177    @Column
178    public String getDefaultRedirectUri() {
179        return defaultRedirectUri;
180    }
181
182    public OAuthClient setDefaultRedirectUri(String defaultRedirectUri) {
183        this.defaultRedirectUri = defaultRedirectUri;
184        return this;
185    }
186
187    @Column
188    public Boolean getAutoApprove() {
189        return autoApprove;
190    }
191
192    public OAuthClient setAutoApprove(Boolean autoApprove) {
193        this.autoApprove = autoApprove;
194        return this;
195    }
196
197    @Column
198    @Converter(name="io.stallion.dataAccess.db.converters.JsonMapConverter")
199    public Map getAdditionalInformation() {
200        return additionalInformation;
201    }
202
203    public OAuthClient setAdditionalInformation(Map additionalInformation) {
204        this.additionalInformation = additionalInformation;
205        return this;
206    }
207
208    @Column
209    public String getPublicName() {
210        return publicName;
211    }
212
213    public OAuthClient setPublicName(String publicName) {
214        this.publicName = publicName;
215        return this;
216    }
217
218    @Column
219    public String getPublicDescription() {
220        return publicDescription;
221    }
222
223    public OAuthClient setPublicDescription(String publicDescription) {
224        this.publicDescription = publicDescription;
225        return this;
226    }
227
228    @Column
229    public String getLogoUrl() {
230        return logoUrl;
231    }
232
233    public OAuthClient setLogoUrl(String logoUrl) {
234        this.logoUrl = logoUrl;
235        return this;
236    }
237
238    @Column
239    public boolean isDisabled() {
240        return disabled;
241    }
242
243    public OAuthClient setDisabled(boolean disabled) {
244        this.disabled = disabled;
245        return this;
246    }
247
248    public boolean hasGrantType(GrantType gt) {
249        String checkGrant = gt.toString().toLowerCase();
250        for (String grant: getAuthorizedGrantTypes()) {
251            if (grant.toUpperCase().equals(checkGrant)) {
252                return true;
253            }
254        }
255        return false;
256    }
257
258    @Column
259    public boolean isPendingApproval() {
260        return pendingApproval;
261    }
262
263    public OAuthClient setPendingApproval(boolean pendingApproval) {
264        this.pendingApproval = pendingApproval;
265        return this;
266    }
267
268    @Column
269    public boolean isRequiresSecret() {
270        return requiresSecret;
271    }
272
273    public OAuthClient setRequiresSecret(boolean requiresSecret) {
274        this.requiresSecret = requiresSecret;
275        return this;
276    }
277
278    @Column
279    public boolean isAllowProvidedCode() {
280        return allowProvidedCode;
281    }
282
283    public OAuthClient setAllowProvidedCode(boolean allProvidedCode) {
284        this.allowProvidedCode = allProvidedCode;
285        return this;
286    }
287}