Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Possible solution:</p> <ul> <li>Add URL interceptor for <code>/admin</code> the requires "ROLE_ADMIN"</li> <li>Configure instance of <code>org.springframework.security.web.authentication.www.BasicAuthenticationFilter</code> to intercept the <code>/admin</code> URL and authenticate user as ROLE_ADMIN if it provides the appropriate credentials</li> </ul> <p>Sample configuration:</p> <pre><code>&lt;security:intercept-url pattern="/admin" access="ROLE_ADMIN"/&gt; &lt;bean id="basicAuthenticationEntryPoint" class="org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint"&gt; &lt;property name="realmName" value="WS realm"/&gt; &lt;/bean&gt; &lt;bean id="basicAuthenticationProcessingFilter" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter"&gt; &lt;property name="authenticationManager" ref="authenticationManager"/&gt; &lt;property name="authenticationEntryPoint" ref="basicAuthenticationEntryPoint"/&gt; &lt;/bean&gt; </code></pre> <p>Note: default implementation of BasicAuthenticationFilter is a passive filter, i.e. it just looks for a basic auth header in the request and if it is not present - does nothing. If you want the filter to explicitly require the basic authentication from the client, you need to extend the default implementation to commence to authentication entry point:</p> <pre><code>public class BasicAuthenticationFilter extends org.springframework.security.web.authentication.www.BasicAuthenticationFilter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; String header = request.getHeader("Authorization"); if ((header != null) &amp;&amp; header.startsWith("Basic ")) { super.doFilter(req, res, chain); } else { getAuthenticationEntryPoint().commence(request, response, new AuthenticationCredentialsNotFoundException("Missing credentials")); } } } </code></pre> <p>In addition, you need to tweak the filter to apply to <code>/admin</code> URL only - either by hard-coding this in <code>doFilter</code> method or by providing an appropriate wrapper bean.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload