1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.acegi;
12
13 import org.mule.api.lifecycle.InitialisationException;
14 import org.mule.api.security.Authentication;
15 import org.mule.api.security.SecurityException;
16 import org.mule.security.AbstractSecurityProvider;
17
18 import java.util.Map;
19
20 import org.acegisecurity.AuthenticationException;
21 import org.acegisecurity.providers.AuthenticationProvider;
22 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
23
24
25
26
27
28 public class AcegiProviderAdapter extends AbstractSecurityProvider implements AuthenticationProvider
29 {
30 private AuthenticationProvider delegate;
31 private Map securityProperties;
32
33
34 public AcegiProviderAdapter()
35 {
36 super("acegi");
37 }
38
39 public AcegiProviderAdapter(AuthenticationProvider delegate)
40 {
41 this(delegate, "acegi");
42 }
43
44 public AcegiProviderAdapter(AuthenticationProvider delegate, String name)
45 {
46 super(name);
47 this.delegate = delegate;
48 }
49
50 protected void doInitialise() throws InitialisationException
51 {
52 setSecurityContextFactory(new AcegiSecurityContextFactory());
53 }
54
55 public Authentication authenticate(Authentication authentication) throws SecurityException
56 {
57 org.acegisecurity.Authentication auth = null;
58 if (authentication instanceof AcegiAuthenticationAdapter)
59 {
60 auth = ((AcegiAuthenticationAdapter)authentication).getDelegate();
61 }
62 else
63 {
64 auth = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(),
65 authentication.getCredentials());
66
67 }
68 auth = delegate.authenticate(auth);
69 return new AcegiAuthenticationAdapter(auth, getSecurityProperties());
70 }
71
72 public org.acegisecurity.Authentication authenticate(org.acegisecurity.Authentication authentication) throws AuthenticationException
73 {
74 return delegate.authenticate(authentication);
75 }
76
77 public AuthenticationProvider getDelegate()
78 {
79 return delegate;
80 }
81
82 public void setDelegate(AuthenticationProvider delegate)
83 {
84 this.delegate = delegate;
85 }
86
87 public Map getSecurityProperties()
88 {
89 return securityProperties;
90 }
91
92 public void setSecurityProperties(Map securityProperties)
93 {
94 this.securityProperties = securityProperties;
95 }
96 }