Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 * Copyright 2010-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License").
6
 * You may not use this file except in compliance with the License.
7
 * A copy of the License is located at
8
 *
9
 *  http://aws.amazon.com/apache2.0
10
 *
11
 * or in the "license" file accompanying this file. This file is distributed
12
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13
 * express or implied. See the License for the specific language governing
14
 * permissions and limitations under the License.
15
 */
16
 
17
/**
18
 * This is the <em>AWS Security Token Service API Reference</em>. The AWS Security Token Service
19
 * is a web service that enables you to request temporary, limited-privilege credentials for AWS
20
 * Identity and Access Management (IAM) users or for users that you authenticate (federated
21
 * users). This guide provides descriptions of the AWS Security Token Service API as well as links
22
 * to related content in <a href="http://docs.amazonwebservices.com/IAM/latest/UserGuide/" target=
23
 * "_blank">Using IAM</a>.
24
 *
25
 * For more detailed information about using this service, go to <a href=
26
 * "http://docs.amazonwebservices.com/IAM/latest/UserGuide/TokenBasedAuth.html" target=
27
 * "_blank">Granting Temporary Access to Your AWS Resources</a> in <em>Using IAM</em>.
28
 *
29
 * For specific information about setting up signatures and authorization through the API, go to
30
 * 	<a href="http://docs.amazonwebservices.com/IAM/latest/UserGuide/IAM_UsingQueryAPI.html" target=
31
 * "_blank">Making Query Requests</a> in <em>Using IAM</em>.
32
 *
33
 * If you're new to AWS and need additional technical information about a specific AWS product,
34
 * you can find the product'stechnical documentation at <a href=
35
 * "http://aws.amazon.com/documentation/" target=
36
 * "_blank">http://aws.amazon.com/documentation/</a>.
37
 *
38
 * We will refer to Amazon Identity and Access Management using the abbreviated form IAM. All
39
 * copyrights and legal protections still apply.
40
 *
41
 * @version 2012.01.16
42
 * @license See the included NOTICE.md file for complete information.
43
 * @copyright See the included NOTICE.md file for complete information.
44
 * @link http://aws.amazon.com/sts/ Amazon Secure Token Service
45
 * @link http://aws.amazon.com/sts/documentation/ Amazon Secure Token Service documentation
46
 */
