#
# repoze.who
#
-who.config_file = %(here)s/who.ini
+#who.config_file = %(here)s/who.ini
+authkit.setup.method = forward,cookie
+
+authkit.forward.signinpath = /authentication/login
+authkit.cookie.signoutpath = /authentication/logout
+authkit.cookie.secret = cookie secret
+authkit.cookie.name = authkit_cookie_name
+#authkit.cookie.params = expires: 3600
+
+
+#authkit.forward.signoutpath = /authentication/logout
yaml.config = %(here)s/swat/config/yaml
#
# repoze.who
#
-from repoze.who.config import make_middleware_with_config
+#from repoze.who.config import make_middleware_with_config
+import authkit.authenticate
+from paste.recursive import RecursiveMiddleware
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
"""Create a Pylons WSGI application and return it
# CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
if asbool(full_stack):
+ app = RecursiveMiddleware(app, global_conf)
+
# Handle Python exceptions
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
#
# repoze.who
#
- app = make_middleware_with_config(app, global_conf, app_conf['who.config_file'])
+ #app = make_middleware_with_config(app, global_conf, app_conf['who.config_file'])
+ app = authkit.authenticate.middleware(app, app_conf)
# Display error documents for 401, 403, 404 status codes (and
# 500 when debug is disabled)
from pylons.controllers.util import abort, redirect_to
from swat.lib.base import BaseController, render
-from swat.lib.helpers import swat_messages
+from swat.lib.helpers import SwatMessages
from pylons.i18n.translation import _
"""
redirect_to(controller = 'authentication', action = 'login')
- def authenticate(self, environ, identity):
+ def __authenticate(self):
""" Performs the custom authentication. This method is required by
repoze and we are sent here by it.
work here. Maybe I'm using repoze.who wrong?
"""
- username = identity['login']
- password = identity['password']
+ username = request.params.get("login", "").strip()
+ password = request.params.get("password", "").strip()
+
+ # FIXME!!!!
+ environ = []
len_username = len(username)
- len_password = len(password)
+ len_password = len(password)
+
+ print username + " -- " + password
if len_username == 0:
- swat_messages.add('Username cannot be empty', 'critical')
+ SwatMessages.add('Username cannot be empty', 'critical')
if len_password == 0:
- swat_messages.add('Password cannot be empty', 'critical')
+ SwatMessages.add('Password cannot be empty', 'critical')
if self.__perform_authentication(username, password, environ):
- swat_messages.add('Authentication successful!')
- log.info("login attempt sucessful by " + username)
+ SwatMessages.add('Authentication successful!')
+ log.info("login attempt successful by " + username)
+ request.environ['paste.auth_tkt.set_user'](username)
- return username
+ return True
log.warning("failed login attempt by " + username)
- swat_messages.add('Authentication failed' + ' -- ' + self.__reason, 'critical')
+ SwatMessages.add('Authentication failed' + ' -- ' + self.__reason, 'critical')
- return None
+ return False
def __perform_authentication(self, username, password, environ):
""" Performs the authentication of a user depending on the available
set this to login otherwise it would just send me to the login method
"""
- pass
+ if self.__authenticate():
+ redirect_to(controller='dashboard', action='index')
+ else:
+ redirect_to(controller='authentication', action='login')
from pylons.i18n.translation import _
from swat.lib.helpers import ControllerConfiguration, DashboardConfiguration, \
-BreadcrumbTrail, SwatMessages, swat_messages
+BreadcrumbTrail, SwatMessages
log = logging.getLogger(__name__)
c.samba_lp.load_default()
def index(self):
- identity = request.environ.get('repoze.who.identity')
+ from authkit.permissions import NotAuthenticatedError
- if identity is None:
- swat_messages.add(_("You must be authenticated to perform that action"), "critical")
+ if not request.environ.has_key('REMOTE_USER'):
+ SwatMessages.add(_("You must be authenticated to perform that action"), "critical")
abort(401)
+ # raise NotAuthenticatedError('Not Authenticated')
+
+
+
+ #identity = request.environ.get('repoze.who.identity')
+
+ #if identity is None:
+ # SwatMessages.add(_("You must be authenticated to perform that action"), "critical")
+ # abort(401)
""" The default Dashboard. The entry point for SWAT """
return render('/default/derived/dashboard.mako')
from pylons.templating import render_mako_def
from pylons.i18n.translation import _
from swat.lib.helpers import ControllerConfiguration, DashboardConfiguration, \
-BreadcrumbTrail, swat_messages, ParamConfiguration, filter_list
+BreadcrumbTrail, SwatMessages, ParamConfiguration, filter_list
log = logging.getLogger(__name__)
is a list of allowed operations that is checked to see if it's ok to
load the configuration
- """
+ """
me = request.environ['pylons.routes_dict']['controller']
action = request.environ['pylons.routes_dict']['action']
log.error( c.samba_lp.get("share backend") + "is unsupported at the moment")
message = _("Your chosen backend is not yet supported")
- swat_messages.add(message, "critical")
+ SwatMessages.add(message, "critical")
def index(self):
""" Point of entry. Loads the Share List Template """
if name not in c.share_list and not is_new:
log.warning("Share " + name + " doesn't exist in the chosen backend")
- swat_messages.add(_("Can't edit a Share that doesn't exist"), "warning")
+ SwatMessages.add(_("Can't edit a Share that doesn't exist"), "warning")
redirect_to(controller='share', action='index')
else:
c.p = ParamConfiguration('share-parameters')
if stored:
message = _("Share Information was Saved")
- swat_messages.add(message)
+ SwatMessages.add(message)
else:
- swat_messages.add(backend.get_error_message(), backend.get_error_type())
+ SwatMessages.add(backend.get_error_message(), backend.get_error_type())
else:
log.error("Error saving because the backend (" + c.samba_lp.get("share backend") + ") is unsupported")
message = _("Your chosen backend is not yet supported")
- swat_messages.add(message, "critical")
+ SwatMessages.add(message, "critical")
if request.environ['pylons.routes_dict']['action'] == "save":
redirect_to(controller='share', action='index')
elif request.params.get("task", "edit") == "edit":
message = _("Cancelled Share editing. No changes were saved!")
- swat_messages.add(message, "warning")
+ SwatMessages.add(message, "warning")
redirect_to(controller='share', action='index')
def path(self):
log.warning(message)
- swat_messages.add(message, type)
+ SwatMessages.add(message, type)
else:
log.error("Error removing because the backend (" + c.samba_lp.get("share backend") + ") is unsupported")
message = _("Your chosen backend is not yet supported")
- swat_messages.add(message, "critical")
+ SwatMessages.add(message, "critical")
redirect_to(controller='share', action='index')
log.warning(message)
- swat_messages.add(message, type)
+ SwatMessages.add(message, type)
else:
log.error("Error copying because the backend (" + c.samba_lp.get("share backend") + ") is unsupported")
message = _("Your chosen backend is not yet supported")
- swat_messages.add(message, "critical")
+ SwatMessages.add(message, "critical")
redirect_to(controller='share', action='index')
if toggled:
message = _("Share Toggled successfuly")
- swat_messages.add(message)
+ SwatMessages.add(message)
else:
- swat_messages.add(backend.get_error_message(), backend.get_error_type())
+ SwatMessages.add(backend.get_error_message(), backend.get_error_type())
else:
message = _("Your chosen backend is not yet supported")
- swat_messages.add(message, "critical")
+ SwatMessages.add(message, "critical")
redirect_to(controller='share', action='index')
from webhelpers.html import literal
from routes import url_for
-from pylons import request, app_globals as g, config
+from pylons import request, app_globals as g, config, session
import yaml
import logging
in there will be a problem of them seeing messages that don't belong to them
"""
- def __init__(self):
- """ Initialization """
- self._items = []
-
- def add(self, text, type='cool'):
+ @staticmethod
+ def add(text, type='cool'):
""" Add a message to the message queue.
Concerning the message type, it can be anything but to have any
type -- the type of message. default value is 'cool'
"""
- if len(type) == 0:
- type = 'cool'
-
- self._items.append({'text' : text, 'type' : type})
-
- def clean(self):
+ if len(type) == 0:
+ type = 'cool'
+
+ if not session.has_key('swat_messages'):
+ session['swat_messages'] = []
+
+ session['swat_messages'].append({'text' : text, 'type' : type})
+ session.save()
+
+ @staticmethod
+ def clean():
""" Cleanup message queue. This should be called after messages are
shown in the template
"""
- del self._items[:]
+ if session.has_key('swat_messages'):
+ del session['swat_messages']
+ session.save()
- def get(self):
+ @staticmethod
+ def get():
""" Gets all messages currently stored as a dictionary """
- return self._items
-
- def __len__(self):
+ return session['swat_messages']
+
+ @staticmethod
+ def __len__():
""" Returns the number of messsages in store """
- return len(self._items)
+ return len(session['swat_messages'])
- def any(self):
+ @staticmethod
+ def any():
""" Checks if there are any messages in the queue.
Returns a boolean value
"""
- has_any = False
-
- if len(self._items) > 0:
+ has_any = False
+
+ if session.has_key('swat_messages') and len(session['swat_messages']) > 0:
has_any = True
return has_any
-swat_messages = SwatMessages()
-
def get_samba_server_status():
""" Gets the current Samba4 status to be used in the CSS class name for the
top template in the Server Name area.
<div id="swat-main-area">
${menu.breadcrumb()}
- % if h.swat_messages.any():
- ${messages.write(h.swat_messages.get())}
- <% h.swat_messages.clean() %>
+ % if h.SwatMessages.any():
+ ${messages.write(h.SwatMessages.get())}
+ <% h.SwatMessages.clean() %>
% endif
${self.body()}
<body>
<div class="swat-content login round-2px">
- % if h.swat_messages.any():
- ${messages.write(h.swat_messages.get())}
- <% h.swat_messages.clean() %>
+ % if h.SwatMessages.any():
+ ${messages.write(h.SwatMessages.get())}
+ <% h.SwatMessages.clean() %>
% endif
${base.samba_logo(False)}
[plugin:auth_tkt]
use = repoze.who.plugins.auth_tkt:make_plugin
-secret = to-be_randomly--generated
+secret = 6CBC8654B175A121826543483E99F9E4
[general]
request_classifier = repoze.who.classifiers:default_request_classifier