Coverage Report - org.mule.extras.acegi.AcegiProviderAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AcegiProviderAdapter
76%
22/29
100%
4/4
1.071
 
 1  
 /*
 2  
  * $Id: AcegiProviderAdapter.java 7963 2007-08-21 08:53:15Z 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  18
         super();
 42  18
     }
 43  
 
 44  
     public AcegiProviderAdapter(AuthenticationProvider delegate)
 45  0
     {
 46  0
         this.delegate = delegate;
 47  0
     }
 48  
 
 49  
     public AcegiProviderAdapter(AuthenticationProvider delegate, String name)
 50  24
     {
 51  24
         this.delegate = delegate;
 52  24
         this.name = name;
 53  24
     }
 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  42
         factory = new AcegiSecurityContextFactory();
 62  42
     }
 63  
 
 64  
     public void setName(String name)
 65  
     {
 66  18
         this.name = name;
 67  18
     }
 68  
 
 69  
     public String getName()
 70  
     {
 71  84
         return name;
 72  
     }
 73  
 
 74  
     public UMOAuthentication authenticate(UMOAuthentication authentication) throws SecurityException
 75  
     {
 76  30
         Authentication auth = null;
 77  30
         if (authentication instanceof AcegiAuthenticationAdapter)
 78  
         {
 79  18
             auth = ((AcegiAuthenticationAdapter)authentication).getDelegate();
 80  
         }
 81  
         else
 82  
         {
 83  12
             auth = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(),
 84  
                 authentication.getCredentials());
 85  
 
 86  
         }
 87  30
         auth = delegate.authenticate(auth);
 88  20
         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  52
         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  18
         this.delegate = delegate;
 109  18
     }
 110  
 
 111  
     public UMOSecurityContext createSecurityContext(UMOAuthentication auth)
 112  
         throws UnknownAuthenticationTypeException
 113  
     {
 114  
         /*
 115  
          * if (strategy != null){ return factory.create(auth, strategy); } else {
 116  
          */
 117  20
         return factory.create(auth);
 118  
         // }
 119  
     }
 120  
 
 121  
     public Map getSecurityProperties()
 122  
     {
 123  20
         return securityProperties;
 124  
     }
 125  
 
 126  
     public void setSecurityProperties(Map securityProperties)
 127  
     {
 128  0
         this.securityProperties = securityProperties;
 129  0
     }
 130  
 }