001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.extensions; 028 029 030 031 import java.util.Arrays; 032 033 import org.opends.messages.Message; 034 import org.opends.server.admin.std.server.ClearPasswordStorageSchemeCfg; 035 import org.opends.server.api.PasswordStorageScheme; 036 import org.opends.server.config.ConfigException; 037 import org.opends.server.types.ByteString; 038 import org.opends.server.types.ByteStringFactory; 039 import org.opends.server.types.DirectoryException; 040 import org.opends.server.types.InitializationException; 041 import org.opends.server.types.ResultCode; 042 043 import static org.opends.messages.ExtensionMessages.*; 044 import static org.opends.server.extensions.ExtensionsConstants.*; 045 046 047 048 /** 049 * This class defines a Directory Server password storage scheme that will store 050 * the values in clear-text with no encoding at all. This is not at all secure 051 * but may be required for backward-compatibility and support for certain legacy 052 * applications. 053 */ 054 public class ClearPasswordStorageScheme 055 extends PasswordStorageScheme<ClearPasswordStorageSchemeCfg> 056 { 057 /** 058 * Creates a new instance of this password storage scheme. Note that no 059 * initialization should be performed here, as all initialization should be 060 * done in the <CODE>initializePasswordStorageScheme</CODE> method. 061 */ 062 public ClearPasswordStorageScheme() 063 { 064 super(); 065 } 066 067 068 069 /** 070 * {@inheritDoc} 071 */ 072 @Override() 073 public void initializePasswordStorageScheme( 074 ClearPasswordStorageSchemeCfg configuration) 075 throws ConfigException, InitializationException 076 { 077 // No initialization is required. 078 } 079 080 081 082 /** 083 * {@inheritDoc} 084 */ 085 @Override() 086 public String getStorageSchemeName() 087 { 088 return STORAGE_SCHEME_NAME_CLEAR; 089 } 090 091 092 093 /** 094 * {@inheritDoc} 095 */ 096 @Override() 097 public ByteString encodePassword(ByteString plaintext) 098 throws DirectoryException 099 { 100 return plaintext.duplicate(); 101 } 102 103 104 105 /** 106 * {@inheritDoc} 107 */ 108 @Override() 109 public ByteString encodePasswordWithScheme(ByteString plaintext) 110 throws DirectoryException 111 { 112 StringBuilder buffer = new StringBuilder(); 113 buffer.append('{'); 114 buffer.append(STORAGE_SCHEME_NAME_CLEAR); 115 buffer.append('}'); 116 buffer.append(plaintext.stringValue()); 117 118 return ByteStringFactory.create(buffer.toString()); 119 } 120 121 122 123 /** 124 * {@inheritDoc} 125 */ 126 @Override() 127 public boolean passwordMatches(ByteString plaintextPassword, 128 ByteString storedPassword) 129 { 130 return Arrays.equals(plaintextPassword.value(), storedPassword.value()); 131 } 132 133 134 135 /** 136 * {@inheritDoc} 137 */ 138 @Override() 139 public boolean isReversible() 140 { 141 return true; 142 } 143 144 145 146 /** 147 * {@inheritDoc} 148 */ 149 @Override() 150 public ByteString getPlaintextValue(ByteString storedPassword) 151 throws DirectoryException 152 { 153 return storedPassword.duplicate(); 154 } 155 156 157 158 /** 159 * {@inheritDoc} 160 */ 161 @Override() 162 public boolean supportsAuthPasswordSyntax() 163 { 164 // This storage scheme does not support the authentication password syntax. 165 return false; 166 } 167 168 169 170 /** 171 * {@inheritDoc} 172 */ 173 @Override() 174 public ByteString encodeAuthPassword(ByteString plaintext) 175 throws DirectoryException 176 { 177 Message message = 178 ERR_PWSCHEME_DOES_NOT_SUPPORT_AUTH_PASSWORD.get(getStorageSchemeName()); 179 throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); 180 } 181 182 183 184 /** 185 * {@inheritDoc} 186 */ 187 @Override() 188 public boolean authPasswordMatches(ByteString plaintextPassword, 189 String authInfo, String authValue) 190 { 191 // This storage scheme does not support the authentication password syntax. 192 return false; 193 } 194 195 196 197 /** 198 * {@inheritDoc} 199 */ 200 @Override() 201 public ByteString getAuthPasswordPlaintextValue(String authInfo, 202 String authValue) 203 throws DirectoryException 204 { 205 Message message = 206 ERR_PWSCHEME_DOES_NOT_SUPPORT_AUTH_PASSWORD.get(getStorageSchemeName()); 207 throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); 208 } 209 210 211 212 /** 213 * {@inheritDoc} 214 */ 215 @Override() 216 public boolean isStorageSchemeSecure() 217 { 218 // Clear-text passwords are not obscured in any way. 219 return false; 220 } 221 } 222