001/*
002 * (C) Copyright 2019 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 *     Salem Aouana
018 */
019
020package org.nuxeo.ecm.platform.oauth2.enums;
021
022import static org.nuxeo.ecm.platform.oauth2.Constants.TOKEN_SERVICE;
023import static org.nuxeo.ecm.platform.oauth2.tokens.NuxeoOAuth2Token.KEY_SERVICE_NAME;
024
025import org.nuxeo.ecm.core.query.sql.model.Predicate;
026import org.nuxeo.ecm.core.query.sql.model.Predicates;
027
028/**
029 * OAuth2 token type can be:
030 * <ul>
031 * <li>Provided by Nuxeo: {@link #AS_PROVIDER}</li>
032 * <li>Consumed by Nuxeo: {@link #AS_CLIENT}</li>
033 * </ul>
034 *
035 * @since 11.1
036 */
037public enum NuxeoOAuth2TokenType {
038
039    AS_PROVIDER("asProvider", Predicates.eq(KEY_SERVICE_NAME, TOKEN_SERVICE)),
040
041    AS_CLIENT("asClient", Predicates.noteq(KEY_SERVICE_NAME, TOKEN_SERVICE));
042
043    protected final String value;
044
045    protected final Predicate predicate;
046
047    NuxeoOAuth2TokenType(String value, Predicate predicate) {
048        this.value = value;
049        this.predicate = predicate;
050    }
051
052    public String getValue() {
053        return value;
054    }
055
056    public Predicate getPredicate() {
057        return predicate;
058    }
059
060}