View Javadoc

1   /**
2    * Copyright 2005-2013 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.kim.client.acegi;
17  
18  import org.acegisecurity.AuthenticationException;
19  import org.acegisecurity.userdetails.UserDetails;
20  import org.acegisecurity.userdetails.UserDetailsService;
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.springframework.util.Assert;
24  
25  /**
26   * Populates the <code>UserDetails</code> associated with a CAS 
27   * authenticated user by reading the response.  This is required to pass
28   * the Distributed Session Ticket around.
29   *  
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   *
32   */
33  public class KualiCasAuthoritiesPopulatorImpl implements KualiCasAuthoritiesPopulator {
34      private KualiUserDetailsService userDetailsService;
35      private static final Log logger = LogFactory.getLog(KualiCasAuthoritiesPopulatorImpl.class);
36  
37      
38      /**
39       * This method validates the Spring configuration
40       * 
41       * @throws Exception
42       */
43      public void afterPropertiesSet() throws Exception {
44          Assert.notNull(this.userDetailsService, "A UserDetailsService must be set");
45      }
46      
47      /**
48       * @param userDetailsService the UserDetailsService to set
49       */
50      public void setUserDetailsService(UserDetailsService userDetailsService) {
51          this.userDetailsService = (KualiUserDetailsService)userDetailsService;
52      }
53      
54      /**
55       * This overridden method should never be used but is required by the 
56       * UserDetails interface
57       * 
58       * @see org.acegisecurity.providers.cas.CasAuthoritiesPopulator#getUserDetails(java.lang.String)
59       */
60      public UserDetails getUserDetails(String casUserId)
61          throws AuthenticationException {
62          if (logger.isDebugEnabled()) {
63              logger.debug("getUserDetails(userID)");
64          }
65          return this.userDetailsService.loadUserByUsername(casUserId);
66      }
67      
68      /**
69       * This overridden method is used to pass the Distributed Session 
70       * Ticket around via the {@link KualiTicketResponse}
71       * 
72       * @see org.kuali.rice.kim.client.acegi.KualiCasAuthoritiesPopulator#getUserDetails(org.kuali.rice.kim.client.acegi.KualiTicketResponse)
73       */
74      public UserDetails getUserDetails(KualiTicketResponse response) 
75          throws AuthenticationException {
76          if (logger.isDebugEnabled()) {
77              logger.debug("getUserDetails(response)");
78          }
79          return this.userDetailsService.loadUserByTicketResponse(response);
80      }
81  
82  }