Skip to content
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

JNG-6116 Fix authentication and authorization #42

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
Expand Up @@ -24,17 +24,25 @@
import hu.blackbelt.judo.generator.commons.annotations.TemplateHelper;
import hu.blackbelt.judo.meta.psm.accesspoint.AbstractActorType;
import hu.blackbelt.judo.meta.psm.derived.ReferenceAccessor;
import hu.blackbelt.judo.meta.psm.namespace.*;
import hu.blackbelt.judo.meta.psm.service.*;
import hu.blackbelt.judo.meta.psm.namespace.Model;
import hu.blackbelt.judo.meta.psm.namespace.NamedElement;
import hu.blackbelt.judo.meta.psm.service.MappedTransferObjectType;
import hu.blackbelt.judo.meta.psm.service.TransferObjectRelation;
import hu.blackbelt.judo.meta.psm.service.TransferObjectType;
import hu.blackbelt.judo.meta.psm.service.TransferOperation;
import hu.blackbelt.judo.meta.psm.support.PsmModelResourceSupport;
import hu.blackbelt.judo.meta.psm.type.*;
import hu.blackbelt.judo.meta.psm.type.EnumerationType;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import java.util.*;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static hu.blackbelt.judo.psm.generator.jaxrs.api.ObjectTypeHelper.*;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ObjectTypeHelper.getRealm;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ObjectTypeHelper.isRangeInputType;

@TemplateHelper
public class ModelHelper extends StaticMethodValueResolver {
Expand Down Expand Up @@ -81,8 +89,7 @@ public static boolean isMapped(TransferObjectType transferObjectType) {
return (transferObjectType instanceof MappedTransferObjectType);
}

public static Set<TransferObjectType> getAllExposedTransferObjectTypesFromAccessPoint(
final TransferObjectType accessPoint) {
public static Set<TransferObjectType> getAllExposedTransferObjectTypesFromAccessPoint(final TransferObjectType accessPoint) {

final Set<TransferObjectType> foundTransferObjectTypes = new HashSet<>();
if (!accessPoint.getOperations().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public static String getRealm(AbstractActorType actorType) {
return actorType.getRealm();
}

public static String getRealmLowerCase(AbstractActorType actorType) {
return getRealm(actorType).toLowerCase();
}


private static CacheLoader<TransferObjectType, EntityType> getEntityCacheLoader = new CacheLoader<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@
*/


import com.github.jknack.handlebars.internal.lang3.StringUtils;
import hu.blackbelt.judo.generator.commons.StaticMethodValueResolver;
import hu.blackbelt.judo.generator.commons.annotations.TemplateHelper;

import hu.blackbelt.judo.meta.psm.data.AssociationEnd;
import hu.blackbelt.judo.meta.psm.data.EntityType;
import hu.blackbelt.judo.meta.psm.data.Relation;
import hu.blackbelt.judo.meta.psm.accesspoint.AbstractActorType;
import hu.blackbelt.judo.meta.psm.namespace.Model;
import hu.blackbelt.judo.meta.psm.namespace.NamedElement;
import hu.blackbelt.judo.meta.psm.namespace.Namespace;
import hu.blackbelt.judo.meta.psm.service.*;

import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.List;

import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaApiHelper.*;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaApiHelper.className;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaApiHelper.namedElementApiParentPath;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.JavaNamespaceHelper.*;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ModelHelper.getAllExposedTransferObjectTypesFromAccessPoint;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ModelHelper.modelWrapper;
import static hu.blackbelt.judo.psm.generator.jaxrs.api.ObjectTypeHelper.*;

@TemplateHelper
Expand Down Expand Up @@ -242,4 +240,22 @@ public static String getOperationTagName(TransferOperation transferOperation) {
return logicalFullName(transferObjectType);
}

public static List<AbstractActorType> getActorsOfOperation(Model model, TransferOperation transferOperation) {
return modelWrapper(model)
.getStreamOfPsmAccesspointAbstractActorType()
.filter(actor -> actor.getRealm() != null)
.filter(actor -> getAllExposedTransferObjectTypesFromAccessPoint(actor)
.stream()
.flatMap(to -> to.getOperations().stream())
.anyMatch(operation -> operation.equals(transferOperation)))
.toList();
}

public static List<String> getRealmsOfOperationLowerCase(Model model, TransferOperation transferOperation) {
return getActorsOfOperation(model, transferOperation)
.stream()
.map(actor -> actor.getRealm().toLowerCase())
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@ public static synchronized Boolean isGenerateOpenApiAnnotations() {
return Boolean.parseBoolean((String) ThreadLocalContextHolder.getVariable("generateOpenApiAnnotations"));
}

public static synchronized String getBaseUri() {
return (String) ThreadLocalContextHolder.getVariable("baseUri");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

package {{ namedElementApiPackageName self }};

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.OpenAPIDefinition(
info = @io.swagger.v3.oas.annotations.info.Info(
title = "{{ model.name }} API",
version = "1.0.0"
),
servers = {
{{# each (allAccessPointActor model) as |actor| }}
@io.swagger.v3.oas.annotations.servers.Server(
description = "{{ actor.name }}",
url = "https://tatami-tests.judo.technology/api/{{ namedElementRestPath actor }}/{{ className actor }}"
),
{{/ each }}
}
)
{{# if (isActorType self) }}
{{# if (getRealm self) }}
@io.swagger.v3.oas.annotations.security.SecuritySchemes(
value = {
@io.swagger.v3.oas.annotations.security.SecurityScheme(
type = io.swagger.v3.oas.annotations.enums.SecuritySchemeType.OPENIDCONNECT,
name = "{{ getRealmLowerCase self }}",
openIdConnectUrl = "{{ getBaseUri }}/auth/realms/{{ getRealm self }}/.well-known/openid-configuration"
),
}
)
{{/ if }}
{{/ if }}
{{/ if }}
public interface {{ self.applicationClassName }} {

public java.util.Map<java.lang.String, java.lang.Object> getProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ package {{ namedElementApiPackageName self }};
*/
{{/ if }}
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForCreateRequest self }}")
{{/ if }}
public class {{ classNameForCreateRequest self }} {

{{# if (isMapped self) }}

private String __referenceId;

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "__referenceId")
{{/ if }}
public String get__referenceId() {
return this.__referenceId;
}
Expand All @@ -24,7 +28,9 @@ public class {{ classNameForCreateRequest self }} {
{{/ if }}

{{# each (allEmbeddedOrMappedRelationForCreate self) as | relation | }}
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }})
{{/ if }}
{{# if (mappedRelationIsAssociation relation)}}
private {{{ relationTargetTypeDefinitionForCreateRequest relation}}} {{ safeName relation.name }};

Expand Down Expand Up @@ -53,7 +59,9 @@ public class {{ classNameForCreateRequest self }} {

private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }};

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }})
{{/ if }}
public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() {
return this.{{ safeName attribute.name }};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,45 @@
package {{ queryCustomizerPackageName self }};

/**
* Query customizer for searching {@link {{ classFqName self }} } instances.
*/
* Query customizer for searching {@link {{ classFqName self }} } instances.
*/
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForRequest self }}")
{{/ if }}
public class {{ queryCustomizerName self }} {
{{# each (allEmbeddedOrMappedRelation self) as | relation | }}
{{# each self.relations as | relation | }}
{{# unless (mappedRelationIsAssociation relation)}}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }})
private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }};
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }})
{{/ if }}
private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }};

public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() {
public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() {
return this.{{ safeName relation.name }};
}
}

public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}) {
public void set{{ relation.name.firstToUpperCase }}({{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }}) {
this.{{ safeName relation.name }} = {{ safeName relation.name }};
}
}
{{/ unless }}
{{/ each }}
{{/ each }}

{{# each self.attributes as | attribute | }}
{{# each self.attributes as | attribute | }}
{{# unless (isQueryOrDefaultValueOrDataPropertyAttribute attribute) }}

private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }};
private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }};

@io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }})
public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() {
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }})
{{/ if }}
public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() {
return this.{{ safeName attribute.name }};
};
public void set{{ attribute.name.firstToUpperCase }}({{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}) {
};
public void set{{ attribute.name.firstToUpperCase }}({{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }}) {
this.{{ safeName attribute.name }} = {{ safeName attribute.name }};
};
};

{{/ unless }}
{{/ each }}
}
{{/ each }}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ package {{ namedElementApiPackageName self }};
*/
{{/ if }}
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForRangeRequest self }}")
{{/ if }}
public class {{ classNameForRangeRequest self }} {

{{# each self.relations as | relation | }}
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }})
{{/ if }}
private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }};

