mirror of
https://github.com/vmware/vsphere-automation-sdk-python.git
synced 2024-11-30 04:10:00 -05:00
161 lines
9.8 KiB
HTML
161 lines
9.8 KiB
HTML
|
|
||
|
|
||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
|
||
|
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
|
||
|
<title>vmware.vapi.security.session — vSphere Automation SDK for Python 6.5.0 documentation</title>
|
||
|
|
||
|
<link rel="stylesheet" href="../../../../_static/vapitheme.css" type="text/css" />
|
||
|
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
|
||
|
|
||
|
<script type="text/javascript">
|
||
|
var DOCUMENTATION_OPTIONS = {
|
||
|
URL_ROOT: '../../../../',
|
||
|
VERSION: '6.5.0',
|
||
|
COLLAPSE_INDEX: false,
|
||
|
FILE_SUFFIX: '.html',
|
||
|
HAS_SOURCE: true
|
||
|
};
|
||
|
</script>
|
||
|
<script type="text/javascript" src="../../../../_static/jquery.js"></script>
|
||
|
<script type="text/javascript" src="../../../../_static/underscore.js"></script>
|
||
|
<script type="text/javascript" src="../../../../_static/doctools.js"></script>
|
||
|
<link rel="top" title="vSphere Automation SDK for Python 6.5.0 documentation" href="../../../../index.html" />
|
||
|
<link rel="up" title="Module code" href="../../../index.html" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="related">
|
||
|
<h3>Navigation</h3>
|
||
|
<ul>
|
||
|
<li class="right" style="margin-right: 10px">
|
||
|
<a href="../../../../genindex.html" title="General Index"
|
||
|
accesskey="I">index</a></li>
|
||
|
<li class="right" >
|
||
|
<a href="../../../../py-modindex.html" title="Python Module Index"
|
||
|
>modules</a> |</li>
|
||
|
<li><a href="../../../../index.html">vSphere Automation SDK for Python 6.5.0 documentation</a> »</li>
|
||
|
<li><a href="../../../index.html" accesskey="U">Module code</a> »</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
<div class="document">
|
||
|
<div class="documentwrapper">
|
||
|
<div class="bodywrapper">
|
||
|
<div class="body">
|
||
|
|
||
|
<h1>Source code for vmware.vapi.security.session</h1><div class="highlight"><pre>
|
||
|
<span class="sd">"""</span>
|
||
|
<span class="sd">Session Security Helper</span>
|
||
|
<span class="sd">"""</span>
|
||
|
|
||
|
<span class="n">__author__</span> <span class="o">=</span> <span class="s">'VMware, Inc.'</span>
|
||
|
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">'Copyright (c) 2015 VMware, Inc. All rights reserved.'</span>
|
||
|
|
||
|
<span class="kn">from</span> <span class="nn">vmware.vapi.core</span> <span class="kn">import</span> <span class="n">SecurityContext</span>
|
||
|
<span class="kn">from</span> <span class="nn">vmware.vapi.lib.constants</span> <span class="kn">import</span> <span class="n">SCHEME_ID</span>
|
||
|
<span class="kn">from</span> <span class="nn">vmware.vapi.security.rest</span> <span class="kn">import</span> <span class="n">SecurityContextParser</span>
|
||
|
|
||
|
<span class="n">SESSION_SCHEME_ID</span> <span class="o">=</span> <span class="s">'com.vmware.vapi.std.security.session_id'</span>
|
||
|
<span class="n">SESSION_ID</span> <span class="o">=</span> <span class="s">'sessionId'</span>
|
||
|
<span class="c"># String used to identify session identifier in REST API HTTP headers</span>
|
||
|
<span class="n">REST_SESSION_ID_KEY</span> <span class="o">=</span> <span class="s">'vmware-api-session-id'</span>
|
||
|
|
||
|
|
||
|
<div class="viewcode-block" id="create_session_security_context"><a class="viewcode-back" href="../../../../vmware.vapi.security.html#vmware.vapi.security.session.create_session_security_context">[docs]</a><span class="k">def</span> <span class="nf">create_session_security_context</span><span class="p">(</span><span class="n">session_id</span><span class="p">):</span>
|
||
|
<span class="sd">"""</span>
|
||
|
<span class="sd"> Create a security context for Session Id based authentication</span>
|
||
|
<span class="sd"> scheme</span>
|
||
|
|
||
|
<span class="sd"> :type session_id: :class:`str`</span>
|
||
|
<span class="sd"> :param session_id: Session ID</span>
|
||
|
<span class="sd"> :rtype: :class:`vmware.vapi.core.SecurityContext`</span>
|
||
|
<span class="sd"> :return: Newly created security context</span>
|
||
|
<span class="sd"> """</span>
|
||
|
<span class="k">return</span> <span class="n">SecurityContext</span><span class="p">({</span><span class="n">SCHEME_ID</span><span class="p">:</span> <span class="n">SESSION_SCHEME_ID</span><span class="p">,</span>
|
||
|
<span class="n">SESSION_ID</span><span class="p">:</span> <span class="n">session_id</span><span class="p">})</span>
|
||
|
|
||
|
</div>
|
||
|
<div class="viewcode-block" id="SessionSecurityContextParser"><a class="viewcode-back" href="../../../../vmware.vapi.security.html#vmware.vapi.security.session.SessionSecurityContextParser">[docs]</a><span class="k">class</span> <span class="nc">SessionSecurityContextParser</span><span class="p">(</span><span class="n">SecurityContextParser</span><span class="p">):</span>
|
||
|
<span class="sd">"""</span>
|
||
|
<span class="sd"> Security context parser used by the REST presentation layer</span>
|
||
|
<span class="sd"> that builds a security context if the REST request has session</span>
|
||
|
<span class="sd"> identifier either in the header or in the cookie.</span>
|
||
|
<span class="sd"> """</span>
|
||
|
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
|
<span class="sd">"""</span>
|
||
|
<span class="sd"> Initialize SessionSecurityContextParser</span>
|
||
|
<span class="sd"> """</span>
|
||
|
<span class="n">SecurityContextParser</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
|
||
|
|
||
|
<div class="viewcode-block" id="SessionSecurityContextParser.build"><a class="viewcode-back" href="../../../../vmware.vapi.security.html#vmware.vapi.security.session.SessionSecurityContextParser.build">[docs]</a> <span class="k">def</span> <span class="nf">build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
|
||
|
<span class="sd">"""</span>
|
||
|
<span class="sd"> Build the security context if the request has the header</span>
|
||
|
<span class="sd"> that contains the session identifier or a cookie that has</span>
|
||
|
<span class="sd"> the session identifier.</span>
|
||
|
|
||
|
<span class="sd"> The method will first check for session identifier in the cookie,</span>
|
||
|
<span class="sd"> if it is not present, then it will check in the HTTP headers.</span>
|
||
|
<span class="sd"> The session security context is created based on the first session</span>
|
||
|
<span class="sd"> identifier it finds.</span>
|
||
|
|
||
|
<span class="sd"> :type request: :class:`werkzeug.wrappers.Request`</span>
|
||
|
<span class="sd"> :param request: Request object</span>
|
||
|
<span class="sd"> :rtype: :class:`vmware.vapi.core.SecurityContext` or ``None``</span>
|
||
|
<span class="sd"> :return: Security context object</span>
|
||
|
<span class="sd"> """</span>
|
||
|
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">cookies</span><span class="p">:</span>
|
||
|
<span class="n">session_id</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">cookies</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">REST_SESSION_ID_KEY</span><span class="p">)</span>
|
||
|
<span class="k">if</span> <span class="n">session_id</span><span class="p">:</span>
|
||
|
<span class="k">return</span> <span class="n">create_session_security_context</span><span class="p">(</span><span class="n">session_id</span><span class="p">)</span>
|
||
|
<span class="k">else</span><span class="p">:</span>
|
||
|
<span class="n">session_id</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">REST_SESSION_ID_KEY</span><span class="p">)</span>
|
||
|
<span class="k">if</span> <span class="n">session_id</span><span class="p">:</span>
|
||
|
<span class="k">return</span> <span class="n">create_session_security_context</span><span class="p">(</span><span class="n">session_id</span><span class="p">)</span></div></div>
|
||
|
</pre></div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="sphinxsidebar">
|
||
|
<div class="sphinxsidebarwrapper">
|
||
|
<div id="searchbox" style="display: none">
|
||
|
<h3>Quick search</h3>
|
||
|
<form class="search" action="../../../../search.html" method="get">
|
||
|
<input type="text" name="q" />
|
||
|
<input type="submit" value="Go" />
|
||
|
<input type="hidden" name="check_keywords" value="yes" />
|
||
|
<input type="hidden" name="area" value="default" />
|
||
|
</form>
|
||
|
<p class="searchtip" style="font-size: 90%">
|
||
|
Enter search terms or a module, class or function name.
|
||
|
</p>
|
||
|
</div>
|
||
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="clearer"></div>
|
||
|
</div>
|
||
|
<div class="related">
|
||
|
<h3>Navigation</h3>
|
||
|
<ul>
|
||
|
<li class="right" style="margin-right: 10px">
|
||
|
<a href="../../../../genindex.html" title="General Index"
|
||
|
>index</a></li>
|
||
|
<li class="right" >
|
||
|
<a href="../../../../py-modindex.html" title="Python Module Index"
|
||
|
>modules</a> |</li>
|
||
|
<li><a href="../../../../index.html">vSphere Automation SDK for Python 6.5.0 documentation</a> »</li>
|
||
|
<li><a href="../../../index.html" >Module code</a> »</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="footer">
|
||
|
© Copyright 2014, VMware, Inc..
|
||
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|