1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.extras.acegi; |
12 | |
|
13 | |
import org.mule.umo.lifecycle.InitialisationException; |
14 | |
import org.mule.umo.security.SecurityException; |
15 | |
import org.mule.umo.security.UMOAuthentication; |
16 | |
import org.mule.umo.security.UMOSecurityContext; |
17 | |
import org.mule.umo.security.UMOSecurityContextFactory; |
18 | |
import org.mule.umo.security.UMOSecurityProvider; |
19 | |
import org.mule.umo.security.UnknownAuthenticationTypeException; |
20 | |
|
21 | |
import java.util.Map; |
22 | |
|
23 | |
import org.acegisecurity.Authentication; |
24 | |
import org.acegisecurity.AuthenticationException; |
25 | |
import org.acegisecurity.providers.AuthenticationProvider; |
26 | |
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class AcegiProviderAdapter implements UMOSecurityProvider, AuthenticationProvider |
33 | |
{ |
34 | |
private AuthenticationProvider delegate; |
35 | |
private String name; |
36 | |
private UMOSecurityContextFactory factory; |
37 | |
private Map securityProperties; |
38 | |
|
39 | |
public AcegiProviderAdapter() |
40 | |
{ |
41 | 0 | super(); |
42 | 0 | } |
43 | |
|
44 | |
public AcegiProviderAdapter(AuthenticationProvider delegate) |
45 | 0 | { |
46 | 0 | this.delegate = delegate; |
47 | 0 | } |
48 | |
|
49 | |
public AcegiProviderAdapter(AuthenticationProvider delegate, String name) |
50 | 0 | { |
51 | 0 | this.delegate = delegate; |
52 | 0 | this.name = name; |
53 | 0 | } |
54 | |
|
55 | |
public void initialise() throws InitialisationException |
56 | |
{ |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | 0 | factory = new AcegiSecurityContextFactory(); |
62 | 0 | } |
63 | |
|
64 | |
public void setName(String name) |
65 | |
{ |
66 | 0 | this.name = name; |
67 | 0 | } |
68 | |
|
69 | |
public String getName() |
70 | |
{ |
71 | 0 | return name; |
72 | |
} |
73 | |
|
74 | |
public UMOAuthentication authenticate(UMOAuthentication authentication) throws SecurityException |
75 | |
{ |
76 | 0 | Authentication auth = null; |
77 | 0 | if (authentication instanceof AcegiAuthenticationAdapter) |
78 | |
{ |
79 | 0 | auth = ((AcegiAuthenticationAdapter)authentication).getDelegate(); |
80 | |
} |
81 | |
else |
82 | |
{ |
83 | 0 | auth = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), |
84 | |
authentication.getCredentials()); |
85 | |
|
86 | |
} |
87 | 0 | auth = delegate.authenticate(auth); |
88 | 0 | return new AcegiAuthenticationAdapter(auth, getSecurityProperties()); |
89 | |
} |
90 | |
|
91 | |
public Authentication authenticate(Authentication authentication) throws AuthenticationException |
92 | |
{ |
93 | 0 | return delegate.authenticate(authentication); |
94 | |
} |
95 | |
|
96 | |
public boolean supports(Class aClass) |
97 | |
{ |
98 | 0 | return UMOAuthentication.class.isAssignableFrom(aClass); |
99 | |
} |
100 | |
|
101 | |
public AuthenticationProvider getDelegate() |
102 | |
{ |
103 | 0 | return delegate; |
104 | |
} |
105 | |
|
106 | |
public void setDelegate(AuthenticationProvider delegate) |
107 | |
{ |
108 | 0 | this.delegate = delegate; |
109 | 0 | } |
110 | |
|
111 | |
public UMOSecurityContext createSecurityContext(UMOAuthentication auth) |
112 | |
throws UnknownAuthenticationTypeException |
113 | |
{ |
114 | |
|
115 | |
|
116 | |
|
117 | 0 | return factory.create(auth); |
118 | |
|
119 | |
} |
120 | |
|
121 | |
public Map getSecurityProperties() |
122 | |
{ |
123 | 0 | return securityProperties; |
124 | |
} |
125 | |
|
126 | |
public void setSecurityProperties(Map securityProperties) |
127 | |
{ |
128 | 0 | this.securityProperties = securityProperties; |
129 | 0 | } |
130 | |
} |