001/*******************************************************************************
002 * Copyright 2014 The MITRE Corporation
003 *   and the MIT Kerberos and Internet Trust Consortium
004 * 
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 * 
009 *   http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 ******************************************************************************/
017/**
018 * 
019 */
020package org.mitre.oauth2.service;
021
022import java.util.Set;
023
024import org.mitre.oauth2.model.SystemScope;
025
026/**
027 * @author jricher
028 *
029 */
030public interface SystemScopeService {
031
032        public static final String OFFLINE_ACCESS = "offline_access";
033        public static final String ID_TOKEN_SCOPE = "id-token";
034        public static final String REGISTRATION_TOKEN_SCOPE = "registration-token";
035        public static final String RESOURCE_TOKEN_SCOPE = "resource-token";
036
037        public Set<SystemScope> getAll();
038
039        /**
040         * Get all scopes that are defaulted to new clients on this system
041         * @return
042         */
043        public Set<SystemScope> getDefaults();
044
045        /**
046         * Get all scopes that are allowed for dynamic registration on this system
047         * @return
048         */
049        public Set<SystemScope> getDynReg();
050
051        public SystemScope getById(Long id);
052
053        public SystemScope getByValue(String value);
054
055        public void remove(SystemScope scope);
056
057        public SystemScope save(SystemScope scope);
058
059        /**
060         * Translate the set of scope strings into a set of SystemScope objects.
061         * @param scope
062         * @return
063         */
064        public Set<SystemScope> fromStrings(Set<String> scope);
065
066        /**
067         * Pluck the scope values from the set of SystemScope objects and return a list of strings
068         * @param scope
069         * @return
070         */
071        public Set<String> toStrings(Set<SystemScope> scope);
072
073        /**
074         * Test whether the scopes in both sets are compatible, with special
075         * processing for structured scopes. All scopes in "actual" must exist in
076         * "expected". If a scope in "expected" is structured and has a value, it
077         * must be matched exactly by its corresponding scope in "actual". If a
078         * scope in "expected" is structured but has no value, it may be matched by
079         * a scope with or without a value in "actual".
080         */
081        public boolean scopesMatch(Set<String> expected, Set<String> actual);
082
083        /**
084         * Remove any system-restricted scopes from the set and return the result.
085         * @param scopes
086         * @return
087         */
088        public Set<String> removeRestrictedScopes(Set<String> scopes);
089}