コード例 #1
0
 def _makeRequest(self, query=None, **kw):
     """Convenience method to construct queries for tests"""
     
     if query is None:
         query = self._createAuthzDecisionQuery(**kw)
         
     elem = AuthzDecisionQueryElementTree.toXML(query)
     soapRequest = SOAPEnvelope()
     soapRequest.create()
     soapRequest.body.elem.append(elem)
     
     request = soapRequest.serialize()
     
     return request
コード例 #2
0
    def _makeRequest(self, query=None, **kw):
        """Convenience method to construct queries for tests"""

        if query is None:
            query = self._createAuthzDecisionQuery(**kw)

        elem = AuthzDecisionQueryElementTree.toXML(query)
        soapRequest = SOAPEnvelope()
        soapRequest.create()
        soapRequest.body.elem.append(elem)

        request = soapRequest.serialize()

        return request
コード例 #3
0
    def __call__(self, environ, start_response):
        """Logs the request and response stored in the session.

        @type environ: dict
        @param environ: WSGI environment variables dictionary
        @type start_response: function
        @param start_response: standard WSGI start response function
        @rtype: iterable
        @return: response
        """
        session = environ.get('beaker.session.ndg.security')
        if session:
            pepCtx = session.get(SamlPepFilterBase.PEPCTX_SESSION_KEYNAME)
            if pepCtx:
                request = pepCtx.get(
                    SamlPepFilterBase.PEPCTX_REQUEST_SESSION_KEYNAME)
                if isinstance(request, AuthzDecisionQuery):
                    requestEtree = AuthzDecisionQueryElementTree.toXML(request)
                    log.debug("AuthzDecisionQuery:\n%s",
                              etree_utils.prettyPrint(requestEtree))
                elif isinstance(request, XACMLAuthzDecisionQuery):
                    requestEtree = XACMLAuthzDecisionQueryElementTree.toXML(
                        request)
                    log.debug("XACMLAuthzDecisionQuery:\n%s",
                              etree_utils.prettyPrint(requestEtree))
                else:
                    log.error(
                        "Request stored in session is of unknown type: %s" %
                        type(request))

                response = pepCtx.get(
                    SamlPepFilterBase.PEPCTX_RESPONSE_SESSION_KEYNAME)
                if isinstance(response, Response):
                    responseEtree = ResponseElementTree.toXML(response)
                    log.debug("Response:\n%s",
                              etree_utils.prettyPrint(responseEtree))
                else:
                    log.error(
                        "Response stored in session is of unknown type: %s" %
                        type(response))

                timestamp = pepCtx.get(
                    SamlPepFilterBase.PEPCTX_TIMESTAMP_SESSION_KEYNAME)
                log.debug("Timestamp: %s", timestamp)
            log.debug("No PEP context found in session.")
        return self._app(environ, start_response)
コード例 #4
0
ファイル: test_saml_core.py プロジェクト: cedadev/ndg_saml
 def test03_serialize_authz_decision_query(self):
     samlUtil = SAMLUtil()
     authzDecisionQuery = samlUtil.buildAuthzDecisionQuery()
     
     # Create ElementTree Assertion Element
     authzDecisionQueryElem = AuthzDecisionQueryElementTree.toXML(
                                                         authzDecisionQuery)
     
     self.assertTrue(ElementTree.iselement(authzDecisionQueryElem))
     
     # Serialise to output 
     xmlOutput = prettyPrint(authzDecisionQueryElem)       
     self.assertTrue(len(xmlOutput))
     
     print(("\n"+"_"*80))
     print(xmlOutput)
     print(("_"*80))
コード例 #5
0
    def __call__(self, environ, start_response):
        """Logs the request and response stored in the session.

        @type environ: dict
        @param environ: WSGI environment variables dictionary
        @type start_response: function
        @param start_response: standard WSGI start response function
        @rtype: iterable
        @return: response
        """
        session = environ.get('beaker.session.ndg.security')
        if session:
            pepCtx = session.get(SamlPepFilterBase.PEPCTX_SESSION_KEYNAME)
            if pepCtx:
                request = pepCtx.get(SamlPepFilterBase.PEPCTX_REQUEST_SESSION_KEYNAME)
                if isinstance(request, AuthzDecisionQuery):
                    requestEtree = AuthzDecisionQueryElementTree.toXML(request)
                    log.debug("AuthzDecisionQuery:\n%s",
                              etree_utils.prettyPrint(requestEtree))
                elif isinstance(request, XACMLAuthzDecisionQuery):
                    requestEtree = XACMLAuthzDecisionQueryElementTree.toXML(request)
                    log.debug("XACMLAuthzDecisionQuery:\n%s",
                              etree_utils.prettyPrint(requestEtree))
                else:
                    log.error("Request stored in session is of unknown type: %s"
                              % type(request))

                response = pepCtx.get(SamlPepFilterBase.PEPCTX_RESPONSE_SESSION_KEYNAME)
                if isinstance(response, Response):
                    responseEtree = ResponseElementTree.toXML(response)
                    log.debug("Response:\n%s",
                              etree_utils.prettyPrint(responseEtree))
                else:
                    log.error("Response stored in session is of unknown type: %s"
                              % type(response))

                timestamp = pepCtx.get(SamlPepFilterBase.PEPCTX_TIMESTAMP_SESSION_KEYNAME)
                log.debug("Timestamp: %s", timestamp)
            log.debug("No PEP context found in session.")
        return self._app(environ, start_response)
コード例 #6
0
ファイル: test_saml_core.py プロジェクト: cedadev/ndg_saml
    def test04_deserialize_authz_decision_query(self):
        samlUtil = SAMLUtil()
        authzDecisionQuery = samlUtil.buildAuthzDecisionQuery()
        
        # Create ElementTree Assertion Element
        authzDecisionQueryElem = AuthzDecisionQueryElementTree.toXML(
                                                            authzDecisionQuery)
        
        self.assertTrue(ElementTree.iselement(authzDecisionQueryElem))
        
        # Serialise to output 
        xmlOutput = prettyPrint(authzDecisionQueryElem)       
        self.assertTrue(len(xmlOutput))
        
        authzDecisionQueryStream = StringIO()
        authzDecisionQueryStream.write(xmlOutput)
        authzDecisionQueryStream.seek(0)

        tree = ElementTree.parse(authzDecisionQueryStream)
        elem2 = tree.getroot()
        
        authzDecisionQuery2 = AuthzDecisionQueryElementTree.fromXML(elem2)
        self.assertTrue(authzDecisionQuery2)
        self.assertTrue(
        authzDecisionQuery2.subject.nameID.value == SAMLUtil.NAMEID_VALUE)
        self.assertTrue(
        authzDecisionQuery2.subject.nameID.format == SAMLUtil.NAMEID_FORMAT)
        self.assertTrue(
            authzDecisionQuery2.issuer.value == SAMLUtil.ISSUER_DN)
        self.assertTrue(
            authzDecisionQuery2.resource == SAMLUtil.RESOURCE_URI)
        self.assertTrue(len(authzDecisionQuery2.actions) == 1)
        self.assertTrue(
            authzDecisionQuery2.actions[0].value == Action.HTTP_GET_ACTION)
        self.assertTrue(
            authzDecisionQuery2.actions[0].namespace == Action.GHPP_NS_URI)
        self.assertTrue(authzDecisionQuery2.evidence is None)