All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.coos.module.ACMessageFactory Maven / Gradle / Ivy

The newest version!
/**
 * COOS - Connected Objects Operating System (www.connectedobjects.org).
 *
 * Copyright (C) 2009 Telenor ASA and Tellu AS. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 *
 * You may also contact one of the following for additional information:
 * Telenor ASA, Snaroyveien 30, N-1331 Fornebu, Norway (www.telenor.no)
 * Tellu AS, Hagalokkveien 13, N-1383 Asker, Norway (www.tellu.no)
 */
package org.coos.module;

import java.util.Hashtable;

import org.coos.messaging.Message;
import org.coos.messaging.impl.DefaultMessage;


public class ACMessageFactory {

    public static String AC_REQUEST_CHECKTOKEN = "ac_request_checktoken";
    public static String AC_REQUEST_LOGIN = "ac_request_login";

    /**
     * Request login by username/password.
     *
     * @param username
     * @param password
     * @return AC_PROP_TOKEN (XML token in a String) or AC_PROP_ERROR_MESSAGE
     *         (String) if something went wrong.
     */
    public static Message createLoginMsg(String username, String password) {
        Message msg = new DefaultMessage(AC_REQUEST_LOGIN);
        Hashtable props = new Hashtable();
        props.put(ACConstants.AC_PROP_USERNAME, username);
        props.put(ACConstants.AC_PROP_PASSWORD, password);
        msg.setBody(props);

        return msg;
    }

    /**
     * Check the validity of a given token.
     *
     * @param token
     * @return AC_PROP_TOKENCHECK (boolean) or AC_PROP_ERROR_MESSAGE (String) if
     *         something went wrong.
     */
    public static Message createCheckTokenMsg(String token) {
        Message msg = new DefaultMessage(AC_REQUEST_CHECKTOKEN);
        Hashtable props = new Hashtable();
        props.put(ACConstants.AC_PROP_TOKEN, token);
        msg.setBody(props);

        return msg;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy