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: EncryptAction.java,v 1.4 2008/08/19 19:14:56 veiming Exp $ 026 * 027 */ 028 029package com.sun.identity.security; 030 031import java.security.PrivilegedAction; 032 033import com.iplanet.am.util.AMPasswordUtil; 034 035/** 036 * 037 * The class is used to perform privileged operation with 038 * <code>AccessController.doPrivileged() 039 * </code> when using 040 * <code> com.iplanet.am.util.AMPasswordUtil</code> to encrypt passwords. Ths 041 * class implements the interface <code> 042 * PrivilegedAction </code> with a 043 * non-default constructor. This class should be used in order to perform the 044 * privileged operation of 045 * <code> com.iplanet.am.util.AMPasswordUtil.encrypt()</code>. 046 * 047 * <PRE> 048 * 049 * This line of code: String encStr = 050 * com.iplanet.am.util.AMPasswordUtil.encrypt(str); should be replaced with: 051 * String encStr = (String) AccessController.doPrivileged( new 052 * EncryptAction(str)); If this is not done and Java security permissions check 053 * is enabled, then the operation will fail and return a null everytime. 054 * 055 * Note: Java security permissions check for OpenSSO can be enabled by 056 * 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 EncryptAction implements PrivilegedAction { 064 protected String value; 065 066 /** 067 * Non default constructor to be used when a <code>doPrivileged()</code> 068 * is performed for encryption operations. 069 * 070 * @param svalue 071 * Value of string to be encoded/decoded 072 * 073 */ 074 public EncryptAction(String svalue) { 075 super(); 076 value = svalue; 077 } 078 079 /* 080 * (non-Javadoc) 081 * 082 * @see java.security.PrivilegedAction#run() 083 */ 084 public Object run() { 085 return AMPasswordUtil.encrypt(value); 086 } 087 088}