Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Configuring the Spring Security Manager

Use Spring Security 3.0 as a Security Manager inside of Mule. You can use any of the library’s security providers such as JAAS, LDAP, CAS (Yale Central Authentication service), and DAO. For more information on the elements you can configure for a Mule security manager, see Security Manager Configuration Reference.

Example

The following example illustrates how to configure a single security provider on Mule, in this case an in-memory database of users. To configure the provider, we set up a <user-service> element and the <authentication-manager> to which Mule delegates.


         
      
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
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:spring="http://www.springframework.org/schema/beans"
    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"
    xsi:schemaLocation="
       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/3.1/mule.xsd
       http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.1/mule-http.xsd
       http://www.mulesoft.org/schema/mule/spring-security
http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd
       http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
 
    <mule-ss:security-manager>
        <mule-ss:delegate-security-provider name="memory-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="ross" password="ross" authorities="ROLE_ADMIN" />
            <ss:user name="anon" password="anon" authorities="ROLE_ANON" />
          </ss:user-service>
        </ss:authentication-provider>
      </ss:authentication-manager>
    </spring:beans>
    ...cut...
</mule>

Adding Spring Security References

To make Spring security work, you need to add XML schema declarations to your Mule App. Notice the above example includes the following references inside the root XML element:


         
      
1
2
3
xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
    xmlns:ss="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd    http://www.springframework.org/schema/security   http://www.springframework.org/schema/security/spring-security-3.0.xsd"
Make sure you include these references, they are important and Studio does not add them automatically.

Security Filters

Security filters can be configured on an object to either authenticate inbound requests or attach credentials to outbound requests. For example, to configure an HTTP basic authorization filter on an HTTP connector, you would use the following connector security filter:


         
      
1
2
3
<inbound-endpoint address="http://localhost:4567">
    <mule-ss:http-security-filter realm="mule-realm"/>
</inbound-endpoint>

When a request is received, the authentication header is read from the request and authenticated against all security providers on the Security Manager. If you only want to validate on certain providers, you can supply a comma-separated list of security provider names.


         
      
1
2
3
<inbound-endpoint address="http://localhost:4567">
    <mule-ss:http-security-filter realm="mule-realm" securityProviders="default,another"/>
</inbound-endpoint>

The realm is an optional attribute required by some servers. You only need to set this attribute if required by the server on the other end.