-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring http security #9
Comments
@BaranovNikita Are your REST controller endpoints packaged within a PortletMVC4Spring based WAR project? If so, is it being deployed to Liferay, Pluto, or some other portal? |
Yes, ofcourse. I have a WAR artifact that deployed in Liferay 7.3.0 portal |
@BaranovNikita When you get an opportunity, please paste an example of a URL that is used to invoke the REST endpoint. Also, could you paste a link to an SSCCE that I can build with Maven or Gradle and deploy locally in order to try and reproduce the problem? |
Hello! I'm try create simple project with this error, but I'm change Order property for Security Config and got other error (CSRF). Can you check it, please? Thanks |
@BaranovNikita Thank you for providing the SSCCE. After commenting out the However, I cannot add the portlet named
Having said that, I think the main problem you are describing is not a portlet-related problem but a instead it is a problem with usage of Please paste an example of a URL that is used to invoke the REST endpoint so that I can try to reproduce the problem. Thanks. |
I dont wanna use it for visible portlet. Only for REST Spring service. In this sample we have 2 endpoints: |
@BaranovNikita I think I know the reason why your |
Here is a new project that I created that shows how to make it work -- it defines a portlet with a JSP that has test URLs that you can invoke: com.liferay.test.portletmvc4spring.portlet-src.zip Also, please take special note of the
I had to create two mappings in order to distinguish between the |
@BaranovNikita Note that the reason why CSRF is enforced is because you specified it in the configuration:
|
but..I use disable() for that? |
@BaranovNikita You're right, I didn't see the call to Do you have the following bean defined in one of your Spring XML config files?
If so, then CSRF will be enabled because of the following: If that's the case, then you could define your RestSecurityConfig like the following:
(Note that in my testing I had to put it just before the delegatingFilterProxy) However, there is a problem with your usage of the following:
Background: You are trying to use a Spring REST controller like you would in a typical webapp environment. PortletMVC4Spring portlet applications are invoked with PortletURLs, which causes the portlet lifecycle to be invoked using PortletRequests. Spring REST goes through a servlet, meaning it does not go through the portlet lifecycle. You are basically using the Servlet API in order to receive HttpServletRequests from Liferay's Web Application Bundle (WAB) Extender, just like you would with a WAR deployed in plain Tomcat. The problem is that the call to So... I decided to try and make this work. Attached you will find com.liferay.test.portletmvc4spring.portlet-try2-src.zip which is an updated project with some new source code. The
(BTW, I changed the role names to contain an UPPER-case first letter: Administrator instead of administrator, and Guest instead of guest) And there is some new source code for LiferayConfigurer.java and some associated classes. When you get an opportunity, please build this project and give it a try in your environment. If it works, then we can publish a new JAR in the PortletMVC4Spring project that contains the LiferayConfigurer. That way you would be able to reuse it in multiple projects. Kind Regards, Neil |
Thanks for that! May be you know, how I can do request from client side? |
You might need to use an absolute URL that contains the scheme, server, port etc like "http://localhost:8080/o/com.liferay.test.portletmvc4spring.portlet/test/secured" Here is an example that I recently got to work in portlet JSP: You're probably not using JSP from within a portlet view so you wouldn't be able to use JSP tags like Please let me know if you get things working and I start scheduling a time to publish a new JAR in the PortletMVC4Spring project that contains the LiferayConfigurer. Kind Regards, Neil |
Hello! I have small fix your code. I check User in request, not ThemeDisplay. May be it not work in JSP/Thymeleaf... But it work for simple REST controller :) Thank you very match! |
Hi @ngriffin7a , Thanks for the example ('com.liferay.test.portletmvc4spring.portlet-try2-src.zip') attached above. However, you're invoking the REST endpoints from JSP (or withing session scope). I would like to have it invoke from client (say Postman, or third party), so what kind of changes we would need to do in LiferayAuthentication.java? We want to extract user information from JWT token as part of JWT authentication. Is there any plan to add LiferayConfigurer and other classes you wrote in distrubution? |
Hello! I'm try to use spring security for some methods of my REST controller. But i have 403 error all time. My security config:
in web.xml:
Or Is it possible to protect some methods? Thanks!
The text was updated successfully, but these errors were encountered: