Coverage Report - org.mule.extras.acegi.AcegiProviderAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AcegiProviderAdapter
0%
0/29
0%
0/2
1.071
 
 1  
 /*
 2  
  * $Id: AcegiProviderAdapter.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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 CPAL v1.0
 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 org.mule.umo.lifecycle.InitialisationException;
 14  
 import org.mule.umo.security.SecurityException;
 15  
 import org.mule.umo.security.UMOAuthentication;
 16  
 import org.mule.umo.security.UMOSecurityContext;
 17  
 import org.mule.umo.security.UMOSecurityContextFactory;
 18  
 import org.mule.umo.security.UMOSecurityProvider;
 19  
 import org.mule.umo.security.UnknownAuthenticationTypeException;
 20  
 
 21  
 import java.util.Map;
 22  
 
 23  
 import org.acegisecurity.Authentication;
 24  
 import org.acegisecurity.AuthenticationException;
 25  
 import org.acegisecurity.providers.AuthenticationProvider;
 26  
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 27  
 
 28  
 /**
 29  
  * <code>AcegiProviderAdapter</code> is a wrapper for an Acegi Security provider to
 30  
  * use with the UMOSecurityManager
 31  
  */
 32  
 public class AcegiProviderAdapter implements UMOSecurityProvider, AuthenticationProvider
 33  
 {
 34  
     private AuthenticationProvider delegate;
 35  
     private String name;
 36  
     private UMOSecurityContextFactory factory;
 37  
     private Map securityProperties;
 38  
 
 39  
     public AcegiProviderAdapter()
 40  
     {
 41  0
         super();
 42  0
     }
 43  
 
 44  
     public AcegiProviderAdapter(AuthenticationProvider delegate)
 45  0
     {
 46  0
         this.delegate = delegate;
 47  0
     }
 48  
 
 49  
     public AcegiProviderAdapter(AuthenticationProvider delegate, String name)
 50  0
     {
 51  0
         this.delegate = delegate;
 52  0
         this.name = name;
 53  0
     }
 54  
 
 55  
     public void initialise() throws InitialisationException
 56  
     {
 57  
         // //all initialisation should be handled in the spring
 58  
         // intitialisation hook afterPropertiesSet()
 59  
 
 60  
         // register context factory
 61  0
         factory = new AcegiSecurityContextFactory();
 62  0
     }
 63  
 
 64  
     public void setName(String name)
 65  
     {
 66  0
         this.name = name;
 67  0
     }
 68  
 
 69  
     public String getName()
 70  
     {
 71  0
         return name;
 72  
     }
 73  
 
 74  
     public UMOAuthentication authenticate(UMOAuthentication authentication) throws SecurityException
 75  
     {
 76  0
         Authentication auth = null;
 77  0
         if (authentication instanceof AcegiAuthenticationAdapter)
 78  
         {
 79  0
             auth = ((AcegiAuthenticationAdapter)authentication).getDelegate();
 80  
         }
 81  
         else
 82  
         {
 83  0
             auth = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(),
 84  
                 authentication.getCredentials());
 85  
 
 86  
         }
 87  0
         auth = delegate.authenticate(auth);
 88  0
         return new AcegiAuthenticationAdapter(auth, getSecurityProperties());
 89  
     }
 90  
 
 91  
     public Authentication authenticate(Authentication authentication) throws AuthenticationException
 92  
     {
 93  0
         return delegate.authenticate(authentication);
 94  
     }
 95  
 
 96  
     public boolean supports(Class aClass)
 97  
     {
 98  0
         return UMOAuthentication.class.isAssignableFrom(aClass);
 99  
     }
 100  
 
 101  
     public AuthenticationProvider getDelegate()
 102  
     {
 103  0
         return delegate;
 104  
     }
 105  
 
 106  
     public void setDelegate(AuthenticationProvider delegate)
 107  
     {
 108  0
         this.delegate = delegate;
 109  0
     }
 110  
 
 111  
     public UMOSecurityContext createSecurityContext(UMOAuthentication auth)
 112  
         throws UnknownAuthenticationTypeException
 113  
     {
 114  
         /*
 115  
          * if (strategy != null){ return factory.create(auth, strategy); } else {
 116  
          */
 117  0
         return factory.create(auth);
 118  
         // }
 119  
     }
 120  
 
 121  
     public Map getSecurityProperties()
 122  
     {
 123  0
         return securityProperties;
 124  
     }
 125  
 
 126  
     public void setSecurityProperties(Map securityProperties)
 127  
     {
 128  0
         this.securityProperties = securityProperties;
 129  0
     }
 130  
 }