Skip to Content

Basic auth in ycommersewebservices rest controller

Hi experts,

In my extension there ist a rest controller which should be secured with basic auth. It gets calles like: https://local.shop.at:9002/rest/v2/SHOP_AT/products/101606/stocks/online and the controller listens at @RequestMapping(value = "/{baseSiteId}/products/{code}/stocks/online") I was following a tutorial and came up with a SecurityConfiguration

 @Configuration
 @EnableWebSecurity
 public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
 
     private static String REALM="STOCKSWAP";
 
     @Autowired
     public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
         auth.inMemoryAuthentication().withUser("name").password("password").roles("STOCKSWAP");
     }
 
     @Override
     protected void configure(HttpSecurity http) throws Exception {
 
         http.csrf().disable()
                 .authorizeRequests()
                 .antMatchers("/**/products/**/stocks/online").hasRole("STOCKSWAP")
                 .and().httpBasic().realmName(REALM).authenticationEntryPoint(getBasicAuthEntryPoint())
                 .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
     }
 
     @Bean
     public CustomBasicAuthenticationEntryPoint getBasicAuthEntryPoint(){
         return new CustomBasicAuthenticationEntryPoint();
     }
 }

On serverstart it gets loaded, was made sure with a breakpoint. But when I call the controller without credentials, I still get a response with data. It seems that maybe something with the antMatcher is wrong, did somebody of you already do this or can you point me into the direction of the problem?

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Jul 03, 2017 at 08:18 PM

    I observed the same behavior with my custom ycomm-ws. Had raised a question here, no responses yet.

    https://answers.sap.com/questions/12762268/custom-ycommercewebservices-extension-works-withou.html

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.