Changeset 6617 for TI12-security/trunk/NDGSecurity
- Timestamp:
- 24/02/10 09:40:47 (11 years ago)
- Location:
- TI12-security/trunk/NDGSecurity/python
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDGSecurity/python/ndg_security_server/ndg/security/server/wsgi/authzservice.py
r6615 r6617 339 339 request.resource[Resource.URI_NS] = authzDecisionQuery.resource 340 340 341 # TODO: incorporate action(s) requested into PDP request 342 341 343 # Call the PDP 342 344 pdpResponse = self.pdp.evaluate(request) 343 345 344 346 # Create the SAML Response 345 response = Response() 346 347 now = datetime.utcnow() 348 response.issueInstant = now 349 350 # Make up a request ID that this response is responding to 351 response.inResponseTo = authzDecisionQuery.id 352 response.id = str(uuid4()) 353 response.version = SAMLVersion(SAMLVersion.VERSION_20) 354 355 response.issuer = Issuer() 356 response.issuer.format = self.issuerFormat 357 response.issuer.value = self.issuerName 358 359 response.status = Status() 360 response.status.statusCode = StatusCode() 361 response.status.statusMessage = StatusMessage() 362 363 response.status.statusCode.value = StatusCode.SUCCESS_URI 364 response.status.statusMessage.value = ("Response created " 365 "successfully") 366 367 assertion = Assertion() 368 response.assertions.append(assertion) 369 370 assertion.version = SAMLVersion(SAMLVersion.VERSION_20) 371 assertion.id = str(uuid4()) 372 assertion.issueInstant = now 373 374 # Add a conditions statement for a validity of 8 hours 375 assertion.conditions = Conditions() 376 assertion.conditions.notBefore = now 377 assertion.conditions.notOnOrAfter = now + timedelta( 378 seconds=self.assertionLifetime) 379 380 assertion.subject = Subject() 381 assertion.subject.nameID = NameID() 382 assertion.subject.nameID.format = \ 383 authzDecisionQuery.subject.nameID.format 384 assertion.subject.nameID.value = \ 385 authzDecisionQuery.subject.nameID.value 386 387 assertion.issuer = Issuer() 388 assertion.issuer.format = self.issuerFormat 389 assertion.issuer.value = self.issuerName 390 391 authzDecisionStatement = AuthzDecisionStatement() 392 assertion.authzDecisionStatements.append(authzDecisionStatement) 393 394 authzDecisionStatement.resource = authzDecisionQuery.resource 395 authzDecisionStatement.actions.append(Action()) 396 authzDecisionStatement.actions[-1].namespace = Action.GHPP_NS_URI 397 authzDecisionStatement.actions[-1].value = Action.HTTP_GET_ACTION 398 347 response = self._createSAMLResponse(authzDecisionQuery) 348 authzDecisionStatement = response.assertions[0 349 ].authzDecisionStatements[0] 350 399 351 if pdpResponse.status == PDPResponse.DECISION_PERMIT: 400 352 log.info("AuthzServiceMiddleware.__call__: PDP granted " … … 429 381 return getAuthzDecision 430 382 383 def _createSAMLResponse(self, authzDecisionQuery): 384 """Helper method to create a SAML Authorisation Decision Response. The 385 resource and actions referred to in the query are set in the 386 Authorization Decision Statement, no decision is set 387 388 @param authzDecisionQuery: SAML authorsation decision query 389 @type authzDecisionQuery: ndg.saml.saml2.core.AuthzDecisionQuery 390 @return: SAML Authorisation Decision Response 391 @rtype: ndg.saml.saml2.core.Response 392 """ 393 response = Response() 394 395 now = datetime.utcnow() 396 response.issueInstant = now 397 398 # Make up a request ID that this response is responding to 399 response.inResponseTo = authzDecisionQuery.id 400 response.id = str(uuid4()) 401 response.version = SAMLVersion(SAMLVersion.VERSION_20) 402 403 response.issuer = Issuer() 404 response.issuer.format = self.issuerFormat 405 response.issuer.value = self.issuerName 406 407 response.status = Status() 408 response.status.statusCode = StatusCode() 409 response.status.statusMessage = StatusMessage() 410 411 response.status.statusCode.value = StatusCode.SUCCESS_URI 412 response.status.statusMessage.value = ("Response created " 413 "successfully") 414 415 assertion = Assertion() 416 response.assertions.append(assertion) 417 418 assertion.version = SAMLVersion(SAMLVersion.VERSION_20) 419 assertion.id = str(uuid4()) 420 assertion.issueInstant = now 421 422 # Add a conditions statement for a validity of 8 hours 423 assertion.conditions = Conditions() 424 assertion.conditions.notBefore = now 425 assertion.conditions.notOnOrAfter = now + timedelta( 426 seconds=self.assertionLifetime) 427 428 assertion.subject = Subject() 429 assertion.subject.nameID = NameID() 430 assertion.subject.nameID.format = \ 431 authzDecisionQuery.subject.nameID.format 432 assertion.subject.nameID.value = \ 433 authzDecisionQuery.subject.nameID.value 434 435 assertion.issuer = Issuer() 436 assertion.issuer.format = self.issuerFormat 437 assertion.issuer.value = self.issuerName 438 439 authzDecisionStatement = AuthzDecisionStatement() 440 assertion.authzDecisionStatements.append(authzDecisionStatement) 441 442 authzDecisionStatement.resource = authzDecisionQuery.resource 443 444 for action in authzDecisionQuery.actions: 445 authzDecisionStatement.actions.append(Action()) 446 authzDecisionStatement.actions[-1].namespace = action.namespace 447 authzDecisionStatement.actions[-1].value = action.value 448 449 return response -
TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/wsgi/__init__.py
r6069 r6617 40 40 ssl_context=ssl_context) 41 41 42 def _getPasteServer(self): 42 @property 43 def pasteServer(self): 43 44 return self.__pasteServer 44 45 45 pasteServer = property(fget=_getPasteServer) 46 47 def _getThread(self): 46 @property 47 def thread(self): 48 48 return self.__thread 49 50 thread = property(fget=_getThread)51 49 52 50 def start(self): -
TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/wsgi/saml/authz-service.ini
r6615 r6617 47 47 # Attribute Authorities 48 48 authz.pip.attributeQuery.subjectIdFormat = urn:esg:openid 49 authz.pip.attributeQuery.verifyTimeConditions = True 49 authz.pip.attributeQuery.queryAttributes.0 = urn:siteA:security:authz:1.0:attr, , http://www.w3.org/2001/XMLSchema#string 50 authz.pip.attributeQuery.sslCACertDir=%(testConfigDir)s/ca 51 authz.pip.attributeQuery.sslCertFilePath=%(testConfigDir)s/pki/test.crt 52 authz.pip.attributeQuery.sslPriKeyFilePath=%(testConfigDir)s/pki/test.key -
TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/wsgi/saml/policy-1.1.xml
r6615 r6617 4 4 5 5 <Target> 6 <URIPattern> http://localhost/dap/data/.*</URIPattern>6 <URIPattern>^http://localhost/dap/data/.*</URIPattern> 7 7 <Attributes> 8 8 <Attribute> 9 9 <Name>urn:siteA:security:authz:1.0:attr:staff</Name> 10 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority </AttributeAuthorityURI>10 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority/saml</AttributeAuthorityURI> 11 11 </Attribute> 12 12 </Attributes> 13 13 </Target> 14 14 <Target> 15 <URIPattern>^ /test_accessDeniedToSecuredURI$</URIPattern>15 <URIPattern>^http://localhost/dap/data/test_accessDeniedToSecuredURI$</URIPattern> 16 16 <Attributes> 17 17 <Attribute> 18 18 <Name>urn:siteA:security:authz:1.0:attr:forbidden</Name> 19 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority </AttributeAuthorityURI>19 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority/saml</AttributeAuthorityURI> 20 20 </Attribute> 21 21 <Attribute> 22 22 <Name>urn:siteA:security:authz:1.0:attr:keepout</Name> 23 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority </AttributeAuthorityURI>23 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority/saml</AttributeAuthorityURI> 24 24 </Attribute> 25 25 </Attributes> … … 31 31 <Attribute> 32 32 <Name>urn:siteA:security:authz:1.0:attr:staff</Name> 33 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority </AttributeAuthorityURI>33 <AttributeAuthorityURI>https://localhost:5443/AttributeAuthority/saml</AttributeAuthorityURI> 34 34 </Attribute> 35 35 </Attributes> -
TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/wsgi/saml/test_soapauthzdecisioninterface.py
r6615 r6617 198 198 CONFIG_FILENAME = 'authz-service.ini' 199 199 RESOURCE_URI = 'http://localhost/dap/data/my.nc.dods?time[0:1:0]' 200 ACCESS_DENIED_RESOURCE_URI = 'http://localhost/dap/data/test_accessDeniedToSecuredURI' 200 201 201 202 def __init__(self, *arg, **kw): … … 205 206 *arg, **kw) 206 207 self.startSiteAAttributeAuthority(withSSL=True, port=5443) 208 209 def test02AccessDenied(self): 210 cls = SOAPAuthzServiceMiddlewareTestCase 211 query = self._createAuthzDecisionQuery( 212 resource=cls.ACCESS_DENIED_RESOURCE_URI) 213 request = self._makeRequest(query=query) 214 215 header = { 216 'soapAction': "http://www.oasis-open.org/committees/security", 217 'Content-length': str(len(request)), 218 'Content-type': 'text/xml' 219 } 220 response = self.app.post('/authorisationservice/', 221 params=request, 222 headers=header, 223 status=200) 224 print("Response status=%d" % response.status) 225 samlResponse = self._getSAMLResponse(response.body) 226 227 self.assert_(samlResponse.status.statusCode.value == \ 228 StatusCode.SUCCESS_URI) 229 self.assert_(samlResponse.inResponseTo == query.id) 230 self.assert_(samlResponse.assertions[0].subject.nameID.value == \ 231 query.subject.nameID.value) 232 self.assert_(samlResponse.assertions[0]) 233 self.assert_(samlResponse.assertions[0].authzDecisionStatements[0]) 234 self.assert_(samlResponse.assertions[0].authzDecisionStatements[0 235 ].decision == DecisionType.DENY) 207 236 208 237
Note: See TracChangeset
for help on using the changeset viewer.