KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > extras > acegi > AcegiProviderAdapter


1 /*
2  * $Id: AcegiProviderAdapter.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.extras.acegi;
12
13 import java.util.Map JavaDoc;
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 /**
28  * <code>AcegiProviderAdapter</code> is a wrapper for an Acegi Security provider to
29  * use with the UMOSecurityManager
30  */

31 public class AcegiProviderAdapter implements UMOSecurityProvider, AuthenticationProvider
32 {
33     private AuthenticationProvider delegate;
34     private String JavaDoc name;
35     private UMOSecurityContextFactory factory;
36     private Map JavaDoc 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 JavaDoc name)
49     {
50         this.delegate = delegate;
51         this.name = name;
52     }
53
54     public void initialise() throws InitialisationException
55     {
56         // //all initialisation should be handled in the spring
57
// intitialisation hook afterPropertiesSet()
58

59         // register context factory
60
factory = new AcegiSecurityContextFactory();
61     }
62
63     public void setName(String JavaDoc name)
64     {
65         this.name = name;
66     }
67
68     public String JavaDoc getName()
69     {
70         return name;
71     }
72
73     public UMOAuthentication authenticate(UMOAuthentication authentication) throws SecurityException JavaDoc
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 JavaDoc 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         /*
114          * if (strategy != null){ return factory.create(auth, strategy); } else {
115          */

116         return factory.create(auth);
117         // }
118
}
119
120     public Map JavaDoc getSecurityProperties()
121     {
122         return securityProperties;
123     }
124
125     public void setSecurityProperties(Map JavaDoc securityProperties)
126     {
127         this.securityProperties = securityProperties;
128     }
129 }
130
Popular Tags