47
class AmazonSTS extends CFRuntime
48
{
49
	/*%******************************************************************************************%*/
50
	// CLASS CONSTANTS
51
 
52
	/**
53
	 * Specify the queue URL for the United States East (Northern Virginia) Region.
54
	 */
55
	const REGION_US_E1 = 'sts.amazonaws.com';
56
 
57
	/**
58
	 * Specify the queue URL for the United States East (Northern Virginia) Region.
59
	 */
60
	const REGION_VIRGINIA = self::REGION_US_E1;
61
 
62
	/**
63
	 * Default service endpoint.
64
	 */
65
	const DEFAULT_URL = self::REGION_US_E1;
66
 
67
 
68
	/*%******************************************************************************************%*/
69
	// CONSTRUCTOR
70
 
71
	/**
72
	 * Constructs a new instance of <AmazonSTS>.
73
	 *
74
	 * @param array $options (Optional) An associative array of parameters that can have the following keys: <ul>
75
	 * 	<li><code>certificate_authority</code> - <code>boolean</code> - Optional - Determines which Cerificate Authority file to use. A value of boolean <code>false</code> will use the Certificate Authority file available on the system. A value of boolean <code>true</code> will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to <code>0755</code>) will use that. Leave this set to <code>false</code> if you're not sure.</li>
76
	 * 	<li><code>credentials</code> - <code>string</code> - Optional - The name of the credential set to use for authentication.</li>
77
	 * 	<li><code>default_cache_config</code> - <code>string</code> - Optional - This option allows a preferred storage type to be configured for long-term caching. This can be changed later using the <set_cache_config()> method. Valid values are: <code>apc</code>, <code>xcache</code>, or a file system path such as <code>./cache</code> or <code>/tmp/cache/</code>.</li>
78
	 * 	<li><code>key</code> - <code>string</code> - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.</li>
79
	 * 	<li><code>secret</code> - <code>string</code> - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.</li>
80
	 * 	<li><code>token</code> - <code>string</code> - Optional - An AWS session token.</li></ul>
81
	 * @return void
82
	 */
83
	public function __construct(array $options = array())
84
	{
85
		$this->api_version = '2011-06-15';
86
		$this->hostname = self::DEFAULT_URL;
87
		$this->auth_class = 'AuthV2Query';
88
 
89
		return parent::__construct($options);
90
	}
91
 
92
 
93
	/*%******************************************************************************************%*/
94
	// SETTERS
95
 
96
	/**
97
	 * This allows you to explicitly sets the region for the service to use.
98
	 *
99
	 * @param string $region (Required) The region to explicitly set. Available options are <REGION_US_E1>.
100
	 * @return $this A reference to the current instance.
101
	 */
102
	public function set_region($region)
103
	{
104
		// @codeCoverageIgnoreStart
105
		$this->set_hostname($region);
106
		return $this;
107
		// @codeCoverageIgnoreEnd
108
	}
109
 
110
 
111
	/*%******************************************************************************************%*/
112
	// SERVICE METHODS
113
 
114
	/**
115
	 * The GetFederationToken action returns a set of temporary credentials for a federated user with
116
	 * the user name and policy specified in the request. The credentials consist of an Access Key ID,
117
	 * a Secret Access Key, and a security token. The credentials are valid for the specified
118
	 * duration, between one and 36 hours.
119
	 *
120
	 * The federated user who holds these credentials has any permissions allowed by the intersection
121
	 * of the specified policy and any resource or user policies that apply to the caller of the
122
	 * GetFederationToken API, and any resource policies that apply to the federated user's Amazon
123
	 * Resource Name (ARN). For more information about how token permissions work, see <a href=
124
	 * "http://docs.amazonwebservices.com/IAM/latest/UserGuide/TokenPermissions.html" target=
125
	 * "_blank">Controlling Permissions in Temporary Credentials</a> in <em>Using AWS Identity and
126
	 * Access Management</em>. For information about using GetFederationToken to create temporary
127
	 * credentials, see <a href=
128
	 * "http://docs.amazonwebservices.com/IAM/latest/UserGuide/CreatingFedTokens.html" target=
129
	 * "_blank">Creating Temporary Credentials to Enable Access for Federated Users</a> in <em>Using
130
	 * AWS Identity and Access Management</em>.
131
	 *
132
	 * @param string $name (Required) The name of the federated user associated with the credentials. For information about limitations on user names, go to <a href="http://docs.amazonwebservices.com/IAM/latest/UserGuide/LimitationsOnEntities.html">Limitations on IAM Entities</a> in <em>Using AWS Identity and Access Management</em>. [Constraints: The value must be between 2 and 32 characters, and must match the following regular expression pattern: <code>[\w+=,.@-]*</code>]
133
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
134
	 * 	<li><code>Policy</code> - <code>string</code> - Optional - A policy specifying the permissions to associate with the credentials. The caller can delegate their own permissions by specifying a policy, and both policies will be checked when a service call is made. For more information about how permissions work in the context of temporary credentials, see <a href="http://docs.amazonwebservices.com/IAM/latest/UserGuide/TokenPermissions.html" target="_blank">Controlling Permissions in Temporary Credentials</a> in <em>Using AWS Identity and Access Management</em>. [Constraints: The value must be between 1 and 2048 characters, and must match the following regular expression pattern: <code>[\u0009\u000A\u000D\u0020-\u00FF]+</code>]</li>
135
	 * 	<li><code>DurationSeconds</code> - <code>integer</code> - Optional - The duration, in seconds, that the session should last. Acceptable durations for federation sessions range from 3600s (one hour) to 129600s (36 hours), with 43200s (12 hours) as the default.</li>
136
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
137
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
138
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
139
	 */
140
	public function get_federation_token($name, $opt = null)
141
	{
142
		if (!$opt) $opt = array();
143
		$opt['Name'] = $name;
144
 
145
		return $this->authenticate('GetFederationToken', $opt);
146
	}
147
 
148
	/**
149
	 * The GetSessionToken action returns a set of temporary credentials for an AWS account or IAM
150
	 * user. The credentials consist of an Access Key ID, a Secret Access Key, and a security token.
151
	 * These credentials are valid for the specified duration only. The session duration for IAM users
152
	 * can be between one and 36 hours, with a default of 12 hours. The session duration for AWS
153
	 * account owners is restricted to one hour.
154
	 *
155
	 * For more information about using GetSessionToken to create temporary credentials, go to
156
	 * 	<a href="http://docs.amazonwebservices.com/IAM/latest/UserGuide/CreatingSessionTokens.html"
157
	 * target="_blank">Creating Temporary Credentials to Enable Access for IAM Users</a> in <em>Using
158
	 * IAM</em>.
159
	 *
160
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
161
	 * 	<li><code>DurationSeconds</code> - <code>integer</code> - Optional - The duration, in seconds, that the credentials should remain valid. Acceptable durations for IAM user sessions range from 3600s (one hour) to 129600s (36 hours), with 43200s (12 hours) as the default. Sessions for AWS account owners are restricted to a maximum of 3600s (one hour).</li>
162
	 * 	<li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
163
	 * 	<li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
164
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
165
	 */
166
	public function get_session_token($opt = null)
167
	{
168
		if (!$opt) $opt = array();
169
 
170
		return $this->authenticate('GetSessionToken', $opt);
171
	}
172
}
173
 
174
 
175
/*%******************************************************************************************%*/
176
// EXCEPTIONS
177
 
178
class STS_Exception extends Exception {}