AuthenticateScript.groovy revision 4b3769ce483ece06f60f983193712492b920144f
4b3769ce483ece06f60f983193712492b920144fJake Feasel/*
4b3769ce483ece06f60f983193712492b920144fJake Feasel *
4b3769ce483ece06f60f983193712492b920144fJake Feasel * Copyright (c) 2014 ForgeRock Inc. All Rights Reserved
4b3769ce483ece06f60f983193712492b920144fJake Feasel *
4b3769ce483ece06f60f983193712492b920144fJake Feasel * The contents of this file are subject to the terms
4b3769ce483ece06f60f983193712492b920144fJake Feasel * of the Common Development and Distribution License
4b3769ce483ece06f60f983193712492b920144fJake Feasel * (the License). You may not use this file except in
4b3769ce483ece06f60f983193712492b920144fJake Feasel * compliance with the License.
4b3769ce483ece06f60f983193712492b920144fJake Feasel *
4b3769ce483ece06f60f983193712492b920144fJake Feasel * You can obtain a copy of the License at
4b3769ce483ece06f60f983193712492b920144fJake Feasel * http://www.opensource.org/licenses/cddl1.php or
4b3769ce483ece06f60f983193712492b920144fJake Feasel * OpenIDM/legal/CDDLv1.0.txt
4b3769ce483ece06f60f983193712492b920144fJake Feasel * See the License for the specific language governing
4b3769ce483ece06f60f983193712492b920144fJake Feasel * permission and limitations under the License.
4b3769ce483ece06f60f983193712492b920144fJake Feasel *
4b3769ce483ece06f60f983193712492b920144fJake Feasel * When distributing Covered Code, include this CDDL
4b3769ce483ece06f60f983193712492b920144fJake Feasel * Header Notice in each file and include the License file
4b3769ce483ece06f60f983193712492b920144fJake Feasel * at OpenIDM/legal/CDDLv1.0.txt.
4b3769ce483ece06f60f983193712492b920144fJake Feasel * If applicable, add the following below the CDDL Header,
4b3769ce483ece06f60f983193712492b920144fJake Feasel * with the fields enclosed by brackets [] replaced by
4b3769ce483ece06f60f983193712492b920144fJake Feasel * your own identifying information:
4b3769ce483ece06f60f983193712492b920144fJake Feasel * "Portions Copyrighted 2010 [name of copyright owner]"
4b3769ce483ece06f60f983193712492b920144fJake Feasel *
4b3769ce483ece06f60f983193712492b920144fJake Feasel * $Id$
4b3769ce483ece06f60f983193712492b920144fJake Feasel */
4b3769ce483ece06f60f983193712492b920144fJake Feaselimport groovy.sql.Sql;
4b3769ce483ece06f60f983193712492b920144fJake Feaselimport org.identityconnectors.framework.common.exceptions.InvalidPasswordException;
4b3769ce483ece06f60f983193712492b920144fJake Feasel
4b3769ce483ece06f60f983193712492b920144fJake Feasel// Parameters:
4b3769ce483ece06f60f983193712492b920144fJake Feasel// The connector sends the following:
4b3769ce483ece06f60f983193712492b920144fJake Feasel// connection
4b3769ce483ece06f60f983193712492b920144fJake Feasel// configuration
4b3769ce483ece06f60f983193712492b920144fJake Feasel// action ("AUTHENTICATE")
4b3769ce483ece06f60f983193712492b920144fJake Feasel// log
4b3769ce483ece06f60f983193712492b920144fJake Feasel// objectClass
4b3769ce483ece06f60f983193712492b920144fJake Feasel// options
4b3769ce483ece06f60f983193712492b920144fJake Feasel// username
4b3769ce483ece06f60f983193712492b920144fJake Feasel// password
4b3769ce483ece06f60f983193712492b920144fJake Feasel
4b3769ce483ece06f60f983193712492b920144fJake Feasel// It is expected that an authentication failure will throw an error from the package org.identityconnectors.framework.common.exceptions
4b3769ce483ece06f60f983193712492b920144fJake Feasel
4b3769ce483ece06f60f983193712492b920144fJake Feasellog.info("Entering "+action+" Script");
4b3769ce483ece06f60f983193712492b920144fJake Feaseldef sql = new Sql(connection);
4b3769ce483ece06f60f983193712492b920144fJake Feaseldef authId = null;
4b3769ce483ece06f60f983193712492b920144fJake Feasel
4b3769ce483ece06f60f983193712492b920144fJake Feaselsql.eachRow("SELECT uid FROM Users WHERE uid = ? AND password = sha2(?, 512)", [username, password]) { authId = it.uid }
4b3769ce483ece06f60f983193712492b920144fJake Feasel
4b3769ce483ece06f60f983193712492b920144fJake Feaselif (authId == null) {
4b3769ce483ece06f60f983193712492b920144fJake Feasel throw new InvalidPasswordException("Authentication Failed")
4b3769ce483ece06f60f983193712492b920144fJake Feasel}
4b3769ce483ece06f60f983193712492b920144fJake Feasel
4b3769ce483ece06f60f983193712492b920144fJake Feaselreturn authId