shiro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harald Wellmann (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (SHIRO-422) Reference CDI Managed Beans from INI files
Date Sun, 10 Mar 2013 16:49:12 GMT

    [ https://issues.apache.org/jira/browse/SHIRO-422?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13598303#comment-13598303
] 

Harald Wellmann edited comment on SHIRO-422 at 3/10/13 4:47 PM:
----------------------------------------------------------------

The attached patch depends on and includes the patch previously submitted for SHIRO-337.

Solution:

There is a new CdiIniWebEnvironment to be configured in web.xml:

    <context-param>
        <param-name>shiroEnvironmentClass</param-name>
        <param-value>org.apache.shiro.cdi.web.CdiIniWebEnvironment</param-value>
    </context-param>

This environment adds all CDI managed beans qualified with @ShiroIni to the Shiro environment.
These beans can be referenced in INI files by the equivalent of their EL name. 

Example:

@ShiroIni
public class DemoRealm extends AuthenticatingRealm {
    
    @Inject
    private UserDao userDao;
}

This bean can be referenced as $demoRealm. When the bean name can not be derived automatically
or when the default should be overriden, it can be specified explicitly by a @Named("foo")
qualifier.

The CdiIniWebEnvironment is provided by a new module shiro-cdi-web which depends on shiro-cdi
and shiro-web.

For non-web applications, the same functionality is provided by a CdiIniSecurityManagerFactory
which takes a BeanManager constructor argument. This factory has been added to the shiro-cdi
module from SHIRO-337.

There is a sample application samples-cdi-web using a CdiIniWebEnvironment and a shiro.ini
including some references to CDI beans.

To see the whole lot in context: https://github.com/hwellmann/shiro
                
      was (Author: hwellmann):
    The attached patch depends on and includes the patch previously submitted for SHIRO-337.
                  
> Reference CDI Managed Beans from INI files
> ------------------------------------------
>
>                 Key: SHIRO-422
>                 URL: https://issues.apache.org/jira/browse/SHIRO-422
>             Project: Shiro
>          Issue Type: New Feature
>          Components: Integration: JEE
>    Affects Versions: 1.2.1
>            Reporter: Harald Wellmann
>             Fix For: 1.3.0
>
>         Attachments: SHIRO-422.patch
>
>
> In Java EE 6, CDI is the default dependency mechanism, which is not currently integrated
with Shiro's lightweight DI using INI files.
> Example:
> [main]
> myRealm = com.example.MyRealm
> securityManager.realms = $myRealm
> In the MyRealm class, it would be natural to @Inject a UserDAO, but this does not work,
since the myRealm instance is directly created by Shiro and not managed by the CDI BeanManager.
> Requirement:
> Find a way to use CDI managed beans in INI files.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message