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