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