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