Skip to content

Commit f990e20

Browse files
Merge pull request #2 from indigo-paas/client_iam
Client iam
2 parents a4ea926 + bb59b64 commit f990e20

File tree

11 files changed

+1455
-366
lines changed

11 files changed

+1455
-366
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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.dto.iam;
19+
20+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
21+
import com.fasterxml.jackson.databind.annotation.JsonNaming;
22+
import java.util.List;
23+
24+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
25+
public class IamClientRequest {
26+
private List<String> redirectUris;
27+
private String clientName;
28+
private List<String> contacts;
29+
private String tokenEndpointAuthMethod;
30+
private String scope;
31+
private List<String> grantTypes;
32+
private List<String> responseTypes;
33+
34+
/**
35+
* Constructor of IAMClientRequest, used to send a request to IAM to create a client.
36+
*/
37+
public IamClientRequest(List<String> redirectUris, String clientName, List<String> contacts,
38+
String tokenEndpointAuthMethod, String scope, List<String> grantTypes,
39+
List<String> responseTypes) {
40+
this.redirectUris = redirectUris;
41+
this.clientName = clientName;
42+
this.contacts = contacts;
43+
this.tokenEndpointAuthMethod = tokenEndpointAuthMethod;
44+
this.scope = scope;
45+
this.grantTypes = grantTypes;
46+
this.responseTypes = responseTypes;
47+
}
48+
49+
// Getter and setter for redirectUris
50+
51+
public List<String> getRedirectUris() {
52+
return redirectUris;
53+
}
54+
55+
public void setRedirectUris(List<String> redirectUris) {
56+
this.redirectUris = redirectUris;
57+
}
58+
59+
// Getter and setter for clientName
60+
61+
public String getClientName() {
62+
return clientName;
63+
}
64+
65+
public void setClientName(String clientName) {
66+
this.clientName = clientName;
67+
}
68+
69+
// Getter and setter for contacts
70+
71+
public List<String> getContacts() {
72+
return contacts;
73+
}
74+
75+
public void setContacts(List<String> contacts) {
76+
this.contacts = contacts;
77+
}
78+
79+
// Getter and setter for tokenEndpointAuthMethod
80+
81+
public String getTokenEndpointAuthMethod() {
82+
return tokenEndpointAuthMethod;
83+
}
84+
85+
public void setTokenEndpointAuthMethod(String tokenEndpointAuthMethod) {
86+
this.tokenEndpointAuthMethod = tokenEndpointAuthMethod;
87+
}
88+
89+
// Getter and setter for scope
90+
91+
public String getScope() {
92+
return scope;
93+
}
94+
95+
public void setScope(String scope) {
96+
this.scope = scope;
97+
}
98+
99+
// Getter and setter for grantTypes
100+
101+
public List<String> getGrantTypes() {
102+
return grantTypes;
103+
}
104+
105+
public void setGrantTypes(List<String> grantTypes) {
106+
this.grantTypes = grantTypes;
107+
}
108+
109+
// Getter and setter for responseTypes
110+
111+
public List<String> getResponseTypes() {
112+
return responseTypes;
113+
}
114+
115+
public void setResponseTypes(List<String> responseTypes) {
116+
this.responseTypes = responseTypes;
117+
}
118+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.dto.iam;
19+
20+
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
21+
import com.fasterxml.jackson.databind.annotation.JsonNaming;
22+
import java.util.List;
23+
24+
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
25+
public class WellKnownResponse {
26+
27+
private List<String> scopesSupported;
28+
private String registrationEndpoint;
29+
private String tokenEndpoint;
30+
31+
public WellKnownResponse() {
32+
// Use the setter functions to set the attributes of the class
33+
}
34+
35+
public List<String> getScopesSupported() {
36+
return scopesSupported;
37+
}
38+
39+
public void setScopesSupported(List<String> scopesSupported) {
40+
this.scopesSupported = scopesSupported;
41+
}
42+
43+
public String getRegistrationEndpoint() {
44+
return registrationEndpoint;
45+
}
46+
47+
public void setRegistrationEndpoint(String registrationEndpoint) {
48+
this.registrationEndpoint = registrationEndpoint;
49+
}
50+
51+
public String getTokenEndpoint() {
52+
return tokenEndpoint;
53+
}
54+
55+
public void setTokenEndpoint(String tokenEndpoint) {
56+
this.tokenEndpoint = tokenEndpoint;
57+
}
58+
59+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
public class IamServiceException extends RuntimeException {
21+
22+
public IamServiceException(String message) {
23+
super(message);
24+
}
25+
26+
public IamServiceException(String message, Throwable e) {
27+
super(message, e);
28+
}
29+
}

0 commit comments

Comments
 (0)