1 /** 2 * Copyright 2005-2011 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.rice.ksb.security.credentials; 17 18 import org.kuali.rice.core.api.security.credentials.Credentials; 19 import org.kuali.rice.core.api.security.credentials.CredentialsSource; 20 import org.kuali.rice.core.api.security.credentials.CredentialsType; 21 import org.springframework.util.Assert; 22 23 /** 24 * Implementation of a CredentialsSource that contains a username and password. 25 * <p> 26 * Note that this implementation is for service-to-service authentication. It 27 * cannot handle user-to-service authentication. 28 * 29 * @author Kuali Rice Team (rice.collab@kuali.org) 30 * @since 0.9 31 */ 32 public final class UsernamePasswordCredentialsSource implements CredentialsSource { 33 34 /** The username. */ 35 private final String username; 36 37 /** The password. */ 38 private final String password; 39 40 public Credentials getCredentials(final String serviceEndpoint) { 41 return new UsernamePasswordCredentials(username, password); 42 } 43 44 /** 45 * Constructor that accepts the username and password for which to construct 46 * UsernamePasswordAuthenticationToken's from. 47 * 48 * @param username the username. 49 * @param password the password. 50 */ 51 public UsernamePasswordCredentialsSource(final String username, 52 final String password) { 53 Assert.notNull(username, "username cannot be null."); 54 Assert.notNull(password, "password cannote be null."); 55 56 this.username = username; 57 this.password = password; 58 } 59 60 public CredentialsType getSupportedCredentialsType() { 61 return CredentialsType.USERNAME_PASSWORD; 62 } 63 }