Skip to content
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

[SHIRO-889] Provide Jakarta jar modules #522

Merged
merged 1 commit into from
Nov 18, 2022
Merged

Conversation

fpapon
Copy link
Member

@fpapon fpapon commented Nov 2, 2022

No description provided.

@bmarwell
Copy link
Contributor

bmarwell commented Nov 2, 2022

Maybe we can user undertow?
Here's a basic setup without deployment and empty instance manager.
All you need to do: configure the .war and stop the server again later.

Switched to non-TLS for test purposes.

fpapon/shiro@SHIRO-889...apache:shiro:SHIRO-889_undertow

WDYT?

@fpapon
Copy link
Member Author

fpapon commented Nov 3, 2022

Maybe we can user undertow? Here's a basic setup without deployment and empty instance manager. All you need to do: configure the .war and stop the server again later.

Switched to non-TLS for test purposes.

fpapon/shiro@SHIRO-889...apache:shiro:SHIRO-889_undertow

WDYT?

Thank you! I will take a look :)

@fpapon fpapon force-pushed the SHIRO-889 branch 2 times, most recently from 434b15f to 5d7e615 Compare November 3, 2022 19:35

// Dealing with a keystore is NOT fun, it's easier to script one with the keytool
// see src/main/resources/createKeyStore.sh for more info
private static File setupKeyStore() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed, as this test now uses http which is sufficient

samples/web-jakarta/src/test/resources/createKeyStore.sh Outdated Show resolved Hide resolved
samples/web-jakarta/src/test/resources/test-keystore.pem Outdated Show resolved Hide resolved
@lprimak
Copy link
Contributor

lprimak commented Nov 6, 2022

Question: why is there separate packages to be renamed in the shade plugin ?
Can’t it just be done in a single javax->jakarta rename and not individual packages such as JaxRS etc?

Copy link
Contributor

@bmarwell bmarwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Just some nits and some imports, then it is close-to-done (imho)!

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are mixing junit4 and junit-jupiter assertions here. Please completely switch to -jupiter for all new tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... or maybe even assertj.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertj is not needed :)

final Client client = ClientBuilder.newClient();

