8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
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 * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
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 * $Id: UMSObject.java,v 1.5 2008/06/25 05:41:46 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * UMSObject class exposes public methods that serve as the entry points to the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * UMS SDK. This class is used to replace the public static methods that are
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * previously available in Session class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * // Previous access class with authenticated context
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * UMSObject.getObject( Context ctx, String guid );
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * UMSObject.removeObject( Context ctx, String guid );
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * UMSObject.logout( Context ctx );
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * // New API with the use of Principal interface that represents an
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * // authenticated principal
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * UMSObject.getObject( java.security.Principal principal, String guid );
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * UMSObject.removeObject(java.security.Principal principal, String guid);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance(IUMSConstants.UMS_DEBUG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static I18n i18n = I18n.getInstance(IUMSConstants.UMS_PKG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the persistent object of correct subclass, for the given id.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The Java class to construct the persistent object is inferred from the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * default creation templates registered with the Template manager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Authenticated principal's single sign on token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param guid GUID identification of the object to get.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the object read, all non operational attributes are read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException if there is an error while instantiating
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the right type of object. In addition, it propagates any
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * exception from the datalayer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static public PersistentObject getObject(SSOToken token, Guid guid)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the persistent object of correct subclass, for the given ID. The
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Java class to construct the persistent object is inferred from the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * default creation templates registered with the Template manager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Authenticated principal's single sign on token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param guid GUID identification of the object to get
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrNames attribute names to read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the object read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException if there is an error while instantiating
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the right type of object. In addition, it propagates any
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * exception from the datalayer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOTokenManager.getInstance().validateToken(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UMSException(i18n.getString(IUMSConstants.INVALID_TOKEN),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UMSException(i18n.getString(IUMSConstants.BAD_TOKEN_HDL),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes an object identified by the given ID.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token Authenticated principal's single sign on token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param guid GUID identification of the object to be removed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws EntryNotFoundException if the entry is not found.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException if there is an error while removing the object from
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * persistence store
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static public void removeObject(SSOToken token, Guid guid)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOTokenManager.getInstance().validateToken(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UMSException(i18n.getString(IUMSConstants.INVALID_TOKEN),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DataLayer.getInstance().deleteEntry(token.getPrincipal(), guid);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UMSException(i18n.getString(IUMSConstants.BAD_TOKEN_HDL),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static PersistentObject getObject(Principal principal, Guid guid)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static PersistentObject getObject(Principal principal, Guid guid,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrSet = DataLayer.getInstance().read(principal, guid);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.arraycopy(attrNames, 0, attrNames1, 0, length);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrSet = DataLayer.getInstance().read(principal, guid, attrNames1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = i18n.getString(IUMSConstants.BAD_ID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Class javaClass = TemplateManager.getTemplateManager()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster po = (PersistentObject) javaClass.newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .getString(IUMSConstants.NEW_INSTANCE_FAILED, args);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Return a PersistentObject given an authenticated token and guid. The
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * validity of the returned PersistentObject can not be guaranteed since the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * object is created in memory, not instantiated from the persistent
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * storage. Using the PersistentObject returned from this method may result
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * exceptions in the later part of the application if the given guid is not
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * valid or represents an entry that does not exist.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Valid and authenticated token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param guid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Globally unique identifier for the entity
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the PersistentObject created in memory
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws UMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for failure to create the object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static PersistentObject getObjectHandle(SSOToken token, Guid guid)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster msg = i18n.getString(IUMSConstants.NULL_TOKEN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("UMSObject.PersistentObject: token is null");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("UMSObject.PersistentObject: dn is null");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOTokenManager.getInstance().validateToken(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UMSException(i18n.getString(IUMSConstants.INVALID_TOKEN),