本文整理汇总了Python中twisted.cred.portal.Portal类的典型用法代码示例。如果您正苦于以下问题:Python Portal类的具体用法?Python Portal怎么用?Python Portal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Portal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.realm = Realm()
portal = Portal(self.realm)
portal.registerChecker(MockChecker())
self.authServer = userauth.SSHUserAuthServer()
self.authServer.transport = FakeTransport(portal)
self.authServer.serviceStarted()
示例2: deploy
def deploy(iface, port, dbLocation, dbType, dbUsername=None, dbPassword=None,
ssl=False, sslRedirect=False, sslPrivate=None, sslCert=None,
sslPort=None):
if dbUsername and dbPassword:
searchService = searchServices[dbType](
dbLocation, dbUsername, dbPassword)
else:
searchService = searchServices[dbType](dbLocation)
portal = Portal(PublicHTMLRealm(searchService), [AllowAnonymousAccess()])
portal.registerChecker(QuasselChecker(searchService), IUsernameHashedPassword)
portal.registerChecker(SessionChecker(), ISessionCredentials)
application = service.Application("Querryl")
site = server.Site(BasicWrapper(portal, []))
site.sessionFactory = LongSession
if ssl:
ctx = DefaultOpenSSLContextFactory(sslPrivate, sslCert)
ssl_sv = internet.SSLServer(sslPort, site, ctx, interface=iface)
ssl_sv.setServiceParent(application)
if sslRedirect:
site = server.Site(RedirectFromRequest(port=sslPort))
sv = internet.TCPServer(port, site, interface=iface)
sv.setServiceParent(application)
return sv
示例3: setUp
def setUp(self):
super(RootTests, self).setUp()
self.docroot = self.mktemp()
os.mkdir(self.docroot)
RootResource.CheckSACL = FakeCheckSACL(sacls={"calendar": ["dreid"]})
directory = XMLDirectoryService({"xmlFile" : xmlFile})
augment.AugmentService = augment.AugmentXMLDB(
xmlFiles=(augmentsFile.path,)
)
principals = DirectoryPrincipalProvisioningResource(
"/principals/",
directory
)
root = RootResource(self.docroot, principalCollections=[principals])
root.putChild("principals",
principals)
portal = Portal(auth.DavRealm())
portal.registerChecker(directory)
self.root = auth.AuthenticationWrapper(
root,
portal,
credentialFactories=(basic.BasicCredentialFactory("Test realm"),),
loginInterfaces=(auth.IPrincipal,))
self.site = server.Site(self.root)
示例4: main_ssh2http
def main_ssh2http():
portal = Portal(ExampleRealm())
c_port = 5022
factory = SSH2HTTPConverterFactory(c_port)
portal.registerChecker(factory)
SSH2HTTPConverterFactory.portal = portal
reactor.listenTCP(c_port, factory)
示例5: makeService
def makeService(self, options):
class LongSession(Session):
sessionTimeout = 3600
if options['steamkey'] is None:
raise ValueError('Must specify steam API key.')
if options['strport'] is None:
raise ValueError('Must specify strport description.')
if options['dbdir'] is None:
raise ValueError('Must specify database path.')
steamAPI = API(key=options['steamkey'])
store = Store(options['dbdir'])
keyPath = FilePath(options['dbdir']).child('fernet.key')
database = Database(store)
loginRedirect = '/'
portal = Portal(MapListRealm(database, options['bundle-path'],
steamAPI, loginRedirect))
portal.registerChecker(PreauthenticatedChecker())
portal.registerChecker(AllowAnonymousAccess())
root = HTTPOpenIDAuthSessionWrapper(portal, [], loginRedirect, keyPath,
database)
site = Site(root)
site.sessionFactory = LongSession
return strports.service(options['strport'], site)
示例6: createPortal
def createPortal(self, realmFactory=None):
if realmFactory is None:
realmFactory = SillyRealm
r = realmFactory()
p = Portal(r)
p.registerChecker(AllowAnonymousAccess(), IAnonymous)
return p
示例7: portal
def portal(self):
portal = Portal(self.realm())
for checker in self.auth_checkers():
portal.registerChecker(checker)
if len(self.auth_checkers()) == 0:
portal.registerChecker(checkers.AllowAnonymousAccess())
return portal
示例8: makeService
def makeService(config):
components.registerAdapter(
GitSession,
GitAvatar,
session.ISession)
with open(config['conf']) as f:
conf = yaml.load(f.read())
port = int(conf.get('port', 22))
host_key = conf.get('host_key')
driver_key = conf.get('driver', 'example')
log.msg('Using driver: \'%s\'' % driver_key)
mgr = driver.DriverManager(
namespace='gitserver.driver',
name=driver_key,
invoke_on_load=False
)
portal = Portal(GitRealm(mgr))
portal.registerChecker(GitPublicKeyChecker(mgr))
# factory.SSHFactory takes no arguments, so unlike the
# websocket server, we will assign portal on the class
# rather than through the constructor.
# TypeError: this constructor takes no arguments
# is raised if we pass portal GitFactory(portal)
GitFactory.portal = portal
GitSession.driver_key = driver_key
return internet.TCPServer(port, GitFactory(host_key=host_key))
示例9: test_unencryptedConnectionWithoutPasswords
def test_unencryptedConnectionWithoutPasswords(self):
"""
If the L{SSHUserAuthServer} is not advertising passwords, then an
unencrypted connection should not cause any warnings or exceptions.
This is a white box test.
"""
# create a Portal without password authentication
portal = Portal(self.realm)
portal.registerChecker(PrivateKeyChecker())
# no encryption
clearAuthServer = userauth.SSHUserAuthServer()
clearAuthServer.transport = FakeTransport(portal)
clearAuthServer.transport.isEncrypted = lambda x: False
clearAuthServer.serviceStarted()
clearAuthServer.serviceStopped()
self.assertEqual(clearAuthServer.supportedAuthentications,
['publickey'])
# only encrypt incoming (the direction the password is sent)
halfAuthServer = userauth.SSHUserAuthServer()
halfAuthServer.transport = FakeTransport(portal)
halfAuthServer.transport.isEncrypted = lambda x: x == 'in'
halfAuthServer.serviceStarted()
halfAuthServer.serviceStopped()
self.assertEqual(clearAuthServer.supportedAuthentications,
['publickey'])
示例10: __init__
def __init__(self, conf):
self._init_keys(conf)
config = cwconfig.instance_configuration(conf.get('cubicweb-instance'))
repo = Repository(config, TasksManager(), vreg=None)
portal = Portal(CubicWebSFTPRealm(repo, conf))
portal.registerChecker(CubicWebCredentialsChecker(repo))
self.portal = portal
示例11: listen
def listen(self, port):
'''
Starts listening on the specified port.
'''
portal = Portal(credentials.Realm())
portal.registerChecker(credentials.PasswordChecker(self.__passwd))
reactor.listenTCP(port, ServerProtocolFactory(portal, self.userlist))
示例12: create_portal
def create_portal(a):
"""I'm responsible for creating the authenticated portal"""
realm = AggregatorRealm(a)
portal = Portal(realm)
checker = InMemoryUsernamePasswordDatabaseDontUse()
checker.addUser(version.apiversion, a.getPassword())
portal.registerChecker(checker)
return portal
示例13: makeService
def makeService(options):
"""
Makes a new swftp-ftp service. The only option is the config file
location. The config file has the following options:
- host
- port
- auth_url
- num_persistent_connections
- connection_timeout
- welcome_message
"""
from twisted.protocols.ftp import FTPFactory
from twisted.web.client import HTTPConnectionPool
from twisted.cred.portal import Portal
from swftp.ftp.server import SwiftFTPRealm
from swftp.auth import SwiftBasedAuthDB
from swftp.utils import print_runtime_info
print('Starting SwFTP-ftp %s' % VERSION)
c = get_config(options['config_file'], options)
ftp_service = service.MultiService()
# Add statsd service
if c.get('ftp', 'log_statsd_host'):
try:
from swftp.statsd import makeService as makeStatsdService
makeStatsdService(
c.get('ftp', 'log_statsd_host'),
c.getint('ftp', 'log_statsd_port'),
sample_rate=c.getfloat('ftp', 'log_statsd_sample_rate'),
prefix=c.get('ftp', 'log_statsd_metric_prefix')
).setServiceParent(ftp_service)
except ImportError:
log.err('Missing Statsd Module. Requires "txstatsd"')
pool = HTTPConnectionPool(reactor, persistent=True)
pool.maxPersistentPerHost = c.getint('ftp', 'num_persistent_connections')
pool.cachedConnectionTimeout = c.getint('ftp', 'connection_timeout')
authdb = SwiftBasedAuthDB(auth_url=c.get('ftp', 'auth_url'),
verbose=c.getboolean('ftp', 'verbose'))
ftpportal = Portal(SwiftFTPRealm())
ftpportal.registerChecker(authdb)
ftpfactory = FTPFactory(ftpportal)
ftpfactory.welcomeMessage = c.get('ftp', 'welcome_message')
ftpfactory.allowAnonymous = False
signal.signal(signal.SIGUSR1, print_runtime_info)
signal.signal(signal.SIGUSR2, print_runtime_info)
internet.TCPServer(
c.getint('ftp', 'port'),
ftpfactory,
interface=c.get('ftp', 'host')).setServiceParent(ftp_service)
return ftp_service
示例14: StartServices
def StartServices(username,password):
from md5 import md5
password = md5(password).digest()
portal = Portal(SimpleRealm())
checker = InMemoryUsernamePasswordDatabaseDontUse()
checker.addUser(username,password)
portal.registerChecker(checker)
reactor.listenTCP(7001,pb.PBServerFactory(portal))
示例15: createDocumentRoot
def createDocumentRoot(self):
docroot = self.mktemp()
os.mkdir(docroot)
userResource = TestDAVPrincipalResource("/principals/users/user01")
userResource.writeDeadProperty(TwistedPasswordProperty("user01"))
principalCollection = TestPrincipalsCollection(
"/principals/",
children={"users": TestPrincipalsCollection(
"/principals/users/",
children={"user01": userResource})})
rootResource = self.resource_class(
docroot, principalCollections=(principalCollection,))
portal = Portal(DavRealm())
portal.registerChecker(TwistedPropertyChecker())
credentialFactories = (basic.BasicCredentialFactory(""),)
loginInterfaces = (IPrincipal,)
self.site = Site(AuthenticationWrapper(
rootResource,
portal,
credentialFactories,
credentialFactories,
loginInterfaces
))
rootResource.setAccessControlList(self.grant(element.All()))
for name, acl in (
("none" , self.grant()),
("read" , self.grant(element.Read())),
("read-write" , self.grant(element.Read(), element.Write())),
("unlock" , self.grant(element.Unlock())),
("all" , self.grant(element.All())),
):
filename = os.path.join(docroot, name)
if not os.path.isfile(filename):
file(filename, "w").close()
resource = self.resource_class(filename)
resource.setAccessControlList(acl)
for name, acl in (
("nobind" , self.grant()),
("bind" , self.grant(element.Bind())),
("unbind" , self.grant(element.Bind(), element.Unbind())),
):
dirname = os.path.join(docroot, name)
if not os.path.isdir(dirname):
os.mkdir(dirname)
resource = self.resource_class(dirname)
resource.setAccessControlList(acl)
return docroot