Failed to get current user: no RequestContext available










3















Getting below exception while fetching logged in user object using xsuaa approuter login



User currentUser = UserAccessor.getCurrentUser();


I am to get currentUser object without using GuiceFilter, If I apply GuiceFilter then getting below exception.



Any one Please suggest me how to get UserAccessor.getCurrentUser() with GuiceFilter



com.sap.cloud.sdk.cloudplatform.security.user.exception.UserAccessException: Failed to get current user: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUserIfAuthenticated(AbstractUserFacade.java:85)
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUser(AbstractUserFacade.java:135)
at com.sap.cloud.sdk.cloudplatform.security.user.UserAccessor.getCurrentUser(UserAccessor.java:122)
at com.company.HelloWorldServlet2.handleRequest(HelloWorldServlet2.java:35)
at com.company.BaseServlet.doPost(BaseServlet.java:120)
at com.company.BaseServlet.doGet(BaseServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:287)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:277)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:182)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:119)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:133)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:130)
at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:203)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:130)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66)
at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:191)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at com.sap.xs.jdbc.datasource.valve.JDBCValve.invoke(JDBCValve.java:62)
at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:19)
at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43)
at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:40)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:695)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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:836)









share|improve this question
























  • Could you provide some details on the SDK version and project archetype that you are using?

    – Sander Wozniak
    Nov 15 '18 at 11:55











  • I did build application using blogs.sap.com/2017/07/18/…

    – Dama Ramesh
    Nov 15 '18 at 12:22
















3















Getting below exception while fetching logged in user object using xsuaa approuter login



User currentUser = UserAccessor.getCurrentUser();


I am to get currentUser object without using GuiceFilter, If I apply GuiceFilter then getting below exception.



Any one Please suggest me how to get UserAccessor.getCurrentUser() with GuiceFilter



com.sap.cloud.sdk.cloudplatform.security.user.exception.UserAccessException: Failed to get current user: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUserIfAuthenticated(AbstractUserFacade.java:85)
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUser(AbstractUserFacade.java:135)
at com.sap.cloud.sdk.cloudplatform.security.user.UserAccessor.getCurrentUser(UserAccessor.java:122)
at com.company.HelloWorldServlet2.handleRequest(HelloWorldServlet2.java:35)
at com.company.BaseServlet.doPost(BaseServlet.java:120)
at com.company.BaseServlet.doGet(BaseServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:287)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:277)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:182)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:119)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:133)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:130)
at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:203)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:130)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66)
at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:191)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at com.sap.xs.jdbc.datasource.valve.JDBCValve.invoke(JDBCValve.java:62)
at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:19)
at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43)
at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:40)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:695)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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:836)









share|improve this question
























  • Could you provide some details on the SDK version and project archetype that you are using?

    – Sander Wozniak
    Nov 15 '18 at 11:55











  • I did build application using blogs.sap.com/2017/07/18/…

    – Dama Ramesh
    Nov 15 '18 at 12:22














3












3








3








Getting below exception while fetching logged in user object using xsuaa approuter login



User currentUser = UserAccessor.getCurrentUser();


I am to get currentUser object without using GuiceFilter, If I apply GuiceFilter then getting below exception.



Any one Please suggest me how to get UserAccessor.getCurrentUser() with GuiceFilter



com.sap.cloud.sdk.cloudplatform.security.user.exception.UserAccessException: Failed to get current user: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUserIfAuthenticated(AbstractUserFacade.java:85)
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUser(AbstractUserFacade.java:135)
at com.sap.cloud.sdk.cloudplatform.security.user.UserAccessor.getCurrentUser(UserAccessor.java:122)
at com.company.HelloWorldServlet2.handleRequest(HelloWorldServlet2.java:35)
at com.company.BaseServlet.doPost(BaseServlet.java:120)
at com.company.BaseServlet.doGet(BaseServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:287)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:277)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:182)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:119)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:133)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:130)
at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:203)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:130)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66)
at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:191)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at com.sap.xs.jdbc.datasource.valve.JDBCValve.invoke(JDBCValve.java:62)
at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:19)
at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43)
at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:40)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:695)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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:836)