public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() {
Expand All @@ -26,7 +30,9 @@ public class {{ classNameForRangeRequest self }} {

private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }};

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }})
{{/ if }}
public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() {
return this.{{ safeName attribute.name }};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ package {{ namedElementApiPackageName self }};
*/
{{/ if }}
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ classNameLogicalFullNameForRequest self }}")
{{/ if }}
public class {{ classNameForRequest self }} {

{{# each (allEmbeddedOrMappedRelation self) as | relation | }}
{{# unless (mappedRelationIsAssociation relation)}}
{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ relation.name }}"{{# if relation.required }}, required = true{{/ if }})
{{/ if }}
private {{{ relationTargetTypeDefinitionForRequest relation }}} {{ safeName relation.name }};

public {{{ relationTargetTypeDefinitionForRequest relation }}} get{{ relation.name.firstToUpperCase }}() {
Expand All @@ -31,7 +35,9 @@ public class {{ classNameForRequest self }} {

private {{{ attributeTargetTypeDefinition attribute }}} {{ safeName attribute.name }};

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "{{ attribute.name }}"{{# if attribute.required }}, required = true{{/ if }})
{{/ if }}
public {{{ attributeTargetTypeDefinition attribute }}} get{{ attribute.name.firstToUpperCase }}() {
return this.{{ safeName attribute.name }};
};
Expand All @@ -47,7 +53,9 @@ public class {{ classNameForRequest self }} {

private String __identifier;

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "__identifier")
{{/ if }}
public String get__identifier() {
return this.__identifier;
}
Expand All @@ -58,7 +66,9 @@ public class {{ classNameForRequest self }} {

private String __signedIdentifier;

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "__signedIdentifier")
{{/ if }}
public String get__signedIdentifier() {
return this.__signedIdentifier;
}
Expand All @@ -69,7 +79,9 @@ public class {{ classNameForRequest self }} {

private String __referenceId;

{{# if generateOpenApiAnnotations }}
@io.swagger.v3.oas.annotations.media.Schema(name = "__referenceId")
{{/ if }}
public String get__referenceId() {
return this.__referenceId;
}
Expand Down
Loading
Loading