use of org.eclipse.microprofile.openapi.models.security.OAuthFlow in project Payara by payara.
the class SecurityBuilderTest method setupBaseDocument.
@Override
@SuppressWarnings("serial")
protected void setupBaseDocument(OpenAPI document) {
document.addSecurityRequirement(createSecurityRequirement().addScheme("scheme1", "scope1").addScheme("scheme2").addScheme("scheme3", Arrays.asList("scope2", "scope3")));
OAuthFlow flow = createOAuthFlow().authorizationUrl("authorizationUrl").tokenUrl("tokenUrl").refreshUrl("refreshUrl").scopes(new HashMap<String, String>() {
{
put("scope", "description");
put("x-ext", "ext-value");
}
}).addExtension("x-ext", "ext-value");
document.getComponents().addSecurityScheme("scheme1", createSecurityScheme().description("description").name("name").type(Type.HTTP).in(In.QUERY).scheme("scheme").bearerFormat("bearerFormat").openIdConnectUrl("openIdConnectUrl").addExtension("x-ext", "ext-value").flows(createOAuthFlows().implicit(flow).password(flow).clientCredentials(flow).authorizationCode(flow).addExtension("x-ext", "ext-value")));
}
use of org.eclipse.microprofile.openapi.models.security.OAuthFlow in project Payara by payara.
the class OAuthFlowsImpl method merge.
public static void merge(OAuthFlows from, OAuthFlows to, boolean override) {
if (from == null) {
return;
}
if (from.getPassword() != null) {
OAuthFlow flow = new OAuthFlowImpl();
OAuthFlowImpl.merge(from.getPassword(), flow, override);
to.setPassword(mergeProperty(to.getPassword(), flow, override));
}
if (from.getAuthorizationCode() != null) {
OAuthFlow flow = new OAuthFlowImpl();
OAuthFlowImpl.merge(from.getAuthorizationCode(), flow, override);
to.setAuthorizationCode(mergeProperty(to.getAuthorizationCode(), flow, override));
}
if (from.getClientCredentials() != null) {
OAuthFlow flow = new OAuthFlowImpl();
OAuthFlowImpl.merge(from.getClientCredentials(), flow, override);
to.setClientCredentials(mergeProperty(to.getClientCredentials(), flow, override));
}
if (from.getImplicit() != null) {
OAuthFlow flow = new OAuthFlowImpl();
OAuthFlowImpl.merge(from.getImplicit(), flow, override);
to.setImplicit(mergeProperty(to.getImplicit(), flow, override));
}
}
use of org.eclipse.microprofile.openapi.models.security.OAuthFlow in project Payara by payara.
the class ModelInvariantsTest method ScopesAddScopeDoesAcceptNull.
@Test
public void ScopesAddScopeDoesAcceptNull() {
OAuthFlow flow = new OAuthFlowImpl();
flow.addScope("foo", null);
assertTrue(flow.getScopes().containsKey("foo"));
}
use of org.eclipse.microprofile.openapi.models.security.OAuthFlow in project Payara by payara.
the class OAuthFlowImpl method createInstance.
@SuppressWarnings("unchecked")
public static OAuthFlow createInstance(AnnotationModel annotation) {
OAuthFlow from = new OAuthFlowImpl();
from.setAuthorizationUrl(annotation.getValue("authorizationUrl", String.class));
from.setTokenUrl(annotation.getValue("tokenUrl", String.class));
from.setRefreshUrl(annotation.getValue("refreshUrl", String.class));
List<AnnotationModel> scopesAnnotation = annotation.getValue("scopes", List.class);
if (scopesAnnotation != null) {
Map<String, String> scopes = createMap();
for (AnnotationModel scopeAnnotation : scopesAnnotation) {
scopes.put(scopeAnnotation.getValue("name", String.class), scopeAnnotation.getValue("description", String.class));
}
from.setScopes(scopes);
}
return from;
}
use of org.eclipse.microprofile.openapi.models.security.OAuthFlow in project Payara by payara.
the class ModelInvariantsTest method addKeyValueIgnoresNull.
@Test
public void addKeyValueIgnoresNull() {
BiPredicate<Extensible<?>, String> hasExtension = (obj, key) -> obj.getExtensions().containsKey(key);
assertAddIgnoresNull(new CallbackImpl(), Callback::addPathItem, Callback::hasPathItem);
assertAddIgnoresNull(new CallbackImpl(), Callback::addExtension, hasExtension);
assertAddIgnoresNull(new ExampleImpl(), Example::addExtension, hasExtension);
assertAddIgnoresNull(new HeaderImpl(), Header::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new HeaderImpl(), Header::addExtension, hasExtension);
assertAddIgnoresNull(new ContactImpl(), Contact::addExtension, hasExtension);
assertAddIgnoresNull(new InfoImpl(), Info::addExtension, hasExtension);
assertAddIgnoresNull(new LicenseImpl(), License::addExtension, hasExtension);
assertAddIgnoresNull(new LinkImpl(), Link::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new LinkImpl(), Link::addExtension, hasExtension);
assertAddIgnoresNull(new ContentImpl(), Content::addMediaType, Content::hasMediaType);
assertAddIgnoresNull(new DiscriminatorImpl(), Discriminator::addMapping, (obj, key) -> obj.getMapping().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new EncodingImpl(), Encoding::addExtension, hasExtension);
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addEncoding, (obj, key) -> obj.getEncoding().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new MediaTypeImpl(), MediaType::addExtension, hasExtension);
assertAddIgnoresNull(new SchemaImpl(), Schema::addProperty, (obj, key) -> obj.getProperties().containsKey(key));
assertAddIgnoresNull(new SchemaImpl(), Schema::addExtension, hasExtension);
assertAddIgnoresNull(new XMLImpl(), XML::addExtension, hasExtension);
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ParameterImpl(), Parameter::addExtension, hasExtension);
assertAddIgnoresNull(new RequestBodyImpl(), RequestBody::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new APIResponseImpl(), APIResponse::addExtension, hasExtension);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addAPIResponse, APIResponses::hasAPIResponse);
assertAddIgnoresNull(new APIResponsesImpl(), APIResponses::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowImpl(), OAuthFlow::addExtension, hasExtension);
assertAddIgnoresNull(new OAuthFlowsImpl(), OAuthFlows::addExtension, hasExtension);
assertAddIgnoresNull(new SecuritySchemeImpl(), SecurityScheme::addExtension, hasExtension);
assertAddIgnoresNull(new ServerImpl(), Server::addExtension, hasExtension);
assertAddIgnoresNull(new ServerVariableImpl(), ServerVariable::addExtension, hasExtension);
assertAddIgnoresNull(new TagImpl(), Tag::addExtension, hasExtension);
assertAddIgnoresNull(new ComponentsImpl(), Components::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExample, (obj, key) -> obj.getExamples().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addHeader, (obj, key) -> obj.getHeaders().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addLink, (obj, key) -> obj.getLinks().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addParameter, (obj, key) -> obj.getParameters().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addRequestBody, (obj, key) -> obj.getRequestBodies().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addResponse, (obj, key) -> obj.getResponses().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSchema, (obj, key) -> obj.getSchemas().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addSecurityScheme, (obj, key) -> obj.getSecuritySchemes().containsKey(key));
assertAddIgnoresNull(new ComponentsImpl(), Components::addExtension, hasExtension);
assertAddIgnoresNull(new ExternalDocumentationImpl(), ExternalDocumentation::addExtension, hasExtension);
assertAddIgnoresNull(new OpenAPIImpl(), OpenAPI::addExtension, hasExtension);
assertAddIgnoresNull(new OperationImpl(), Operation::addCallback, (obj, key) -> obj.getCallbacks().containsKey(key));
assertAddIgnoresNull(new OperationImpl(), Operation::addExtension, hasExtension);
assertAddIgnoresNull(new PathItemImpl(), PathItem::addExtension, hasExtension);
assertAddIgnoresNull(new PathsImpl(), Paths::addPathItem, Paths::hasPathItem);
assertAddIgnoresNull(new PathsImpl(), Paths::addExtension, hasExtension);
}
Aggregations