Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dm/zope/saml2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"""SAML2 support."""

def initialize(context):
from authority import SamlAuthority
from permission import manage_saml
from dm.zope.saml2.authority import SamlAuthority
from dm.zope.saml2.permission import manage_saml
from dm.zope.schema.z2.constructor import add_form_factory, SchemaConfiguredZmiAddForm

context.registerClass(
Expand All @@ -12,6 +12,6 @@ def initialize(context):
permission=manage_saml,
)

from idpsso.idpsso import initialize; initialize(context)
from spsso import initialize; initialize(context)
from entity import initialize; initialize(context)
from dm.zope.saml2.idpsso.idpsso import initialize; initialize(context)
from dm.zope.saml2.spsso import initialize; initialize(context)
from dm.zope.saml2.entity import initialize; initialize(context)
23 changes: 13 additions & 10 deletions dm/zope/saml2/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
provider class."""
from logging import getLogger

from zope.interface import implements
from zope.interface import implementer

from AccessControl import ClassSecurityInfo
from OFS.SimpleItem import SimpleItem
Expand All @@ -24,11 +24,11 @@
from dm.zope.saml2.util import getCharset
from dm.saml2.util import xs_convert_to_xml

from interfaces import IProvidedAttributeSchema, IRequestedAttributeSchema, \
from dm.zope.saml2.interfaces import IProvidedAttributeSchema, IRequestedAttributeSchema, \
IItemSchema, IAttributeConsumingServiceSchema, \
ISimpleAttributeProvider
from permission import manage_saml
from role import Role
from dm.zope.saml2.permission import manage_saml
from dm.zope.saml2.role import Role

logger = getLogger(__name__)

Expand All @@ -43,25 +43,26 @@ class BaseAttribute(SchemaConfigured, SimpleItem):
)


@implementer(IRequestedAttributeSchema)
class RequestedAttribute(BaseAttribute):
meta_type = "Saml requested attribute"

implements(IRequestedAttributeSchema)

SC_SCHEMAS = (IRequestedAttributeSchema,)

# for backward compatibility
type = None


@implementer(IProvidedAttributeSchema)
class ProvidedAttribute(BaseAttribute):
meta_type = "Saml provided attribute"

implements(IProvidedAttributeSchema)

SC_SCHEMAS = (IProvidedAttributeSchema,)


@implementer(IItemSchema)
class HomogenousContainer(SchemaConfigured, Folder):
"""Abstract base class for the implementation of homogenous containers.

Expand All @@ -71,7 +72,6 @@ class HomogenousContainer(SchemaConfigured, Folder):
does not use cooperative super calling.
"""

implements(IItemSchema)
SC_SCHEMAS = (IItemSchema,)

# to be overridden by derived classes
Expand Down Expand Up @@ -114,7 +114,10 @@ def __class_init__(cls):
# cannot use the name "HomogenourContainer" here as it is not yet bound
scls = super(cls, cls)
else: raise SystemError("class %s has not set `CONTENT_TYPE`" % str(cls))
scls.__class_init__.im_func(cls)
try:
scls.__class_init__.im_func(cls)
except AttributeError:
scls.__class_init__(cls)


class AttributeContainer(HomogenousContainer):
Expand All @@ -124,15 +127,16 @@ class AttributeContainer(HomogenousContainer):
CONTENT_TYPE = ProvidedAttribute


@implementer(IAttributeConsumingServiceSchema)
class AttributeConsumingService(HomogenousContainer):
meta_type = "Saml attribute consuming service"

implements(IAttributeConsumingServiceSchema)
SC_SCHEMAS = (IAttributeConsumingServiceSchema,)

CONTENT_TYPE = RequestedAttribute


@implementer(ISimpleAttributeProvider)
class SimpleAttributeProvider(AttributeContainer, Role):
"""Attribute provider.

