You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lp...@apache.org on 2023/03/29 03:34:21 UTC

[shiro-site] branch main updated: CDI Principal injection sync Optional -> ShiroPrincipal

This is an automated email from the ASF dual-hosted git repository.

lprimak pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shiro-site.git


The following commit(s) were added to refs/heads/main by this push:
     new 0ee3ce850 CDI Principal injection sync Optional -> ShiroPrincipal
0ee3ce850 is described below

commit 0ee3ce850165523febda7675ada00b942096d834
Author: lprimak <le...@flowlogix.com>
AuthorDate: Tue Mar 28 22:33:45 2023 -0500

    CDI Principal injection sync Optional -> ShiroPrincipal
---
 src/site/content/jakarta-ee.adoc | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/site/content/jakarta-ee.adoc b/src/site/content/jakarta-ee.adoc
index e05c926be..e11f01629 100644
--- a/src/site/content/jakarta-ee.adoc
+++ b/src/site/content/jakarta-ee.adoc
@@ -136,6 +136,7 @@ public class MyBean {
 
 === Injecting Shiro components and APIs
 Shiro APIs can be `@Inject` into CDI and EJB beans:
+
 [source,java]
 ----
 @ApplicationScoped
@@ -148,7 +149,7 @@ public class MyBean {
 
     @Inject
     @Principal
-    Optional<MyUserAccount> userAccount;
+    ShiroPrincipal<MyUserAccount> userAccount;
 
     @Inject
     Session session;
@@ -158,10 +159,9 @@ public class MyBean {
     Session optionalSession;
 }
 ----
-`Subject`, `Session` and `@Principal` are always treated as Request-Scoped beans. +
-If `Session` is annotated with `@NoSessionCreation` and if there is no existing session, `InvalidSessionException` is thrown when accessing the Injected session.
-Any Shiro Principal can be injected if annotated by `@Principal`. It must be injected as a Java optional, and may not be
-present if Shiro cannot retrieve it.
+`Subject`, `Session` and `ShiroPrincipal` are always treated as Request-Scoped beans. They are injectable into any Jakarta EE bean including Jax-RS, Servlet and other CDI beans. +
+If `Session` is annotated with `@NoSessionCreation` and there is no existing session, `InvalidSessionException` is thrown when accessing the Injected session. +
+Any Shiro principal object can be injected if annotated by `@Principal`. It must be injected as `ShiroPrincipal`, and `ShiroPrincipal.get()` may return null if there are no principals available of the injected type.
 
 == Jakarta EE Integration Module
 Jakarta EE integration module was inspired by this link:https://balusc.omnifaces.org/2013/01/apache-shiro-is-it-ready-for-java-ee-6.html[OmniFaces article] and brings everything together to seamlessly create secure Jakarta EE applications easily and with minimal configuration. The module works "the Shiro way" and uses shiro.ini in a straight-forward and intuitive way.