share|improve this question
















Getting below exception while fetching logged in user object using xsuaa approuter login



User currentUser = UserAccessor.getCurrentUser();


I am to get currentUser object without using GuiceFilter, If I apply GuiceFilter then getting below exception.



Any one Please suggest me how to get UserAccessor.getCurrentUser() with GuiceFilter



com.sap.cloud.sdk.cloudplatform.security.user.exception.UserAccessException: Failed to get current user: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUserIfAuthenticated(AbstractUserFacade.java:85)
at com.sap.cloud.sdk.cloudplatform.security.user.AbstractUserFacade.getCurrentUser(AbstractUserFacade.java:135)
at com.sap.cloud.sdk.cloudplatform.security.user.UserAccessor.getCurrentUser(UserAccessor.java:122)
at com.company.HelloWorldServlet2.handleRequest(HelloWorldServlet2.java:35)
at com.company.BaseServlet.doPost(BaseServlet.java:120)
at com.company.BaseServlet.doGet(BaseServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:287)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:277)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:182)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:119)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:133)
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:130)
at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:203)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:130)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66)
at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:191)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at com.sap.xs.jdbc.datasource.valve.JDBCValve.invoke(JDBCValve.java:62)
at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:19)
at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43)
at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:40)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:695)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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:836)






java s4sdk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:57









Sander Wozniak

1,008412




1,008412










asked Nov 15 '18 at 6:46









Dama RameshDama Ramesh

626




626












  • Could you provide some details on the SDK version and project archetype that you are using?

    – Sander Wozniak
    Nov 15 '18 at 11:55











  • I did build application using blogs.sap.com/2017/07/18/…

    – Dama Ramesh
    Nov 15 '18 at 12:22


















  • Could you provide some details on the SDK version and project archetype that you are using?

    – Sander Wozniak
    Nov 15 '18 at 11:55











  • I did build application using blogs.sap.com/2017/07/18/…

    – Dama Ramesh
    Nov 15 '18 at 12:22

















Could you provide some details on the SDK version and project archetype that you are using?

– Sander Wozniak
Nov 15 '18 at 11:55





Could you provide some details on the SDK version and project archetype that you are using?

– Sander Wozniak
Nov 15 '18 at 11:55













I did build application using blogs.sap.com/2017/07/18/…

– Dama Ramesh
Nov 15 '18 at 12:22






I did build application using blogs.sap.com/2017/07/18/…

– Dama Ramesh
Nov 15 '18 at 12:22













2 Answers
2






active

oldest

votes


















3














Essentially, Sander's answer is already correct (please kindly accept his). To be more precise your definition in web.xml must look the following way (omitting all the other ServletFilters before):



<!-- other filter go here -->

<filter>
<filter-name>RequestContextServletFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RequestContextServletFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


I've tried your minimal non-working example with this and the exception disappears. Using the ALLOW_MOCKED_AUTH_HEADER: true environment variable an empty user is returned which is proof enough that the filter applies before the Guice filter:



enter image description here






share|improve this answer























  • Philipp, I am confusing.. My application should work with login authentication (localhost:5000/hello1) right? I need to get loggedin user object & Destination object. Please suggest me good approach...

    – Dama Ramesh
    Nov 26 '18 at 3:47











  • Your question was about the RequestContext exception. If this has disappeared, I suggest accepting this answer and raising a follow-up question if you have troubles gerting the user principal from a secured application.

    – Philipp Herzig
    Nov 26 '18 at 7:57



















1














From the stack trace, it looks like the GuiceFilter is invoked while the RequestContextServletFilter is not. The RequestContextServletFilter initializes a RequestContext, which is a prerequisite for retrieving user information.



Can you try to explicitly declare the RequestContextServletFilter in your web.xml file?






