Coverage Report - org.mule.module.spring.security.SpringProviderAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringProviderAdapter
0%
0/27
0%
0/4
1.167
 
 1  
 /*
 2  
  * $Id: SpringProviderAdapter.java 20477 2010-12-06 23:38:52Z mike.schilling $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.module.spring.security;
 12  
 
 13  
 import org.mule.api.lifecycle.InitialisationException;
 14  
 import org.mule.api.security.Authentication;
 15  
 import org.mule.api.security.SecurityException;
 16  
 import org.mule.security.AbstractSecurityProvider;
 17  
 
 18  
 import java.util.Map;
 19  
 
 20  
 import org.springframework.security.core.AuthenticationException;
 21  
 import org.springframework.security.authentication.AuthenticationManager;
 22  
 import org.springframework.security.authentication.AuthenticationProvider;
 23  
 
 24  
 
 25  
 /**
 26  
  * <code>AcegiProviderAdapter</code> is a wrapper for an Acegi Security provider to
 27  
  * use with the SecurityManager
 28  
  */
 29  
 public class SpringProviderAdapter extends AbstractSecurityProvider implements AuthenticationProvider
 30  
 {
 31  
     private AuthenticationManager delegate;
 32  
     private Map securityProperties;
 33  
     private SpringAuthenticationProvider authenticationProvider;
 34  
 
 35  
     /** For Spring IoC only */
 36  
     public SpringProviderAdapter()
 37  
     {
 38  0
         super("spring-security");
 39  0
     }
 40  
 
 41  
     public SpringProviderAdapter(AuthenticationManager delegate)
 42  
     {
 43  0
         this(delegate, "spring-security");
 44  0
     }
 45  
 
 46  
     public SpringProviderAdapter(AuthenticationManager delegate, String name)
 47  
     {
 48  0
         super(name);
 49  0
         this.delegate = delegate;
 50  0
     }
 51  
 
 52  
     protected void doInitialise() throws InitialisationException
 53  
     {
 54  0
         setSecurityContextFactory(new SpringSecurityContextFactory());
 55  0
     }
 56  
 
 57  
     public Authentication authenticate(Authentication authentication) throws SecurityException
 58  
     {
 59  0
         org.springframework.security.core.Authentication auth = null;        
 60  0
         if (authentication instanceof SpringAuthenticationAdapter)
 61  
         {
 62  0
             auth = ((SpringAuthenticationAdapter)authentication).getDelegate();
 63  
         }
 64  
         else
 65  
         {
 66  0
             auth = this.getAuthenticationProvider().getAuthentication(authentication);
 67  
 
 68  
         }
 69  0
         auth = delegate.authenticate(auth);
 70  0
         return new SpringAuthenticationAdapter(auth, getSecurityProperties());
 71  
     }
 72  
 
 73  
     public org.springframework.security.core.Authentication authenticate(org.springframework.security.core.Authentication authentication) throws AuthenticationException    
 74  
     {
 75  0
         return delegate.authenticate(authentication);
 76  
     }
 77  
 
 78  
     public AuthenticationManager getDelegate()
 79  
     {
 80  0
         return delegate;
 81  
     }
 82  
 
 83  
     public void setDelegate(AuthenticationManager delegate)
 84  
     {
 85  0
         this.delegate = delegate;
 86  0
     }
 87  
 
 88  
     public Map getSecurityProperties()
 89  
     {
 90  0
         return securityProperties;
 91  
     }
 92  
 
 93  
     public void setSecurityProperties(Map securityProperties)
 94  
     {
 95  0
         this.securityProperties = securityProperties;
 96  0
     }
 97  
 
 98  
     public SpringAuthenticationProvider getAuthenticationProvider()
 99  
     {
 100  0
         if (this.authenticationProvider == null) {
 101  0
             this.authenticationProvider = new UserAndPasswordAuthenticationProvider();
 102  
         }
 103  0
         return authenticationProvider;
 104  
     }
 105  
 
 106  
     public void setAuthenticationProvider(SpringAuthenticationProvider authenticationProvider)
 107  
     {
 108  0
         this.authenticationProvider = authenticationProvider;
 109  0
     }
 110  
 }