JavaCloud.Models.Token.java Source code

Java tutorial

Introduction

Here is the source code for JavaCloud.Models.Token.java

Source

/**
 * Copyright (c) 2014 Marta Nabozny, Maciej Nabozny
 *
 * This file is part of OverCluster project.
 *
 * OverCluster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package JavaCloud.Models;

import JavaCloud.CoreException;
import JavaCloud.Utils;
import org.json.simple.JSONObject;

public class Token {
    String address;
    String login;
    String password;
    String seed;

    public int id;
    public String token;
    public String name;
    public String valid_to;
    public String creation_date;
    public String function_filter;

    public Token(String address, String login, String password, String seed, JSONObject token_dict) {
        this.address = address;
        this.login = login;
        this.password = password;
        this.seed = seed;

        id = Integer.parseInt(token_dict.get("id").toString());
        name = token_dict.get("name").toString();
        token = token_dict.get("token").toString();
        valid_to = token_dict.get("valid_to").toString();
        creation_date = token_dict.get("creation_date").toString();
        function_filter = token_dict.get("function_filter").toString();
    }

    public String toString() {
        return name;
    }

    public void delete() throws CoreException {
        JSONObject object = new JSONObject();
        object.put("login", login);
        object.put("pw_hash", Utils.calcHash(password, seed));
        object.put("token_id", id);
        Utils.request(address, "/user/token/delete/", object);
    }
}