-2

I am making a servlet that is not meant to be used by browsers, it will be used by an java application that will use https requests to it.

So far I've managed to follow http://docs.spring.io/spring-security/site/docs/current/guides/html5//helloworld.html. If I attempt to access http://localhost:8080/myservlet/MainServletClass, it will redirect me to http://localhost:8080/myservlet/login as expected, but I don't get how I am supposed to use the methods from http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html to logout

Guedez
  • 189
  • 3
  • 14
  • 2
    You need to properly tag your question to get any type of real answer. Try tagging the actual software/framework name you are using, or at least the languages involved. – djhoese Feb 18 '16 at 11:55
  • I asked from http://spring.io/questions so I assumed that it was some sort of internal stackoverflow thingy, didn't notice that it redirected to http://stackoverflow.com – Guedez Feb 18 '16 at 12:05
  • Possible duplicate of [How to manually log out a user with spring security?](http://stackoverflow.com/questions/5727380/how-to-manually-log-out-a-user-with-spring-security) – Gimby Nov 04 '16 at 11:01

1 Answers1

0

You don't need to use HttpServletRequest, follow the guide you linked in your question..

Use a Standard Spring security example form to log out:

<body>
  <div class="container">
    <h1>This is secured!</h1>
    <p>
      Hello <b><c:out value="${pageContext.request.remoteUser}"/></b>
    </p>
    <c:url var="logoutUrl" value="/logout"/>
    <form class="form-inline" action="${logoutUrl}" method="post">
      <input type="submit" value="Log out" />
      <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
    </form>
  </div>
</body>

Using this form will authenticate your logged in user if you are using the latest version of Spring security.

If not, you need to ensure the forms action matches the configured .logoutUrl() configuration in your Spring Security configuration.

Community
  • 1
  • 1
syncdk
  • 2,820
  • 3
  • 25
  • 31
  • I actually gave up on this and and already managed to do with netty instead of servlets, so I have no idea if this is correct or not. Should I delete the question or just assume this answer is correct? or neither? – Guedez Nov 01 '16 at 18:23
  • Well this is the one from the Spring samples and works perfectly. – syncdk Nov 01 '16 at 19:43