我一直在寻找一种方式,通过用户和密码在网上浏览用户。
curl --user user1:pass1 http://localhost:6543/the_resource
设想是检查是否通过全权证书,使用户能够看到* ——资源* ,如果不能返回 401 - 隐蔽。
I ve 仅举出认证政策的实例,其中必须有一个标志和记录观点,或。 我不知道如何与《科索沃宪法》挂钩。
我将赞赏任何帮助,如何开始。
我也想到了一点。 如何将这一顶级标识窗口用于基本认证?
我一直在寻找一种方式,通过用户和密码在网上浏览用户。
curl --user user1:pass1 http://localhost:6543/the_resource
设想是检查是否通过全权证书,使用户能够看到* ——资源* ,如果不能返回 401 - 隐蔽。
I ve 仅举出认证政策的实例,其中必须有一个标志和记录观点,或。 我不知道如何与《科索沃宪法》挂钩。
我将赞赏任何帮助,如何开始。
我也想到了一点。 如何将这一顶级标识窗口用于基本认证?
最终,如何使用认证和授权变得十分清楚。 实际上,我只字不提这一概念。 我试图写一下,我是如何去做解释的,我不得不向我解释。 我希望这将对某人有用。 最终来源可能有助于了解我的著作...... 欢迎所有意见。 如果我错了,请更正我。
最重要的是basiccreditation,其中基础知识政策必须具备可在金字塔德应用中日后使用的方法,如认证的_userid(request)。 这些方法使用__get_basicauth_credentials() ,其中删除了标识和密码,这些密码在网上通过。 实际检查日志和密码是否正确,则在我的核对中进行。
现在,在__init__.py,我们必须增加基本知识政策,把方法神秘化作为我们应用工具的理由,以便金字塔能够使用。
在认证问题上,都是如此。 现在,如果和谁使用认证的“使用(要求)”来认证,就应当能够(见观点)。
用金字塔核准资源,我们需要在资源中增加ACLAuthorizationPolicy加入我们的主编——init__.py,并增加__acl__。 根基(见this和
授权的最后一步是允许某些观点使用矫正器(或添加_route)。 如果我们加入《欧洲刑法》允许的话——以观点看待——然后一页: 观众可以看到该页(供人浏览的网页)。 basic_authentication.py 我的项目__init__.py 模式。 y 意见。 yimport binascii
from zope.interface import implements
from paste.httpheaders import AUTHORIZATION
from paste.httpheaders import WWW_AUTHENTICATE
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.security import Everyone
from pyramid.security import Authenticated
import yaml
def mycheck(credentials, request):
login = credentials[ login ]
password = credentials[ password ]
USERS = { user1 : pass1 ,
user2 : pass2 }
GROUPS = { user1 :[ group:viewers ],
user2 :[ group:editors ]}
if login in USERS and USERS[login] == password:
return GROUPS.get(login, [])
else:
return None
def _get_basicauth_credentials(request):
authorization = AUTHORIZATION(request.environ)
try:
authmeth, auth = authorization.split( , 1)
except ValueError: # not enough values to unpack
return None
if authmeth.lower() == basic :
try:
auth = auth.strip().decode( base64 )
except binascii.Error: # can t decode
return None
try:
login, password = auth.split( : , 1)
except ValueError: # not enough values to unpack
return None
return { login :login, password :password}
return None
class BasicAuthenticationPolicy(object):
""" A :app:`Pyramid` :term:`authentication policy` which
obtains data from basic authentication headers.
Constructor Arguments
``check``
A callback passed the credentials and the request,
expected to return None if the userid doesn t exist or a sequence
of group identifiers (possibly empty) if the user does exist.
Required.
``realm``
Default: ``Realm``. The Basic Auth realm string.
"""
implements(IAuthenticationPolicy)
def __init__(self, check, realm= Realm ):
self.check = check
self.realm = realm
def authenticated_userid(self, request):
credentials = _get_basicauth_credentials(request)
if credentials is None:
return None
userid = credentials[ login ]
if self.check(credentials, request) is not None: # is not None!
return userid
def effective_principals(self, request):
effective_principals = [Everyone]
credentials = _get_basicauth_credentials(request)
if credentials is None:
return effective_principals
userid = credentials[ login ]
groups = self.check(credentials, request)
if groups is None: # is None!
return effective_principals
effective_principals.append(Authenticated)
effective_principals.append(userid)
effective_principals.extend(groups)
return effective_principals
def unauthenticated_userid(self, request):
creds = self._get_credentials(request)
if creds is not None:
return creds[ login ]
return None
def remember(self, request, principal, **kw):
return []
def forget(self, request):
head = WWW_AUTHENTICATE.tuples( Basic realm="%s" % self.realm)
return head
from pyramid.config import Configurator
from myproject.resources import Root
from myproject.basic_authentication import BasicAuthenticationPolicy, mycheck
from pyramid.authorization import ACLAuthorizationPolicy
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory= myproject.models.RootFactory ,
settings=settings,
authentication_policy=BasicAuthenticationPolicy(mycheck),
authorization_policy=ACLAuthorizationPolicy(),
)
config.add_static_view( static , myproject:static , cache_max_age=3600)
config.add_route( view_page , /view )
config.add_route( edit_page , /edit )
config.scan()
app = config.make_wsgi_app()
return app
from pyramid.security import Allow
class RootFactory(object):
__acl__ = [ (Allow, group:viewers , view ),
(Allow, group:editors , edit ) ]
def __init__(self, request):
pass
from pyramid.security import authenticated_userid
from pyramid.view import view_config
#def my_view(request):
# return render_to_response( templates/simple.pt , {})
@view_config(route_name= view_page , renderer= templates/view.pt , permission= view )
def view_page(request):
return {}
@view_config(route_name= edit_page , renderer= templates/edit.pt , permission= edit )
def edit_page(request):
return {}
你们要求的是基本条件。 你与你想要使用的reci子有关。 这处理识别用户和计算其本金。 校长们被阿盟系统使用,并得到了意见中规定的许可,以确定允许/拒绝准入。
我认为,这一陷阱正在形成如何处理不让用户获得资源的问题,而该表并未列举这一点。 你们可以这样做,提供一种习俗,“隐蔽观点”,在《古兰经》中被援引,但这种观点拒绝接触。 当时,“基本”指出,你向客户提出了挑战。
@forbidden_view_config()
def forbidden_view(request):
resp = HTTPUnauthorized()
resp.www_authenticate = Basic realm="Secure Area"
return resp
That s untested, but gives you the general idea of how to use a forbidden view. This will challenge the client, and then they are free to make another request (hopefully with credentials) that gets turned into principals that are mapped to the permissions you care about.
Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...
I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...
Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...
Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...
Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...
I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...