share|improve this answer























  • Not working after adding RequestContextServletFilter in my web.xml

    – Dama Ramesh
    Nov 15 '18 at 9:38












  • Getting same exception after adding new RequestContextExecutor().execute(...); also. Suggest me what I missed

    – Dama Ramesh
    Nov 15 '18 at 11:39











  • Could you please present the entire stacktrace again and whether the RequestContextServletFilter now appears in the trace? If yes, could you please post a MWE so that we can reproduce the issue?

    – Philipp Herzig
    Nov 15 '18 at 20:31






  • 1





    Can you try to move the RequestContextServletFilter before the GuiceFilter in the web.xml?

    – Sander Wozniak
    Nov 19 '18 at 14:46






  • 1





    Sander, I uploaded non-working example in github, please suggest me.

    – Dama Ramesh
    Nov 22 '18 at 9:35










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313837%2ffailed-to-get-current-user-no-requestcontext-available%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Essentially, Sander's answer is already correct (please kindly accept his). To be more precise your definition in web.xml must look the following way (omitting all the other ServletFilters before):



<!-- other filter go here -->

<filter>
<filter-name>RequestContextServletFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RequestContextServletFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


I've tried your minimal non-working example with this and the exception disappears. Using the ALLOW_MOCKED_AUTH_HEADER: true environment variable an empty user is returned which is proof enough that the filter applies before the Guice filter:



enter image description here






share|improve this answer























  • Philipp, I am confusing.. My application should work with login authentication (localhost:5000/hello1) right? I need to get loggedin user object & Destination object. Please suggest me good approach...

    – Dama Ramesh
    Nov 26 '18 at 3:47











  • Your question was about the RequestContext exception. If this has disappeared, I suggest accepting this answer and raising a follow-up question if you have troubles gerting the user principal from a secured application.

    – Philipp Herzig
    Nov 26 '18 at 7:57
















3














Essentially, Sander's answer is already correct (please kindly accept his). To be more precise your definition in web.xml must look the following way (omitting all the other ServletFilters before):



<!-- other filter go here -->

<filter>
<filter-name>RequestContextServletFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RequestContextServletFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


I've tried your minimal non-working example with this and the exception disappears. Using the ALLOW_MOCKED_AUTH_HEADER: true environment variable an empty user is returned which is proof enough that the filter applies before the Guice filter:



enter image description here






share|improve this answer























  • Philipp, I am confusing.. My application should work with login authentication (localhost:5000/hello1) right? I need to get loggedin user object & Destination object. Please suggest me good approach...

    – Dama Ramesh
    Nov 26 '18 at 3:47











  • Your question was about the RequestContext exception. If this has disappeared, I suggest accepting this answer and raising a follow-up question if you have troubles gerting the user principal from a secured application.

    – Philipp Herzig
    Nov 26 '18 at 7:57














3












3








3







Essentially, Sander's answer is already correct (please kindly accept his). To be more precise your definition in web.xml must look the following way (omitting all the other ServletFilters before):



<!-- other filter go here -->

<filter>
<filter-name>RequestContextServletFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RequestContextServletFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


I've tried your minimal non-working example with this and the exception disappears. Using the ALLOW_MOCKED_AUTH_HEADER: true environment variable an empty user is returned which is proof enough that the filter applies before the Guice filter:



enter image description here






share|improve this answer













Essentially, Sander's answer is already correct (please kindly accept his). To be more precise your definition in web.xml must look the following way (omitting all the other ServletFilters before):



<!-- other filter go here -->

<filter>
<filter-name>RequestContextServletFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RequestContextServletFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


I've tried your minimal non-working example with this and the exception disappears. Using the ALLOW_MOCKED_AUTH_HEADER: true environment variable an empty user is returned which is proof enough that the filter applies before the Guice filter:



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 17:29









Philipp HerzigPhilipp Herzig

68048




68048












  • Philipp, I am confusing.. My application should work with login authentication (localhost:5000/hello1) right? I need to get loggedin user object & Destination object. Please suggest me good approach...

    – Dama Ramesh
    Nov 26 '18 at 3:47











  • Your question was about the RequestContext exception. If this has disappeared, I suggest accepting this answer and raising a follow-up question if you have troubles gerting the user principal from a secured application.

    – Philipp Herzig
    Nov 26 '18 at 7:57


















  • Philipp, I am confusing.. My application should work with login authentication (localhost:5000/hello1) right? I need to get loggedin user object & Destination object. Please suggest me good approach...

    – Dama Ramesh
    Nov 26 '18 at 3:47











  • Your question was about the RequestContext exception. If this has disappeared, I suggest accepting this answer and raising a follow-up question if you have troubles gerting the user principal from a secured application.

    – Philipp Herzig
    Nov 26 '18 at 7:57

















Philipp, I am confusing.. My application should work with login authentication (localhost:5000/hello1) right? I need to get loggedin user object & Destination object. Please suggest me good approach...

– Dama Ramesh
Nov 26 '18 at 3:47





Philipp, I am confusing.. My application should work with login authentication (localhost:5000/hello1) right? I need to get loggedin user object & Destination object. Please suggest me good approach...

– Dama Ramesh
Nov 26 '18 at 3:47













Your question was about the RequestContext exception. If this has disappeared, I suggest accepting this answer and raising a follow-up question if you have troubles gerting the user principal from a secured application.

– Philipp Herzig
Nov 26 '18 at 7:57






Your question was about the RequestContext exception. If this has disappeared, I suggest accepting this answer and raising a follow-up question if you have troubles gerting the user principal from a secured application.

– Philipp Herzig
Nov 26 '18 at 7:57














1














From the stack trace, it looks like the GuiceFilter is invoked while the RequestContextServletFilter is not. The RequestContextServletFilter initializes a RequestContext, which is a prerequisite for retrieving user information.



Can you try to explicitly declare the RequestContextServletFilter in your web.xml file?






share|improve this answer























  • Not working after adding RequestContextServletFilter in my web.xml

    – Dama Ramesh
    Nov 15 '18 at 9:38












  • Getting same exception after adding new RequestContextExecutor().execute(...); also. Suggest me what I missed

    – Dama Ramesh
    Nov 15 '18 at 11:39











  • Could you please present the entire stacktrace again and whether the RequestContextServletFilter now appears in the trace? If yes, could you please post a MWE so that we can reproduce the issue?

    – Philipp Herzig
    Nov 15 '18 at 20:31






  • 1





    Can you try to move the RequestContextServletFilter before the GuiceFilter in the web.xml?

    – Sander Wozniak
    Nov 19 '18 at 14:46






  • 1





    Sander, I uploaded non-working example in github, please suggest me.

    – Dama Ramesh
    Nov 22 '18 at 9:35















1














From the stack trace, it looks like the GuiceFilter is invoked while the RequestContextServletFilter is not. The RequestContextServletFilter initializes a RequestContext, which is a prerequisite for retrieving user information.



Can you try to explicitly declare the RequestContextServletFilter in your web.xml file?






share|improve this answer























  • Not working after adding RequestContextServletFilter in my web.xml

    – Dama Ramesh
    Nov 15 '18 at 9:38












  • Getting same exception after adding new RequestContextExecutor().execute(...); also. Suggest me what I missed

    – Dama Ramesh
    Nov 15 '18 at 11:39











  • Could you please present the entire stacktrace again and whether the RequestContextServletFilter now appears in the trace? If yes, could you please post a MWE so that we can reproduce the issue?

    – Philipp Herzig
    Nov 15 '18 at 20:31






  • 1





    Can you try to move the RequestContextServletFilter before the GuiceFilter in the web.xml?

    – Sander Wozniak
    Nov 19 '18 at 14:46






  • 1





    Sander, I uploaded non-working example in github, please suggest me.

    – Dama Ramesh
    Nov 22 '18 at 9:35













1












