1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.providers.cas.proxy;
17
18 import java.util.List;
19
20 import org.acegisecurity.AcegiMessageSource;
21 import org.acegisecurity.providers.cas.CasProxyDecider;
22 import org.acegisecurity.providers.cas.ProxyUntrustedException;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.springframework.beans.factory.InitializingBean;
26 import org.springframework.context.MessageSource;
27 import org.springframework.context.MessageSourceAware;
28 import org.springframework.context.support.MessageSourceAccessor;
29 import org.springframework.util.Assert;
30
31
32 /***
33 * Accepts proxied requests if the closest proxy is named in the
34 * <code>validProxies</code> list.
35 *
36 * <P>
37 * Also accepts the request if there was no proxy (ie the user directly
38 * authenticated against this service).
39 * </p>
40 */
41 public class NamedCasProxyDecider implements CasProxyDecider, InitializingBean,
42 MessageSourceAware {
43
44
45 private static final Log logger = LogFactory.getLog(NamedCasProxyDecider.class);
46
47
48
49 private List validProxies;
50 protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
51
52
53
54 public void afterPropertiesSet() throws Exception {
55 Assert.notNull(this.validProxies, "A validProxies list must be set");
56 Assert.notNull(this.messages, "A message source must be set");
57 }
58
59 public void confirmProxyListTrusted(List proxyList)
60 throws ProxyUntrustedException {
61 Assert.notNull(proxyList, "proxyList cannot be null");
62
63 if (logger.isDebugEnabled()) {
64 logger.debug("Proxy list: " + proxyList.toString());
65 }
66
67 if (proxyList.size() == 0) {
68
69 return;
70 }
71
72 if (!validProxies.contains(proxyList.get(0))) {
73 throw new ProxyUntrustedException(messages.getMessage(
74 "NamedCasProxyDecider.untrusted",
75 new Object[] {proxyList.get(0)},
76 "Nearest proxy {0} is untrusted"));
77 }
78 }
79
80 public List getValidProxies() {
81 return validProxies;
82 }
83
84 public void setMessageSource(MessageSource messageSource) {
85 this.messages = new MessageSourceAccessor(messageSource);
86 }
87
88 public void setValidProxies(List validProxies) {
89 this.validProxies = validProxies;
90 }
91 }