Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement UsernamePassword method #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ local/

.vscode/
.venv/
build/
1 change: 1 addition & 0 deletions cepces/soap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

NS_SOAP = 'http://www.w3.org/2003/05/soap-envelope'
NS_ADDRESSING = 'http://www.w3.org/2005/08/addressing'
NS_WSSE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'

# ACTION_FAULT = 'http://www.w3.org/2005/08/addressing/fault'
QNAME_FAULT = QName('http://www.w3.org/2003/05/soap-envelope', 'Fault')
9 changes: 8 additions & 1 deletion cepces/soap/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from cepces.krb5 import types as ktypes
from cepces.krb5.core import Context, Keytab, Principal
from cepces.krb5.core import CredentialOptions, Credentials, CredentialCache
from cepces.soap.types import Security as WSSecurity, UsernameToken


class Authentication(Base, metaclass=ABCMeta):
Expand Down Expand Up @@ -152,7 +153,13 @@ def clientcertificate(self):
return None

def post_process(self, envelope):
raise NotImplementedError()
envelope.header.element.append(WSSecurity.create())

envelope.header.security.element.append(UsernameToken.create())
envelope.header.security.usernametoken.username = self._username
envelope.header.security.usernametoken.password = self._password

return envelope


class TransportCertificateAuthentication(Authentication):
Expand Down
43 changes: 42 additions & 1 deletion cepces/soap/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# pylint: disable=invalid-name
"""This module contains common SOAP types."""
from xml.etree.ElementTree import Element, QName
from cepces.soap import NS_ADDRESSING, NS_SOAP
from cepces.soap import NS_ADDRESSING, NS_SOAP, NS_WSSE
from cepces.xml import NS_XSI
from cepces.xml.binding import XMLElement, XMLNode, XMLValue
from cepces.xml.converter import StringConverter
Expand Down Expand Up @@ -100,6 +100,43 @@ def create():
return element


class UsernameToken(XMLNode):
"""WSSE UsernameToken."""
username = XMLValue('Username',
converter=StringConverter,
namespace=NS_WSSE)
password = XMLValue('Password',
converter=StringConverter,
namespace=NS_WSSE)

@staticmethod
def create():
usernametoken = Element(QName(NS_WSSE, 'UsernameToken'))

username = Element(QName(NS_WSSE, 'Username'))
usernametoken.append(username)

password = Element(QName(NS_WSSE, 'Password'))
password.attrib[QName(NS_WSSE, 'Type' )] = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
usernametoken.append(password)

return usernametoken


class Security(XMLNode):
"""WSSE Security."""
usernametoken = XMLElement('UsernameToken',
binder=UsernameToken,
namespace=NS_WSSE)

@staticmethod
def create():
security = Element(QName(NS_WSSE, 'Security'))
security.attrib[QName(NS_SOAP, 'mustUnderstand')] = '1'

return security


class Header(XMLNode):
"""SOAP Header."""
action = XMLValue('Action',
Expand All @@ -122,6 +159,10 @@ class Header(XMLNode):
namespace=NS_ADDRESSING,
nillable=True)

security = XMLElement ('Security',
binder=Security,
namespace=NS_WSSE)

@staticmethod
def create():
header = Element(QName(NS_SOAP, 'Header'))
Expand Down
11 changes: 11 additions & 0 deletions conf/cepces.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,14 @@ delegate=True
#
# Default: <not defined>
#keyfile = /path/to/openssl-keyfile.pem

[usernamepassword]
# Use the following AD username in UPN notation.
#
# Default: <not defined>
#username = [email protected]

# Use the following AD password.
#
# Default: <not defined>
#password = ADpassword
Loading