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.kim.client.acegi;
017
018 import org.acegisecurity.Authentication;
019 import org.acegisecurity.AuthenticationException;
020 import org.acegisecurity.GrantedAuthority;
021 import org.acegisecurity.GrantedAuthorityImpl;
022 import org.acegisecurity.providers.AuthenticationProvider;
023 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
024 import org.apache.commons.logging.Log;
025 import org.apache.commons.logging.LogFactory;
026
027 /**
028 * This is the out of box authentication method used by rice. It authenticates any username/password pairs that match
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 *
032 */
033 public class KualiTestAuthenticationProvider implements AuthenticationProvider {
034
035 public Authentication authenticate(Authentication authentication)
036 throws AuthenticationException {
037
038 if (authentication.getPrincipal().equals(authentication.getCredentials())) {
039 Authentication auth = authenticateNow(authentication);
040 return auth;
041 } else {
042 return authentication;
043 }
044 }
045
046 private UsernamePasswordAuthenticationToken authenticateNow(Authentication authentication) throws AuthenticationException {
047 return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_KUALI_USER")});
048 }
049
050 public boolean supports(Class authentication) {
051 if (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)) {
052 return true;
053 } else {
054 return false;
055 }
056 }
057 }