summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@apheleia-it.ch>2022-08-22 21:42:43 +0200
committerChristian Mollekopf <mollekopf@apheleia-it.ch>2022-08-22 21:42:43 +0200
commit9c4fbffe81f9e1596910977684aecc1c2eab3aa0 (patch)
tree62d330a11970119b8330db065112bbbfeed27c3f
parent9fdc386924501e9c03f5280940f111d05dbb238d (diff)
downloadpykolab-dev/python3.tar.gz
Auth command to test authenticationdev/python3
-rw-r--r--pykolab/cli/cmd_auth.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/pykolab/cli/cmd_auth.py b/pykolab/cli/cmd_auth.py
new file mode 100644
index 0000000..46c4a77
--- /dev/null
+++ b/pykolab/cli/cmd_auth.py
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+from __future__ import print_function
+
+import sys
+
+from . import commands
+
+import pykolab
+
+from pykolab.auth import Auth
+from pykolab.translate import _
+from pykolab import utils
+
+log = pykolab.getLogger('pykolab.cli')
+conf = pykolab.getConf()
+
+def __init__():
+ commands.register('auth', execute, description=description())
+
+def cli_options():
+ my_option_group = conf.add_cli_parser_option_group(_("CLI Options"))
+ my_option_group.add_option(
+ '--user',
+ dest = "user",
+ action = "store",
+ default = None,
+ metavar = "USER",
+ help = _("Authenticate as user USER")
+ )
+
+ my_option_group.add_option(
+ '--password',
+ dest = "password",
+ action = "store",
+ default = None,
+ metavar = "PASSWORD",
+ help = _("Authenticate with password PASSWORD")
+ )
+
+def description():
+ return """Test authentication."""
+
+def execute(*args, **kw):
+
+ if not conf.user == None and len(conf.user.split('@')) > 1:
+ domain = conf.user.split('@')[1]
+ else:
+ domain = conf.get('kolab', 'primary_domain')
+
+ print(conf.user)
+ print(conf.password)
+ auth = Auth(domain=domain)
+ auth.connect()
+
+ success = False
+
+ try:
+ success = auth.authenticate([conf.user, conf.password, "imap", domain])
+ except:
+ print("exception")
+ success = False
+
+ if success:
+ print("Success!")
+ else:
+ print("Failed")