bali.registry.Context.java Source code

Java tutorial

Introduction

Here is the source code for bali.registry.Context.java

Source

/************************************************************************
 * Copyright (c) Crater Dog Technologies(TM).  All Rights Reserved.     *
 ************************************************************************
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.        *
 *                                                                      *
 * This code is free software; you can redistribute it and/or modify it *
 * under the terms of The MIT License (MIT), as published by the Open   *
 * Source Initiative. (See http://opensource.org/licenses/MIT)          *
 ************************************************************************/
package bali.registry;

import craterdog.primitives.Tag;
import org.joda.time.DateTime;

/**
 * This class captures the context information about the account that is making a request on an API.  The
 * private key for the specified account must be used to sign the entire request, and the signature must
 * be passed along in the context so that the service implementing the API can authenticate and authorize
 * the account making the request.
 *
 * @author Derk Norton
 */
public final class Context {

    /**
     * The identifier for the account making the request.
     */
    public final Tag accountTag;

    /**
     * A galactically unique identifier associated with this request and no other request across all space
     * and time.
     */
    public final Tag requestTag;

    /**
     * The signature of the request, created with the private key for the account.
     */
    public final byte[] signature;

    /**
     * The timestamp of when the request was made.
     */
    public final DateTime timestamp;

    /**
     * The attempt number for this request.  This number will start at one and be incremented each time a
     * request is retried after a timeout.
     */
    public int attempt;

    /**
     * This constructor takes the account identifier and the signature for the request and creates a
     * account context that can be used by the services implementing the API to authenticate and
     * authorize the request before executing it.
     *
     * @param accountTag The identifier for the account making the request.
     * @param signature A signature generated using the private key of the account.
     */
    public Context(Tag accountTag, byte[] signature) {
        this.accountTag = accountTag;
        this.requestTag = new Tag();
        this.signature = signature;
        this.timestamp = new DateTime();
        this.attempt = 1;
    }

}