I don't seem to get it all to work.
I have my own WebEnvironment and try to inject the JpaRealm into it.
The problem seems to be that the JpaRealm is not instantiated and is not
injected into the CdiWebEnvironment.
This is basically what I currently have:
### WEB.XML SNIPPET ###
<context-param>
<param-name>shiroEnvironmentClass</param-name>
<param-value>****.shiro.CdiWebEnvironment</param-value>
</context-param>
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
### SHIRO.INI ###
[main]
authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
authc.loginUrl = /login.jsf
[users]
[roles]
[urls]
/login.jsf = authc
/secure/** = authc
### CUSTOM WEB ENVIRONMENT ###
@ApplicationScoped
public class CdiWebEnvironment extends IniWebEnvironment
{
private static Logger LOG = Logger.getLogger(CdiWebEnvironment.class);
@Inject
private JpaRealm jpaRealm;
@Inject
public CdiWebEnvironment() {
LOG.debug("CdiWebEnvironment instantiated!");
}
@Override
protected void configure() {
super.configure();
/* WHILE DEBUGGING jpaRealm IS NULL AT THIS POINT! */
RealmSecurityManager securityManager = (RealmSecurityManager)
getSecurityManager();
securityManager.setRealm(jpaRealm);
}
}
### JPA REALM CLASS ###
@ApplicationScoped
public class JpaRealm extends AuthorizingRealm
{
private static Logger LOG = Logger.getLogger(JpaRealm.class);
@PersistenceContext
private EntityManager entityManager;
public JpaRealm() {
/* THIS LINE IS NEVER REACHED, SO NO INSTANCE IS CREATED! */
setName("JpaRealm");
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher();
matcher.setHashAlgorithmName("SHA-256");
setCredentialsMatcher(matcher);
LOG.debug("JpaRealm instantiated!");
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken
authenticationToken) { ... }
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection
principals) { ... }
}
atomicknight wrote
>
> The Environment is loaded by a servlet context listener, which is managed
> by the container and consequently supports injection. Then it's just a
> matter of injecting your JpaRealm, building a WebSecurityManager from it,
> and associating the SecurityManager with the Environment.
>
--
View this message in context:
http://shiro-user.582556.n2.nabble.com/Shiro-in-CDI-JPA2-JSF2-project-tp7577437p7577442.html
Sent from the Shiro User mailing list archive at Nabble.com.