<commit_before>/*
 * This file is part of signon
 *
 * Copyright (C) 2009-2010 Nokia Corporation.
 * Copyright (C) 2011 Intel Corporation.
 *
 * Contact: <NAME> <<EMAIL>>
 * Contact: <NAME> <<EMAIL>>
 * Contact: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include "signondaemonadaptor.h"
#include "signondisposable.h"
#include "accesscontrolmanagerhelper.h"

namespace SignonDaemonNS {

    SignonDaemonAdaptor::SignonDaemonAdaptor(SignonDaemon *parent)
        : QDBusAbstractAdaptor(parent),
          m_parent(parent)
    {
        setAutoRelaySignals(false);
    }

    SignonDaemonAdaptor::~SignonDaemonAdaptor()
    {}

    void SignonDaemonAdaptor::registerNewIdentity(QDBusObjectPath &objectPath)
    {
        m_parent->registerNewIdentity(objectPath);

        SignonDisposable::destroyUnused();
    }

    void SignonDaemonAdaptor::securityErrorReply(const char *failedMethodName)
    {
        QString errMsg;
        QTextStream(&errMsg) << SIGNOND_PERMISSION_DENIED_ERR_STR
                             << "Method:"
                             << failedMethodName;

        QDBusMessage errReply =
                    parentDBusContext().message().createErrorReply(
                                            SIGNOND_PERMISSION_DENIED_ERR_NAME,
                                            errMsg);
        SIGNOND_BUS.send(errReply);
        TRACE() << "\nMethod FAILED Access Control check:\n" << failedMethodName;
    }

    void SignonDaemonAdaptor::registerStoredIdentity(const quint32 id, QDBusObjectPath &objectPath, QList<QVariant> &identityData)
    {
        if (!AccessControlManagerHelper::instance()->isPeerAllowedToUseIdentity(
                                        parentDBusContext().message(), id)) {
            securityErrorReply(__func__);
            return;
        }

        m_parent->registerStoredIdentity(id, objectPath, identityData);

        SignonDisposable::destroyUnused();
    }

    QStringList SignonDaemonAdaptor::queryMethods()
    {
        return m_parent->queryMethods();
    }

    QString SignonDaemonAdaptor::getAuthSessionObjectPath(const quint32 id, const QString &type)
    {
        SignonDisposable::destroyUnused();

        /* Access Control */<commit_msg>Signond: fix error replies from AuthService<commit_after>/*
 * This file is part of signon
 *
 * Copyright (C) 2009-2010 Nokia Corporation.
 * Copyright (C) 2011 Intel Corporation.
 *
 * Contact: <NAME> <<EMAIL>>
 * Contact: <NAME> <<EMAIL>>
 * Contact: <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include "signondaemonadaptor.h"
#include "signondisposable.h"
#include "accesscontrolmanagerhelper.h"

namespace SignonDaemonNS {

    SignonDaemonAdaptor::SignonDaemonAdaptor(SignonDaemon *parent)
        : QDBusAbstractAdaptor(parent),
          m_parent(parent)
    {
        setAutoRelaySignals(false);
    }

    SignonDaemonAdaptor::~SignonDaemonAdaptor()
    {}

    void SignonDaemonAdaptor::registerNewIdentity(QDBusObjectPath &objectPath)
    {
        m_parent->registerNewIdentity(objectPath);

        SignonDisposable::destroyUnused();
    }

    void SignonDaemonAdaptor::securityErrorReply(const char *failedMethodName)
    {
        QString errMsg;
        QTextStream(&errMsg) << SIGNOND_PERMISSION_DENIED_ERR_STR
                             << "Method:"
                             << failedMethodName;

        QDBusMessage msg = parentDBusContext().message();
        msg.setDelayedReply(true);
        QDBusMessage errReply =
                    msg.createErrorReply(SIGNOND_PERMISSION_DENIED_ERR_NAME,
                                         errMsg);
        SIGNOND_BUS.send(errReply);
        TRACE() << "\nMethod FAILED Access Control check:\n" << failedMethodName;
    }

    void SignonDaemonAdaptor::registerStoredIdentity(const quint32 id, QDBusObjectPath &objectPath, QList<QVariant> &identityData)
    {
        if (!AccessControlManagerHelper::instance()->isPeerAllowedToUseIdentity(
                                        parentDBusContext().message(), id)) {
            securityErrorReply(__func__);
            return;
        }

        m_parent->registerStoredIdentity(id, objectPath, identityData);

        SignonDisposable::destroyUnused();
    }

    QStringList SignonDaemonAdaptor::queryMethods()
    {
        return m_parent->queryMethods();
    }

    QString SignonDaemonAdaptor::getAuthSessionObjectPath(const quint32 id, const QString &type)
    {
        SignonDisposable::destroyUnused();

        /* Access Control */
{'fraction_non_alphanumeric': 0.08699397071490095, 'fraction_numerical': 0.009991386735572783, 'mean_word_length': 2.8758344459279037, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5546165', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1562, 'n_words': 418}