Token.java revision 1b5cb8422c825dbdc6d7669e74f285cede6ab71c
/**
* Copyright 2013-2015 ForgeRock AS.
*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*/
/**
* A simple domain value responsible for modelling a Core Token Service Token. This container is intended
* to be generic and has little knowledge of the data it is storing.
*
* The Token is backed by the CoreTokenField enumeration which contains the known fields that can be
* written to. Every value being stored must be mapped to one of these CoreTokenFields.
*
* There are some read only fields which can only be set during initialisation of the Token.
*
* The Token models the data stored in two ways. Firstly the primary fields of the Token are accessible
* via getters and setters. All other fields are accessed in a more generic way.
*
* @author robert.wapshott@forgerock.com
*/
public class Token {
/**
* Note: This map stores all data for the Token. It is intentionally using a String to Object mapping
* rather than a CoreTokenField based key because this works better with Jackson based JSON
* serialisation.
*/
/**
* Private constructor performs some initialisation to ensure the main fields appear
* in a consistent manner when performing a toString on this Token.
*/
private Token() {
}
/**
* Create an instance of the Token.
*
* @param tokenId Required field which cannot be null.
* @param type Required to define the type of Token.
*/
this();
throw new IllegalArgumentException("Arguments cannot be null.");
}
}
/**
* Copy constructor will create a shallow-copy of the provided Token.
*
* @param copy Non null Token to copy.
*/
}
}
/**
* @return The unique id for this Token.
*/
public String getTokenId() {
}
/**
* @return The TokenType of the Token.
*/
}
/**
* @return The unique id for the user.
*/
}
/**
* @param userId The unique id for the user.
*/
}
/**
* @return The timestamp (with timezone information) when the Token is due to expire.
*/
public Calendar getExpiryTimestamp() {
}
/**
* @param expiryDate Assign the timestamp of when the Token will expire.
*/
}
/**
* A binary representation of the Token being stored can be placed in the Token.
*
* This ensures that attributes that are not modelled at the Token level can still be
* persisted.
*
* @return The the serialised binary object for this Token.
*/
public byte[] getBlob() {
}
/**
* @param data Assign the binary data that represents the object being stored in the Token.
*/
}
/**
* The Token supports being accessed in a generic way allowing a caller to iterate
* over all fields that are assigned in this token.
*
* @return A non null, non modifiable list of the CoreTokenField fields currently assigned.
*/
continue;
}
}
}
/**
* Accessor for the non-primary CoreTokenField attributes.
*
* @param field The CoreTokenField to request the value for.
* @return The value assigned which may be null.
*/
}
/**
* Mutator for the non-primary fields of the Token.
*
* @param field The CoreTokenField field to store the value against.
* @param value The possibly null value to store in this Token.
*/
if (isFieldReadOnly(field)) {
"Token Field {0} is read only and cannot be set.",
}
// Validate that the type matches the field they are assigning.
try {
} catch (CoreTokenException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
/**
* Clear a set attribute.
*
* Regardless of whether the attribute was set, it will be cleared as a result of this call.
*
* @param field Non null field to clear.
*/
}
/**
* Trying to change a read-only field will trigger a runtime exception.
*
* @param field The CoreTokenField to check.
* @return True if the field is read only, and cannot be changed once assigned.
*/
return true;
}
return true;
}
return false;
}
/**
* Store a value in the map.
*
* Note: We are performing conversions based on the field because it has been found that
* the Jackson based JSON encoding doesn't handle all data types equally well.
*
* @param field Non null
* @param value May be null
*/
String s;
s = null;
} else {
}
}
/**
* Get a value in the map.
*
* Note: We are performing conversions based on the field because it has been found that
* the Jackson based JSON encoding doesn't handle all data types equally well.
*
* @param field Non null
* @return May be null
*/
if (s == null) {
return null;
} else {
return s;
}
}
}
/**
* Returns a formatted version fo the Token which is intended to be human readable.
* Some of the field values have been formatted to ensure that their contents are more
* meaningful.
*
* for debugging use only as its conversion logic will not be performant.
*
* @return Non null string which describes the Token.
*/
} else {
}
value = "[null]";
}
}
return r;
}
}