signon  8.58
passwordplugin.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * version 2.1 as published by the Free Software Foundation.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00020  * 02110-1301 USA
00021  */
00022 
00023 #include "passwordplugin.h"
00024 #include "SignOn/signonplugincommon.h"
00025 
00026 using namespace SignOn;
00027 
00028 namespace PasswordPluginNS {
00029 
00030 PasswordPlugin::PasswordPlugin(QObject *parent):
00031     AuthPluginInterface(parent)
00032 {
00033     TRACE();
00034 }
00035 
00036 PasswordPlugin::~PasswordPlugin()
00037 {
00038     TRACE();
00039 }
00040 
00041 QString PasswordPlugin::type() const
00042 {
00043     return QLatin1String("password");
00044 }
00045 
00046 QStringList PasswordPlugin::mechanisms() const
00047 {
00048     QStringList res = QStringList(QLatin1String("password"));
00049 
00050     return res;
00051 }
00052 
00053 void PasswordPlugin::cancel()
00054 {
00055     emit error(Error(Error::SessionCanceled));
00056 }
00057 
00058 /*
00059  * Password plugin is used for returning password
00060  * */
00061 void PasswordPlugin::process(const SignOn::SessionData &inData,
00062                             const QString &mechanism )
00063 {
00064     TRACE();
00065     Q_UNUSED(mechanism);
00066     SignOn::SessionData response;
00067 
00068     if (!inData.UserName().isEmpty())
00069         response.setUserName(inData.UserName());
00070 
00071     if (!inData.Secret().isEmpty()) {
00072         response.setSecret(inData.Secret());
00073         emit result(response);
00074         return;
00075     }
00076 
00077     //we didn't receive password from signond, so ask from user
00078     SignOn::UiSessionData data;
00079     if (inData.UserName().isEmpty())
00080         data.setQueryUserName(true);
00081     else
00082         data.setUserName(inData.UserName());
00083 
00084     data.setQueryPassword(true);
00085     emit userActionRequired(data);
00086 
00087     return;
00088 }
00089 
00090 void PasswordPlugin::userActionFinished(const SignOn::UiSessionData &data)
00091 {
00092     TRACE();
00093 
00094     if (data.QueryErrorCode() == QUERY_ERROR_NONE) {
00095         SignOn::SessionData response;
00096         response.setUserName(data.UserName());
00097         response.setSecret(data.Secret());
00098         emit result(response);
00099         return;
00100     }
00101 
00102     if (data.QueryErrorCode() == QUERY_ERROR_CANCELED)
00103         emit error(Error::SessionCanceled);
00104     else
00105         emit error(Error(Error::UserInteraction,
00106                    QLatin1String("userActionFinished error: ")
00107                    + QString::number(data.QueryErrorCode())));
00108 
00109     return;
00110 }
00111 
00112 SIGNON_DECL_AUTH_PLUGIN(PasswordPlugin)
00113 
00114 } //namespace PasswordPluginNS