/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.provider.permission; import java.util.Arrays; import java.util.Map; import java.util.Set; import java.util.TreeSet; import org.joda.beans.Bean; import org.joda.beans.BeanBuilder; import org.joda.beans.BeanDefinition; import org.joda.beans.JodaBeanUtils; import org.joda.beans.MetaProperty; import org.joda.beans.Property; import org.joda.beans.PropertyDefinition; import org.joda.beans.impl.direct.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaBean; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.id.ExternalId; import com.opengamma.id.ExternalIdBundle; import com.opengamma.util.ArgumentChecker; import com.opengamma.util.PublicSPI; /** * Request to check for user permissions for a given resources * <p> * This class is mutable and not thread-safe. */ @PublicSPI @BeanDefinition public class PermissionCheckProviderRequest implements Bean { /** * The user identity bundle. */ @PropertyDefinition(validate = "notNull") private ExternalIdBundle _userIdBundle; /** * The network address where user is logged in. * This is intended to be an IP address. */ @PropertyDefinition private String _networkAddress; /** * The set of requested permissions. */ @PropertyDefinition(validate = "notNull") private final Set<String> _requestedPermissions = new TreeSet<>(); //------------------------------------------------------------------------- /** * Obtains an instance to get user permissions check request. * * @param userId the identifier of user credentials, not null * @param networkAddress the user network address, may be null * @param requestedPermissions the requested permissions, not null * @return the request, not null */ public static PermissionCheckProviderRequest createGet(ExternalId userId, String networkAddress, String... requestedPermissions) { return createGet(userId, networkAddress, Arrays.asList(requestedPermissions)); } /** * Obtains an instance to get user permissions check request. * * @param userIdBundle the identifier bundle of user credentials, not null * @param networkAddress the user network address, may be null * @param requestedPermissions the requested permissions, not null * @return the request, not null */ public static PermissionCheckProviderRequest createGet(ExternalIdBundle userIdBundle, String networkAddress, String... requestedPermissions) { return createGet(userIdBundle, networkAddress, Arrays.asList(requestedPermissions)); } /** * Obtains an instance to get user permissions check request. * * @param userId the identifier of user credentials, not null * @param networkAddress the user network address, may be null * @param requestedPermissions the requested permissions, not null * @return the request, not null */ public static PermissionCheckProviderRequest createGet(ExternalId userId, String networkAddress, Iterable<String> requestedPermissions) { ArgumentChecker.notNull(userId, "userId"); return createGet(ExternalIdBundle.of(userId), networkAddress, requestedPermissions); } /** * Obtains an instance to get user permissions check request. * * @param userIdBundle the external id bundle of user credentials, not null * @param networkAddress the user network address, may be null * @param requestedPermissions the requested permissions, not null * @return the request, not null */ public static PermissionCheckProviderRequest createGet(ExternalIdBundle userIdBundle, String networkAddress, Iterable<String> requestedPermissions) { ArgumentChecker.notNull(userIdBundle, "userIdBundle"); ArgumentChecker.notNull(requestedPermissions, "requestedPermissions"); PermissionCheckProviderRequest request = new PermissionCheckProviderRequest(); request.setUserIdBundle(userIdBundle); request.setNetworkAddress(networkAddress); for (String permission : requestedPermissions) { request.getRequestedPermissions().add(permission); } return request; } /** * Creates an instance. */ protected PermissionCheckProviderRequest() { } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code PermissionCheckProviderRequest}. * @return the meta-bean, not null */ public static PermissionCheckProviderRequest.Meta meta() { return PermissionCheckProviderRequest.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(PermissionCheckProviderRequest.Meta.INSTANCE); } @Override public PermissionCheckProviderRequest.Meta metaBean() { return PermissionCheckProviderRequest.Meta.INSTANCE; } @Override public <R> Property<R> property(String propertyName) { return metaBean().<R>metaProperty(propertyName).createProperty(this); } @Override public Set<String> propertyNames() { return metaBean().metaPropertyMap().keySet(); } //----------------------------------------------------------------------- /** * Gets the user identity bundle. * @return the value of the property, not null */ public ExternalIdBundle getUserIdBundle() { return _userIdBundle; } /** * Sets the user identity bundle. * @param userIdBundle the new value of the property, not null */ public void setUserIdBundle(ExternalIdBundle userIdBundle) { JodaBeanUtils.notNull(userIdBundle, "userIdBundle"); this._userIdBundle = userIdBundle; } /** * Gets the the {@code userIdBundle} property. * @return the property, not null */ public final Property<ExternalIdBundle> userIdBundle() { return metaBean().userIdBundle().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the network address where user is logged in. * This is intended to be an IP address. * @return the value of the property */ public String getNetworkAddress() { return _networkAddress; } /** * Sets the network address where user is logged in. * This is intended to be an IP address. * @param networkAddress the new value of the property */ public void setNetworkAddress(String networkAddress) { this._networkAddress = networkAddress; } /** * Gets the the {@code networkAddress} property. * This is intended to be an IP address. * @return the property, not null */ public final Property<String> networkAddress() { return metaBean().networkAddress().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the set of requested permissions. * @return the value of the property, not null */ public Set<String> getRequestedPermissions() { return _requestedPermissions; } /** * Sets the set of requested permissions. * @param requestedPermissions the new value of the property, not null */ public void setRequestedPermissions(Set<String> requestedPermissions) { JodaBeanUtils.notNull(requestedPermissions, "requestedPermissions"); this._requestedPermissions.clear(); this._requestedPermissions.addAll(requestedPermissions); } /** * Gets the the {@code requestedPermissions} property. * @return the property, not null */ public final Property<Set<String>> requestedPermissions() { return metaBean().requestedPermissions().createProperty(this); } //----------------------------------------------------------------------- @Override public PermissionCheckProviderRequest clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { PermissionCheckProviderRequest other = (PermissionCheckProviderRequest) obj; return JodaBeanUtils.equal(getUserIdBundle(), other.getUserIdBundle()) && JodaBeanUtils.equal(getNetworkAddress(), other.getNetworkAddress()) && JodaBeanUtils.equal(getRequestedPermissions(), other.getRequestedPermissions()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getUserIdBundle()); hash = hash * 31 + JodaBeanUtils.hashCode(getNetworkAddress()); hash = hash * 31 + JodaBeanUtils.hashCode(getRequestedPermissions()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("PermissionCheckProviderRequest{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } protected void toString(StringBuilder buf) { buf.append("userIdBundle").append('=').append(JodaBeanUtils.toString(getUserIdBundle())).append(',').append(' '); buf.append("networkAddress").append('=').append(JodaBeanUtils.toString(getNetworkAddress())).append(',').append(' '); buf.append("requestedPermissions").append('=').append(JodaBeanUtils.toString(getRequestedPermissions())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code PermissionCheckProviderRequest}. */ public static class Meta extends DirectMetaBean { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code userIdBundle} property. */ private final MetaProperty<ExternalIdBundle> _userIdBundle = DirectMetaProperty.ofReadWrite( this, "userIdBundle", PermissionCheckProviderRequest.class, ExternalIdBundle.class); /** * The meta-property for the {@code networkAddress} property. */ private final MetaProperty<String> _networkAddress = DirectMetaProperty.ofReadWrite( this, "networkAddress", PermissionCheckProviderRequest.class, String.class); /** * The meta-property for the {@code requestedPermissions} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<Set<String>> _requestedPermissions = DirectMetaProperty.ofReadWrite( this, "requestedPermissions", PermissionCheckProviderRequest.class, (Class) Set.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "userIdBundle", "networkAddress", "requestedPermissions"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1899430296: // userIdBundle return _userIdBundle; case 1443604966: // networkAddress return _networkAddress; case 1660990518: // requestedPermissions return _requestedPermissions; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends PermissionCheckProviderRequest> builder() { return new DirectBeanBuilder<PermissionCheckProviderRequest>(new PermissionCheckProviderRequest()); } @Override public Class<? extends PermissionCheckProviderRequest> beanType() { return PermissionCheckProviderRequest.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code userIdBundle} property. * @return the meta-property, not null */ public final MetaProperty<ExternalIdBundle> userIdBundle() { return _userIdBundle; } /** * The meta-property for the {@code networkAddress} property. * @return the meta-property, not null */ public final MetaProperty<String> networkAddress() { return _networkAddress; } /** * The meta-property for the {@code requestedPermissions} property. * @return the meta-property, not null */ public final MetaProperty<Set<String>> requestedPermissions() { return _requestedPermissions; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1899430296: // userIdBundle return ((PermissionCheckProviderRequest) bean).getUserIdBundle(); case 1443604966: // networkAddress return ((PermissionCheckProviderRequest) bean).getNetworkAddress(); case 1660990518: // requestedPermissions return ((PermissionCheckProviderRequest) bean).getRequestedPermissions(); } return super.propertyGet(bean, propertyName, quiet); } @SuppressWarnings("unchecked") @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -1899430296: // userIdBundle ((PermissionCheckProviderRequest) bean).setUserIdBundle((ExternalIdBundle) newValue); return; case 1443604966: // networkAddress ((PermissionCheckProviderRequest) bean).setNetworkAddress((String) newValue); return; case 1660990518: // requestedPermissions ((PermissionCheckProviderRequest) bean).setRequestedPermissions((Set<String>) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((PermissionCheckProviderRequest) bean)._userIdBundle, "userIdBundle"); JodaBeanUtils.notNull(((PermissionCheckProviderRequest) bean)._requestedPermissions, "requestedPermissions"); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }