Spring Security Authentication using RestTemplate

后端 未结 7 1234
你的背包
你的背包 2020-12-02 17:58

I have 2 spring web apps that provide 2 separate set of services. Web App 1 has Spring Security implemented using a user-based authentication.

Now, Web App 2 needs

7条回答
  •  情歌与酒
    2020-12-02 18:16

    I was in the same situation. Here there is my solution.

    Server - spring security config

    
        
        
        
    
    
    
        
            
                
            
        
    
    

    Client side RestTemplate config

    
        
        
    
    
    
        
    
    
    
        
        
    
    
    
        
    
    
    
    
                        
    
    

    Custom HttpState implementation

    /**
     * Custom implementation of {@link HttpState} with credentials property.
     *
     * @author banterCZ
     */
    public class CustomHttpState extends HttpState {
    
        /**
         * Set credentials property.
         *
         * @param credentials
         * @see #setCredentials(org.apache.commons.httpclient.auth.AuthScope, org.apache.commons.httpclient.Credentials)
         */
        public void setCredentials(final Credentials credentials) {
            super.setCredentials(AuthScope.ANY, credentials);
        }
    
    }
    

    Maven dependency

    
       commons-httpclient
       commons-httpclient
       3.1
    
    

提交回复
热议问题