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

com.azure.resourcemanager.servicelinker.models.ServicePrincipalSecretAuthInfo Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.servicelinker.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
 * The authentication info when authType is servicePrincipal secret.
 */
@Fluent
public final class ServicePrincipalSecretAuthInfo extends AuthInfoBase {
    /*
     * The authentication type.
     */
    private AuthType authType = AuthType.SERVICE_PRINCIPAL_SECRET;

    /*
     * ServicePrincipal application clientId for servicePrincipal auth.
     */
    private String clientId;

    /*
     * Principal Id for servicePrincipal auth.
     */
    private String principalId;

    /*
     * Secret for servicePrincipal auth.
     */
    private String secret;

    /*
     * Indicates whether to clean up previous operation when Linker is updating or deleting
     */
    private DeleteOrUpdateBehavior deleteOrUpdateBehavior;

    /*
     * Optional, this value specifies the Azure roles to be assigned. Automatically
     */
    private List roles;

    /*
     * Username created in the database which is mapped to a user in AAD.
     */
    private String username;

    /**
     * Creates an instance of ServicePrincipalSecretAuthInfo class.
     */
    public ServicePrincipalSecretAuthInfo() {
    }

    /**
     * Get the authType property: The authentication type.
     * 
     * @return the authType value.
     */
    @Override
    public AuthType authType() {
        return this.authType;
    }

    /**
     * Get the clientId property: ServicePrincipal application clientId for servicePrincipal auth.
     * 
     * @return the clientId value.
     */
    public String clientId() {
        return this.clientId;
    }

    /**
     * Set the clientId property: ServicePrincipal application clientId for servicePrincipal auth.
     * 
     * @param clientId the clientId value to set.
     * @return the ServicePrincipalSecretAuthInfo object itself.
     */
    public ServicePrincipalSecretAuthInfo withClientId(String clientId) {
        this.clientId = clientId;
        return this;
    }

    /**
     * Get the principalId property: Principal Id for servicePrincipal auth.
     * 
     * @return the principalId value.
     */
    public String principalId() {
        return this.principalId;
    }

    /**
     * Set the principalId property: Principal Id for servicePrincipal auth.
     * 
     * @param principalId the principalId value to set.
     * @return the ServicePrincipalSecretAuthInfo object itself.
     */
    public ServicePrincipalSecretAuthInfo withPrincipalId(String principalId) {
        this.principalId = principalId;
        return this;
    }

    /**
     * Get the secret property: Secret for servicePrincipal auth.
     * 
     * @return the secret value.
     */
    public String secret() {
        return this.secret;
    }

    /**
     * Set the secret property: Secret for servicePrincipal auth.
     * 
     * @param secret the secret value to set.
     * @return the ServicePrincipalSecretAuthInfo object itself.
     */
    public ServicePrincipalSecretAuthInfo withSecret(String secret) {
        this.secret = secret;
        return this;
    }

    /**
     * Get the deleteOrUpdateBehavior property: Indicates whether to clean up previous operation when Linker is updating
     * or deleting.
     * 
     * @return the deleteOrUpdateBehavior value.
     */
    public DeleteOrUpdateBehavior deleteOrUpdateBehavior() {
        return this.deleteOrUpdateBehavior;
    }

    /**
     * Set the deleteOrUpdateBehavior property: Indicates whether to clean up previous operation when Linker is updating
     * or deleting.
     * 
     * @param deleteOrUpdateBehavior the deleteOrUpdateBehavior value to set.
     * @return the ServicePrincipalSecretAuthInfo object itself.
     */
    public ServicePrincipalSecretAuthInfo withDeleteOrUpdateBehavior(DeleteOrUpdateBehavior deleteOrUpdateBehavior) {
        this.deleteOrUpdateBehavior = deleteOrUpdateBehavior;
        return this;
    }

    /**
     * Get the roles property: Optional, this value specifies the Azure roles to be assigned. Automatically.
     * 
     * @return the roles value.
     */
    public List roles() {
        return this.roles;
    }

    /**
     * Set the roles property: Optional, this value specifies the Azure roles to be assigned. Automatically.
     * 
     * @param roles the roles value to set.
     * @return the ServicePrincipalSecretAuthInfo object itself.
     */
    public ServicePrincipalSecretAuthInfo withRoles(List roles) {
        this.roles = roles;
        return this;
    }

    /**
     * Get the username property: Username created in the database which is mapped to a user in AAD.
     * 
     * @return the username value.
     */
    public String username() {
        return this.username;
    }

    /**
     * Set the username property: Username created in the database which is mapped to a user in AAD.
     * 
     * @param username the username value to set.
     * @return the ServicePrincipalSecretAuthInfo object itself.
     */
    public ServicePrincipalSecretAuthInfo withUsername(String username) {
        this.username = username;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ServicePrincipalSecretAuthInfo withAuthMode(AuthMode authMode) {
        super.withAuthMode(authMode);
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        if (clientId() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property clientId in model ServicePrincipalSecretAuthInfo"));
        }
        if (principalId() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property principalId in model ServicePrincipalSecretAuthInfo"));
        }
        if (secret() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property secret in model ServicePrincipalSecretAuthInfo"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(ServicePrincipalSecretAuthInfo.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("authMode", authMode() == null ? null : authMode().toString());
        jsonWriter.writeStringField("clientId", this.clientId);
        jsonWriter.writeStringField("principalId", this.principalId);
        jsonWriter.writeStringField("secret", this.secret);
        jsonWriter.writeStringField("authType", this.authType == null ? null : this.authType.toString());
        jsonWriter.writeStringField("deleteOrUpdateBehavior",
            this.deleteOrUpdateBehavior == null ? null : this.deleteOrUpdateBehavior.toString());
        jsonWriter.writeArrayField("roles", this.roles, (writer, element) -> writer.writeString(element));
        jsonWriter.writeStringField("userName", this.username);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of ServicePrincipalSecretAuthInfo from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ServicePrincipalSecretAuthInfo if the JsonReader was pointing to an instance of it, or
     * null if it was pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the ServicePrincipalSecretAuthInfo.
     */
    public static ServicePrincipalSecretAuthInfo fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            ServicePrincipalSecretAuthInfo deserializedServicePrincipalSecretAuthInfo
                = new ServicePrincipalSecretAuthInfo();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("authMode".equals(fieldName)) {
                    deserializedServicePrincipalSecretAuthInfo.withAuthMode(AuthMode.fromString(reader.getString()));
                } else if ("clientId".equals(fieldName)) {
                    deserializedServicePrincipalSecretAuthInfo.clientId = reader.getString();
                } else if ("principalId".equals(fieldName)) {
                    deserializedServicePrincipalSecretAuthInfo.principalId = reader.getString();
                } else if ("secret".equals(fieldName)) {
                    deserializedServicePrincipalSecretAuthInfo.secret = reader.getString();
                } else if ("authType".equals(fieldName)) {
                    deserializedServicePrincipalSecretAuthInfo.authType = AuthType.fromString(reader.getString());
                } else if ("deleteOrUpdateBehavior".equals(fieldName)) {
                    deserializedServicePrincipalSecretAuthInfo.deleteOrUpdateBehavior
                        = DeleteOrUpdateBehavior.fromString(reader.getString());
                } else if ("roles".equals(fieldName)) {
                    List roles = reader.readArray(reader1 -> reader1.getString());
                    deserializedServicePrincipalSecretAuthInfo.roles = roles;
                } else if ("userName".equals(fieldName)) {
                    deserializedServicePrincipalSecretAuthInfo.username = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedServicePrincipalSecretAuthInfo;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy