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  
  * 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.spring.security;
 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.springframework.security.core.AuthenticationException;
 17  
 import org.springframework.security.authentication.AuthenticationManager;
 18  
 import org.springframework.security.authentication.AuthenticationProvider;
 19  
 
 20  
 
 21  
 /**
 22  
  * <code>AcegiProviderAdapter</code> is a wrapper for an Acegi Security provider to
 23  
  * use with the SecurityManager
 24  
  */
 25  
 public class SpringProviderAdapter extends AbstractSecurityProvider implements AuthenticationProvider
 26  
 {
 27  
     private AuthenticationManager delegate;
 28  
     private Map securityProperties;
 29  
     private SpringAuthenticationProvider authenticationProvider;
 30  
 
 31  
     /** For Spring IoC only */
 32  
     public SpringProviderAdapter()
 33  
     {
 34  0
         super("spring-security");
 35  0
     }
 36  
 
 37  
     public SpringProviderAdapter(AuthenticationManager delegate)
 38  
     {
 39  0
         this(delegate, "spring-security");
 40  0
     }
 41  
 
 42  
     public SpringProviderAdapter(AuthenticationManager delegate, String name)
 43  
     {
 44  0
         super(name);
 45  0
         this.delegate = delegate;
 46  0
     }
 47  
 
 48  
     protected void doInitialise() throws InitialisationException
 49  
     {
 50  0
         setSecurityContextFactory(new SpringSecurityContextFactory());
 51  0
     }
 52  
 
 53  
     public Authentication authenticate(Authentication authentication) throws SecurityException
 54  
     {
 55  0
         org.springframework.security.core.Authentication auth = null;        
 56  0
         if (authentication instanceof SpringAuthenticationAdapter)
 57  
         {
 58  0
             auth = ((SpringAuthenticationAdapter)authentication).getDelegate();
 59  
         }
 60  
         else
 61  
         {
 62  0
             auth = this.getAuthenticationProvider().getAuthentication(authentication);
 63  
 
 64  
         }
 65  0
         auth = delegate.authenticate(auth);
 66  0
         return new SpringAuthenticationAdapter(auth, getSecurityProperties());
 67  
     }
 68  
 
 69  
     public org.springframework.security.core.Authentication authenticate(org.springframework.security.core.Authentication authentication) throws AuthenticationException    
 70  
     {
 71  0
         return delegate.authenticate(authentication);
 72  
     }
 73  
 
 74  
     public AuthenticationManager getDelegate()
 75  
     {
 76  0
         return delegate;
 77  
     }
 78  
 
 79  
     public void setDelegate(AuthenticationManager 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  
 
 94  
     public SpringAuthenticationProvider getAuthenticationProvider()
 95  
     {
 96  0
         if (this.authenticationProvider == null) {
 97  0
             this.authenticationProvider = new UserAndPasswordAuthenticationProvider();
 98  
         }
 99  0
         return authenticationProvider;
 100  
     }
 101  
 
 102  
     public void setAuthenticationProvider(SpringAuthenticationProvider authenticationProvider)
 103  
     {
 104  0
         this.authenticationProvider = authenticationProvider;
 105  0
     }
 106  
 }