com.opengamma.sdk.common.auth.AccessTokenResult Maven / Gradle / Ivy
Show all versions of sdk-common Show documentation
/*
* 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 java.util.Set;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.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;
/**
* The result returned to the client from an oauth2 request.
*
* OAuth2 Access Token Response per https://tools.ietf.org/html/rfc6749#section-4.4
*
* @deprecated Since 1.3.0. Replaced by {@link com.opengamma.sdk.common.auth.v3.AccessTokenResult} with an updated implementation.
* The current class will be removed in future versions.
*/
@Deprecated
@BeanDefinition(builderScope = "private", metaScope = "private")
public final class AccessTokenResult implements ImmutableBean {
/**
* The 'bearer' token type.
*/
public static final String BEARER = "bearer";
/**
* The access token.
*/
@PropertyDefinition(validate = "notNull")
private final String accessToken;
/**
* The token type.
*/
@PropertyDefinition(validate = "notNull")
private final String tokenType;
/**
* The lifetime of the token in seconds.
*/
@PropertyDefinition
private final long expiresIn;
/**
* The refresh token.
*/
@PropertyDefinition
private final String refreshToken;
//-------------------------------------------------------------------------
/**
* Obtains an instance.
*
* @param accessToken the access token
* @param tokenType the token type
* @param expiresIn the expires in
* @return the instance
*/
public static AccessTokenResult of(String accessToken, String tokenType, long expiresIn) {
return new AccessTokenResult(accessToken, tokenType, expiresIn, null);
}
/**
* Obtains an instance with a refresh token.
*
* @param accessToken the access token
* @param tokenType the token type
* @param expiresIn the expires in
* @param refreshToken the refresh token
* @return the instance
*/
public static AccessTokenResult of(String accessToken, String tokenType, long expiresIn, String refreshToken) {
return new AccessTokenResult(accessToken, tokenType, expiresIn, refreshToken);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code AccessTokenResult}.
* @return the meta-bean, not null
*/
public static MetaBean meta() {
return AccessTokenResult.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(AccessTokenResult.Meta.INSTANCE);
}
private AccessTokenResult(
String accessToken,
String tokenType,
long expiresIn,
String refreshToken) {
JodaBeanUtils.notNull(accessToken, "accessToken");
JodaBeanUtils.notNull(tokenType, "tokenType");
this.accessToken = accessToken;
this.tokenType = tokenType;
this.expiresIn = expiresIn;
this.refreshToken = refreshToken;
}
@Override
public MetaBean metaBean() {
return AccessTokenResult.Meta.INSTANCE;
}
@Override
public Property property(String propertyName) {
return metaBean().metaProperty(propertyName).createProperty(this);
}
@Override
public Set propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
/**
* Gets the access token.
* @return the value of the property, not null
*/
public String getAccessToken() {
return accessToken;
}
//-----------------------------------------------------------------------
/**
* Gets the token type.
* @return the value of the property, not null
*/
public String getTokenType() {
return tokenType;
}
//-----------------------------------------------------------------------
/**
* Gets the lifetime of the token in seconds.
* @return the value of the property
*/
public long getExpiresIn() {
return expiresIn;
}
//-----------------------------------------------------------------------
/**
* Gets the refresh token.
* @return the value of the property
*/
public String getRefreshToken() {
return refreshToken;
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
AccessTokenResult other = (AccessTokenResult) obj;
return JodaBeanUtils.equal(accessToken, other.accessToken) &&
JodaBeanUtils.equal(tokenType, other.tokenType) &&
(expiresIn == other.expiresIn) &&
JodaBeanUtils.equal(refreshToken, other.refreshToken);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(accessToken);
hash = hash * 31 + JodaBeanUtils.hashCode(tokenType);
hash = hash * 31 + JodaBeanUtils.hashCode(expiresIn);
hash = hash * 31 + JodaBeanUtils.hashCode(refreshToken);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(160);
buf.append("AccessTokenResult{");
buf.append("accessToken").append('=').append(accessToken).append(',').append(' ');
buf.append("tokenType").append('=').append(tokenType).append(',').append(' ');
buf.append("expiresIn").append('=').append(expiresIn).append(',').append(' ');
buf.append("refreshToken").append('=').append(JodaBeanUtils.toString(refreshToken));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code AccessTokenResult}.
*/
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 accessToken} property.
*/
private final MetaProperty accessToken = DirectMetaProperty.ofImmutable(
this, "accessToken", AccessTokenResult.class, String.class);
/**
* The meta-property for the {@code tokenType} property.
*/
private final MetaProperty tokenType = DirectMetaProperty.ofImmutable(
this, "tokenType", AccessTokenResult.class, String.class);
/**
* The meta-property for the {@code expiresIn} property.
*/
private final MetaProperty expiresIn = DirectMetaProperty.ofImmutable(
this, "expiresIn", AccessTokenResult.class, Long.TYPE);
/**
* The meta-property for the {@code refreshToken} property.
*/
private final MetaProperty refreshToken = DirectMetaProperty.ofImmutable(
this, "refreshToken", AccessTokenResult.class, String.class);
/**
* The meta-properties.
*/
private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"accessToken",
"tokenType",
"expiresIn",
"refreshToken");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -1042689291: // accessToken
return accessToken;
case 141498579: // tokenType
return tokenType;
case 250196857: // expiresIn
return expiresIn;
case -56506402: // refreshToken
return refreshToken;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder extends AccessTokenResult> builder() {
return new AccessTokenResult.Builder();
}
@Override
public Class extends AccessTokenResult> beanType() {
return AccessTokenResult.class;
}
@Override
public Map> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -1042689291: // accessToken
return ((AccessTokenResult) bean).getAccessToken();
case 141498579: // tokenType
return ((AccessTokenResult) bean).getTokenType();
case 250196857: // expiresIn
return ((AccessTokenResult) bean).getExpiresIn();
case -56506402: // refreshToken
return ((AccessTokenResult) bean).getRefreshToken();
}
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 AccessTokenResult}.
*/
private static final class Builder extends DirectPrivateBeanBuilder {
private String accessToken;
private String tokenType;
private long expiresIn;
private String refreshToken;
/**
* Restricted constructor.
*/
private Builder() {
super(meta());
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -1042689291: // accessToken
return accessToken;
case 141498579: // tokenType
return tokenType;
case 250196857: // expiresIn
return expiresIn;
case -56506402: // refreshToken
return refreshToken;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -1042689291: // accessToken
this.accessToken = (String) newValue;
break;
case 141498579: // tokenType
this.tokenType = (String) newValue;
break;
case 250196857: // expiresIn
this.expiresIn = (Long) newValue;
break;
case -56506402: // refreshToken
this.refreshToken = (String) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public AccessTokenResult build() {
return new AccessTokenResult(
accessToken,
tokenType,
expiresIn,
refreshToken);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(160);
buf.append("AccessTokenResult.Builder{");
buf.append("accessToken").append('=').append(JodaBeanUtils.toString(accessToken)).append(',').append(' ');
buf.append("tokenType").append('=').append(JodaBeanUtils.toString(tokenType)).append(',').append(' ');
buf.append("expiresIn").append('=').append(JodaBeanUtils.toString(expiresIn)).append(',').append(' ');
buf.append("refreshToken").append('=').append(JodaBeanUtils.toString(refreshToken));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}