0

I used POST method but getting following error. Last line shows the error. Initially , I didn't use SecurityConfiguration. Right now, I am using SecurityConfiguration to permit all and still getting authentication error.

public class SecurityConfiguration extends WebSecurityConfigurerAdapter{

    public void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.authorizeRequests().antMatchers("/").permitAll();
    }
}

[2020-02-19 16:02:59.357] [DEBUG] [Context:FilterSecurityInterceptor] [] [Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@64bc4ef4: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@380f4: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 53EB7CECE3D38AF3B70968DB6125DA86; Granted Authorities: ROLE_ANONYMOUS] [2020-02-19 16:02:59.368] [DEBUG] [Context:AffirmativeBased] [] [Voter: org.springframework.security.web.access.expression.WebExpressionVoter@1173b3b2, returned: -1] [2020-02-19 16:02:59.371] [DEBUG] [Context:ExceptionTranslationFilter] [] [Access is denied (user is anonymous); redirecting to authentication entry point] org.springframework.security.access.AccessDeniedException: Access is denied at org.springframework.security.access.vote.AffirmativeBased.decide(AffirmativeBased.java:84) at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:233) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:123) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:118) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:158) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:216) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:394) at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:253) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:175) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) [2020-02-19 16:02:59.385] [DEBUG] [Context:AndRequestMatcher] [] [Trying to match using Ant [pattern='/', GET]] **[2020-02-19 16:02:59.386] [DEBUG] [Context:AntPathRequestMatcher] [] [Request 'POST /error' doesn't match 'GET /']**


   @PostMapping(value ="/createAncillaries")
   public CreateOrderResponseType createAncillaries(@RequestBody(required=true) String message ) {
      return orderDetailsService.createAncillaries(message);
   }

Bandita Pradhan
  • 85
  • 2
  • 16
  • did you try using httpSecurity.authorizeRequests().antMatchers(HttpMethod.GET, "/").permitAll(); – Lalit Mehra Feb 24 '20 at 22:29
  • I tried and got same error. – Bandita Pradhan Feb 24 '20 at 22:53
  • 1
    If you check this line: "[Context:AntPathRequestMatcher] [] [Request 'POST /error' doesn't match 'GET /']**" it seems to be forwarding the request to /error page. Did you check the issue here. You might want to use "/*" instead of "/" in antMatchers – Lalit Mehra Feb 24 '20 at 22:55
  • I think it worked as I am not getting authentication error. It moved to the service layer . Right now, I don't have test data. So, unable to test completely. Thanks Lalit. – Bandita Pradhan Feb 25 '20 at 00:29

1 Answers1

1

URLs have length restrictions. Check this - https://stackoverflow.com/a/417184/919158.

Try using POST method and post the data as @RequestBody

kann
  • 687
  • 10
  • 22
  • I tried to use POST method with @RequestBody but I am getting spring security authentication error even though I have same authentication spring: security: user: name: XXX password: YYY – Bandita Pradhan Feb 19 '20 at 20:50
  • I updated the post and it is giving authentication error because of POST method as it is expecting GET method – Bandita Pradhan Feb 19 '20 at 22:15
  • Authentication is giving trouble, not the post method which you have already correct. Access denied error and this route /error is causing issue. Is the error routing uses wrong Http method? Check your antMatchers. – kann Feb 20 '20 at 00:58
  • I have same authentication for GET and POST , also throughout the project. It is working for GET . Just this POST transaction is not working. I have other POST transactions which are meant to be POST and is working fine. – Bandita Pradhan Feb 20 '20 at 17:18
  • I got the String of message from Find method - step 1 , then passing the message in createOrder - Step 2. Now I merge both the method , so there is no problem of message passing. – Bandita Pradhan Feb 20 '20 at 17:22
  • I am now trying to use POST method so that I can reuse the code for multiple calls. – Bandita Pradhan Feb 24 '20 at 22:18