Coverage Report - org.mule.module.acegi.AcegiProviderAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AcegiProviderAdapter
0%
0/22
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.acegi;
 8  
 
 9  
 import org.mule.api.lifecycle.InitialisationException;
 10  
 import org.mule.api.security.Authentication;
 11  
 import org.mule.api.security.SecurityException;
 12  
 import org.mule.security.AbstractSecurityProvider;
 13  
 
 14  
 import java.util.Map;
 15  
 
 16  
 import org.acegisecurity.AuthenticationException;
 17  
 import org.acegisecurity.providers.AuthenticationProvider;
 18  
 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 19  
 
 20  
 /**
 21  
  * <code>AcegiProviderAdapter</code> is a wrapper for an Acegi Security provider to
 22  
  * use with the SecurityManager
 23  
  */
 24  
 public class AcegiProviderAdapter extends AbstractSecurityProvider implements AuthenticationProvider
 25  
 {
 26  
     private AuthenticationProvider delegate;
 27  
     private Map securityProperties;
 28  
 
 29  
     /** For Spring IoC only */
 30  
     public AcegiProviderAdapter()
 31  
     {
 32  0
         super("acegi");
 33  0
     }
 34  
 
 35  
     public AcegiProviderAdapter(AuthenticationProvider delegate)
 36  
     {
 37  0
         this(delegate, "acegi");
 38  0
     }
 39  
 
 40  
     public AcegiProviderAdapter(AuthenticationProvider delegate, String name)
 41  
     {
 42  0
         super(name);
 43  0
         this.delegate = delegate;
 44  0
     }
 45  
 
 46  
     @Override
 47  
     protected void doInitialise() throws InitialisationException
 48  
     {
 49  0
         setSecurityContextFactory(new AcegiSecurityContextFactory());
 50  0
     }
 51  
 
 52  
     public Authentication authenticate(Authentication authentication) throws SecurityException
 53  
     {
 54  0
         org.acegisecurity.Authentication auth = null;
 55  0
         if (authentication instanceof AcegiAuthenticationAdapter)
 56  
         {
 57  0
             auth = ((AcegiAuthenticationAdapter)authentication).getDelegate();
 58  
         }
 59  
         else
 60  
         {
 61  0
             auth = new UsernamePasswordAuthenticationToken(authentication.getPrincipal(),
 62  
                 authentication.getCredentials());
 63  
 
 64  
         }
 65  0
         auth = delegate.authenticate(auth);
 66  0
         return new AcegiAuthenticationAdapter(auth, getSecurityProperties());
 67  
     }
 68  
 
 69  
     public org.acegisecurity.Authentication authenticate(org.acegisecurity.Authentication authentication) throws AuthenticationException
 70  
     {
 71  0
         return delegate.authenticate(authentication);
 72  
     }
 73  
 
 74  
     public AuthenticationProvider getDelegate()
 75  
     {
 76  0
         return delegate;
 77  
     }
 78  
 
 79  
     public void setDelegate(AuthenticationProvider delegate)
 80  
     {
 81  0
         this.delegate = delegate;
 82  0
     }
 83  
 
 84  
     public Map getSecurityProperties()
 85  
     {
 86  0
         return securityProperties;
 87  
     }
 88  
 
 89  
     public void setSecurityProperties(Map securityProperties)
 90  
     {
 91  0
         this.securityProperties = securityProperties;
 92  0
     }
 93  
 }