Expand All @@ -141,7 +145,6 @@ class SimpleAttributeProvider(AttributeContainer, Role):
"""
meta_type = "Saml attribute provider"

implements(ISimpleAttributeProvider)
SC_SCHEMAS = ISimpleAttributeProvider,

def _make_attribute_statement(self, target, req, subject, member, index):
Expand Down
18 changes: 7 additions & 11 deletions dm/zope/saml2/authority.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Copyright (C) 2011-2012 by Dr. Dieter Maurer <dieter@handshake.de>
"""Authority and metadata."""
from tempfile import NamedTemporaryFile

from persistent import Persistent
from persistent.list import PersistentList
from persistent.mapping import PersistentMapping
from AccessControl import ClassSecurityInfo
#from Globals import InitializeClass

from zope.interface import Interface, implements
from zope.interface import Interface, implementer
from zope.component import getUtility
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
Expand All @@ -27,14 +23,14 @@
from dm.saml2 import signature
from dm.saml2.util import utcnow

from interfaces import ISamlAuthority, \
from dm.zope.saml2.interfaces import ISamlAuthority, \
IIdpssoRole, ISpssoRole, IApRole, IAuthnRole, IPdpRole, \
INameidFormatSupport, \
IUrlCustomizer

from permission import manage_saml
from util import ZodbSynchronized
from entity import ManageableEntityMixin, EntityManagerMixin
from dm.zope.saml2.permission import manage_saml
from dm.zope.saml2.util import ZodbSynchronized
from dm.zope.saml2.entity import ManageableEntityMixin, EntityManagerMixin


# Note: `EntityByUrl` lacks a way to access the context for signature
Expand All @@ -55,9 +51,9 @@ class IEntityMetadata(Interface):
# a persistent list for internal purposes.
# This is okay as long as we use a persistent storage (as we do).
# Not using persistent classes here leads to less ZODB loads.
@implementer(IEntityMetadata)
class EntityMetadata(EntityMetadata):
"""extend basic `EntityMetadata` by `ObjectModified` events."""
implements(IEntityMetadata)

def default_validity(self):
return getUtility(ISamlAuthority).default_validity
Expand Down Expand Up @@ -99,6 +95,7 @@ def _get_authority(self):
return getUtility(ISamlAuthority)


@implementer(ISamlAuthority)
class SamlAuthority(SchemaConfiguredEvolution, EntityManagerMixin,
SimpleItem, SchemaConfigured, MetadataRepository
):
Expand All @@ -113,7 +110,6 @@ class SamlAuthority(SchemaConfiguredEvolution, EntityManagerMixin,
"""
meta_type = "Saml authority"

implements(ISamlAuthority)

INTERNAL_STORAGE_CLASS = PersistentMapping
METADATA_STORAGE_CLASS = PersistentMapping
Expand Down
2 changes: 2 additions & 0 deletions dm/zope/saml2/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
/>

<!-- formlib widget support for ZMI -->
<include package="zope.formlib" />

<adapter
for="zope.schema.interfaces.ITuple
zope.schema.interfaces.IVocabularyTokenized
Expand Down
11 changes: 7 additions & 4 deletions dm/zope/saml2/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

We assume that our entities are schema configured and implement `IEntity`.
"""
from urllib import quote, unquote
try:
from urllib import quote, unquote
except ImportError:
from urllib.parse import quote, unquote

from zope.interface import Interface, implements
from zope.interface import implementer
from zope.schema import URI, TextLine

from OFS.SimpleItem import SimpleItem
Expand All @@ -29,6 +32,7 @@ class IManageableEntity(IEntity):



@implementer(IManageableEntity)
class ManageableEntityMixin(SchemaConfigured, SimpleItem):
"""Mixin class to provide `SchemaConfigured` based manageability.

Expand All @@ -37,7 +41,6 @@ class ManageableEntityMixin(SchemaConfigured, SimpleItem):

The instances expect to be managed inside a `MetadataRepository`.
"""
implements(IManageableEntity)

manage_options = (
{"label" : "Edit", "action" : "@@edit"},
Expand Down Expand Up @@ -88,8 +91,8 @@ class IEntityByUrl(IManageableEntity):



@implementer(IEntityByUrl)
class EntityByUrl(ManageableEntityMixin, EntityByUrl):
implements(IEntityByUrl)

meta_type = "Saml2 entity defined by metadata providing url"

Expand Down
4 changes: 2 additions & 2 deletions dm/zope/saml2/events.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dm.zope.saml2.interfaces import ISamlUserAuthenticated
from zope.interface import implements
from zope.interface import implementer
from zope.component.interfaces import ObjectEvent


@implementer(ISamlUserAuthenticated)
class SamlUserAuthenticated(ObjectEvent):
"""
SAML user got authenticated
:param user_id: id of authenticated user
"""
implements(ISamlUserAuthenticated)
4 changes: 2 additions & 2 deletions dm/zope/saml2/idpsso/idpsso.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""The Idpsso implementation."""
from datetime import timedelta

