Skip to content

Commit 5296f6e

Browse files
authored
Merge pull request #112 from tsurdilo/addauth
Adding auth
2 parents 3d5b195 + 34226a8 commit 5296f6e

File tree

18 files changed

+478
-2
lines changed

18 files changed

+478
-2
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.api.deserializers;
17+
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.databind.DeserializationContext;
20+
import com.fasterxml.jackson.databind.JsonNode;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
23+
import io.serverlessworkflow.api.auth.AuthDefinition;
24+
import io.serverlessworkflow.api.auth.BasicAuthDefinition;
25+
import io.serverlessworkflow.api.auth.BearerAuthDefinition;
26+
import io.serverlessworkflow.api.auth.OauthDefinition;
27+
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
28+
29+
import java.io.IOException;
30+
31+
public class AuthDefinitionDeserializer extends StdDeserializer<AuthDefinition> {
32+
33+
private static final long serialVersionUID = 510l;
34+
35+
@SuppressWarnings("unused")
36+
private WorkflowPropertySource context;
37+
38+
public AuthDefinitionDeserializer() {
39+
this(AuthDefinition.class);
40+
}
41+
42+
public AuthDefinitionDeserializer(Class<?> vc) {
43+
super(vc);
44+
}
45+
46+
public AuthDefinitionDeserializer(WorkflowPropertySource context) {
47+
this(AuthDefinition.class);
48+
this.context = context;
49+
}
50+
51+
@Override
52+
public AuthDefinition deserialize(JsonParser jp,
53+
DeserializationContext ctxt) throws IOException {
54+
55+
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
56+
JsonNode node = jp.getCodec().readTree(jp);
57+
58+
AuthDefinition authDefinition = new AuthDefinition();
59+
60+
if(node.get("name") != null) {
61+
authDefinition.setName(node.get("name").asText());
62+
}
63+
64+
if(node.get("scheme") != null) {
65+
authDefinition.setScheme(AuthDefinition.Scheme.fromValue(node.get("scheme").asText()));
66+
}
67+
68+
if(node.get("properties") != null) {
69+
JsonNode propsNode = node.get("properties");
70+
71+
if(propsNode.get("grantType") != null) {
72+
authDefinition.setOauth(mapper.treeToValue(propsNode, OauthDefinition.class));
73+
} else if(propsNode.get("token") != null) {
74+
authDefinition.setBearerauth(mapper.treeToValue(propsNode, BearerAuthDefinition.class));
75+
} else {
76+
authDefinition.setBasicauth(mapper.treeToValue(propsNode, BasicAuthDefinition.class));
77+
}
78+
}
79+
80+
return authDefinition;
81+
}
82+
}

api/src/main/java/io/serverlessworkflow/api/mapper/WorkflowModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.serverlessworkflow.api.mapper;
1717

1818
import com.fasterxml.jackson.databind.module.SimpleModule;
19+
import io.serverlessworkflow.api.auth.AuthDefinition;
1920
import io.serverlessworkflow.api.cron.Cron;
2021
import io.serverlessworkflow.api.datainputschema.DataInputSchema;
2122
import io.serverlessworkflow.api.deserializers.*;
@@ -34,7 +35,6 @@
3435
import io.serverlessworkflow.api.states.DefaultState;
3536
import io.serverlessworkflow.api.states.OperationState;
3637
import io.serverlessworkflow.api.states.ParallelState;
37-
import io.serverlessworkflow.api.timeouts.TimeoutsDefinition;
3838
import io.serverlessworkflow.api.transitions.Transition;
3939
import io.serverlessworkflow.api.workflow.*;
4040

@@ -76,6 +76,7 @@ private void addDefaultSerializers() {
7676
addSerializer(new CronSerializer());
7777
addSerializer(new ScheduleSerializer());
7878
addSerializer(new SubFlowRefSerializer());
79+
addSerializer(new AuthDefinitionSerializer());
7980
addSerializer(extensionSerializer);
8081
}
8182

