打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Mule Spring Security | Mule Training | Mule ESB, Anypoint Registry, Anypoint Connectors, MMC, APIKit

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Mule ESB uses Spring security to provide basic authentication features. It uses delegated security providers that intercept an incoming request, authenticate through applicable security providers and finally return either authenticated or failed response to the user. A typical security request-response flow is depicted below:

Lets see how we can implement a very common use case – securing a Webservice endpoint using basic authentication. We need three elements in order to achieve this result – a security manager, one or more security providers linked to authentication managers and finally a security filter to intercept incoming HTTP requests.

We’ll use the SOAP Code-First service built earlier to introduce basic authentication.

First, the security manager. As you can see in below code snippet, security manager in turn uses one or more delegated security providers. Each security provider is linked to an Authentication Managers specified by “delegate-ref” attribute.

1
2
3
4
    <mule-ss:security-manager>
        <mule-ss:delegate-security-provider name="mws-provider"
             delegate-ref="authenticationManager" />
    </mule-ss:security-manager>

Second, we need to define Authentication Manager. As you can see below, an authentication manager consists of authentication providers. In this example, we’ll use static user=middleware and password=school combination. However, you can link LDAP or Database source as well.

1
2
3
4
5
6
7
8
9
    <spring:beans>
      <ss:authentication-manager alias="authenticationManager">
        <ss:authentication-provider>
          <ss:user-service id="userService">
            <ss:user name="middleware" password="school" authorities="ROLE_ADMIN" />
          </ss:user-service>
        </ss:authentication-provider>
      </ss:authentication-manager>
    </spring:beans>

Finally, we need to introduce security filter for our HTTP requests. A simple modification to SOAP Code-First service look like below. Do observe the highlighted portion.

1
2
3
4
5
6
7
8
    <flow name="soapFlow" doc:name="soapFlow">
        <http:inbound-endpoint exchange-pattern="request-response"
            host="localhost" port="8084" path="soap" doc:name="HTTP" />
        <mule-ss:http-security-filter realm="mule-realm"/>
        <cxf:jaxws-service serviceClass="training.IHelloWorld"
            doc:name="SOAP" />
        <component class="training.HelloWorld" doc:name="Java" />
    </flow>

Complete Mule flow is shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
    xmlns:ss="http://www.springframework.org/schema/security" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core"
    version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/current/mule-spring-security.xsd">
    <mule-ss:security-manager>
        <mule-ss:delegate-security-provider name="mws-provider" delegate-ref="authenticationManager" />
    </mule-ss:security-manager>
    <spring:beans>
      <ss:authentication-manager alias="authenticationManager">
        <ss:authentication-provider>
          <ss:user-service id="userService">
            <ss:user name="middleware" password="school" authorities="ROLE_ADMIN" />
          </ss:user-service>
        </ss:authentication-provider>
      </ss:authentication-manager>
    </spring:beans>
    <flow name="soapFlow" doc:name="soapFlow">
        <http:inbound-endpoint exchange-pattern="request-response"
            host="localhost" port="8084" path="soap" doc:name="HTTP" />
        <mule-ss:http-security-filter realm="mule-realm"/>
        <cxf:jaxws-service serviceClass="training.IHelloWorld"
            doc:name="SOAP" />
        <component class="training.HelloWorld" doc:name="Java" />
    </flow>
</mule>

Run this project and access WSDL using http://localhost:8084/soap?WSDL. A Basic Authentication dialog will be popped up. You won’t be able to see WSDL until you specify correct user and password.

Rating: 0.0/10 (0 votes cast)
Rating: 0 (from 0 votes)
(Visited 568 times, 1 visits today)
Written by: admin on March 23, 2014.
No tags for this post.

Related posts

  • No related posts.
On March 23, 2014   /   Security   /   Leave a comment
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Mule 3.x 中对 Ftp 协议的支持
MuleSoft知识总结-1.MuleSoft的简要介绍
spring security 3.1配置过程从简单到复杂详细配置
Spring Security笔记:使用数据库进行用户认证(form login using database)
spring security 3.1.0 控制用户重复登陆
使用 Spring Security 构建一个 HTTP 基本认证示例
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服