from zope.interface import implements
from zope.interface import implementer

from AccessControl import ClassSecurityInfo
from OFS.SimpleItem import SimpleItem
Expand All @@ -25,6 +25,7 @@


# might want to implement as a tool
@implementer(ISimpleIdpsso)
class SimpleIdpsso(SimpleItem, SchemaConfigured, Sso):
"""Zope2 implementation for a simple SAML Idpsso.

Expand All @@ -36,7 +37,6 @@ class SimpleIdpsso(SimpleItem, SchemaConfigured, Sso):
# how long should authentication responses be valid
BROWSER_SSO_VALIDITY = timedelta(minutes=5)

implements(ISimpleIdpsso)

SC_SCHEMAS = (ISimpleIdpsso,)

Expand Down
2 changes: 1 addition & 1 deletion dm/zope/saml2/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
XSCHEMA_BASE_TYPES, \
NAMEID_FORMATS

from util import vocab_from_urns
from dm.zope.saml2.util import vocab_from_urns
from zope.component.interfaces import IObjectEvent

_ = MessageFactory('dm_zope_saml2')
Expand Down
8 changes: 4 additions & 4 deletions dm/zope/saml2/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from logging import getLogger
from os import environ

from zope.interface import implements
from zope.interface import implementer
from zope.component import getUtility
from BTrees.OOBTree import OOBTree
from ExtensionClass import Base
Expand All @@ -19,9 +19,9 @@
from dm.saml2.util import normalize_nameid_format, utcnow, as_utc
from dm.saml2.binding.util import Store, UnmanagedError, RelayStateManager

from interfaces import ISamlAuthority, IHttpTransport, INameidFormatSupport, \
from dm.zope.saml2.interfaces import ISamlAuthority, IHttpTransport, INameidFormatSupport, \
IRelayStateStore
from exception import SamlError
from dm.zope.saml2.exception import SamlError

logger = getLogger(__name__)

Expand Down Expand Up @@ -387,9 +387,9 @@ def move_handler(o, e):

###### NameID format support

@implementer(INameidFormatSupport)
class NameidFormatSupport(object):
"""Default name id format support."""
implements(INameidFormatSupport)

def __init__(self, context): self.context = context

Expand Down
4 changes: 2 additions & 2 deletions dm/zope/saml2/spsso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
"""

def initialize(context):
from spsso import initialize; initialize(context)
from plugin import initialize; initialize(context)
from dm.zope.saml2.spsso.spsso import initialize; initialize(context)
from dm.zope.saml2.spsso.plugin import initialize; initialize(context)
4 changes: 0 additions & 4 deletions dm/zope/saml2/spsso/browser/idp.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# Copyright (C) 2011-2012 by Dr. Dieter Maurer <dieter@handshake.de>
"""Idp related views."""
from urllib import quote, unquote

from zope.schema import Choice, ASCIILine
from zope.formlib.form import Fields, action
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm

from Products.CMFCore.utils import getToolByName

from dm.zope.schema.z2.form import PageForm
from dm.zope.schema.widget import GenericTextWidget, make_hidden

Expand Down
6 changes: 3 additions & 3 deletions dm/zope/saml2/spsso/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""PAS plugins for SAML2 based authentication (Spsso)."""
from datetime import datetime

from zope.interface import implements
from zope.interface import implementer

from AccessControl import ClassSecurityInfo
from ZTUtils import make_query
Expand All @@ -28,9 +28,10 @@
from dm.zope.saml2.interfaces import ISimpleSpssoPluginSchema, \
ISimpleSpsso

from spsso import SimpleSpsso
from dm.zope.saml2.spsso.spsso import SimpleSpsso


@implementer(ISimpleSpssoPluginSchema)
class DetachedSimpleSpssoPlugin(BasePlugin, SchemaConfigured):
"""Spsso plugin working with a separate `Spsso`."""

Expand All @@ -40,7 +41,6 @@ class DetachedSimpleSpssoPlugin(BasePlugin, SchemaConfigured):
security.declareObjectProtected(manage_saml)
security.declarePublic("login")

implements(ISimpleSpssoPluginSchema)

manage_options = (
{"label" : "View", "action" : "@@view"},
Expand Down
Loading