You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by "lprimak (via GitHub)" <gi...@apache.org> on 2026/01/30 21:00:38 UTC

[PR] [3.0] Support scoped values [shiro]

lprimak opened a new pull request, #2485:
URL: https://github.com/apache/shiro/pull/2485

   …Local
   
   Allows for graceful fallback to ThreadLocal if something goes wrong
   
   <!--
   For Security Vulnerabilities, please email: security@shiro.apache.org
   For more details on how to report a vulnerability see: https://www.apache.org/security/
   -->
   
   Following this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Make sure there is a [GitHub issue](https://github.com/apache/shiro/issues) filed
          for the change (usually before you start working on it).  Trivial changes like typos do not
          require a GitHub issue.  Your pull request should address just this issue, without pulling in other changes.
    - [ ] Format the pull request title like `[#XXX] - Fixes bug in SessionManager`,
          where you replace `#XXX` with the appropriate GitHub issue. Best practice
          is to use the GitHub issue title in the pull request title and in the first line of the commit message.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] add `fixes #XXX` if merging the PR should close a related issue.
    - [ ] Run `mvn verify` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
    - [ ] Committers: Make sure a milestone is set on the PR
    - [ ] Committers: Use "Squash and Merge" to combine all commits into one when merging a PR when appropriate.
   
   Trivial changes like typos do not require a GitHub issue (javadoc, comments...).
   In this case, just format the pull request title like `[DOC] - Add javadoc in SessionManager`.
   
   If this is your first contribution, you have to read the [Contribution Guidelines](https://github.com/apache/shiro/blob/master/CONTRIBUTING.md)
   
   If your pull request is about ~20 lines of code you don't need to sign an [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf)
   if you are unsure please ask on the developers list.
   
   To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on PR #2485:
URL: https://github.com/apache/shiro/pull/2485#issuecomment-3873139594

   @boris-petrov Can you please review this please?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on PR #2485:
URL: https://github.com/apache/shiro/pull/2485#issuecomment-3878835904

   @bmarwell you are the only reviewer left :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on PR #2485:
URL: https://github.com/apache/shiro/pull/2485#issuecomment-3877971899

   Possible... but thing like that are "enterprise feature" INHO


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "bmarwell (via GitHub)" <gi...@apache.org>.
bmarwell commented on code in PR #2485:
URL: https://github.com/apache/shiro/pull/2485#discussion_r2781056782


##########
core/src/main/java25/org/apache/shiro/util/ScopedValues.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;
+
+import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.subject.support.SubjectCallable;
+import org.apache.shiro.subject.support.SubjectRunnable;
+import java.util.concurrent.Callable;
+
+public final class ScopedValues {
+    private static final ScopedValue<Values> VALUES = ScopedValue.newInstance();
+
+    public static final boolean SCOPED_VALUES_SUPPORTED = true;
+    public record Values(SecurityManager securityManager, Subject subject) { }

Review Comment:
   Same, documentation. Ah yes, this is the other implementation :) 
   
   My recommendation when using MR-Jars is always: Implement an interface and only use the methods. Reason: Do not let the implementations diverge.
   



##########
core/src/main/java/org/apache/shiro/util/ScopedValues.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;
+
+import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.subject.support.SubjectCallable;
+import org.apache.shiro.subject.support.SubjectRunnable;
+import java.util.concurrent.Callable;
+
+public final class ScopedValues {
+    public static final boolean SCOPED_VALUES_SUPPORTED = false;
+    public record Values(SecurityManager securityManager, Subject subject) { }

Review Comment:
   This needs documentation how you think this might be used in the future. MR-JARs?



##########
core/src/main/java25/org/apache/shiro/util/ScopedValues.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;
+
+import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.subject.support.SubjectCallable;
+import org.apache.shiro.subject.support.SubjectRunnable;
+import java.util.concurrent.Callable;
+
+public final class ScopedValues {
+    private static final ScopedValue<Values> VALUES = ScopedValue.newInstance();
+
+    public static final boolean SCOPED_VALUES_SUPPORTED = true;
+    public record Values(SecurityManager securityManager, Subject subject) { }

Review Comment:
   Same for the values record. Make it an interface, and implement it only in the JDK25 class. I does not need to live in the <25 source code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on PR #2485:
URL: https://github.com/apache/shiro/pull/2485#issuecomment-3873788375

   Thanks for the review, @boris-petrov 
   What you are suggesting was my first thought, but unfortunately it really didn't wind up having advantages, just disadvantages. 
   
   The main issue here is that ScopedValues is not really a polymorphism and shoehorning strategy pattern only made things worse.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "boris-petrov (via GitHub)" <gi...@apache.org>.
boris-petrov commented on PR #2485:
URL: https://github.com/apache/shiro/pull/2485#issuecomment-3873381779

   I haven't looked in details at the implementation but wouldn't it be better if there were a couple of new classes like `ScopedValuesCallable` and `ScopedValuesRunnable` which would extend `SubjectCallable`/`SubjectRunnable` (or perhaps even directly `Callable`/`Runnable`)? And then at the instantiation site choose which one is appropriate? Not sure if that would make sense and if it would make the code "better"?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "boris-petrov (via GitHub)" <gi...@apache.org>.
boris-petrov commented on PR #2485:
URL: https://github.com/apache/shiro/pull/2485#issuecomment-3877287937

   So it's great then! Do you think it would be easy/possible to back-port this to Shiro 2.x?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak merged PR #2485:
URL: https://github.com/apache/shiro/pull/2485


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on PR #2485:
URL: https://github.com/apache/shiro/pull/2485#issuecomment-3873097654

   @bmarwell I have refactored the code into interfaces, like you suggested. Thank you!
   Can you please re-review?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#1862] [3.0] Support for JDK 25 scoped values [shiro]

Posted by "lprimak (via GitHub)" <gi...@apache.org>.
lprimak commented on code in PR #2485:
URL: https://github.com/apache/shiro/pull/2485#discussion_r2783457362


##########
core/src/main/java25/org/apache/shiro/util/ScopedValues.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.util;
+
+import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.subject.support.SubjectCallable;
+import org.apache.shiro.subject.support.SubjectRunnable;
+import java.util.concurrent.Callable;
+
+public final class ScopedValues {
+    private static final ScopedValue<Values> VALUES = ScopedValue.newInstance();
+
+    public static final boolean SCOPED_VALUES_SUPPORTED = true;
+    public record Values(SecurityManager securityManager, Subject subject) { }

Review Comment:
   Ah yes, the latest implementation does support that pattern.
   I will make it so.
   Yes!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org