All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yubico.webauthn.data.RegistrationExtensionInputs Maven / Gradle / Ivy

The newest version!
// Copyright (c) 2018, Yubico AB
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package com.yubico.webauthn.data;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.yubico.webauthn.RelyingParty;
import com.yubico.webauthn.StartRegistrationOptions;
import com.yubico.webauthn.extension.appid.AppId;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import lombok.Builder;
import lombok.Value;

/**
 * Contains client
 * extension inputs to a navigator.credentials.create() operation. All members are
 * optional.
 *
 * 

The authenticator extension inputs are derived from these client extension inputs. * * @see §9. WebAuthn * Extensions */ @Value @Builder(toBuilder = true) @JsonIgnoreProperties(ignoreUnknown = true) public final class RegistrationExtensionInputs implements ExtensionInputs { private final AppId appidExclude; private final Boolean credProps; private final Extensions.LargeBlob.LargeBlobRegistrationInput largeBlob; private final Boolean uvm; @JsonCreator private RegistrationExtensionInputs( @JsonProperty("appidExclude") AppId appidExclude, @JsonProperty("credProps") Boolean credProps, @JsonProperty("largeBlob") Extensions.LargeBlob.LargeBlobRegistrationInput largeBlob, @JsonProperty("uvm") Boolean uvm) { this.appidExclude = appidExclude; this.credProps = credProps; this.largeBlob = largeBlob; this.uvm = uvm; } /** * Merge other into this. Non-null field values from this * take precedence. * * @return a new {@link RegistrationExtensionInputs} instance with the settings from both * this and other. */ public RegistrationExtensionInputs merge(RegistrationExtensionInputs other) { return new RegistrationExtensionInputs( this.appidExclude != null ? this.appidExclude : other.appidExclude, this.credProps != null ? this.credProps : other.credProps, this.largeBlob != null ? this.largeBlob : other.largeBlob, this.uvm != null ? this.uvm : other.uvm); } /** * @return The value of the FIDO AppID Exclusion Extension (appidExclude) input if * configured, empty otherwise. * @see RegistrationExtensionInputsBuilder#appidExclude(AppId) * @see §10.2. * FIDO AppID Exclusion Extension (appidExclude) */ public Optional getAppidExclude() { return Optional.ofNullable(appidExclude); } /** * @return true if the Credential Properties Extension (credProps) is * enabled, false otherwise. * @see RegistrationExtensionInputsBuilder#credProps() * @see §10.4. * Credential Properties Extension (credProps) */ public boolean getCredProps() { return credProps != null && credProps; } /** For JSON serialization, to omit false values. */ @JsonProperty("credProps") private Boolean getCredPropsJson() { return getCredProps() ? true : null; } /** * @return The value of the Large blob storage extension (largeBlob) input if * configured, empty otherwise. * @see * RegistrationExtensionInputsBuilder#largeBlob(Extensions.LargeBlob.LargeBlobRegistrationInput) * @see * RegistrationExtensionInputsBuilder#largeBlob(Extensions.LargeBlob.LargeBlobRegistrationInput.LargeBlobSupport) * @see §10.5. * Large blob storage extension (largeBlob) */ public Optional getLargeBlob() { return Optional.ofNullable(largeBlob); } /** * @return true if the User Verification Method Extension (uvm) is * enabled, false otherwise. * @see RegistrationExtensionInputsBuilder#uvm() * @see §10.3. * User Verification Method Extension (uvm) */ public boolean getUvm() { return uvm != null && uvm; } /** For JSON serialization, to omit false values. */ @JsonProperty("uvm") private Boolean getUvmJson() { return getUvm() ? true : null; } /** * @return The extension identifiers of all extensions configured. * @see §9.1. * Extension Identifiers */ @Override public Set getExtensionIds() { Set ids = new HashSet<>(); if (appidExclude != null) { ids.add(Extensions.AppidExclude.EXTENSION_ID); } if (getCredProps()) { ids.add(Extensions.CredentialProperties.EXTENSION_ID); } if (largeBlob != null) { ids.add(Extensions.LargeBlob.EXTENSION_ID); } if (getUvm()) { ids.add(Extensions.Uvm.EXTENSION_ID); } return Collections.unmodifiableSet(ids); } public static class RegistrationExtensionInputsBuilder { /** * Enable or disable the FIDO AppID Exclusion Extension (appidExclude). * *

You usually do not need to call this method explicitly; if {@link RelyingParty#getAppId()} * is present, then {@link RelyingParty#startRegistration(StartRegistrationOptions)} will enable * this extension automatically. * *

If this is set to empty, then {@link * RelyingParty#startRegistration(StartRegistrationOptions)} may overwrite it. * * @see RelyingParty#startRegistration(StartRegistrationOptions) * @see §10.2. * FIDO AppID Exclusion Extension (appidExclude) */ public RegistrationExtensionInputsBuilder appidExclude(Optional appidExclude) { this.appidExclude = appidExclude.orElse(null); return this; } /** * Enable the FIDO AppID Exclusion Extension (appidExclude). * *

You usually do not need to call this method explicitly; if {@link RelyingParty#getAppId()} * is present, then {@link RelyingParty#startRegistration(StartRegistrationOptions)} will enable * this extension automatically. * *

If this is set to null, then {@link * RelyingParty#startRegistration(StartRegistrationOptions)} may overwrite it. * * @see RelyingParty#startRegistration(StartRegistrationOptions) * @see §10.2. * FIDO AppID Exclusion Extension (appidExclude) */ public RegistrationExtensionInputsBuilder appidExclude(AppId appidExclude) { this.appidExclude = appidExclude; return this; } /** * Enable the Credential Properties (credProps) Extension. * * @see §10.4. * Credential Properties Extension (credProps) */ public RegistrationExtensionInputsBuilder credProps() { this.credProps = true; return this; } /** * Enable or disable the Credential Properties (credProps) Extension. * *

A true argument enables the extension. A false argument disables * the extension, and will not be overwritten by {@link * RelyingParty#startRegistration(StartRegistrationOptions)}. A null argument disables the * extension, and will be overwritten by {@link * RelyingParty#startRegistration(StartRegistrationOptions)}. * * @see RelyingParty#startRegistration(StartRegistrationOptions) * @see §10.4. * Credential Properties Extension (credProps) */ public RegistrationExtensionInputsBuilder credProps(Boolean credProps) { this.credProps = credProps; return this; } /** * Enable the Large blob storage extension (largeBlob). * *

Alias of largeBlob(new Extensions.LargeBlob.LargeBlobRegistrationInput(support)) * . * * @param support an {@link * com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobRegistrationInput.LargeBlobSupport} * value to set as the support attribute of the largeBlob * extension input. * @see #largeBlob(Extensions.LargeBlob.LargeBlobRegistrationInput) * @see §10.5. * Large blob storage extension (largeBlob) */ public RegistrationExtensionInputsBuilder largeBlob( Extensions.LargeBlob.LargeBlobRegistrationInput.LargeBlobSupport support) { this.largeBlob = new Extensions.LargeBlob.LargeBlobRegistrationInput(support); return this; } /** * Enable the Large blob storage extension (largeBlob). * * @see #largeBlob(Extensions.LargeBlob.LargeBlobRegistrationInput.LargeBlobSupport) * @see §10.5. * Large blob storage extension (largeBlob) */ public RegistrationExtensionInputsBuilder largeBlob( Extensions.LargeBlob.LargeBlobRegistrationInput largeBlob) { this.largeBlob = largeBlob; return this; } /** * Enable the User Verification Method Extension (uvm). * * @see §10.3. * User Verification Method Extension (uvm) */ public RegistrationExtensionInputsBuilder uvm() { this.uvm = true; return this; } /** For compatibility with {@link Builder}(toBuilder = true) */ private RegistrationExtensionInputsBuilder uvm(Boolean uvm) { this.uvm = uvm; return this; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy