Darin Gordon
PyGotham 2016
Based On
Security is a High Priority for my Projects
Looking For Support for RBAC policies
Friends don't let Friends Roll their Own
Evolved over more than 10 years of production use, but written in Java
Yosai began a port of Apache Shiro v2 alpha, but took on its own unique identity
Showcase Few of the Main Features
Use Yosai to Secure a Web Application
NOT a talk about web app development
(I will include the app with upcoming release)
2. Yosai hooks into the request/response workflow
Details will be provided with upcoming release!
- a much more simplified version
Physicians, Nurse Practitioners, Patients
User logs into the application
Role-based nav elements get rendered
User navigates, performs activities constrained by authorization policy
Verifying that a user is
who it claims to be
current_user = Yosai.get_current_subject()
authc_token = UsernamePasswordToken(username='patient123',
credentials='pygotham')
try:
current_user.login(authc_token)
except AuthenticationException:
...
@view_config(route_name='login', renderer='../templates/login.jinja2')
def login(request):
login_form = LoginForm(request.POST, context={'request': request})
if request.method == "POST" and login_form.validate():
authc_token = UsernamePasswordToken(username=login_form.username.data,
password=login_form.password.data)
try:
subject = Yosai.get_current_subject()
subject.login(authc_token)
next_url = request.route_url('launchpad')
return HTTPFound(location=next_url)
except AuthenticationException:
request.session.flash('Invalid Login Credentials.')
return {'login_form': login_form}
else:
return {'login_form': login_form}
Rules and mechanisms govening who can do what
"Do This to That"
(Group of Permissions)
Yosai uses Permissions, which are derived from an RBAC data model
Customized RBAC data models can be very powerful!
Core RBAC
Hierarchical RBAC
(Medical Prescription Workflow)
(Prescription Writing)
A user may write a prescription for any medicine if the user is a physician
1) Membership of the physician role
2) write-prescription permission assigned to physician role
A user may write a prescription only for a particular medicine if the user is a nurse practitioner
1) Membership of the nurse_practitioner role
2) write-prescription-medicineid permission assigned to nurse_practitioner role
Prescription Writing Authorization
@requires_permission(['prescription:write'])
@view_config(route_name='write_rx', renderer='../templates/write_rx.jinja2')
def write_rx(request):
write_rx_form = WriteRXForm(request.POST, context={'request': request})
if request.method == "POST" and write_rx_form.validate():
current_user = Yosai.get_current_subject()
create_rx(current_user, . . . )
next_url = request.route_url('write_rx')
return HTTPFound(location=next_url)
else:
return {'write_rx_form': write_rx_form}
@requires_dynamic_permission(['prescription:write:{medicine}'])
@view_config(route_name='write_rx', renderer='../templates/write_rx.jinja2')
def write_rx(request):
write_rx_form = WriteRXForm(request.POST, context={'request': request})
if request.method == "POST" and write_rx_form.validate():
current_user = Yosai.get_current_subject()
create_rx(current_user, . . . )
next_url = request.route_url('write_rx')
return HTTPFound(location=next_url)
else:
return {'write_rx_form': write_rx_form}Prescription Writing Authorization
@view_config(route_name='write_rx', renderer='../templates/write_rx.jinja2')
def write_rx(request):
write_rx_form = WriteRXForm(request.POST, context={'request': request})
if request.method == "POST" and write_rx_form.validate():
current_user = Yosai.get_current_subject()
medicine = request.matchdict['medicine']
permission = 'prescription:write:' + medicine
try:
current_subject.check_permission([permission])
except AuthorizationException:
print('Not Permitted')
else:
create_rx(current_user, . . . )
. . . . Prescription Writing Authorization
(but the approach remains the same)
First Milestone: release v0.1 end of March 2016
Next Milestone: release v0.2 (ETA Sept 2016)