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