/* * Copyright 2010-2023 Amazon.com, Inc. or its affiliates. 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. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file 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 com.amazonaws.services.iot.model; import java.io.Serializable; import com.amazonaws.AmazonWebServiceRequest; /** *

* Tests if a specified principal is authorized to perform an IoT action on a * specified resource. Use this to test and debug the authorization behavior of * devices that connect to the IoT device gateway. *

*

* Requires permission to access the TestAuthorization action. *

*/ public class TestAuthorizationRequest extends AmazonWebServiceRequest implements Serializable { /** *

* The principal. Valid principals are CertificateArn * (arn:aws:iot:region:accountId:cert/certificateId), * thingGroupArn * (arn:aws:iot:region:accountId:thinggroup/groupName) * and CognitoId (region:id). *

*/ private String principal; /** *

* The Cognito identity pool ID. *

*/ private String cognitoIdentityPoolId; /** *

* A list of authorization info objects. Simulating authorization will * create a response for each authInfo object in the list. *

*/ private java.util.List authInfos; /** *

* The MQTT client ID. *

*/ private String clientId; /** *

* When testing custom authorization, the policies specified here are * treated as if they are attached to the principal being authorized. *

*/ private java.util.List policyNamesToAdd; /** *

* When testing custom authorization, the policies specified here are * treated as if they are not attached to the principal being authorized. *

*/ private java.util.List policyNamesToSkip; /** *

* The principal. Valid principals are CertificateArn * (arn:aws:iot:region:accountId:cert/certificateId), * thingGroupArn * (arn:aws:iot:region:accountId:thinggroup/groupName) * and CognitoId (region:id). *

* * @return

* The principal. Valid principals are CertificateArn * (arn:aws:iot:region:accountId:cert/certificateId), * thingGroupArn * (arn:aws:iot:region:accountId:thinggroup * /groupName) and CognitoId (region:id). *

*/ public String getPrincipal() { return principal; } /** *

* The principal. Valid principals are CertificateArn * (arn:aws:iot:region:accountId:cert/certificateId), * thingGroupArn * (arn:aws:iot:region:accountId:thinggroup/groupName) * and CognitoId (region:id). *

* * @param principal

* The principal. Valid principals are CertificateArn * (arn:aws:iot * :region:accountId:cert/certificateId), * thingGroupArn * (arn:aws:iot:region:accountId:thinggroup * /groupName) and CognitoId (region:id). *

*/ public void setPrincipal(String principal) { this.principal = principal; } /** *

* The principal. Valid principals are CertificateArn * (arn:aws:iot:region:accountId:cert/certificateId), * thingGroupArn * (arn:aws:iot:region:accountId:thinggroup/groupName) * and CognitoId (region:id). *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param principal

* The principal. Valid principals are CertificateArn * (arn:aws:iot * :region:accountId:cert/certificateId), * thingGroupArn * (arn:aws:iot:region:accountId:thinggroup * /groupName) and CognitoId (region:id). *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withPrincipal(String principal) { this.principal = principal; return this; } /** *

* The Cognito identity pool ID. *

* * @return

* The Cognito identity pool ID. *

*/ public String getCognitoIdentityPoolId() { return cognitoIdentityPoolId; } /** *

* The Cognito identity pool ID. *

* * @param cognitoIdentityPoolId

* The Cognito identity pool ID. *

*/ public void setCognitoIdentityPoolId(String cognitoIdentityPoolId) { this.cognitoIdentityPoolId = cognitoIdentityPoolId; } /** *

* The Cognito identity pool ID. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param cognitoIdentityPoolId

* The Cognito identity pool ID. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withCognitoIdentityPoolId(String cognitoIdentityPoolId) { this.cognitoIdentityPoolId = cognitoIdentityPoolId; return this; } /** *

* A list of authorization info objects. Simulating authorization will * create a response for each authInfo object in the list. *

* * @return

* A list of authorization info objects. Simulating authorization * will create a response for each authInfo object in * the list. *

*/ public java.util.List getAuthInfos() { return authInfos; } /** *

* A list of authorization info objects. Simulating authorization will * create a response for each authInfo object in the list. *

* * @param authInfos

* A list of authorization info objects. Simulating authorization * will create a response for each authInfo object * in the list. *

*/ public void setAuthInfos(java.util.Collection authInfos) { if (authInfos == null) { this.authInfos = null; return; } this.authInfos = new java.util.ArrayList(authInfos); } /** *

* A list of authorization info objects. Simulating authorization will * create a response for each authInfo object in the list. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param authInfos

* A list of authorization info objects. Simulating authorization * will create a response for each authInfo object * in the list. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withAuthInfos(AuthInfo... authInfos) { if (getAuthInfos() == null) { this.authInfos = new java.util.ArrayList(authInfos.length); } for (AuthInfo value : authInfos) { this.authInfos.add(value); } return this; } /** *

* A list of authorization info objects. Simulating authorization will * create a response for each authInfo object in the list. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param authInfos

* A list of authorization info objects. Simulating authorization * will create a response for each authInfo object * in the list. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withAuthInfos(java.util.Collection authInfos) { setAuthInfos(authInfos); return this; } /** *

* The MQTT client ID. *

* * @return

* The MQTT client ID. *

*/ public String getClientId() { return clientId; } /** *

* The MQTT client ID. *

* * @param clientId

* The MQTT client ID. *

*/ public void setClientId(String clientId) { this.clientId = clientId; } /** *

* The MQTT client ID. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param clientId

* The MQTT client ID. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withClientId(String clientId) { this.clientId = clientId; return this; } /** *

* When testing custom authorization, the policies specified here are * treated as if they are attached to the principal being authorized. *

* * @return

* When testing custom authorization, the policies specified here * are treated as if they are attached to the principal being * authorized. *

*/ public java.util.List getPolicyNamesToAdd() { return policyNamesToAdd; } /** *

* When testing custom authorization, the policies specified here are * treated as if they are attached to the principal being authorized. *

* * @param policyNamesToAdd

* When testing custom authorization, the policies specified here * are treated as if they are attached to the principal being * authorized. *

*/ public void setPolicyNamesToAdd(java.util.Collection policyNamesToAdd) { if (policyNamesToAdd == null) { this.policyNamesToAdd = null; return; } this.policyNamesToAdd = new java.util.ArrayList(policyNamesToAdd); } /** *

* When testing custom authorization, the policies specified here are * treated as if they are attached to the principal being authorized. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param policyNamesToAdd

* When testing custom authorization, the policies specified here * are treated as if they are attached to the principal being * authorized. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withPolicyNamesToAdd(String... policyNamesToAdd) { if (getPolicyNamesToAdd() == null) { this.policyNamesToAdd = new java.util.ArrayList(policyNamesToAdd.length); } for (String value : policyNamesToAdd) { this.policyNamesToAdd.add(value); } return this; } /** *

* When testing custom authorization, the policies specified here are * treated as if they are attached to the principal being authorized. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param policyNamesToAdd

* When testing custom authorization, the policies specified here * are treated as if they are attached to the principal being * authorized. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withPolicyNamesToAdd( java.util.Collection policyNamesToAdd) { setPolicyNamesToAdd(policyNamesToAdd); return this; } /** *

* When testing custom authorization, the policies specified here are * treated as if they are not attached to the principal being authorized. *

* * @return

* When testing custom authorization, the policies specified here * are treated as if they are not attached to the principal being * authorized. *

*/ public java.util.List getPolicyNamesToSkip() { return policyNamesToSkip; } /** *

* When testing custom authorization, the policies specified here are * treated as if they are not attached to the principal being authorized. *

* * @param policyNamesToSkip

* When testing custom authorization, the policies specified here * are treated as if they are not attached to the principal being * authorized. *

*/ public void setPolicyNamesToSkip(java.util.Collection policyNamesToSkip) { if (policyNamesToSkip == null) { this.policyNamesToSkip = null; return; } this.policyNamesToSkip = new java.util.ArrayList(policyNamesToSkip); } /** *

* When testing custom authorization, the policies specified here are * treated as if they are not attached to the principal being authorized. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param policyNamesToSkip

* When testing custom authorization, the policies specified here * are treated as if they are not attached to the principal being * authorized. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withPolicyNamesToSkip(String... policyNamesToSkip) { if (getPolicyNamesToSkip() == null) { this.policyNamesToSkip = new java.util.ArrayList(policyNamesToSkip.length); } for (String value : policyNamesToSkip) { this.policyNamesToSkip.add(value); } return this; } /** *

* When testing custom authorization, the policies specified here are * treated as if they are not attached to the principal being authorized. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param policyNamesToSkip

* When testing custom authorization, the policies specified here * are treated as if they are not attached to the principal being * authorized. *

* @return A reference to this updated object so that method calls can be * chained together. */ public TestAuthorizationRequest withPolicyNamesToSkip( java.util.Collection policyNamesToSkip) { setPolicyNamesToSkip(policyNamesToSkip); return this; } /** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getPrincipal() != null) sb.append("principal: " + getPrincipal() + ","); if (getCognitoIdentityPoolId() != null) sb.append("cognitoIdentityPoolId: " + getCognitoIdentityPoolId() + ","); if (getAuthInfos() != null) sb.append("authInfos: " + getAuthInfos() + ","); if (getClientId() != null) sb.append("clientId: " + getClientId() + ","); if (getPolicyNamesToAdd() != null) sb.append("policyNamesToAdd: " + getPolicyNamesToAdd() + ","); if (getPolicyNamesToSkip() != null) sb.append("policyNamesToSkip: " + getPolicyNamesToSkip()); sb.append("}"); return sb.toString(); } @Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getPrincipal() == null) ? 0 : getPrincipal().hashCode()); hashCode = prime * hashCode + ((getCognitoIdentityPoolId() == null) ? 0 : getCognitoIdentityPoolId().hashCode()); hashCode = prime * hashCode + ((getAuthInfos() == null) ? 0 : getAuthInfos().hashCode()); hashCode = prime * hashCode + ((getClientId() == null) ? 0 : getClientId().hashCode()); hashCode = prime * hashCode + ((getPolicyNamesToAdd() == null) ? 0 : getPolicyNamesToAdd().hashCode()); hashCode = prime * hashCode + ((getPolicyNamesToSkip() == null) ? 0 : getPolicyNamesToSkip().hashCode()); return hashCode; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof TestAuthorizationRequest == false) return false; TestAuthorizationRequest other = (TestAuthorizationRequest) obj; if (other.getPrincipal() == null ^ this.getPrincipal() == null) return false; if (other.getPrincipal() != null && other.getPrincipal().equals(this.getPrincipal()) == false) return false; if (other.getCognitoIdentityPoolId() == null ^ this.getCognitoIdentityPoolId() == null) return false; if (other.getCognitoIdentityPoolId() != null && other.getCognitoIdentityPoolId().equals(this.getCognitoIdentityPoolId()) == false) return false; if (other.getAuthInfos() == null ^ this.getAuthInfos() == null) return false; if (other.getAuthInfos() != null && other.getAuthInfos().equals(this.getAuthInfos()) == false) return false; if (other.getClientId() == null ^ this.getClientId() == null) return false; if (other.getClientId() != null && other.getClientId().equals(this.getClientId()) == false) return false; if (other.getPolicyNamesToAdd() == null ^ this.getPolicyNamesToAdd() == null) return false; if (other.getPolicyNamesToAdd() != null && other.getPolicyNamesToAdd().equals(this.getPolicyNamesToAdd()) == false) return false; if (other.getPolicyNamesToSkip() == null ^ this.getPolicyNamesToSkip() == null) return false; if (other.getPolicyNamesToSkip() != null && other.getPolicyNamesToSkip().equals(this.getPolicyNamesToSkip()) == false) return false; return true; } }