001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.ksb.security.credentials;
017    
018    import org.kuali.rice.core.api.security.credentials.Credentials;
019    import org.kuali.rice.core.api.security.credentials.CredentialsSource;
020    import org.kuali.rice.core.api.security.credentials.CredentialsType;
021    import org.springframework.util.Assert;
022    
023    /**
024     * Implementation of a CredentialsSource that contains a username and password.
025     * <p>
026     * Note that this implementation is for service-to-service authentication. It
027     * cannot handle user-to-service authentication.
028     * 
029     * @author Kuali Rice Team (rice.collab@kuali.org)
030     * @since 0.9
031     */
032    public final class UsernamePasswordCredentialsSource implements CredentialsSource {
033    
034        /** The username. */
035        private final String username;
036    
037        /** The password. */
038        private final String password;
039    
040        public Credentials getCredentials(final String serviceEndpoint) {
041            return new UsernamePasswordCredentials(username, password);
042            }
043    
044            /**
045         * Constructor that accepts the username and password for which to construct
046         * UsernamePasswordAuthenticationToken's from.
047         * 
048         * @param username the username.
049         * @param password the password.
050         */
051        public UsernamePasswordCredentialsSource(final String username,
052            final String password) {
053            Assert.notNull(username, "username cannot be null.");
054            Assert.notNull(password, "password cannote be null.");
055    
056            this.username = username;
057            this.password = password;
058        }
059        
060        public CredentialsType getSupportedCredentialsType() {
061            return CredentialsType.USERNAME_PASSWORD;
062        }
063    }