001/*
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: AdminPasswordAction.java,v 1.5 2008/08/19 19:09:21 veiming Exp $
026 *
027 * Portions Copyrighted 2015 ForgeRock AS.
028 */
029
030package com.sun.identity.security;
031
032import java.security.PrivilegedAction;
033
034import com.iplanet.am.util.AdminUtils;
035
036/**
037 * 
038 * The class is used to perform privileged operations using
039 * <code>AccessController.doPrivileged()
040 * </code> when using
041 * <code> com.iplanet.am.util.AdminUtils</code> to obtain Administrator
042 * passwords. Ths class implements the interface <code>PrivilegedAction</code>
043 * with a non-default constructor. * This class should be used in order to
044 * perform the privileged operation of
045 * <code> com.iplanet.am.util.AdminUtils.getAdminPassword()</code>.
046 * 
047 * <PRE>
048 * 
049 * This line of code: String adminDN =
050 * com.iplanet.am.util.AdminUtils.getAdminDN(); should be replaced with: String
051 * adminDN = (String) AccessController.doPrivileged( new AdminPasswordAction());
052 * If this is not done and Java security permissions check is enabled, then the
053 * operation will fail and return a null everytime.
054 * 
055 * Note: Java security permissions check for OpenAM can be enabled
056 * by setting the property <code>com.sun.identity.security.checkcaller</code> to
057 * true in AMConfig properties file.
058 * 
059 * </PRE>
060 *
061 * @supported.all.api
062 */
063public class AdminPasswordAction implements PrivilegedAction {
064
065    /**
066     * Default constructor
067     */
068    public AdminPasswordAction() {
069        super();
070    }
071
072    /*
073     * (non-Javadoc)
074     * 
075     * @see java.security.PrivilegedAction#run()
076     */
077    public Object run() {
078        if (AdminUtils.getAdminPassword()==null) {
079            return null;
080        }
081        return new String(AdminUtils.getAdminPassword());
082    }
083
084}