Skip to content

Adding auth #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api.deserializers;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import io.serverlessworkflow.api.auth.AuthDefinition;
import io.serverlessworkflow.api.auth.BasicAuthDefinition;
import io.serverlessworkflow.api.auth.BearerAuthDefinition;
import io.serverlessworkflow.api.auth.OauthDefinition;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;

import java.io.IOException;

public class AuthDefinitionDeserializer extends StdDeserializer<AuthDefinition> {

private static final long serialVersionUID = 510l;

@SuppressWarnings("unused")
private WorkflowPropertySource context;

public AuthDefinitionDeserializer() {
this(AuthDefinition.class);
}

public AuthDefinitionDeserializer(Class<?> vc) {
super(vc);
}

public AuthDefinitionDeserializer(WorkflowPropertySource context) {
this(AuthDefinition.class);
this.context = context;
}

@Override
public AuthDefinition deserialize(JsonParser jp,
DeserializationContext ctxt) throws IOException {

ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = jp.getCodec().readTree(jp);

AuthDefinition authDefinition = new AuthDefinition();

if(node.get("name") != null) {
authDefinition.setName(node.get("name").asText());
}

if(node.get("scheme") != null) {
authDefinition.setScheme(AuthDefinition.Scheme.fromValue(node.get("scheme").asText()));
}

if(node.get("properties") != null) {
JsonNode propsNode = node.get("properties");

if(propsNode.get("grantType") != null) {
authDefinition.setOauth(mapper.treeToValue(propsNode, OauthDefinition.class));
} else if(propsNode.get("token") != null) {
authDefinition.setBearerauth(mapper.treeToValue(propsNode, BearerAuthDefinition.class));
} else {
authDefinition.setBasicauth(mapper.treeToValue(propsNode, BasicAuthDefinition.class));
}
}

return authDefinition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.serverlessworkflow.api.mapper;

import com.fasterxml.jackson.databind.module.SimpleModule;
import io.serverlessworkflow.api.auth.AuthDefinition;
import io.serverlessworkflow.api.cron.Cron;
import io.serverlessworkflow.api.datainputschema.DataInputSchema;
import io.serverlessworkflow.api.deserializers.*;
Expand All @@ -34,7 +35,6 @@
import io.serverlessworkflow.api.states.DefaultState;
import io.serverlessworkflow.api.states.OperationState;
import io.serverlessworkflow.api.states.ParallelState;
import io.serverlessworkflow.api.timeouts.TimeoutsDefinition;
import io.serverlessworkflow.api.transitions.Transition;
import io.serverlessworkflow.api.workflow.*;

Expand Down Expand Up @@ -76,6 +76,7 @@ private void addDefaultSerializers() {
addSerializer(new CronSerializer());
addSerializer(new ScheduleSerializer());
addSerializer(new SubFlowRefSerializer());
addSerializer(new AuthDefinitionSerializer());
addSerializer(extensionSerializer);
}

Expand Down Expand Up @@ -107,6 +108,7 @@ private void addDefaultDeserializers() {
addDeserializer(Cron.class, new CronDeserializer(workflowPropertySource));
addDeserializer(Schedule.class, new ScheduleDeserializer(workflowPropertySource));
addDeserializer(DataInputSchema.class, new DataInputSchemaDeserializer(workflowPropertySource));
addDeserializer(AuthDefinition.class, new AuthDefinitionDeserializer(workflowPropertySource));
}

public ExtensionSerializer getExtensionSerializer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.api.serializers;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import io.serverlessworkflow.api.auth.AuthDefinition;

import java.io.IOException;

public class AuthDefinitionSerializer extends StdSerializer<AuthDefinition> {

public AuthDefinitionSerializer() {
this(AuthDefinition.class);
}

protected AuthDefinitionSerializer(Class<AuthDefinition> t) {
super(t);
}

@Override
public void serialize(AuthDefinition authDefinition,
JsonGenerator gen,
SerializerProvider provider) throws IOException {

gen.writeStartObject();
if (authDefinition != null) {
if (authDefinition.getName() != null && !authDefinition.getName().isEmpty()) {
gen.writeStringField("name",
authDefinition.getName());
}

if (authDefinition.getScheme() != null) {
gen.writeStringField("scheme",
authDefinition.getScheme().value());
}

if (authDefinition.getBasicauth() != null || authDefinition.getBearerauth() != null
|| authDefinition.getOauth() != null) {

if(authDefinition.getBasicauth() != null) {
gen.writeObjectField("properties", authDefinition.getBasicauth());
}

if(authDefinition.getBearerauth() != null) {
gen.writeObjectField("properties", authDefinition.getBearerauth());
}

if(authDefinition.getOauth() != null) {
gen.writeObjectField("properties", authDefinition.getOauth());
}

}
}
gen.writeEndObject();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public void serialize(Workflow workflow,
gen.writeObjectField("timeouts", workflow.getTimeouts());
}

if (workflow.getAuth() != null) {
gen.writeObjectField("auth", workflow.getAuth());
}

if (workflow.getStates() != null && !workflow.getStates().isEmpty()) {
gen.writeArrayFieldStart("states");
for (State state : workflow.getStates()) {
Expand Down
34 changes: 34 additions & 0 deletions api/src/main/resources/schema/auth/auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.auth.AuthDefinition",
"description": "Auth Definition",
"properties": {
"name": {
"type": "string",
"description": "Unique auth definition name",
"minLength": 1
},
"scheme": {
"type": "string",
"description": "Defines the auth type",
"enum": [
"basic",
"bearer",
"oauth2"
],
"default": "basic"
},
"basicauth": {
"$ref": "basicauthdef.json"
},
"bearerauth": {
"$ref": "bearerauthdef.json"
},
"oauth": {
"$ref": "oauthdef.json"
}
},
"required": [

]
}
23 changes: 23 additions & 0 deletions api/src/main/resources/schema/auth/basicauthdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.auth.BasicAuthDefinition",
"properties": {
"username": {
"type": "string",
"description": "String or a workflow expression. Contains the user name",
"minLength": 1
},
"password": {
"type": "string",
"description": "String or a workflow expression. Contains the user password",
"minLength": 1
},
"metadata": {
"$ref": "../metadata/metadata.json"
}
},
"required": [
"username",
"password"
]
}
17 changes: 17 additions & 0 deletions api/src/main/resources/schema/auth/bearerauthdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.auth.BearerAuthDefinition",
"properties": {
"token": {
"type": "string",
"description": "String or a workflow expression. Contains the token",
"minLength": 1
},
"metadata": {
"$ref": "../metadata/metadata.json"
}
},
"required": [
"token"
]
}
79 changes: 79 additions & 0 deletions api/src/main/resources/schema/auth/oauthdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"type": "object",
"javaType": "io.serverlessworkflow.api.auth.OauthDefinition",
"properties": {
"authority": {
"type": "string",
"description": "String or a workflow expression. Contains the authority information",
"minLength": 1
},
"grantType": {
"type": "string",
"description": "Defines the grant type",
"enum": [
"password",
"clientCredentials",
"tokenExchange"
],
"additionalItems": false
},
"clientId": {
"type": "string",
"description": "String or a workflow expression. Contains the client identifier",
"minLength": 1
},
"clientSecret": {
"type": "string",
"description": "Workflow secret or a workflow expression. Contains the client secret",
"minLength": 1
},
"scopes": {
"type": "array",
"description": "Array containing strings or workflow expressions. Contains the OAuth2 scopes",
"items": {
"type": "string"
},
"minItems": 1
},
"username": {
"type": "string",
"description": "String or a workflow expression. Contains the user name. Used only if grantType is 'resourceOwner'",
"minLength": 1
},
"password": {
"type": "string",
"description": "String or a workflow expression. Contains the user password. Used only if grantType is 'resourceOwner'",
"minLength": 1
},
"audiences": {
"type": "array",
"description": "Array containing strings or workflow expressions. Contains the OAuth2 audiences",
"items": {
"type": "string"
},
"minItems": 1
},
"subjectToken": {
"type": "string",
"description": "String or a workflow expression. Contains the subject token",
"minLength": 1
},
"requestedSubject": {
"type": "string",
"description": "String or a workflow expression. Contains the requested subject",
"minLength": 1
},
"requestedIssuer": {
"type": "string",
"description": "String or a workflow expression. Contains the requested issuer",
"minLength": 1
},
"metadata": {
"$ref": "../metadata/metadata.json"
}
},
"required": [
"grantType",
"clientId"
]
}
5 changes: 5 additions & 0 deletions api/src/main/resources/schema/functions/functiondef.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
],
"default": "rest"
},
"authRef": {
"type": "string",
"description": "References an auth definition name to be used to access to resource defined in the operation parameter",
"minLength": 1
},
"metadata": {
"$ref": "../metadata/metadata.json"
}
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/resources/schema/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"timeouts": {
"$ref": "timeouts/timeoutsdef.json"
},
"auth": {
"$ref": "auth/auth.json"
},
"states": {
"type": "array",
"description": "State Definitions",
Expand Down
Loading
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