001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security.spi;
018:
019: import java.sql.Date;
020: import java.util.Set;
021:
022: import org.apache.jetspeed.security.SecurityException;
023:
024: /**
025: * <p>
026: * This interface encapsulates the handling of security credentials.
027: * </p>
028: * <p>
029: * This provides a central placeholder for changing the mapping of user
030: * credentials. The default implementation only supports <code>PasswordCredential</code>
031: * </p>
032: * <p>
033: * A security implementation wanting to map additional credentials should do so
034: * here.
035: * </p>
036: *
037: * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
038: */
039: public interface CredentialHandler {
040: /**
041: * <p>
042: * Gets the public credentials for the user.
043: * </p>
044: *
045: * @param username The username.
046: * @return The set of public credentials.
047: */
048: Set getPublicCredentials(String username);
049:
050: /**
051: * <p>
052: * Gets the private credentials for the user.
053: * </p>
054: *
055: * @param username The username.
056: * @return The set of private credentials.
057: */
058: Set getPrivateCredentials(String username);
059:
060: /**
061: * <p>
062: * Adds or updates a private password credential.<br>
063: * Note that there is no checking of the <code>oldPassword</code> and the provided password is
064: * assumed to be encoded. Hence no encoding will take place.
065: *
066: * </p>
067: *
068: * @param username The user to be updated.
069: * @param newPassword The new password.
070: * @throws SecurityException Throws a {@link SecurityException}.
071: */
072: void importPassword(String userName, String newPassword)
073: throws SecurityException;
074:
075: /**
076: * <p>
077: * Adds or updates a private password credential.<br>
078: * If <code>oldPassword</code> is not null, the oldPassword will first be checked (authenticated).<br>
079: * </p>
080: *
081: * @param username The user to be updated.
082: * @param oldPassword The old password.
083: * @param newPassword The new password.
084: * @throws SecurityException Throws a {@link SecurityException}.
085: */
086: void setPassword(String userName, String oldPassword,
087: String newPassword) throws SecurityException;
088:
089: /**
090: * <p>
091: * Set the update required state of the user password credential.
092: * </p>
093: *
094: * @param userName The user name.
095: * @param updateRequired The update required state.
096: * @throws Throws a security exception.
097: */
098: void setPasswordUpdateRequired(String userName,
099: boolean updateRequired) throws SecurityException;
100:
101: /**
102: * <p>
103: * Set the enabled state of the user password credential.
104: * </p>
105: *
106: * @param userName The user name.
107: * @param enabled The enabled state.
108: * @throws Throws a security exception.
109: */
110: void setPasswordEnabled(String userName, boolean enabled)
111: throws SecurityException;
112:
113: /**
114: * <p>
115: * Set the expiration date and the expired flag of the password credential.</p>
116: * <p>
117: * If a date equal or before the current date is provided, the expired flag will be set to true,
118: * otherwise to false.</p>
119: *
120: * @param userName The user name.
121: * @param expirationDate The expiration date to set.
122: * @throws Throws a security exception.
123: */
124: void setPasswordExpiration(String userName, Date expirationDate)
125: throws SecurityException;
126:
127: /**
128: * <p>
129: * Authenticate a user.
130: * </p>
131: *
132: * @param userName The user name.
133: * @param password The user password.
134: * @return Whether or not a user is authenticated.
135: */
136: boolean authenticate(String userName, String password)
137: throws SecurityException;
138: }
|