-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from indigo-dc/token-management
Token management
- Loading branch information
Showing
14 changed files
with
301 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,3 +122,5 @@ buildNumber.properties | |
|
||
/.idea/ | ||
/.idea/libraries/ | ||
.idea | ||
.idea/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
src/main/java/org/springframework/social/oidc/api/impl/OidcTemplate.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
src/main/java/org/springframework/social/oidc/connect/OidcConnectionFactory.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/java/org/springframework/social/oidc/deep/api/DeepOrchestrator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.springframework.social.oidc.deep.api; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.social.ApiBinding; | ||
|
||
public interface DeepOrchestrator extends ApiBinding { | ||
|
||
/** | ||
* Returns the profile of the logged user. | ||
* @return The profile of the logged user. | ||
*/ | ||
OidcUserProfile getProfile(); | ||
|
||
/** | ||
* Gets a list of deployments of the logged user. | ||
* @return The list of deployments in plain text. It must be parsed by the calling client. | ||
*/ | ||
ResponseEntity<String> callGetDeployments(); | ||
|
||
/** | ||
* Deploys a template in the orchestrator. | ||
* @param yamlTopology The yaml topology to deploy in plain text. | ||
* @return The operation result in plain text. It must be parsed by the calling client. | ||
*/ | ||
ResponseEntity<String> callDeploy(String yamlTopology); | ||
|
||
/** | ||
* Gets the status of a deployment. | ||
* @param deploymentId The deployment identifier. | ||
* @return The deployment status in plain text. It must be parsed by the calling client. | ||
*/ | ||
ResponseEntity<String> callDeploymentStatus(String deploymentId); | ||
|
||
/** | ||
* Undeploys a deployment. | ||
* @param deploymentId The deployment identifier. | ||
* @return The operation result in plain text. It must be parsed by the calling client. | ||
*/ | ||
ResponseEntity<String> callUndeploy(String deploymentId); | ||
} |
2 changes: 1 addition & 1 deletion
2
...rk/social/oidc/api/OidcConfiguration.java → ...cial/oidc/deep/api/OidcConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...work/social/oidc/api/OidcUserProfile.java → ...social/oidc/deep/api/OidcUserProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/main/java/org/springframework/social/oidc/deep/api/impl/DeepOrchestratorTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package org.springframework.social.oidc.deep.api.impl; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.http.conn.ssl.SSLContextBuilder; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | ||
import org.springframework.social.oauth2.AbstractOAuth2ApiBinding; | ||
import org.springframework.social.oidc.deep.api.DeepOrchestrator; | ||
import org.springframework.social.oidc.deep.api.OidcConfiguration; | ||
import org.springframework.social.oidc.deep.api.OidcUserProfile; | ||
import org.springframework.social.support.URIBuilder; | ||
|
||
import java.net.URI; | ||
import java.security.KeyManagementException; | ||
import java.security.KeyStore; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import javax.net.ssl.SSLContext; | ||
|
||
public class DeepOrchestratorTemplate extends AbstractOAuth2ApiBinding implements DeepOrchestrator { | ||
|
||
private static final Log logger = LogFactory.getLog(DeepOrchestratorTemplate.class); | ||
|
||
private OidcConfiguration configuration; | ||
|
||
private URI baseUrl; | ||
/** Web service path for deployments operations; It is appended to the orchestrator endpoint. */ | ||
public static final String WS_PATH_DEPLOYMENTS = "/deployments"; | ||
|
||
/** | ||
* Creates a new OIDC Template based on the OIDC endpoint configuration. | ||
* | ||
* @param configuration Configuration of the OIDC endpoint | ||
* @param accessToken Obtained access token | ||
*/ | ||
public DeepOrchestratorTemplate( | ||
String orchestratorBaseUrl, | ||
KeyStore orchestratorCert, | ||
OidcConfiguration configuration, | ||
String accessToken) | ||
throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { | ||
super(accessToken); | ||
this.configuration = configuration; | ||
this.baseUrl = URI.create(orchestratorBaseUrl + WS_PATH_DEPLOYMENTS); | ||
if (orchestratorCert != null) { | ||
setSslContext(orchestratorCert); | ||
} | ||
} | ||
|
||
/** | ||
* When the orchestrator is using an invalid certificate, this method can be called to accept the | ||
* certificate. | ||
* | ||
* @param cert A JKS keystore containing the orchestrator certificate. | ||
* @throws KeyStoreException The keystore is invalid. | ||
* @throws NoSuchAlgorithmException A problem occurred opening the keystore. | ||
* @throws KeyManagementException A problem occurred opening the keystore. | ||
*/ | ||
public void setSslContext(KeyStore cert) | ||
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { | ||
if (cert != null) { | ||
SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); | ||
sslContextBuilder.loadTrustMaterial(cert); | ||
SSLContext context = sslContextBuilder.build(); | ||
HttpComponentsClientHttpRequestFactory requestFactory = | ||
new HttpComponentsClientHttpRequestFactory(); | ||
requestFactory.setHttpClient(HttpClients.custom().setSslcontext(context).build()); | ||
this.setRequestFactory(requestFactory); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the profile of the logged user. | ||
* | ||
* @return The profile of the logged user. | ||
*/ | ||
public OidcUserProfile getProfile() { | ||
return getRestTemplate() | ||
.getForObject(configuration.getUserinfoEndpoint(), OidcUserProfile.class); | ||
} | ||
|
||
/** | ||
* Gets a list of deployments of the logged user. | ||
* | ||
* @return The list of deployments in plain text. It must be parsed by the calling client. | ||
*/ | ||
public ResponseEntity<String> callGetDeployments() { | ||
URIBuilder builder = URIBuilder.fromUri(baseUrl); | ||
builder.queryParam("createdBy", "me"); | ||
|
||
return getRestTemplate().getForEntity(builder.build().toString(), String.class); | ||
} | ||
|
||
/** | ||
* Deploys a template in the orchestrator. | ||
* | ||
* @param yamlTopology The yaml topology to deploy in plain text. | ||
* @return The operation result in plain text. It must be parsed by the calling client. | ||
*/ | ||
public ResponseEntity<String> callDeploy(String yamlTopology) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
|
||
HttpEntity<String> entity = new HttpEntity<String>(yamlTopology, headers); | ||
return getRestTemplate().postForEntity(baseUrl, entity, String.class); | ||
} | ||
|
||
/** | ||
* Gets the status of a deployment. | ||
* | ||
* @param deploymentId The deployment identifier. | ||
* @return The deployment status in plain text. It must be parsed by the calling client. | ||
*/ | ||
public ResponseEntity<String> callDeploymentStatus(String deploymentId) { | ||
return getRestTemplate() | ||
.getForEntity(URI.create(baseUrl.toString() + "/" + deploymentId), String.class); | ||
} | ||
|
||
/** | ||
* Undeploys a deployment. | ||
* | ||
* @param deploymentId The deployment identifier. | ||
* @return The operation result in plain text. It must be parsed by the calling client. | ||
*/ | ||
public ResponseEntity<String> callUndeploy(String deploymentId) { | ||
RequestEntity<Void> requestEntity = | ||
new RequestEntity<Void>( | ||
HttpMethod.DELETE, URI.create(baseUrl.toString() + "/" + deploymentId)); | ||
return getRestTemplate().exchange(requestEntity, String.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.