1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.spring.security; |
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.springframework.security.AuthenticationException; |
21 | |
import org.springframework.security.AuthenticationManager; |
22 | |
import org.springframework.security.providers.AuthenticationProvider; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class SpringProviderAdapter extends AbstractSecurityProvider implements AuthenticationProvider |
29 | |
{ |
30 | |
private AuthenticationManager delegate; |
31 | |
private Map securityProperties; |
32 | |
private SpringAuthenticationProvider authenticationProvider; |
33 | |
|
34 | |
|
35 | |
public SpringProviderAdapter() |
36 | |
{ |
37 | 0 | super("spring-security"); |
38 | 0 | } |
39 | |
|
40 | |
public SpringProviderAdapter(AuthenticationManager delegate) |
41 | |
{ |
42 | 0 | this(delegate, "spring-security"); |
43 | 0 | } |
44 | |
|
45 | |
public SpringProviderAdapter(AuthenticationManager delegate, String name) |
46 | |
{ |
47 | 0 | super(name); |
48 | 0 | this.delegate = delegate; |
49 | 0 | } |
50 | |
|
51 | |
protected void doInitialise() throws InitialisationException |
52 | |
{ |
53 | 0 | setSecurityContextFactory(new SpringSecurityContextFactory()); |
54 | 0 | } |
55 | |
|
56 | |
public Authentication authenticate(Authentication authentication) throws SecurityException |
57 | |
{ |
58 | 0 | org.springframework.security.Authentication auth = null; |
59 | 0 | if (authentication instanceof SpringAuthenticationAdapter) |
60 | |
{ |
61 | 0 | auth = ((SpringAuthenticationAdapter)authentication).getDelegate(); |
62 | |
} |
63 | |
else |
64 | |
{ |
65 | 0 | auth = this.getAuthenticationProvider().getAuthentication(authentication); |
66 | |
|
67 | |
} |
68 | 0 | auth = delegate.authenticate(auth); |
69 | 0 | return new SpringAuthenticationAdapter(auth, getSecurityProperties()); |
70 | |
} |
71 | |
|
72 | |
public org.springframework.security.Authentication authenticate(org.springframework.security.Authentication authentication) throws AuthenticationException |
73 | |
{ |
74 | 0 | return delegate.authenticate(authentication); |
75 | |
} |
76 | |
|
77 | |
public AuthenticationManager getDelegate() |
78 | |
{ |
79 | 0 | return delegate; |
80 | |
} |
81 | |
|
82 | |
public void setDelegate(AuthenticationManager 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 | |
|
97 | |
public SpringAuthenticationProvider getAuthenticationProvider() |
98 | |
{ |
99 | 0 | if (this.authenticationProvider == null) { |
100 | 0 | this.authenticationProvider = new UserAndPasswordAuthenticationProvider(); |
101 | |
} |
102 | 0 | return authenticationProvider; |
103 | |
} |
104 | |
|
105 | |
public void setAuthenticationProvider(SpringAuthenticationProvider authenticationProvider) |
106 | |
{ |
107 | 0 | this.authenticationProvider = authenticationProvider; |
108 | 0 | } |
109 | |
} |