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

com.opengamma.sdk.common.auth.ApiKeyCredentials Maven / Gradle / Ivy

There is a newer version: 3.6.4
Show newest version
/*
 * Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.sdk.common.auth;

import java.util.Map;
import java.util.NoSuchElementException;

import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.joda.beans.impl.direct.DirectPrivateBeanBuilder;

/**
 * API key and secret credentials, used to authenticate with the service.
 * 

* This is the OAuth2 "client credentials" concept. */ @BeanDefinition(builderScope = "private", metaScope = "private", factoryName = "of") final class ApiKeyCredentials implements Credentials, ImmutableBean { // this class is intended to stay package-scoped // users are not exposed to the data, to reduce attempts to query the data held within /** * The API Key ID with which to authenticate */ @PropertyDefinition(validate = "notBlank", get = "") private final String apiKey; /** * The secret corresponding to the id with which to authenticate */ @PropertyDefinition(validate = "notBlank", get = "") private final String secret; //------------------------------------------------------------------------- @Override public AccessTokenResult authenticate(AuthClient client) { return client.authenticateApiKey(apiKey, secret); } //------------------------- AUTOGENERATED START ------------------------- /** * The meta-bean for {@code ApiKeyCredentials}. * @return the meta-bean, not null */ public static MetaBean meta() { return ApiKeyCredentials.Meta.INSTANCE; } static { MetaBean.register(ApiKeyCredentials.Meta.INSTANCE); } /** * Obtains an instance. * @param apiKey the value of the property, not blank * @param secret the value of the property, not blank * @return the instance */ public static ApiKeyCredentials of( String apiKey, String secret) { return new ApiKeyCredentials( apiKey, secret); } private ApiKeyCredentials( String apiKey, String secret) { JodaBeanUtils.notBlank(apiKey, "apiKey"); JodaBeanUtils.notBlank(secret, "secret"); this.apiKey = apiKey; this.secret = secret; } @Override public MetaBean metaBean() { return ApiKeyCredentials.Meta.INSTANCE; } //----------------------------------------------------------------------- @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { ApiKeyCredentials other = (ApiKeyCredentials) obj; return JodaBeanUtils.equal(apiKey, other.apiKey) && JodaBeanUtils.equal(secret, other.secret); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(apiKey); hash = hash * 31 + JodaBeanUtils.hashCode(secret); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("ApiKeyCredentials{"); buf.append("apiKey").append('=').append(apiKey).append(',').append(' '); buf.append("secret").append('=').append(JodaBeanUtils.toString(secret)); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code ApiKeyCredentials}. */ private static final class Meta extends DirectMetaBean { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code apiKey} property. */ private final MetaProperty apiKey = DirectMetaProperty.ofImmutable( this, "apiKey", ApiKeyCredentials.class, String.class); /** * The meta-property for the {@code secret} property. */ private final MetaProperty secret = DirectMetaProperty.ofImmutable( this, "secret", ApiKeyCredentials.class, String.class); /** * The meta-properties. */ private final Map> metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "apiKey", "secret"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1411301915: // apiKey return apiKey; case -906277200: // secret return secret; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder builder() { return new ApiKeyCredentials.Builder(); } @Override public Class beanType() { return ApiKeyCredentials.class; } @Override public Map> metaPropertyMap() { return metaPropertyMap$; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1411301915: // apiKey return ((ApiKeyCredentials) bean).apiKey; case -906277200: // secret return ((ApiKeyCredentials) bean).secret; } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { metaProperty(propertyName); if (quiet) { return; } throw new UnsupportedOperationException("Property cannot be written: " + propertyName); } } //----------------------------------------------------------------------- /** * The bean-builder for {@code ApiKeyCredentials}. */ private static final class Builder extends DirectPrivateBeanBuilder { private String apiKey; private String secret; /** * Restricted constructor. */ private Builder() { } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case -1411301915: // apiKey return apiKey; case -906277200: // secret return secret; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case -1411301915: // apiKey this.apiKey = (String) newValue; break; case -906277200: // secret this.secret = (String) newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return this; } @Override public ApiKeyCredentials build() { return new ApiKeyCredentials( apiKey, secret); } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("ApiKeyCredentials.Builder{"); buf.append("apiKey").append('=').append(JodaBeanUtils.toString(apiKey)).append(',').append(' '); buf.append("secret").append('=').append(JodaBeanUtils.toString(secret)); buf.append('}'); return buf.toString(); } } //-------------------------- AUTOGENERATED END -------------------------- }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy