The following example implements form-based authentication. . To change it to http auth (which is more suitable for REST services), you need to look for the following form-login in your security.xml:
<form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/login?error" username-parameter="username" password-parameter="password" />
And just change it to an empty http-basic tag:
<http-basic />
If you havenβt changed anything, then it should work perfectly. You can also check your settings in your browser, trying to access your page. If you configured everything correctly, this time you will get a popup, not a form. This will be the HTTP basic authentication that greets you.
Since you are probably using a Java based configuration, the equivalent of this change should replace:
http.authorizeRequests() .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')") .antMatchers("/dba/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_DBA')") .and().formLogin();
from:
http.authorizeRequests() .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')") .antMatchers("/dba/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_DBA')") .and().httpBasic();
Gergely bacso
source share