Commit 947955ef authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added identity update at login

parent 5febae64
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -77,4 +77,6 @@ interface UserDAO {
    function joinUsers($userId1, $userId2);

    function isAdmin($userId): bool;

    function updateIdentity(Identity $identity): void;
}
+22 −2
Original line number Diff line number Diff line
@@ -159,17 +159,20 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
                . " WHERE i.user_id IN"
                . " (SELECT user_id FROM identity"
                . " WHERE `email` LIKE :email OR `email` LIKE :emailPart"
                . " OR `eppn` = :eppn"
                . " OR `eppn` LIKE :eppn"
                . " OR `name` LIKE :name OR `surname` LIKE :surname"
                . " OR CONCAT(`name`,' ',`surname`) LIKE :namesurname)";

        $stmt = $dbh->prepare($query);

        $searchParam = $searchText . '%';
        if (count_chars($searchText) > 4) {
            $searchParam = '%' . $searchParam;
        }
        $emailPartSearchParam = '%.' . $searchText . '%';
        $stmt->bindParam(':email', $searchParam);
        $stmt->bindParam(':emailPart', $emailPartSearchParam);
        $stmt->bindParam(':eppn', $searchText);
        $stmt->bindParam(':eppn', $searchParam);
        $stmt->bindParam(':name', $searchParam);
        $stmt->bindParam(':surname', $searchParam);
        $stmt->bindParam(':namesurname', $searchParam);
@@ -281,4 +284,21 @@ class MySQLUserDAO extends BaseMySQLDAO implements UserDAO {
        return count($result) === 1;
    }

    function updateIdentity(Identity $identity): void {

        $dbh = $this->getDBHandler();

        $query = "UPDATE identity SET email = :email, name = :name, surname = :surname, institution = :institution"
                . " WHERE id = :id";

        $stmt = $dbh->prepare($query);
        $stmt->bindParam(':email', $identity->email);
        $stmt->bindParam(':name', $identity->name);
        $stmt->bindParam(':surname', $identity->surname);
        $stmt->bindParam(':institution', $identity->institution);
        $stmt->bindParam(':id', $identity->id);

        $stmt->execute();
    }

}
+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ class LoginHandler {

        if ($user === null) {
            return $this->handleNewIdentity($typedId, $fillIdentityData);
        } else {
            $this->updateUser($user, $typedId, $fillIdentityData);
        }

        return $this->getAfterLoginRedirect($user);
@@ -68,6 +70,12 @@ class LoginHandler {
        return $this->locator->getBasePath() . '/tou-check';
    }

    private function updateUser(User $user, string $typedId, \Closure $fillIdentityData): void {
        $identity = $user->getIdentityByTypedId($typedId);
        $fillIdentityData($identity);
        $this->locator->getUserDAO()->updateIdentity($identity);
    }

    public function getAfterLoginRedirect(User $user): string {

        $session = $this->locator->getSession();
+9 −0
Original line number Diff line number Diff line
@@ -42,6 +42,15 @@ class User {
        array_push($this->identities, $identity);
    }

    public function getIdentityByTypedId(string $typedId): Identity {
        foreach ($this->identities as $identity) {
            if ($identity->typedId === $typedId) {
                return $identity;
            }
        }
        throw new \Exception("Identity not found for typed id " . $typedId);
    }

    public function getPrimaryEmail() {
        foreach ($this->identities as $identity) {
            if ($identity->primary) {

config-example.php

deleted100644 → 0
+0 −86
Original line number Diff line number Diff line
<?php

/* ----------------------------------------------------------------------------
 *               INAF - National Institute for Astrophysics
 *               IRA  - Radioastronomical Institute - Bologna
 *               OATS - Astronomical Observatory - Trieste
 * ----------------------------------------------------------------------------
 *
 * Copyright (C) 2016 Istituto Nazionale di Astrofisica
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License Version 3 as published by the
 * Free Software Foundation.
 *
 * 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, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

$CONTEXT_ROOT = "/rap-ia2";
$VERSION = "1.0.2";

$PROTOCOL = stripos($_SERVER['SERVER_PROTOCOL'], 'https') ? 'https://' : 'http://';
$BASE_PATH = $PROTOCOL . $_SERVER['HTTP_HOST'] . $CONTEXT_ROOT;

$LOG_PATH = ROOT . "/logs/rap-service.log";
$AUDIT_LOG_PATH = ROOT . "/logs/rap-audit.log";
$LOG_LEVEL = Monolog\Logger::DEBUG;

$CALLBACKS = [
    array(
        'url' => 'http://localhost:8087/grouper',
        'title' => 'Login to Grouper',
        'logo' => 'grouper.png'
    ),
    array(
        'url' => 'http://localhost/rap-ia2/',
        'title' => 'Account Management',
        'logo' => 'account-manager.png'
    )
];

$DATABASE = array(
    'dbtype' => 'MySQL',
    'hostname' => 'localhost',
    'port' => 3306,
    'username' => 'XXXXXX',
    'password' => 'XXXXXX',
    'dbname' => 'rap'
);

$AUTHENTICATION_METHODS = array(
    'eduGAIN' => array(),
    'Google' => array(
        'id' => "XXXXXX",
        'secret' => "XXXXXX",
        'callback' => $BASE_PATH . "/auth/social/google_token.php"),
    'Facebook' => array(
        'id' => "XXXXXX",
        'secret' => "XXXXXX",
        'version' => "v3.0",
        'callback' => $BASE_PATH . "/auth/social/facebook_token.php"),
    'LinkedIn' => array(
        'id' => 'XXXXXX',
        'secret' => 'XXXXXX',
        'callback' => $BASE_PATH . '/auth/social/linkedin_token.php'
    ),
    'X.509' => array(),
    'DirectIdP' => array(
        'url' => 'https://sso.ia2.inaf.it/Shibboleth.sso/Login?entityID=https://sso.ia2.inaf.it/idp/shibboleth&target=https://sso.ia2.inaf.it/rap-ia2/auth/saml2/aai.php',
        'logo' => 'img/ia2-logo-60x60.png',
        'logo_alt' => 'IA2 logo',
        'description' => 'Use the IA2 Logo to Login if you have an account provided by IA2 or self registered'
    )
);

$GROUPER = array(
    'wsURL' => 'http://hostname/grouper-ws/',
    'user' => 'XXXXXX',
    'password' => 'XXXXXX'
);
Loading