43
43
from keystone import policy
44
44
from keystone import service
45
45
from keystone import token
46
+ from keystone .common import logging
46
47
from keystone .common import manager
47
48
from keystone .common import utils
48
49
from keystone .common import wsgi
49
50
50
51
51
52
CONF = config .CONF
53
+ LOG = logging .getLogger (__name__ )
52
54
53
55
54
56
class Manager (manager .Manager ):
@@ -112,9 +114,9 @@ def check_signature(self, creds_ref, credentials):
112
114
credentials ['host' ] = hostname
113
115
signature = signer .generate (credentials )
114
116
if not utils .auth_str_equal (credentials .signature , signature ):
115
- raise exception .Unauthorized (message = 'Invalid EC2 signature.' )
117
+ raise exception .Unauthorized ()
116
118
else :
117
- raise exception .Unauthorized (message = 'EC2 signature not supplied.' )
119
+ raise exception .Unauthorized ()
118
120
119
121
def authenticate (self , context , credentials = None ,
120
122
ec2Credentials = None ):
@@ -145,7 +147,7 @@ def authenticate(self, context, credentials=None,
145
147
credentials = ec2Credentials
146
148
147
149
if not 'access' in credentials :
148
- raise exception .Unauthorized (message = 'EC2 signature not supplied.' )
150
+ raise exception .Unauthorized ()
149
151
150
152
creds_ref = self ._get_credentials (context ,
151
153
credentials ['access' ])
@@ -157,9 +159,19 @@ def authenticate(self, context, credentials=None,
157
159
tenant_ref = self .identity_api .get_tenant (
158
160
context = context ,
159
161
tenant_id = creds_ref ['tenant_id' ])
162
+ # If the tenant is disabled don't allow them to authenticate
163
+ if tenant_ref and not tenant_ref .get ('enabled' , True ):
164
+ msg = 'Tenant %s is disabled' % tenant_ref ['id' ]
165
+ LOG .warning (msg )
166
+ raise exception .Unauthorized ()
160
167
user_ref = self .identity_api .get_user (
161
168
context = context ,
162
169
user_id = creds_ref ['user_id' ])
170
+ # If the user is disabled don't allow them to authenticate
171
+ if not user_ref .get ('enabled' , True ):
172
+ msg = 'User %s is disabled' % user_ref ['id' ]
173
+ LOG .warning (msg )
174
+ raise exception .Unauthorized ()
163
175
metadata_ref = self .identity_api .get_metadata (
164
176
context = context ,
165
177
user_id = user_ref ['id' ],
@@ -170,7 +182,7 @@ def authenticate(self, context, credentials=None,
170
182
# fill out the roles in the metadata
171
183
roles = metadata_ref .get ('roles' , [])
172
184
if not roles :
173
- raise exception .Unauthorized (message = 'User not valid for tenant.' )
185
+ raise exception .Unauthorized ()
174
186
roles_ref = [self .identity_api .get_role (context , role_id )
175
187
for role_id in roles ]
176
188
@@ -275,7 +287,7 @@ def _get_credentials(self, context, credential_id):
275
287
creds = self .ec2_api .get_credential (context ,
276
288
credential_id )
277
289
if not creds :
278
- raise exception .Unauthorized (message = 'EC2 access key not found.' )
290
+ raise exception .Unauthorized ()
279
291
return creds
280
292
281
293
def _assert_identity (self , context , user_id ):
0 commit comments