1
votes

When using Spring Security you map a chain of filters to URL patters to specify how those URLs are secured. These patterns can contain wildcards such as

/foo/*/bar
/foo/**/bar

I couldn't find any docs for these wildcards, but my guess is that the first pattern would match

/foo/baz/bar

but not

/foo/baz/baz/bar

whereas the second pattern (/foo/**/bar) would match both of these

2
* wildcard doesn't contains ‘/’; ** wildcard contains '/'. - Gospel

2 Answers

0
votes

maybe this code will help:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/security
                           http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <security:http auto-config="true">

        <security:intercept-url pattern="/login.do"
            access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <security:intercept-url pattern="/logout.do"
            access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <security:intercept-url pattern="/fail2login.do"
            access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <security:intercept-url pattern="/json/*.do"
            access="IS_AUTHENTICATED_ANONYMOUSLY" />

        <security:intercept-url pattern="/*" access="ROLE_ADMIN" />
        <security:form-login login-page="/login.do"
            default-target-url="/home.do" authentication-failure-url="/fail2login.do" />

        <security:session-management>
            <security:concurrency-control
                max-sessions="1" />
        </security:session-management>
        <security:logout logout-success-url="/logout.do"
            delete-cookies="JSESSIONID" invalidate-session="true" />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider>
            <security:jdbc-user-service
                data-source-ref="dataSource"
                users-by-username-query="select userName, password, status from User where userName=?"
                authorities-by-username-query="select us.userName, ur.userRoleName from User us, UserRole ur   
                where ur.userName =?  " />
        </security:authentication-provider>
    </security:authentication-manager>
</beans>
0
votes

You are correct in your assumption. The single wildcard * matches anything in that particular level of the url tree, whereas the double wildcard ** matches any string pattern.

So

/foo/*/bar

Would match

/foo/abc/bar and /foo/xyz/bar but not /foo/abc/xyz/bar

Whereas

/foo/**/bar

Would match all of the above.