1








1







From the stack trace, it looks like the GuiceFilter is invoked while the RequestContextServletFilter is not. The RequestContextServletFilter initializes a RequestContext, which is a prerequisite for retrieving user information.



Can you try to explicitly declare the RequestContextServletFilter in your web.xml file?






share|improve this answer













From the stack trace, it looks like the GuiceFilter is invoked while the RequestContextServletFilter is not. The RequestContextServletFilter initializes a RequestContext, which is a prerequisite for retrieving user information.



Can you try to explicitly declare the RequestContextServletFilter in your web.xml file?







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 8:08









Sander WozniakSander Wozniak

1,008412




1,008412












  • Not working after adding RequestContextServletFilter in my web.xml

    – Dama Ramesh
    Nov 15 '18 at 9:38












  • Getting same exception after adding new RequestContextExecutor().execute(...); also. Suggest me what I missed

    – Dama Ramesh
    Nov 15 '18 at 11:39











  • Could you please present the entire stacktrace again and whether the RequestContextServletFilter now appears in the trace? If yes, could you please post a MWE so that we can reproduce the issue?

    – Philipp Herzig
    Nov 15 '18 at 20:31






  • 1





    Can you try to move the RequestContextServletFilter before the GuiceFilter in the web.xml?

    – Sander Wozniak
    Nov 19 '18 at 14:46






  • 1





    Sander, I uploaded non-working example in github, please suggest me.

    – Dama Ramesh
    Nov 22 '18 at 9:35

















  • Not working after adding RequestContextServletFilter in my web.xml

    – Dama Ramesh
    Nov 15 '18 at 9:38












  • Getting same exception after adding new RequestContextExecutor().execute(...); also. Suggest me what I missed

    – Dama Ramesh
    Nov 15 '18 at 11:39











  • Could you please present the entire stacktrace again and whether the RequestContextServletFilter now appears in the trace? If yes, could you please post a MWE so that we can reproduce the issue?

    – Philipp Herzig
    Nov 15 '18 at 20:31






  • 1





    Can you try to move the RequestContextServletFilter before the GuiceFilter in the web.xml?

    – Sander Wozniak
    Nov 19 '18 at 14:46






  • 1





    Sander, I uploaded non-working example in github, please suggest me.

    – Dama Ramesh
    Nov 22 '18 at 9:35
















Not working after adding RequestContextServletFilter in my web.xml

– Dama Ramesh
Nov 15 '18 at 9:38






Not working after adding RequestContextServletFilter in my web.xml

– Dama Ramesh
Nov 15 '18 at 9:38














Getting same exception after adding new RequestContextExecutor().execute(...); also. Suggest me what I missed

– Dama Ramesh
Nov 15 '18 at 11:39





Getting same exception after adding new RequestContextExecutor().execute(...); also. Suggest me what I missed

– Dama Ramesh
Nov 15 '18 at 11:39













Could you please present the entire stacktrace again and whether the RequestContextServletFilter now appears in the trace? If yes, could you please post a MWE so that we can reproduce the issue?

– Philipp Herzig
Nov 15 '18 at 20:31





Could you please present the entire stacktrace again and whether the RequestContextServletFilter now appears in the trace? If yes, could you please post a MWE so that we can reproduce the issue?

– Philipp Herzig
Nov 15 '18 at 20:31




1




1





Can you try to move the RequestContextServletFilter before the GuiceFilter in the web.xml?

– Sander Wozniak
Nov 19 '18 at 14:46





Can you try to move the RequestContextServletFilter before the GuiceFilter in the web.xml?

– Sander Wozniak
Nov 19 '18 at 14:46




1




1





Sander, I uploaded non-working example in github, please suggest me.

– Dama Ramesh
Nov 22 '18 at 9:35





Sander, I uploaded non-working example in github, please suggest me.

– Dama Ramesh
Nov 22 '18 at 9:35

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313837%2ffailed-to-get-current-user-no-requestcontext-available%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto