01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.providers.cas.proxy;
17:
18: import org.acegisecurity.AcegiMessageSource;
19:
20: import org.acegisecurity.providers.cas.CasProxyDecider;
21: import org.acegisecurity.providers.cas.ProxyUntrustedException;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25:
26: import org.springframework.beans.factory.InitializingBean;
27:
28: import org.springframework.context.MessageSource;
29: import org.springframework.context.MessageSourceAware;
30: import org.springframework.context.support.MessageSourceAccessor;
31:
32: import org.springframework.util.Assert;
33:
34: import java.util.List;
35:
36: /**
37: * Accepts no proxied requests.<P>This class should be used if only service tickets wish to be accepted (ie no
38: * proxy tickets at all).</p>
39: */
40: public class RejectProxyTickets implements CasProxyDecider,
41: MessageSourceAware, InitializingBean {
42: //~ Static fields/initializers =====================================================================================
43:
44: private static final Log logger = LogFactory
45: .getLog(RejectProxyTickets.class);
46:
47: //~ Instance fields ================================================================================================
48:
49: protected MessageSourceAccessor messages = AcegiMessageSource
50: .getAccessor();
51:
52: //~ Methods ========================================================================================================
53:
54: public void afterPropertiesSet() throws Exception {
55: Assert.notNull(this .messages, "A message source must be set");
56: }
57:
58: public void confirmProxyListTrusted(List proxyList)
59: throws ProxyUntrustedException {
60: Assert.notNull(proxyList, "proxyList cannot be null");
61:
62: if (proxyList.size() == 0) {
63: // A Service Ticket (not a Proxy Ticket)
64: return;
65: }
66:
67: if (logger.isDebugEnabled()) {
68: logger
69: .debug("Proxies are unacceptable; proxy list provided: "
70: + proxyList.toString());
71: }
72:
73: throw new ProxyUntrustedException(messages.getMessage(
74: "RejectProxyTickets.reject",
75: "Proxy tickets are rejected"));
76: }
77:
78: public void setMessageSource(MessageSource messageSource) {
79: this .messages = new MessageSourceAccessor(messageSource);
80: }
81: }
|