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