@@ -107,6 +108,7 @@ private void addDefaultDeserializers() {
107108
addDeserializer(Cron.class, new CronDeserializer(workflowPropertySource));
108109
addDeserializer(Schedule.class, new ScheduleDeserializer(workflowPropertySource));
109110
addDeserializer(DataInputSchema.class, new DataInputSchemaDeserializer(workflowPropertySource));
111+
addDeserializer(AuthDefinition.class, new AuthDefinitionDeserializer(workflowPropertySource));
110112
}
111113

112114
public ExtensionSerializer getExtensionSerializer() {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.api.serializers;
17+
18+
import com.fasterxml.jackson.core.JsonGenerator;
19+
import com.fasterxml.jackson.databind.SerializerProvider;
20+
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
21+
import io.serverlessworkflow.api.auth.AuthDefinition;
22+
23+
import java.io.IOException;
24+
25+
public class AuthDefinitionSerializer extends StdSerializer<AuthDefinition> {
26+
27+
public AuthDefinitionSerializer() {
28+
this(AuthDefinition.class);
29+
}
30+
31+
protected AuthDefinitionSerializer(Class<AuthDefinition> t) {
32+
super(t);
33+
}
34+
35+
@Override
36+
public void serialize(AuthDefinition authDefinition,
37+
JsonGenerator gen,
38+
SerializerProvider provider) throws IOException {
39+
40+
gen.writeStartObject();
41+
if (authDefinition != null) {
42+
if (authDefinition.getName() != null && !authDefinition.getName().isEmpty()) {
43+
gen.writeStringField("name",
44+
authDefinition.getName());
45+
}
46+
47+
if (authDefinition.getScheme() != null) {
48+
gen.writeStringField("scheme",
49+
authDefinition.getScheme().value());
50+
}
51+
52+
if (authDefinition.getBasicauth() != null || authDefinition.getBearerauth() != null
53+
|| authDefinition.getOauth() != null) {
54+
55+
if(authDefinition.getBasicauth() != null) {
56+
gen.writeObjectField("properties", authDefinition.getBasicauth());
57+
}
58+
59+
if(authDefinition.getBearerauth() != null) {
60+
gen.writeObjectField("properties", authDefinition.getBearerauth());
61+
}
62+
63+
if(authDefinition.getOauth() != null) {
64+
gen.writeObjectField("properties", authDefinition.getOauth());
65+
}
66+
67+
}
68+
}
69+
gen.writeEndObject();
70+
}
71+
}
72+

api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ public void serialize(Workflow workflow,
159159
gen.writeObjectField("timeouts", workflow.getTimeouts());
160160
}
161161

162+
if (workflow.getAuth() != null) {
163+
gen.writeObjectField("auth", workflow.getAuth());
164+
}
165+
162166
if (workflow.getStates() != null && !workflow.getStates().isEmpty()) {
163167
gen.writeArrayFieldStart("states");
164168
for (State state : workflow.getStates()) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.auth.AuthDefinition",
4+
"description": "Auth Definition",
5+
"properties": {
6+
"name": {
7+
"type": "string",
8+
"description": "Unique auth definition name",
9+
"minLength": 1
10+
},
11+
"scheme": {
12+
"type": "string",
13+
"description": "Defines the auth type",
14+
"enum": [
15+
"basic",
16+
"bearer",
17+
"oauth2"
18+
],
19+
"default": "basic"
20+
},
21+
"basicauth": {
22+
"$ref": "basicauthdef.json"
23+
},
24+
"bearerauth": {
25+
"$ref": "bearerauthdef.json"
26+
},
27+
"oauth": {
28+
"$ref": "oauthdef.json"
29+
}
30+
},
31+
"required": [
32+
33+
]
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.auth.BasicAuthDefinition",
4+
"properties": {
5+
"username": {
6+
"type": "string",
7+
"description": "String or a workflow expression. Contains the user name",
8+
"minLength": 1
9+
},
10+
"password": {
11+
"type": "string",
12+
"description": "String or a workflow expression. Contains the user password",
13+
"minLength": 1
14+
},
15+
"metadata": {
16+
"$ref": "../metadata/metadata.json"
17+
}
18+
},
19+
"required": [
20+
"username",
21+
"password"
22+
]
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.auth.BearerAuthDefinition",
4+
"properties": {
5+
"token": {
6+
"type": "string",
7+
"description": "String or a workflow expression. Contains the token",
8+
"minLength": 1
9+
},
10+
"metadata": {
11+
"$ref": "../metadata/metadata.json"
12+
}
13+
},
14+
"required": [
15+
"token"
16+
]
17+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"type": "object",
3+
"javaType": "io.serverlessworkflow.api.auth.OauthDefinition",
4+
"properties": {
5+
"authority": {
6+
"type": "string",
7+
"description": "String or a workflow expression. Contains the authority information",
8+
"minLength": 1
9+
},
10+
"grantType": {
11+
"type": "string",
12+
"description": "Defines the grant type",
13+
"enum": [
14+
"password",
15+
"clientCredentials",
16+
"tokenExchange"
17+
],
18+
"additionalItems": false
19+
},
20+
"clientId": {
21+
"type": "string",
22+
"description": "String or a workflow expression. Contains the client identifier",
23+
"minLength": 1
24+
},
25+
"clientSecret": {
26+
"type": "string",
27+
"description": "Workflow secret or a workflow expression. Contains the client secret",
28+
"minLength": 1
29+
},
30+
"scopes": {
31+
"type": "array",
32+
"description": "Array containing strings or workflow expressions. Contains the OAuth2 scopes",
33+
"items": {
34+
"type": "string"
35+
},
36+
"minItems": 1
37+
},
38+
"username": {
39+
"type": "string",
40+
"description": "String or a workflow expression. Contains the user name. Used only if grantType is 'resourceOwner'",
41+
"minLength": 1
42+
},
43+
"password": {
44+
"type": "string",
45+
"description": "String or a workflow expression. Contains the user password. Used only if grantType is 'resourceOwner'",
46+
"minLength": 1
47+
},
48+
"audiences": {
49+
"type": "array",
50+
"description": "Array containing strings or workflow expressions. Contains the OAuth2 audiences",
51+
"items": {
52+
"type": "string"
53+
},
54+
"minItems": 1
55+
},
56+
"subjectToken": {
57+
"type": "string",
58+
"description": "String or a workflow expression. Contains the subject token",
59+
"minLength": 1
60+
},
61+
"requestedSubject": {
62+
"type": "string",
63+
"description": "String or a workflow expression. Contains the requested subject",
64+
"minLength": 1
65+
},
66+
"requestedIssuer": {
67+
"type": "string",
68+
"description": "String or a workflow expression. Contains the requested issuer",
69+
"minLength": 1
70+
},
71+
"metadata": {
72+
"$ref": "../metadata/metadata.json"
73+
}
74+
},
75+
"required": [
76+
"grantType",
77+
"clientId"
78+
]
79+
}

api/src/main/resources/schema/functions/functiondef.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
],
2424
"default": "rest"
2525
},
26+
"authRef": {
27+
"type": "string",
28+
"description": "References an auth definition name to be used to access to resource defined in the operation parameter",
29+
"minLength": 1
30+
},
2631
"metadata": {
2732
"$ref": "../metadata/metadata.json"
2833
}

api/src/main/resources/schema/workflow.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
"timeouts": {
8282
"$ref": "timeouts/timeoutsdef.json"
8383
},
84+
"auth": {
85+
"$ref": "auth/auth.json"
86+
},
8487
"states": {
8588
"type": "array",
8689
"description": "State Definitions",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy