com.opengamma.sdk.common.auth.UserPasswordCredentials Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-common Show documentation
Show all versions of sdk-common Show documentation
OpenGamma SDK - Common code for accessing remote services
/*
* 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;
/**
* Username and password credentials, used to authenticate with the service.
*
* @deprecated Since 1.3.0. Will be removed in future versions of the SDK, since the new V3 API does not support username/passwords for authentication purposes.
*/
@Deprecated
@BeanDefinition(builderScope = "private", metaScope = "private", factoryName = "of")
final class UserPasswordCredentials implements Credentials, ImmutableBean {
/**
* The username with which to authenticate
*/
@PropertyDefinition(validate = "notEmpty", get = "")
private final String username;
/**
* The password corresponding to the username with which to authenticate
*/
@PropertyDefinition(validate = "notEmpty", get = "")
private final String password;
//-------------------------------------------------------------------------
@Override
public AccessTokenResult authenticate(AuthClient client) {
return client.authenticatePassword(username, password);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code UserPasswordCredentials}.
* @return the meta-bean, not null
*/
public static MetaBean meta() {
return UserPasswordCredentials.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(UserPasswordCredentials.Meta.INSTANCE);
}
/**
* Obtains an instance.
* @param username the value of the property, not empty
* @param password the value of the property, not empty
* @return the instance
*/
public static UserPasswordCredentials of(
String username,
String password) {
return new UserPasswordCredentials(
username,
password);
}
private UserPasswordCredentials(
String username,
String password) {
JodaBeanUtils.notEmpty(username, "username");
JodaBeanUtils.notEmpty(password, "password");
this.username = username;
this.password = password;
}
@Override
public MetaBean metaBean() {
return UserPasswordCredentials.Meta.INSTANCE;
}
@Override
public Property property(String propertyName) {
return metaBean().metaProperty(propertyName).createProperty(this);
}
@Override
public Set propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
UserPasswordCredentials other = (UserPasswordCredentials) obj;
return JodaBeanUtils.equal(username, other.username) &&
JodaBeanUtils.equal(password, other.password);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(username);
hash = hash * 31 + JodaBeanUtils.hashCode(password);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("UserPasswordCredentials{");
buf.append("username").append('=').append(username).append(',').append(' ');
buf.append("password").append('=').append(JodaBeanUtils.toString(password));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code UserPasswordCredentials}.
*/
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 username} property.
*/
private final MetaProperty username = DirectMetaProperty.ofImmutable(
this, "username", UserPasswordCredentials.class, String.class);
/**
* The meta-property for the {@code password} property.
*/
private final MetaProperty password = DirectMetaProperty.ofImmutable(
this, "password", UserPasswordCredentials.class, String.class);
/**
* The meta-properties.
*/
private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"username",
"password");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -265713450: // username
return username;
case 1216985755: // password
return password;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder extends UserPasswordCredentials> builder() {
return new UserPasswordCredentials.Builder();
}
@Override
public Class extends UserPasswordCredentials> beanType() {
return UserPasswordCredentials.class;
}
@Override
public Map> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -265713450: // username
return ((UserPasswordCredentials) bean).username;
case 1216985755: // password
return ((UserPasswordCredentials) bean).password;
}
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 UserPasswordCredentials}.
*/
private static final class Builder extends DirectPrivateBeanBuilder {
private String username;
private String password;
/**
* Restricted constructor.
*/
private Builder() {
super(meta());
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -265713450: // username
return username;
case 1216985755: // password
return password;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -265713450: // username
this.username = (String) newValue;
break;
case 1216985755: // password
this.password = (String) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public UserPasswordCredentials build() {
return new UserPasswordCredentials(
username,
password);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("UserPasswordCredentials.Builder{");
buf.append("username").append('=').append(JodaBeanUtils.toString(username)).append(',').append(' ');
buf.append("password").append('=').append(JodaBeanUtils.toString(password));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy