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

io.fusionauth.domain.oauth2.OAuth2Configuration Maven / Gradle / Ivy

There is a newer version: 1.53.0
Show newest version
/*
 * Copyright (c) 2018-2019, FusionAuth, All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */
package io.fusionauth.domain.oauth2;

import java.net.URI;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

import com.fasterxml.jackson.annotation.JsonMerge;
import com.fasterxml.jackson.annotation.OptBoolean;
import com.inversoft.json.JacksonConstructor;
import com.inversoft.json.ToString;
import io.fusionauth.domain.Buildable;
import static io.fusionauth.domain.util.Normalizer.removeEmpty;
import static io.fusionauth.domain.util.Normalizer.trim;

/**
 * @author Daniel DeGroff
 */
public class OAuth2Configuration implements Buildable {
  @JsonMerge(OptBoolean.FALSE)
  public List authorizedOriginURLs = new ArrayList<>();

  @JsonMerge(OptBoolean.FALSE)
  public List authorizedRedirectURLs = new ArrayList<>();

  public String clientId;

  public String clientSecret;

  public URI deviceVerificationURL;

  @JsonMerge(OptBoolean.FALSE)
  public Set enabledGrants = new TreeSet<>(Comparator.comparing(GrantType::grantName, Comparator.reverseOrder()));

  public boolean generateRefreshTokens;

  public LogoutBehavior logoutBehavior = LogoutBehavior.AllApplications;

  /**
   * Logout redirect URL when calling the /oauth2/logout endpoint. If this is left null,
   * Application.oauthConfiguration.logoutURL will be used instead.
   */
  public URI logoutURL;

  public boolean requireClientAuthentication = true;

  @JacksonConstructor
  public OAuth2Configuration() {
  }

  public OAuth2Configuration(String clientId, String clientSecret) {
    this.clientId = clientId;
    this.clientSecret = clientSecret;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof OAuth2Configuration)) {
      return false;
    }
    OAuth2Configuration that = (OAuth2Configuration) o;
    return generateRefreshTokens == that.generateRefreshTokens &&
           requireClientAuthentication == that.requireClientAuthentication &&
           Objects.equals(authorizedOriginURLs, that.authorizedOriginURLs) &&
           Objects.equals(authorizedRedirectURLs, that.authorizedRedirectURLs) &&
           Objects.equals(clientId, that.clientId) &&
           Objects.equals(clientSecret, that.clientSecret) &&
           Objects.equals(deviceVerificationURL, that.deviceVerificationURL) &&
           Objects.equals(enabledGrants, that.enabledGrants) &&
           Objects.equals(logoutBehavior, that.logoutBehavior) &&
           Objects.equals(logoutURL, that.logoutURL);
  }

  @Override
  public int hashCode() {
    return Objects.hash(authorizedOriginURLs, authorizedRedirectURLs, clientId, clientSecret, deviceVerificationURL, enabledGrants, generateRefreshTokens, logoutBehavior, logoutURL, requireClientAuthentication);
  }

  public void normalize() {
    removeEmpty(authorizedOriginURLs);
    removeEmpty(authorizedRedirectURLs);
    clientId = trim(clientId);
    clientSecret = trim(clientSecret);
  }

  @Override
  public String toString() {
    return ToString.toString(this);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy