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