org.eclipse.ditto.wot.model.OAuth2SecurityScheme Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ditto-wot-model Show documentation
Show all versions of ditto-wot-model Show documentation
Eclipse Ditto is a framework for creating and managing digital twins in the IoT.
The newest version!
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.wot.model;
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
/**
* An OAuth2SecurityScheme is a {@link SecurityScheme} indicating to use {@code OAuth 2.0} for authentication.
*
* @see RFC6749 - The OAuth 2.0 Authorization Framework
* @see RFC8252 - OAuth 2.0 for native Apps
* @see RFC8628 - OAuth 2.0 Device Authorization Grant
* @see WoT TD OAuth2SecurityScheme
* @since 2.4.0
*/
public interface OAuth2SecurityScheme extends SecurityScheme {
static OAuth2SecurityScheme fromJson(final String securitySchemeName, final JsonObject jsonObject) {
return new ImmutableOAuth2SecurityScheme(securitySchemeName, jsonObject);
}
static OAuth2SecurityScheme.Builder newBuilder(final CharSequence securitySchemeName) {
return OAuth2SecurityScheme.Builder.newBuilder(securitySchemeName);
}
static OAuth2SecurityScheme.Builder newBuilder(final CharSequence securitySchemeName, final JsonObject jsonObject) {
return OAuth2SecurityScheme.Builder.newBuilder(securitySchemeName, jsonObject);
}
@Override
default SecuritySchemeScheme getScheme() {
return SecuritySchemeScheme.OAUTH2;
}
Optional getAuthorization();
Optional getToken();
Optional getRefresh();
Optional getScopes();
Optional getFlow();
interface Builder extends SecurityScheme.Builder {
static Builder newBuilder(final CharSequence securitySchemeName) {
return new MutableOAuth2SecuritySchemeBuilder(
checkNotNull(securitySchemeName, "securitySchemeName").toString(),
JsonObject.newBuilder());
}
static Builder newBuilder(final CharSequence securitySchemeName, final JsonObject jsonObject) {
return new MutableOAuth2SecuritySchemeBuilder(
checkNotNull(securitySchemeName, "securitySchemeName").toString(),
jsonObject.toBuilder());
}
Builder setAuthorization(@Nullable IRI authorization);
Builder setToken(@Nullable IRI token);
Builder setRefresh(@Nullable IRI refresh);
Builder setScopes(@Nullable OAuth2Scopes scopes);
Builder setFlow(@Nullable String flow);
}
/**
* An enumeration of the known {@link JsonFieldDefinition}s of an OAuth2SecurityScheme.
*/
@Immutable
final class JsonFields {
public static final JsonFieldDefinition AUTHORIZATION = JsonFactory.newStringFieldDefinition(
"authorization");
public static final JsonFieldDefinition TOKEN = JsonFactory.newStringFieldDefinition(
"token");
public static final JsonFieldDefinition REFRESH = JsonFactory.newStringFieldDefinition(
"refresh");
public static final JsonFieldDefinition SCOPES = JsonFactory.newStringFieldDefinition(
"scopes");
public static final JsonFieldDefinition SCOPES_MULTIPLE = JsonFactory.newJsonArrayFieldDefinition(
"scopes");
public static final JsonFieldDefinition FLOW = JsonFactory.newStringFieldDefinition(
"flow");
private JsonFields() {
throw new AssertionError();
}
}
}