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 | 0 | super("acegi"); |
37 | 0 | } |
38 | |
|
39 | |
public AcegiProviderAdapter(AuthenticationProvider delegate) |
40 | |
{ |
41 | 0 | this(delegate, "acegi"); |
42 | 0 | } |
43 | |
|
44 | |
public AcegiProviderAdapter(AuthenticationProvider delegate, String name) |
45 | |
{ |
46 | 0 | super(name); |
47 | 0 | this.delegate = delegate; |
48 | 0 | } |
49 | |
|
50 | |
protected void doInitialise() throws InitialisationException |
51 | |
{ |
52 | 0 | setSecurityContextFactory(new AcegiSecurityContextFactory()); |
53 | 0 | } |
54 | |
|
55 | |
public Authentication authenticate(Authentication authentication) throws SecurityException |
56 | |
{ |
57 | 0 | org.acegisecurity.Authentication auth = null; |
58 | 0 | if (authentication instanceof AcegiAuthenticationAdapter) |
59 | |
{ |
60 | 0 | auth = ((AcegiAuthenticationAdapter)authentication).getDelegate(); |
61 | |
} |
62 | |
else |
63 | |
{ |
64 | 0 | auth = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), |
65 | |
authentication.getCredentials()); |
66 | |
|
67 | |
} |
68 | 0 | auth = delegate.authenticate(auth); |
69 | 0 | return new AcegiAuthenticationAdapter(auth, getSecurityProperties()); |
70 | |
} |
71 | |
|
72 | |
public org.acegisecurity.Authentication authenticate(org.acegisecurity.Authentication authentication) throws AuthenticationException |
73 | |
{ |
74 | 0 | return delegate.authenticate(authentication); |
75 | |
} |
76 | |
|
77 | |
public AuthenticationProvider getDelegate() |
78 | |
{ |
79 | 0 | return delegate; |
80 | |
} |
81 | |
|
82 | |
public void setDelegate(AuthenticationProvider delegate) |
83 | |
{ |
84 | 0 | this.delegate = delegate; |
85 | 0 | } |
86 | |
|
87 | |
public Map getSecurityProperties() |
88 | |
{ |
89 | 0 | return securityProperties; |
90 | |
} |
91 | |
|
92 | |
public void setSecurityProperties(Map securityProperties) |
93 | |
{ |
94 | 0 | this.securityProperties = securityProperties; |
95 | 0 | } |
96 | |
} |