• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Products.PluggableAuthService / 3775730124

pending completion
3775730124

push

github

Jens Vagelpohl
- vb [ci skip]

1303 of 1776 branches covered (73.37%)

Branch coverage included in aggregate %.

9659 of 10404 relevant lines covered (92.84%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.52
/src/Products/PluggableAuthService/plugins/InlineAuthHelper.py
1
##############################################################################
2
#
3
# Copyright (c) 2001 Zope Foundation and Contributors
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this
7
# distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14
""" Class: CookieAuthHelper
1✔
15
"""
16

17
from AccessControl.class_init import InitializeClass
1✔
18
from AccessControl.SecurityInfo import ClassSecurityInfo
1✔
19
from OFS.Folder import Folder
1✔
20
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
1✔
21
from zope.interface import Interface
1✔
22

23
from ..interfaces.plugins import IChallengePlugin
1✔
24
from ..interfaces.plugins import ILoginPasswordHostExtractionPlugin
1✔
25
from ..plugins.BasePlugin import BasePlugin
1✔
26
from ..utils import classImplements
1✔
27

28

29
class IInlineAuthHelper(Interface):
1✔
30
    """ Marker interface.
31
    """
32

33

34
manage_addInlineAuthHelperForm = PageTemplateFile(
1✔
35
    'www/iaAdd', globals(), __name__='manage_addInlineAuthHelperForm')
36

37

38
def addInlineAuthHelper(dispatcher, id, title=None, REQUEST=None):
1✔
39
    """ Add an Inline Auth Helper to a Pluggable Auth Service. """
40
    iah = InlineAuthHelper(id, title)
×
41
    dispatcher._setObject(iah.getId(), iah)
×
42

43
    if REQUEST is not None:
×
44
        REQUEST['RESPONSE'].redirect('%s/manage_workspace'
×
45
                                     '?manage_tabs_message='
46
                                     'InlineAuthHelper+added.' %
47
                                     dispatcher.absolute_url())
48

49

50
class InlineAuthHelper(Folder, BasePlugin):
1✔
51
    """ Multi-plugin for managing details of Inline Authentication. """
52
    meta_type = 'Inline Auth Helper'
1✔
53
    zmi_icon = 'fas fa-fingerprint'
1✔
54
    security = ClassSecurityInfo()
1✔
55

56
    _properties = ({'id': 'title', 'label': 'Title',
1✔
57
                    'type': 'string', 'mode': 'w'},)
58

59
    manage_options = (BasePlugin.manage_options[:1]
1✔
60
                      + Folder.manage_options[:1]
61
                      + Folder.manage_options[2:])
62

63
    def __init__(self, id, title=None):
1✔
64
        self.id = self._id = id
1✔
65
        self.title = title
1✔
66
        self.body = BASIC_LOGIN_FORM
1✔
67

68
    @security.private
1✔
69
    def extractCredentials(self, request):
1✔
70
        """ Extract credentials from cookie or 'request'. """
71
        creds = {}
1✔
72

73
        # Look in the request for the names coming from the login form
74
        login = request.get('__ac_name', '')
1✔
75
        password = request.get('__ac_password', '')
1✔
76

77
        if login:
1✔
78
            creds['login'] = login
1✔
79
            creds['password'] = password
1✔
80

81
        if creds:
1✔
82
            creds['remote_host'] = request.get('REMOTE_HOST', '')
1✔
83

84
            try:
1✔
85
                creds['remote_address'] = request.getClientAddr()
1✔
86
            except AttributeError:
1✔
87
                creds['remote_address'] = request.get('REMOTE_ADDR', '')
1✔
88

89
        return creds
1✔
90

91
    @security.private
1✔
92
    def challenge(self, request, response, **kw):
1✔
93
        """ Challenge the user for credentials. """
94
        response.setStatus('200')
1✔
95
        response.setHeader('Content-Type', 'text/html')
1✔
96
        response.setBody(self.body)
1✔
97

98
        # Keep HTTPResponse.exception() from further writing on the
99
        # response body, without using HTTPResponse.write()
100
        response._locked_status = True
1✔
101
        response.setBody = self._setBody  # Keep response.exception
1✔
102
        return True
1✔
103

104
    # Methods to override on response
105

106
    def _setBody(self, body, *args, **kw):
1✔
107
        pass
×
108

109

110
classImplements(InlineAuthHelper, IInlineAuthHelper,
1✔
111
                ILoginPasswordHostExtractionPlugin, IChallengePlugin)
112

113
InitializeClass(InlineAuthHelper)
1✔
114

115

116
BASIC_LOGIN_FORM = """<html>
1✔
117
  <head>
118
    <title> Login Form </title>
119
  </head>
120

121
  <body>
122

123
    <h3> Please log in </h3>
124

125
    <form method="post">
126
      <table cellpadding="2">
127
        <tr>
128
          <td><b>Login:</b> </td>
129
          <td><input type="text" name="__ac_name" size="30" /></td>
130
        </tr>
131
        <tr>
132
          <td><b>Password:</b></td>
133
          <td><input type="password" name="__ac_password" size="30" /></td>
134
        </tr>
135
        <tr>
136
          <td colspan="2">
137
            <br />
138
            <input type="submit" value=" Log In " />
139
          </td>
140
        </tr>
141
      </table>
142

143
    </form>
144

145
  </body>
146

147
</html>
148
"""
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc