|
| 1 | +/* |
| 2 | + * Copyright © 2015-2021 I.N.F.N. |
| 3 | + * Copyright © 2015-2020 Santer Reply S.p.A. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package it.reply.orchestrator.service; |
| 19 | + |
| 20 | +import it.reply.orchestrator.dal.entity.Resource; |
| 21 | +import it.reply.orchestrator.dto.iam.WellKnownResponse; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.Set; |
| 24 | +import org.springframework.web.client.RestTemplate; |
| 25 | + |
| 26 | +public interface IamService { |
| 27 | + |
| 28 | + public String getOrchestratorScopes(); |
| 29 | + |
| 30 | + /** |
| 31 | + * Create a WellKnownResponse object for an IAM idp containing registration_endpoint, |
| 32 | + * token_endpoint, and scopes_supported. |
| 33 | + * |
| 34 | + * @param restTemplate object used to make HTTP requests |
| 35 | + * @param issuer the identity provider |
| 36 | + * @return the WellKnownResponse object |
| 37 | + */ |
| 38 | + public WellKnownResponse getWellKnown(RestTemplate restTemplate, String issuer); |
| 39 | + |
| 40 | + /** |
| 41 | + * Get a token with client credentials as grant type. |
| 42 | + * |
| 43 | + * @param restTemplate object used to make HTTP requests |
| 44 | + * @param iamClientId client_id |
| 45 | + * @param iamClientSecret client_secret |
| 46 | + * @param iamClientScopes scopes to ask in the request |
| 47 | + * @param iamTokenEndpoint IAM token endpoint |
| 48 | + * @return the token with client credentials as grant type |
| 49 | + */ |
| 50 | + public String getTokenClientCredentials(RestTemplate restTemplate, String iamClientId, |
| 51 | + String iamClientSecret, String iamClientScopes, String iamTokenEndpoint); |
| 52 | + |
| 53 | + /** |
| 54 | + * Create an IAM client setting the minimal information, in addition to the mail field. |
| 55 | + * As output it gives the client_id and registration_access_token of the created client. |
| 56 | + * |
| 57 | + * @param restTemplate object used to make HTTP requests |
| 58 | + * @param iamRegistration registration endpoint used to create a client |
| 59 | + * @param uuid uuid of the deployment, used to set the client name |
| 60 | + * @param userEmail user email, used to set the contacts field of the client |
| 61 | + * @param scopes scopes to set for the new client |
| 62 | + * @return a map of client_id:registration_access_token |
| 63 | + */ |
| 64 | + public Map<String, String> createClient(RestTemplate restTemplate, String iamRegistration, |
| 65 | + String uuid, String userEmail, String scopes); |
| 66 | + |
| 67 | + /** |
| 68 | + * Delete a client. |
| 69 | + * |
| 70 | + * @param restTemplate object used to make HTTP requests |
| 71 | + * @param clientId client_id |
| 72 | + * @param iamUrl IAM endpoint to contact for the client deletion |
| 73 | + * @param token the registration_access_token used for the deletion |
| 74 | + * @return true if the deletion has been successful |
| 75 | + */ |
| 76 | + public boolean deleteClient(RestTemplate restTemplate, String clientId, String iamUrl, |
| 77 | + String token); |
| 78 | + |
| 79 | + /** |
| 80 | + * Delete all the clients stored in resources. |
| 81 | + * |
| 82 | + * @param restTemplate object used to make HTTP requests |
| 83 | + * @param resources resources linked to a given deployment |
| 84 | + */ |
| 85 | + public void deleteAllClients(RestTemplate restTemplate, Map<Boolean, Set<Resource>> resources); |
| 86 | + |
| 87 | + /** |
| 88 | + * Assign the ownership of a client. |
| 89 | + * |
| 90 | + * @param restTemplate object used to make HTTP requests |
| 91 | + * @param clientId client_id |
| 92 | + * @param iamUrl IAM Url |
| 93 | + * @param accountId the id of the owner to be assigned to the client |
| 94 | + * @param token the token with client credentials as grant type using the orchestrator client |
| 95 | + */ |
| 96 | + public void assignOwnership(RestTemplate restTemplate, String clientId, String iamUrl, |
| 97 | + String accountId, String token); |
| 98 | + |
| 99 | + /** |
| 100 | + * Check if a given idp ia an IAM. |
| 101 | + * |
| 102 | + * @param restTemplate object used to make HTTP requests |
| 103 | + * @param idpUrl Url to be checked if it is an IAM or not |
| 104 | + * @return true if the idpurl is an IAM, otherwise false |
| 105 | + */ |
| 106 | + public boolean checkIam(RestTemplate restTemplate, String idpUrl); |
| 107 | + |
| 108 | + /** |
| 109 | + * Get information about a client. |
| 110 | + * |
| 111 | + * @param restTemplate object used to make HTTP requests |
| 112 | + * @param clientId client_id |
| 113 | + * @param iamUrl IAM Url |
| 114 | + * @param token the token to use |
| 115 | + * @return the json obtained as output from the HTPP request |
| 116 | + */ |
| 117 | + public String getInfoIamClient(RestTemplate restTemplate, String clientId, String iamUrl, |
| 118 | + String token); |
| 119 | + |
| 120 | + /** |
| 121 | + * Update information about a client. |
| 122 | + * |
| 123 | + * @param restTemplate object used to make HTTP requests |
| 124 | + * @param clientId client_id |
| 125 | + * @param iamUrl IAM Url |
| 126 | + * @param token the token to use |
| 127 | + * @param jsonUpdated the updated json obtained as output |
| 128 | + * @return the json with the updated info about the client |
| 129 | + */ |
| 130 | + public String updateClient(RestTemplate restTemplate, String clientId, String iamUrl, |
| 131 | + String token, String jsonUpdated); |
| 132 | + |
| 133 | +} |
0 commit comments