Skip to content

Commit

Permalink
feat: STS API spec
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Oct 16, 2023
1 parent 9fbad3c commit 5fc1492
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

plugins {
`java-library`
`maven-publish`
id("io.swagger.core.v3.swagger-gradle-plugin")
}

dependencies {
api(project(":spi:common:web-spi"))

implementation(libs.jakarta.rsApi)
implementation(libs.swagger.annotations.jakarta)

testImplementation(libs.jersey.common)
testImplementation(libs.jersey.server)

testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":extensions:common:http:jersey-core")))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.api.sts;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.BeanParam;
import org.eclipse.edc.connector.api.sts.model.StsAccessToken;
import org.eclipse.edc.connector.api.sts.model.StsTokenRequest;
import org.eclipse.edc.connector.api.sts.model.StsTokenRequestError;

@OpenAPIDefinition
@Tag(name = "Secure Token Service Api")
public interface SecureTokenServiceApi {


@Operation(description = "",
responses = {
@ApiResponse(responseCode = "200", description = "The Self-Issued ID token",
content = @Content(schema = @Schema(implementation = StsAccessToken.class))),
@ApiResponse(responseCode = "400", description = "Invalid Request",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = StsTokenRequestError.class))))
})
StsAccessToken token(@BeanParam StsTokenRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.api.sts.controller;

import jakarta.ws.rs.BeanParam;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.edc.connector.api.sts.SecureTokenServiceApi;
import org.eclipse.edc.connector.api.sts.model.StsAccessToken;
import org.eclipse.edc.connector.api.sts.model.StsTokenRequest;

@Path("/")
public class SecureTokenServiceApiController implements SecureTokenServiceApi {

@Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.APPLICATION_JSON })
@Path("token")
@POST
@Override
public StsAccessToken token(@BeanParam StsTokenRequest request) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.api.sts.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class StsAccessToken {

@JsonProperty("access_token")
private String accessToken;

@JsonProperty("tokenType")
private String tokenType = "Bearer";

@JsonProperty("expires_in")
private long expiresIn;


public long getExpiresIn() {
return expiresIn;
}

public String getAccessToken() {
return accessToken;
}

public String getTokenType() {
return tokenType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.api.sts.model;

import jakarta.ws.rs.FormParam;

public class StsTokenRequest {

@FormParam("grant_type")
private String grantType;

@FormParam("client_id")
private String clientId;

@FormParam("client_secret")
private String clientSecret;

@FormParam("bearer_access_scope")
private String bearerAccessScope;

@FormParam("access_token")
private String accessToken;

public String getGrantType() {
return grantType;
}


public String getClientId() {
return clientId;
}

public String getClientSecret() {
return clientSecret;
}

public String getBearerAccessScope() {
return bearerAccessScope;
}

public String getAccessToken() {
return accessToken;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.api.sts.model;

import com.fasterxml.jackson.annotation.JsonProperty;


public class StsTokenRequestError {

@JsonProperty
private String error;
@JsonProperty
private String errorDescription;
@JsonProperty
private String errorUri;

private StsTokenRequestError() {

}

public String getError() {
return error;
}

public String getErrorDescription() {
return errorDescription;
}

public String getErrorUri() {
return errorUri;
}


public static class Builder {

private final StsTokenRequestError apiError = new StsTokenRequestError();

private Builder() {
}

public static Builder newInstance() {
return new Builder();
}

public Builder error(String message) {
apiError.error = message;
return this;
}

public Builder errorDescription(String type) {
apiError.errorDescription = type;
return this;
}

public Builder errorUri(String path) {
apiError.errorUri = path;
return this;
}


public StsTokenRequestError build() {
return apiError;
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ include(":extensions:common:iam:identity-trust:identity-trust-transform")
include(":extensions:common:iam:identity-trust:identity-trust-service")
include(":extensions:common:iam:identity-trust:identity-trust-core")
include(":extensions:common:iam:identity-trust:identity-trust-sts-embedded")
include(":extensions:common:iam:identity-trust:identity-trust-sts-api")
include(":extensions:common:json-ld")
include(":extensions:common:metrics:micrometer-core")
include(":extensions:common:monitor:monitor-jdk-logger")
Expand Down Expand Up @@ -226,4 +227,3 @@ include(":system-tests:telemetry:telemetry-test-runner")
include(":system-tests:telemetry:telemetry-test-runtime")

include(":version-catalog")

0 comments on commit 5fc1492

Please sign in to comment.