8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: TokenRestrictionFactory.java,v 1.3 2008/06/25 05:41:29 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
f0e56106ee05e35ce4aa00ba4f47ba1789341ec7Mark de Reeper * Portions Copyrighted 2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.dpro.session;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.encode.Base64;
f0e56106ee05e35ce4aa00ba4f47ba1789341ec7Mark de Reeperimport org.forgerock.openam.utils.IOUtils;
f0e56106ee05e35ce4aa00ba4f47ba1789341ec7Mark de Reeper
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.ByteArrayOutputStream;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.ObjectOutputStream;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Helper class to marshal/unmarshal a Token Restriction object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class TokenRestrictionFactory {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Serializes the restriction object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param tr Token Restriction object to be serialized.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a serialized form of the restriction object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if the there was an error.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static String marshal(TokenRestriction tr) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // perform general Java serialization
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ByteArrayOutputStream bs = new ByteArrayOutputStream();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ObjectOutputStream os = new ObjectOutputStream(bs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster os.writeObject(tr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster os.flush();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster os.close();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return Base64.encode(bs.toByteArray());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Deserialize the string into Token Restriction object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param data Token Restriction object in the string format
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a Token Restriction object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception if the there was an error.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static TokenRestriction unmarshal(String data) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // perform general Java deserialization
f0e56106ee05e35ce4aa00ba4f47ba1789341ec7Mark de Reeper return IOUtils.deserialise(Base64.decode(data), false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}