java - Spring REST Security : Enable Basic Authentication only on a specific endpoint -


i have configured spring security rest api (with headerhttpsessionstrategy).

my 'websecurityconfigureradapter' implementation looks below.

@override     protected void configure(httpsecurity http) throws exception {          http              .csrf().disable()              .authorizerequests()                 .antmatchers("/user/**").authenticated()                 .antmatchers("/**").permitall()                  .and()             .requestcache()                 .requestcache(new nullrequestcache())                 .and()              .httpbasic()             ;      } 

now, how can configure 'httpsecurity' object basic authentication possible specific endpoint.

for example:

/user/login : basic authentication should possible on end point.after sucessfull authentication x-auth-token header returned.

/user/create : client should not able authenticate on endpoint.should return 401.can accessed using 'x-auth-token' created using /user/login endpoint.

you can define multiple websecurityconfigureradapters. 1 of higher priority has request matcher restrict applicability /user/login like: http.requestmatcher(new antpathrequestmatcher("/user/login")), , 1 catch-all rest. can omit requestmatcher make http definition unrestricted.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -