01: /*
02: * Copyright 2005 - 2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.kuali.bus.security.credentials;
18:
19: import java.io.IOException;
20:
21: import org.acegisecurity.context.SecurityContextHolder;
22: import org.acegisecurity.providers.cas.CasAuthenticationToken;
23: import org.acegisecurity.ui.cas.CasProcessingFilter;
24: import org.kuali.rice.security.credentials.Credentials;
25: import org.kuali.rice.security.credentials.CredentialsSource;
26:
27: import edu.yale.its.tp.cas.proxy.ProxyTicketReceptor;
28:
29: /**
30: * Retrieves a proxy ticket for the user based on their provided Proxy Granting
31: * Ticket. This assumes that the Proxy GrantingTicket is available from a
32: * ThreadLocal and that the service is protected by Acegi.
33: * <p>
34: * Note: this class can be used for user-to-service authentication.
35: * <p>
36: * This assumes the services are stateless and will not maintain an HttpSession
37: * so each call for credentials will result in a new Proxy Ticket being granted.
38: *
39: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
40: * @version $Revision: 1.2.24.1 $ $Date: 2007/10/17 20:32:05 $
41: * @since 0.9
42: * @see ThreadLocal
43: * @see ProxyTicketReceptor
44: */
45: public final class CasProxyTicketCredentialsSource implements
46: CredentialsSource {
47:
48: public Credentials getCredentials(final String serviceEndpoint) {
49: final String proxyGrantingTicketIou = ((CasAuthenticationToken) (SecurityContextHolder
50: .getContext()).getAuthentication())
51: .getProxyGrantingTicketIou();
52: try {
53: final String proxyTicket = ProxyTicketReceptor
54: .getProxyTicket(proxyGrantingTicketIou,
55: serviceEndpoint);
56: return new UsernamePasswordCredentials(
57: CasProcessingFilter.CAS_STATELESS_IDENTIFIER,
58: proxyTicket);
59: } catch (final IOException e) {
60: return null;
61: }
62: }
63:
64: public CredentialsType getSupportedCredentialsType() {
65: return CredentialsType.CAS;
66: }
67: }
|