try {
final Response loginPage = client.target(getBaseUri())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response needs to be close()d. However, you might be able to use auto-closeable. https://jakarta.ee/specifications/platform/8/apidocs/javax/ws/rs/core/response#close--

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client is closed in finally so I don't think we need to close the response but I can close it also in finally.

final Cookie jsessionid = new Cookie("JSESSIONID",loginPage.getMetadata().get("Set-Cookie").get(0).toString().split(";")[0].split("=")[1]);
Assertions.assertTrue(loginPage.readEntity(String.class).contains("loginform"));

final Response loginAction = client.target(getBaseUri())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. Needs close().

color: black;
background: #eee;
border: thick black solid;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line feed missing at end of file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird because I copy/paste the web module sample without modification...

--%>

<%-- Forward the user to the home page --%>
<jsp:forward page="home.jsp"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line feed missing at EOF

<%@ page import="org.apache.shiro.SecurityUtils" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LF at EOF

<p><a href="<c:url value="/logout"/>" onclick="document.getElementById('logout_form').submit();return false;">Log out.</a></p>
<form id="logout_form" action="<c:url value="/logout"/>" method="post"></form>
</body>
</html>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+LF

@fpapon
Copy link
Member Author

fpapon commented Nov 11, 2022

@bmarwell changes done

Copy link
Member

@bdemers bdemers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm +0.5, I worry a little about the jakarta classifier, as the exclude * will drop all of the dependencies (so the user would probably need to add the other bits like shiro-core to their pom)
But... that's not the end of the world, and other projects are doing the same thing (e.g. meecrowave)
I think getting it in as is and getting feedback from interested parties makes it worth merging now.
(given other projects are doing something similar, I'm hesitant to try to suggest an over-engineered solution 🤣 :)

TL;DR - my opinion is to merge it

@fpapon
Copy link
Member Author

fpapon commented Nov 18, 2022

I'm +0.5, I worry a little about the jakarta classifier, as the exclude * will drop all of the dependencies (so the user would probably need to add the other bits like shiro-core to their pom) But... that's not the end of the world, and other projects are doing the same thing (e.g. meecrowave) I think getting it in as is and getting feedback from interested parties makes it worth merging now. (given other projects are doing something similar, I'm hesitant to try to suggest an over-engineered solution rofl :)

TL;DR - my opinion is to merge it

Hi, yes but honestly I don't know how to do it differently without a lot of code...
I will add a page on the Shiro website to well document the usage of the jakarta classifier.

@garydgregory
Copy link
Member

Releasing takes time and effort, which will happen, just not right now.

@bdemers
Copy link
Member

bdemers commented Nov 18, 2022

without a lot of code...

@fpapon exactly my concern too! Let’s move forward with this PR 🚢

@fpapon fpapon merged commit b6b5849 into apache:main Nov 18, 2022
@fpapon
Copy link
Member Author

fpapon commented Nov 18, 2022

Thanks, now I will prepare a PR for 1.11.x

@lucasdillmann
Copy link
Contributor

Hello everyone.

First of all, a huge thanks on the work to provide the Jakarta JARs.

Looking in the 2.0.0 nightly snapshots, I was able to find the artifacts over the shiro-web and shiro-spring modules, but I couldn't find them in the shiro-spring-boot, shiro-spring-boot-starter and shiro-spring-boot-web-started.

Isn't needed to create the jakarta variant JAR/POM on the Spring Boot modules as well?

@lprimak
Copy link
Contributor

lprimak commented Jan 5, 2023

@lucasdillmann I don't think Shiro spring is compatible with Spring 6 or SpringBoot 3 quite yet. Not sure if those modules can be currently done. I am not a Spring user so I can't comment further.

@lucasdillmann
Copy link
Contributor

lucasdillmann commented Jan 5, 2023

@lprimak Is there any way I could help you guys in order to check/test if it's compatible?

For example, if I create a test project with some basic scenarios as a POC (using a Shiro fork just to change to the Jakarta APIs on the boot modules), will it be useful in any way?

@lprimak
Copy link
Contributor

lprimak commented Jan 5, 2023

If it's only that Jakarta relocations are needed, you can try to add the shade plugin in your fork the same way other modules are done. That would be very helpful and appreciated!
The issue is that I personally can't test it because I am not a spring user.
Thank you!

@lucasdillmann
Copy link
Contributor

I'll do it and get back here with the results soon. As far I've seen in the source code, the changes come down to one single import change in this file (apart from the dependency graph between the modules).

@lucasdillmann
Copy link
Contributor

@lprimak I finished the tests here using Spring Boot 3.0.1, and everything seems to be working just fine.

The source code of the test project is available here. I didn't uplod the changes in the Shiro source, but it is just the inclusion of the maven-shade-plugin in the shiro-spring-boot module.

In short, these are the (exploratory) tests I've made:

  • Check if subject is authenticated or not using both the annotations (RequiresUser, RequiresGuest and RequiresAuthentication) and programmatic code.
  • Check if subject has a permission or not, also using the RequiresPermissions annotation and the Subject#checkPermission method.
  • Check if subject has a role or not, also using the RequiresRoles annotation and Subject#checkRole
  • Login and logout procedures

The only "problem" I've found is in the dependency management: If you check the build.gradle file here you will see that I needed to explicitly include every module with the jakarta variant and exclude the regular one. This happens because of the POM file contents, which bring the regular JAR as transitive.

I don't know if this is expected or not and, if it isn't, if it should be changed or not.

@lprimak
Copy link
Contributor

lprimak commented Jan 6, 2023

Can you please submit a PR for this? Sounds like a simple fix. Yes, the dependency management issue is expected.

@lucasdillmann
Copy link
Contributor

Sure. PR code is #632.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants