001/* 002 * (C) Copyright 2017 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 * Thomas Roger 018 * Arnaud Kervern 019 * 020 */ 021package org.nuxeo.ecm.platform.oauth2.clients; 022 023import java.util.List; 024 025import org.nuxeo.ecm.core.api.NuxeoException; 026import org.nuxeo.ecm.core.api.NuxeoPrincipal; 027 028/** 029 * @since 9.2 030 */ 031public interface OAuth2ClientService { 032 033 String OAUTH2CLIENT_DIRECTORY_NAME = "oauth2Clients"; 034 035 String OAUTH2CLIENT_SCHEMA = "oauth2Client"; 036 037 /** 038 * Checks if an oAuth2 client with the given client id exists. 039 * <p> 040 * Done as a privileged user. 041 * 042 * @param clientId the client id of the oAuth2 client whose existence to check 043 * @return {@code true} if an oAuth2 client with the given client id exists, {@code false} otherwise 044 */ 045 boolean hasClient(String clientId); 046 047 /** 048 * Checks if the oAuth2 client with the given client id is valid regarding the given client secret. 049 * <p> 050 * Done as a privileged user. 051 * 052 * @param clientId the client id of the oAuth2 client to validate 053 * @param clientSecret the client secret used for validation 054 * @return {@code true} if the oAuth2 client with the given client id is valid regarding the given client secret, 055 * {@code false} otherwise 056 */ 057 boolean isValidClient(String clientId, String clientSecret); 058 059 /** 060 * Gets the oAuth2 client with the given client id. 061 * <p> 062 * Done as a privileged user. 063 * 064 * @param clientId the client id of the oAuth2 client to get 065 * @return the oAuth2 client with the given client id if it exists, {@code null} otherwise 066 */ 067 OAuth2Client getClient(String clientId); 068 069 /** 070 * Gets all the oAuth2 clients. 071 * <p> 072 * Done as a privileged user. 073 * 074 * @return the oAuth2 clients 075 * @since 10.2 076 */ 077 List<OAuth2Client> getClients(); 078 079 /** 080 * Registers a new oAuth2 client as the given principal. 081 * 082 * @param oAuth2Client the {@link OAuth2Client} to register 083 * @param principal the current user 084 * @return the newly registered client 085 * @throws NuxeoException with 403 status code if the given principal doesn't have access to the oAuth2 clients 086 * @since 11.1 087 */ 088 OAuth2Client create(OAuth2Client oAuth2Client, NuxeoPrincipal principal); 089 090 /** 091 * Updates an exiting oAuth2 client as the given principal. 092 * 093 * @param clientId the client id of oAuth2Client to update 094 * @param oAuth2Client the new {@link OAuth2Client} data 095 * @param principal the current user 096 * @return the updated oAuth2Client 097 * @throws NuxeoException with 403 status code if the given principal doesn't have access to the oAuth2 clients 098 * @since 11.1 099 */ 100 OAuth2Client update(String clientId, OAuth2Client oAuth2Client, NuxeoPrincipal principal); 101 102 /** 103 * Deletes an oAuth2 client as the given principal. 104 * 105 * @param clientId the client id of the oAuth2Client to delete 106 * @param principal the current user 107 * @throws NuxeoException with 403 status code if the given principal doesn't have access to the oAuth2 clients 108 * @since 11.1 109 */ 110 void delete(String clientId, NuxeoPrincipal principal); 111}