Skip to content

Commit 3323167

Browse files
authored
Support authorization on external resource loading (#1063)
Signed-off-by: fjtirado <ftirados@redhat.com>
1 parent d0d92d6 commit 3323167

35 files changed

+234
-206
lines changed

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/auth/requestbuilder/AbstractAuthRequestBuilder.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/AbstractAuthRequestBuilder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http.auth.requestbuilder;
16+
package io.serverlessworkflow.impl.auth;
1717

1818
import static io.serverlessworkflow.api.types.OAuth2AuthenticationDataClient.ClientAuthentication.CLIENT_SECRET_POST;
1919
import static io.serverlessworkflow.impl.WorkflowUtils.isValid;
20-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.AUDIENCES;
21-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.AUTHENTICATION;
22-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.CLIENT;
23-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.ENCODING;
24-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.REQUEST;
25-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.SCOPES;
20+
import static io.serverlessworkflow.impl.auth.AuthUtils.AUDIENCES;
21+
import static io.serverlessworkflow.impl.auth.AuthUtils.AUTHENTICATION;
22+
import static io.serverlessworkflow.impl.auth.AuthUtils.CLIENT;
23+
import static io.serverlessworkflow.impl.auth.AuthUtils.ENCODING;
24+
import static io.serverlessworkflow.impl.auth.AuthUtils.REQUEST;
25+
import static io.serverlessworkflow.impl.auth.AuthUtils.SCOPES;
2626

2727
import io.serverlessworkflow.api.types.OAuth2AuthenticationData;
2828
import io.serverlessworkflow.api.types.OAuth2AuthenticationDataClient;

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/DigestAuthProvider.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/AccessTokenProvider.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http;
16+
package io.serverlessworkflow.impl.auth;
1717

18-
import io.serverlessworkflow.api.types.DigestAuthenticationPolicy;
19-
import io.serverlessworkflow.api.types.Workflow;
2018
import io.serverlessworkflow.impl.TaskContext;
21-
import io.serverlessworkflow.impl.WorkflowApplication;
2219
import io.serverlessworkflow.impl.WorkflowContext;
2320
import io.serverlessworkflow.impl.WorkflowModel;
24-
import jakarta.ws.rs.client.Invocation.Builder;
2521

26-
public class DigestAuthProvider implements AuthProvider {
27-
28-
public DigestAuthProvider(
29-
WorkflowApplication app, Workflow workflow, DigestAuthenticationPolicy authPolicy) {
30-
throw new UnsupportedOperationException("Digest auth not supported yet");
31-
}
32-
33-
@Override
34-
public Builder build(
35-
Builder builder, WorkflowContext workflow, TaskContext task, WorkflowModel model) {
36-
// TODO Auto-generated method stub
37-
return builder;
38-
}
22+
public interface AccessTokenProvider {
23+
JWT validateAndGet(WorkflowContext workflow, TaskContext context, WorkflowModel model);
3924
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl.auth;
17+
18+
import java.util.List;
19+
20+
public interface AccessTokenProviderFactory {
21+
22+
AccessTokenProvider build(
23+
HttpRequestInfo requestInfo, List<String> issuers, JWTConverter converter);
24+
}

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/AuthProvider.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/AuthProvider.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http;
16+
package io.serverlessworkflow.impl.auth;
1717

1818
import io.serverlessworkflow.impl.TaskContext;
1919
import io.serverlessworkflow.impl.WorkflowContext;
2020
import io.serverlessworkflow.impl.WorkflowModel;
21-
import jakarta.ws.rs.client.Invocation;
2221

23-
interface AuthProvider {
24-
Invocation.Builder build(
25-
Invocation.Builder builder, WorkflowContext workflow, TaskContext task, WorkflowModel model);
22+
public interface AuthProvider {
23+
24+
String authScheme();
25+
26+
String authParameter(WorkflowContext workflow, TaskContext task, WorkflowModel model);
2627
}

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/AuthProviderFactory.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/AuthProviderFactory.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http;
16+
package io.serverlessworkflow.impl.auth;
1717

1818
import io.serverlessworkflow.api.types.AuthenticationPolicyUnion;
19+
import io.serverlessworkflow.api.types.EndpointConfiguration;
1920
import io.serverlessworkflow.api.types.ReferenceableAuthenticationPolicy;
2021
import io.serverlessworkflow.api.types.Workflow;
2122
import io.serverlessworkflow.impl.WorkflowApplication;
2223
import io.serverlessworkflow.impl.WorkflowDefinition;
2324
import java.util.Optional;
2425

25-
class AuthProviderFactory {
26+
public class AuthProviderFactory {
2627

2728
private AuthProviderFactory() {}
2829

29-
static final String AUTH_HEADER_NAME = "Authorization";
30+
public static Optional<AuthProvider> getAuth(
31+
WorkflowDefinition definition, EndpointConfiguration configuration) {
32+
return configuration == null
33+
? Optional.empty()
34+
: getAuth(definition, configuration.getAuthentication());
35+
}
3036

3137
public static Optional<AuthProvider> getAuth(
3238
WorkflowDefinition definition, ReferenceableAuthenticationPolicy auth) {
@@ -64,9 +70,8 @@ private static Optional<AuthProvider> buildFromPolicy(
6470
new BearerAuthProvider(
6571
app, workflow, authenticationPolicy.getBearerAuthenticationPolicy()));
6672
} else if (authenticationPolicy.getDigestAuthenticationPolicy() != null) {
67-
return Optional.of(
68-
new DigestAuthProvider(
69-
app, workflow, authenticationPolicy.getDigestAuthenticationPolicy()));
73+
// TODO implement digest authentication
74+
return Optional.empty();
7075
} else if (authenticationPolicy.getOAuth2AuthenticationPolicy() != null) {
7176
return Optional.of(
7277
new OAuth2AuthProvider(

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/auth/requestbuilder/AuthRequestBuilder.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/AuthRequestBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http.auth.requestbuilder;
16+
package io.serverlessworkflow.impl.auth;
1717

1818
import io.serverlessworkflow.api.types.OAuth2AuthenticationData;
1919
import java.util.Map;

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/SecretKeys.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/AuthUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http;
16+
package io.serverlessworkflow.impl.auth;
1717

18-
public class SecretKeys {
18+
public class AuthUtils {
1919

20-
private SecretKeys() {}
20+
private AuthUtils() {}
2121

22+
public static final String AUTH_HEADER_NAME = "Authorization";
2223
public static final String GRANT = "grant";
2324
public static final String USER = "username";
2425
public static final String CLIENT = "client";
@@ -34,4 +35,10 @@ private SecretKeys() {}
3435
public static final String REQUEST = "request";
3536
public static final String ENCODING = "encoding";
3637
public static final String AUTHENTICATION = "authentication";
38+
39+
private static final String AUTH_HEADER_FORMAT = "%s %s";
40+
41+
public static String authHeaderValue(String scheme, String parameter) {
42+
return String.format(AUTH_HEADER_FORMAT, scheme, parameter);
43+
}
3744
}

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/BasicAuthProvider.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/BasicAuthProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http;
16+
package io.serverlessworkflow.impl.auth;
1717

1818
import static io.serverlessworkflow.impl.WorkflowUtils.checkSecret;
1919
import static io.serverlessworkflow.impl.WorkflowUtils.secretProp;
20-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.PASSWORD;
21-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.USER;
20+
import static io.serverlessworkflow.impl.auth.AuthUtils.PASSWORD;
21+
import static io.serverlessworkflow.impl.auth.AuthUtils.USER;
2222

2323
import io.serverlessworkflow.api.types.BasicAuthenticationPolicy;
2424
import io.serverlessworkflow.api.types.Workflow;
@@ -30,7 +30,7 @@
3030
import io.serverlessworkflow.impl.WorkflowValueResolver;
3131
import java.util.Base64;
3232

33-
class BasicAuthProvider extends AbstractAuthProvider {
33+
class BasicAuthProvider implements AuthProvider {
3434

3535
private static final String USER_PASSWORD = "%s:%s";
3636

@@ -57,7 +57,7 @@ public BasicAuthProvider(
5757
}
5858

5959
@Override
60-
protected String authParameter(WorkflowContext workflow, TaskContext task, WorkflowModel model) {
60+
public String authParameter(WorkflowContext workflow, TaskContext task, WorkflowModel model) {
6161
return new String(
6262
Base64.getEncoder()
6363
.encode(
@@ -69,7 +69,7 @@ protected String authParameter(WorkflowContext workflow, TaskContext task, Workf
6969
}
7070

7171
@Override
72-
protected String authScheme() {
72+
public String authScheme() {
7373
return "Basic";
7474
}
7575
}

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/BearerAuthProvider.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/BearerAuthProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http;
16+
package io.serverlessworkflow.impl.auth;
1717

1818
import static io.serverlessworkflow.impl.WorkflowUtils.checkSecret;
1919
import static io.serverlessworkflow.impl.WorkflowUtils.secretProp;
20-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.TOKEN;
20+
import static io.serverlessworkflow.impl.auth.AuthUtils.TOKEN;
2121

2222
import io.serverlessworkflow.api.types.BearerAuthenticationPolicy;
2323
import io.serverlessworkflow.api.types.BearerAuthenticationPolicyConfiguration;
@@ -29,7 +29,7 @@
2929
import io.serverlessworkflow.impl.WorkflowUtils;
3030
import io.serverlessworkflow.impl.WorkflowValueResolver;
3131

32-
class BearerAuthProvider extends AbstractAuthProvider {
32+
class BearerAuthProvider implements AuthProvider {
3333

3434
private WorkflowValueResolver<String> tokenFilter;
3535

@@ -48,12 +48,12 @@ public BearerAuthProvider(
4848
}
4949

5050
@Override
51-
protected String authParameter(WorkflowContext workflow, TaskContext task, WorkflowModel model) {
51+
public String authParameter(WorkflowContext workflow, TaskContext task, WorkflowModel model) {
5252
return tokenFilter.apply(workflow, task, model);
5353
}
5454

5555
@Override
56-
protected String authScheme() {
56+
public String authScheme() {
5757
return "Bearer";
5858
}
5959
}

impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/auth/requestbuilder/ClientSecretBasic.java renamed to impl/core/src/main/java/io/serverlessworkflow/impl/auth/ClientSecretBasic.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.serverlessworkflow.impl.executors.http.auth.requestbuilder;
16+
package io.serverlessworkflow.impl.auth;
1717

18-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.CLIENT;
19-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.GRANT;
20-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.ID;
21-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.PASSWORD;
22-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.SECRET;
23-
import static io.serverlessworkflow.impl.executors.http.SecretKeys.USER;
18+
import static io.serverlessworkflow.impl.auth.AuthUtils.CLIENT;
19+
import static io.serverlessworkflow.impl.auth.AuthUtils.GRANT;
20+
import static io.serverlessworkflow.impl.auth.AuthUtils.ID;
21+
import static io.serverlessworkflow.impl.auth.AuthUtils.PASSWORD;
22+
import static io.serverlessworkflow.impl.auth.AuthUtils.SECRET;
23+
import static io.serverlessworkflow.impl.auth.AuthUtils.USER;
2424

2525
import io.serverlessworkflow.api.types.OAuth2AuthenticationData;
2626
import io.serverlessworkflow.impl.WorkflowApplication;

0 commit comments

Comments
 (0)