Package: yosai
![yosai_logo](/doc/docs/img/yosai_logo_with_title.png)# A Security Framework for Python Applications## Project web site:  http://yosaiproject.github.io/yosai# What is YosaiYosai is a "security framework" that features authentication, authorization, and sessionmanagement from a common, intuitive API.![authc_authz_sess](/doc/docs/img/authc_authz_sess.png)Yosai is based on Apache Shiro, written in Java and widely used today.# Yosai is a Framework![framework](/doc/docs/img/yosai_framework.png)It is a framework that is is designed in such a way that it can be used to securea variety of python applications, not just web applications.  This is accomplishedby completely decoupling security-related services from the rest of an applicationand writing adapters for each specific type of client.# Key Features- Enables Role-Based Access Control policies through permission-level and role-levelaccess control- Two-Factor Authentication, featuring Time-based One-Time Passwords- Native Support for Caching and Serialization- A Complete Audit Trail of Events- Batteries Included:  Extensions Ready for Use- "RunAs" Administration Tool- Event-driven Processing- Ready for Web Integration## Python 3 SupportedYosai requires Python 3.4 or newer. There are no plans to support python2due to anticipated optimizations that require newer versions of python.## InstallationFirst, install Yosai from PyPI using pip:``pip install yosai``Installing from PyPI, using pip, will install the project package that includes``yosai.core`` and ``yosai.web``, a default configuration, and project dependencies.## Basic Authentication:  UsernamePassword```Pythonyosai = Yosai(env_var='YOSAI_SETTINGS')with Yosai.context(yosai):current_user = Yosai.get_current_subject()authc_token = UsernamePasswordToken(username='thedude',credentials='letsgobowling')try:current_user.login(authc_token)except AuthenticationException:# insert here```## Two-Factor Authentication:  UsernamePassword and TOTP### 2FA Step 1:  UsernamePassword```Pythonyosai = Yosai(env_var='YOSAI_SETTINGS')with Yosai.context(yosai):current_user = Yosai.get_current_subject()userpass_token = UsernamePasswordToken(username='thedude',credentials='letsgobowling')try:current_user.login(userpass_token)except AdditionalAuthenticationRequired:# communicate a two-factor token request to userexcept IncorrectCredentialsException:# user failed to authenticate```### 2FA Step 2:  TOTP```Pythonyosai = Yosai(env_var='YOSAI_SETTINGS')with Yosai.context(yosai):current_user = Yosai.get_current_subject()totp_token = TOTPToken(user_provided_token)try:current_user.login(totp_token)except IncorrectCredentialsException:# user failed to authenticate```## Authorization ExampleThe following example was created to illustrate the myriad ways that youcan declare an authorization policy in an application, ranging from generalrole-level specification to very specific "scoped" permissions.  Theauthorization policy for this example is as follows:- Either a user with role membership "patient" or "nurse" may request arefill of a medical prescription- A user who is granted permission to write prescriptions may obtain thelist of pending prescription refill requests- A user who is granted permission to write prescriptions for a specificpatient may issue a prescription for that patient```Python@Yosai.requires_role(roleid_s=['patient', 'nurse'], logical_operator=any)def request_prescription_refill(patient, prescription):...@Yosai.requires_permission(['prescription:write'])def get_prescription_refill_requests(patient):...@Yosai.requires_dynamic_permission(['prescription:write:{patient.patient_id}'])def issue_prescription(patient, prescription):...```Note how the authorization policy is declared using yosai's authorizationdecorators.  These global decorators are associated with the yosai instancewhen the yosai instance is used as a context manager.```Pythonwith Yosai.context(yosai):issue_prescription(patient)for prescription in get_prescription_refill_requests(patient):issue_prescription(patient, prescription)```If you were using Yosai with a web application, the syntax would be similarto that above but requires that a ``WebRegistry`` instance be passed asas argument to the context manager.  The web integration library is furtherelaborated upon in the Web Integration section of this documentation.```Pythonwith WebYosai.context(yosai, web_registry):...```This is just a README file.  Please visit [the project web site](http://yosaiproject.github.io/yosai) to get a full overview.# WORD ORIGIN:  YosaiIn Japanese, the word Shiro translates to "Castle".  Yosai translates to "Fortress".Like the words, the frameworks are similar yet different.# Development StatusYosai v0.3 was released Nov 24, 2016.This release includes:1) General support for second factor authentication (2FA)2) A complete time-based one time password authentication solution (TOTP)3) Configurable rate limiting / account locking4) Significant refactoring / optimizatioPlease see the [release notes](https://yosaiproject.github.io/yosai/devstatus/)for details about that release.v0.3 test coverage stats (ao 11/24/2016):|Name                                         |Stmt |Miss|Cover ||:---------------------------------------------|:-----:|:----:|:------:|| yosai/core/account/account.py               | 5   | 1  | 80%  || yosai/core/authc/authc.py                   | 196 | 33 | 83%  || yosai/core/authc/authc_settings.py          | 19  | 2  | 89%  || yosai/core/authc/credential.py              | 51  | 5  | 90%  || yosai/core/authc/strategy.py                | 40  | 0  | 100% || yosai/core/authz/authz.py                   | 199 | 28 | 86%  || yosai/core/concurrency/concurrency.py       | 16  | 4  | 75%  || yosai/core/conf/yosaisettings.py            | 59  | 7  | 88%  || yosai/core/event/event.py                   | 28  | 0  | 100% || yosai/core/exceptions.py                    | 40  | 0  | 100% || yosai/core/logging/formatters.py            | 35  | 0  | 100% || yosai/core/logging/slogging.py              | 5   | 0  | 100% || yosai/core/mgt/mgt.py                       | 285 | 5  | 98%  || yosai/core/mgt/mgt_settings.py              | 37  | 2  | 95%  || yosai/core/realm/realm.py                   | 186 | 11 | 94%  || yosai/core/serialize/marshalling.py         | 14  | 8  | 43%  || yosai/core/serialize/serialize.py           | 24  | 0  | 100% || yosai/core/serialize/serializers/cbor.py    | 53  | 3  | 94%  || yosai/core/serialize/serializers/json.py    | 56  | 41 | 27%  || yosai/core/serialize/serializers/msgpack.py | 49  | 29 | 41%  || yosai/core/session/session.py               | 547 | 63 | 88%  || yosai/core/session/session_settings.py      | 13  | 1  | 92%  || yosai/core/subject/identifier.py            | 60  | 3  | 95%  || yosai/core/subject/subject.py               | 451 | 22 | 95%  || yosai/core/utils/utils.py                   | 137 | 87 | 36%  || yosai/web/exceptions.py                     | 7   | 0  | 100% || yosai/web/mgt/mgt.py                        | 74  | 1  | 99%  || yosai/web/registry/registry_settings.py     | 5   | 0  | 100% || yosai/web/session/session.py                | 143 | 2  | 99%  || yosai/web/subject/subject.py                | 162 | 4  | 98%  ||---------------------------------------------|-----|----|------|# GROUP COMMUNICATIONGoogle Groups Mailing List:  https://groups.google.com/d/forum/yosai# CONTACT INFORMATIONDarin Gordon is the author of Yosai  http://www.daringordon.com# LICENSELicensed under the Apache License, Version 2.0 (the "License"); you may notuse any portion of Yosai except in compliance with the License.Contributors agree to license their work under the same License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0