<div dir="ltr"><div><div><div><div>Hello, I&#39;m trying to configure security for simple Spring Rest Webapp and Keycloak.<br></div>I&#39;ve configured Keycloak server 1.7.0.Final on WildFly 9.0.2 (created realms, clients, roles, etc.). And it works just fine.<br></div>Then I created simple Spring Rest App (boot-less) to test Keycloak security login. I generated keycloak.json file and put it in my WEB-INF folder.<br></div><div>Then I configured web.xml and Spring dispatcher-servlet.xml. And finally created annotation driven security config.<br><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:&quot;Courier New&quot;"><span style="color:rgb(0,0,128);font-weight:bold">protected void </span>configure(HttpSecurity http) <span style="color:rgb(0,0,128);font-weight:bold">throws </span>Exception {<br>    <span style="color:rgb(0,0,128);font-weight:bold">super</span>.configure(http);<br>    http.authorizeRequests().antMatchers(<span style="color:rgb(0,128,0);font-weight:bold">&quot;/*&quot;</span>).hasRole(<span style="color:rgb(0,128,0);font-weight:bold">&quot;tms-rest&quot;</span>);<br>}</pre></div><div></div>But when I try to test my web app in browser it does not redirect me to keycloak login page. I made it work when I configured security-constraint in web.xml.<br><br><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:&quot;Courier New&quot;"><span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">security-constraint</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>    <span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">web-resource-collection</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>        <span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">web-resource-name</span><span style="background-color:rgb(239,239,239)">&gt;</span>tms<span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">web-resource-name</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>        <span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">url-pattern</span><span style="background-color:rgb(239,239,239)">&gt;</span>/*<span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">url-pattern</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>    <span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">web-resource-collection</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>    <span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">auth-constraint</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>        <span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">role-name</span><span style="background-color:rgb(239,239,239)">&gt;</span>tms-rest<span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">role-name</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>    <span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">auth-constraint</span><span style="background-color:rgb(239,239,239)">&gt;</span><br><span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">security-constraint</span><span style="background-color:rgb(239,239,239)">&gt;</span><br><br><span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">security-role</span><span style="background-color:rgb(239,239,239)">&gt;</span><br>    <span style="background-color:rgb(239,239,239)">&lt;</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">role-name</span><span style="background-color:rgb(239,239,239)">&gt;</span>tms-rest<span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">role-name</span><span style="background-color:rgb(239,239,239)">&gt;</span><br><span style="background-color:rgb(239,239,239)">&lt;/</span><span style="color:rgb(0,0,128);background-color:rgb(239,239,239);font-weight:bold">security-role</span><span style="background-color:rgb(239,239,239)">&gt;</span></pre><br></div>It seems to me that Spring isn&#39;t picking up my security rules from security config bean. Is there any suggestion what am I doing wrong? <br>And how to be able to set config programmatically?<br><div><div><br></div><div>My app source is in attachment.<br></div></div></div>