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