Skip to Content
author's profile photo Former Member
Former Member

HCP Java Servlet Filter / Principal was not set on initial request

Dear community,

I have a Java Application with Java Web Runtime running and need to authenticate the user via FORM authentication.

Declarative authentication is currently not possible for my usecase.

So I use the following code inside a filter to do programmatical authentication:

public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain)
        throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;

if(request.getRemoteUser() == null) {
     try {
          LoginContext loginContext = LoginContextFactory.createLoginContext("FORM");
      } catch (LoginException e) {
         unauthorized(response, "FORM Login failed");

The filter is the first and only one in the chain.

However I get the following exception after successful authentication and the application crashes:

2016 07 05 11:52:39#+00#ERROR#org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/xxxxxxx].[]##D066389#http-bio-8041-exec-5#na#abb86455f#osg#web#abb86455f#Servlet.service() for servlet [] in context with path [/xxxxxxx] threw exception Principal 'xxxxxxx(authentication method: SAML2)


MNI terminated=false

' was not set on initial request, but was received on a subsequent request which is illegal.

Principal was not sent on initial request? What does that mean?

I thought that it is always the case that we get the principal after redirect from SAP cloud id service?

Can someone please tell me what is going wrong here?

Best Regards

Martin Löper

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 19, 2016 at 04:37 PM

    Has anybody an idea? Is there a documentation somewhere on what this exception means and how it is triggered?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      I found the reason for this exception.

      For anybody who is interested: This exception happened due to a misconfiguration of HttpDestinations within the servlet which was applied after the Filter. It reused an existing Destination instead of requesting a new one.

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.