You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Alex Sviridov <oo...@mail.ru> on 2020/05/06 08:22:50 UTC

Re[2]: onInit method on AuthenticatingRealm is called twice

Hi Brian,
 
Thank you for quick answer.
 
1) This is my shiro.ini
 
[main]
cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $cacheManager
realm = com.foo.TestRealm
securityManager.realms = $realm
 
2) This is my init code:
 
            Environment env = new BasicIniEnvironment(url.toString());
            final SecurityManager securityManager = env.getSecurityManager();
            SecurityUtils.setSecurityManager(securityManager);
 
3) This is my TestRealm
 
public class TestRealm extends AuthenticatingRealm {
    
    private static final Logger logger = LoggerFactory.getLogger(TestRealm.class);
    @Override
    protected void onInit() {
        logger.info("************************************On INIT");
        try {
            throw new Exception();
        } catch (Exception ex) {
            logger.error("Error", ex);
        }
        setCredentialsMatcher((AuthenticationToken at, AuthenticationInfo ai) -> {
            logger.info("################################ [{}], [{}]", at, ai);
            return false;
        });
        
    }
    
    
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
        logger.info("REALM username [{}], password [{}]", upToken.getUsername(), upToken.getPassword());
         return new SimpleAuthenticationInfo(new UserEntity(), null , getName());
    }
    
}
 
 
4) I tried to use shiro-core + shiro-web, but it seems to be impossible to use
shiro modules in jpms environment, so, I had to take shiro-all.
 
5) By the way, I couldn’t find javadoc and sources for shiro-al in maven repo
https://repo1.maven.org/maven2/org/apache/shiro/shiro-all/1.5.3/
 
Best regards, Alex
  
>Среда, 6 мая 2020, 4:09 +03:00 от Brian Demers <br...@gmail.com>:
> 
>It depends, we would need to see the full stack trace, it's unclear what is setting up your environment.  How are you configuring Shiro?
> 
>Also, I'd recommend against using the `shiro-all` and instead use `shiro-web`  
>On Tue, May 5, 2020 at 7:01 PM Alex Sviridov < ooo_saturn7@mail.ru > wrote:
>>Hi all,
>> 
>>I am just learning Shiro, but I noticed that onInit method on  on AuthenticatingRealm
>>is called twice. I have one TestRealm and this is stacktrace:
>> 
>>First call:
>> 
>>    at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>>    at org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:829) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:288) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41) [shiro-all-1.5.3.jar:?]
>> 
>> 
>>Second call:
>> 
>>    at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>>    at org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:61) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:292) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37) [shiro-all-1.5.3.jar:?]
>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41) [shiro-all-1.5.3.jar:?]
>> 
>>Could anyone say if it is a bug or it was done intentionally?
>> 
>>--
>>Best regards, Alex Sviridov 
 
 
--
Alex Sviridov
 

Re[4]: onInit method on AuthenticatingRealm is called twice

Posted by Alex Sviridov <oo...@mail.ru>.
Hi Brian,
 
1-3) I tried with Servket Filter and without it anyway onInit method is called twice. It seems to be bug.
 
4) As I see you have same packages for different modules, for example
shiro/core/src/main/java/org/apache/shiro/config
shiro/config/core/src/main/java/org/apache/shiro/config
Besides I found this issue —  https://issues.apache.org/jira/browse/SHIRO-679
 
5) I understood that you don’t have sources and javadoc for shiro-all. Maybe there is sense to add them?
If people can’t use your modules, please, make their lives easier.
 
Best regards, Alex
>Четверг, 7 мая 2020, 1:25 +03:00 от Brian Demers <br...@gmail.com>:
> 
>Hi Alex,
> 
> 
>1-3.)
>Do you also have the Shiro Servlet Filter configured?
> 
>4.) We don't currently generate module-info metadata, but if there is something that isn't working for you please start another thread :)
> 
>5.) We don't have sources & Javadoc jars for `shiro-all` we only produce them for the individual modules.
>   
>On Wed, May 6, 2020 at 4:23 AM Alex Sviridov < ooo_saturn7@mail.ru > wrote:
>>Hi Brian,
>> 
>>Thank you for quick answer.
>> 
>>1) This is my shiro.ini
>> 
>>[main]
>>cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
>>securityManager.cacheManager = $cacheManager
>>realm = com.foo.TestRealm
>>securityManager.realms = $realm
>> 
>>2) This is my init code:
>> 
>>            Environment env = new BasicIniEnvironment(url.toString());
>>            final SecurityManager securityManager = env.getSecurityManager();
>>            SecurityUtils.setSecurityManager(securityManager);
>> 
>>3) This is my TestRealm
>> 
>>public class TestRealm extends AuthenticatingRealm {
>>    
>>    private static final Logger logger = LoggerFactory.getLogger(TestRealm.class);
>>    @Override
>>    protected void onInit() {
>>         logger.info ("************************************On INIT");
>>        try {
>>            throw new Exception();
>>        } catch (Exception ex) {
>>            logger.error("Error", ex);
>>        }
>>        setCredentialsMatcher((AuthenticationToken at, AuthenticationInfo ai) -> {
>>             logger.info ("################################ [{}], [{}]", at, ai);
>>            return false;
>>        });
>>        
>>    }
>>    
>>    
>>    @Override
>>    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
>>        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
>>         logger.info ("REALM username [{}], password [{}]", upToken.getUsername(), upToken.getPassword());
>>         return new SimpleAuthenticationInfo(new UserEntity(), null , getName());
>>    }
>>    
>>}
>> 
>> 
>>4) I tried to use shiro-core + shiro-web, but it seems to be impossible to use
>>shiro modules in jpms environment, so, I had to take shiro-all.
>> 
>>5) By the way, I couldn’t find javadoc and sources for shiro-al in maven repo
>>https://repo1.maven.org/maven2/org/apache/shiro/shiro-all/1.5.3/
>> 
>>Best regards, Alex
>>  
>>>Среда, 6 мая 2020, 4:09 +03:00 от Brian Demers < brian.demers@gmail.com >:
>>> 
>>>It depends, we would need to see the full stack trace, it's unclear what is setting up your environment.  How are you configuring Shiro?
>>> 
>>>Also, I'd recommend against using the `shiro-all` and instead use `shiro-web`  
>>>On Tue, May 5, 2020 at 7:01 PM Alex Sviridov < ooo_saturn7@mail.ru > wrote:
>>>>Hi all,
>>>> 
>>>>I am just learning Shiro, but I noticed that onInit method on  on AuthenticatingRealm
>>>>is called twice. I have one TestRealm and this is stacktrace:
>>>> 
>>>>First call:
>>>> 
>>>>    at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>>>>    at org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:829) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:288) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41) [shiro-all-1.5.3.jar:?]
>>>> 
>>>> 
>>>>Second call:
>>>> 
>>>>    at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>>>>    at org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:61) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:292) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41) [shiro-all-1.5.3.jar:?]
>>>> 
>>>>Could anyone say if it is a bug or it was done intentionally?
>>>> 
>>>>--
>>>>Best regards, Alex Sviridov 
>> 
>> 
>>--
>>Alex Sviridov
>>  
 
 
--
Alex Sviridov
 

Re[5]: onInit method on AuthenticatingRealm is called twice

Posted by Alex Sviridov <oo...@mail.ru>.
Hi Brian,
 
1-3) I made a project on the base of your tutorial project. Its here:  https://github.com/PashaTurok/shirotest.git
Just do: mvn jetty:run
 
Best regards
  
>Четверг, 7 мая 2020, 1:25 +03:00 от Brian Demers <br...@gmail.com>:
> 
>Hi Alex,
> 
> 
>1-3.)
>Do you also have the Shiro Servlet Filter configured?
> 
>4.) We don't currently generate module-info metadata, but if there is something that isn't working for you please start another thread :)
> 
>5.) We don't have sources & Javadoc jars for `shiro-all` we only produce them for the individual modules.
>   
>On Wed, May 6, 2020 at 4:23 AM Alex Sviridov < ooo_saturn7@mail.ru > wrote:
>>Hi Brian,
>> 
>>Thank you for quick answer.
>> 
>>1) This is my shiro.ini
>> 
>>[main]
>>cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
>>securityManager.cacheManager = $cacheManager
>>realm = com.foo.TestRealm
>>securityManager.realms = $realm
>> 
>>2) This is my init code:
>> 
>>            Environment env = new BasicIniEnvironment(url.toString());
>>            final SecurityManager securityManager = env.getSecurityManager();
>>            SecurityUtils.setSecurityManager(securityManager);
>> 
>>3) This is my TestRealm
>> 
>>public class TestRealm extends AuthenticatingRealm {
>>    
>>    private static final Logger logger = LoggerFactory.getLogger(TestRealm.class);
>>    @Override
>>    protected void onInit() {
>>         logger.info ("************************************On INIT");
>>        try {
>>            throw new Exception();
>>        } catch (Exception ex) {
>>            logger.error("Error", ex);
>>        }
>>        setCredentialsMatcher((AuthenticationToken at, AuthenticationInfo ai) -> {
>>             logger.info ("################################ [{}], [{}]", at, ai);
>>            return false;
>>        });
>>        
>>    }
>>    
>>    
>>    @Override
>>    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
>>        UsernamePasswordToken upToken = (UsernamePasswordToken) token;
>>         logger.info ("REALM username [{}], password [{}]", upToken.getUsername(), upToken.getPassword());
>>         return new SimpleAuthenticationInfo(new UserEntity(), null , getName());
>>    }
>>    
>>}
>> 
>> 
>>4) I tried to use shiro-core + shiro-web, but it seems to be impossible to use
>>shiro modules in jpms environment, so, I had to take shiro-all.
>> 
>>5) By the way, I couldn’t find javadoc and sources for shiro-al in maven repo
>>https://repo1.maven.org/maven2/org/apache/shiro/shiro-all/1.5.3/
>> 
>>Best regards, Alex
>>  
>>>Среда, 6 мая 2020, 4:09 +03:00 от Brian Demers < brian.demers@gmail.com >:
>>> 
>>>It depends, we would need to see the full stack trace, it's unclear what is setting up your environment.  How are you configuring Shiro?
>>> 
>>>Also, I'd recommend against using the `shiro-all` and instead use `shiro-web`  
>>>On Tue, May 5, 2020 at 7:01 PM Alex Sviridov < ooo_saturn7@mail.ru > wrote:
>>>>Hi all,
>>>> 
>>>>I am just learning Shiro, but I noticed that onInit method on  on AuthenticatingRealm
>>>>is called twice. I have one TestRealm and this is stacktrace:
>>>> 
>>>>First call:
>>>> 
>>>>    at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>>>>    at org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:829) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:288) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41) [shiro-all-1.5.3.jar:?]
>>>> 
>>>> 
>>>>Second call:
>>>> 
>>>>    at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>>>>    at org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:61) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:292) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37) [shiro-all-1.5.3.jar:?]
>>>>    at org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41) [shiro-all-1.5.3.jar:?]
>>>> 
>>>>Could anyone say if it is a bug or it was done intentionally?
>>>> 
>>>>--
>>>>Best regards, Alex Sviridov 
>> 
>> 
>>--
>>Alex Sviridov
>>  
 
 
--
Alex Sviridov
 

Re: Re[4]: onInit method on AuthenticatingRealm is called twice

Posted by Brian Demers <bd...@apache.org>.
Alex

1-3) if you can put together a full example and stick it on GitHub we might
be able to point out if there is an issue.  I've seen cases where folks are
using the Servlet Filter and initializing Shiro manually which would cause
this problem.

4.) Ahh right, that is caused by the bundle plugin, we are working on that.

5.) correct, shiro-all is just an aggregate of the other module's classes,
The `all` module will likely be dropped in the next major version of Shiro.

That said, needing to use the shiro-all jar to workaround JPMS is valid (at
least until we get #4 resolved)

Thanks!
-Brian

On Wed, May 6, 2020 at 9:41 PM Alex Sviridov <oo...@mail.ru> wrote:

> Hi Brian,
>
> 1-3) I tried with Servket Filter and without it anyway onInit method is
> called twice. It seems to be bug.
>
> 4) As I see you have same packages for different modules, for example
> shiro/core/src/main/java/org/apache/shiro/config
> shiro/config/core/src/main/java/org/apache/shiro/config
> Besides I found this issue —
> https://issues.apache.org/jira/browse/SHIRO-679
>
> 5) I understood that you don’t have sources and javadoc for shiro-all.
> Maybe there is sense to add them?
> If people can’t use your modules, please, make their lives easier.
>
> Best regards, Alex
>
>
> Четверг, 7 мая 2020, 1:25 +03:00 от Brian Demers <br...@gmail.com>:
>
> Hi Alex,
>
>
> 1-3.)
> Do you also have the Shiro Servlet Filter configured?
>
> 4.) We don't currently generate module-info metadata, but if there is
> something that isn't working for you please start another thread :)
>
> 5.) We don't have sources & Javadoc jars for `shiro-all` we only produce
> them for the individual modules.
>
>
> On Wed, May 6, 2020 at 4:23 AM Alex Sviridov <ooo_saturn7@mail.ru
> <//...@mail.ru>> wrote:
>
> Hi Brian,
>
> Thank you for quick answer.
>
> 1) This is my shiro.ini
>
> [main]
> cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
> securityManager.cacheManager = $cacheManager
> realm = com.foo.TestRealm
> securityManager.realms = $realm
>
> 2) This is my init code:
>
>             Environment env = new BasicIniEnvironment(url.toString());
>             final SecurityManager securityManager =
> env.getSecurityManager();
>             SecurityUtils.setSecurityManager(securityManager);
>
> 3) This is my TestRealm
>
> public class TestRealm extends AuthenticatingRealm {
>
>     private static final Logger logger =
> LoggerFactory.getLogger(TestRealm.class);
>     @Override
>     protected void onInit() {
>         logger.info("************************************On INIT");
>         try {
>             throw new Exception();
>         } catch (Exception ex) {
>             logger.error("Error", ex);
>         }
>         setCredentialsMatcher((AuthenticationToken at, AuthenticationInfo
> ai) -> {
>             logger.info("################################ [{}], [{}]",
> at, ai);
>             return false;
>         });
>
>     }
>
>
>     @Override
>     protected AuthenticationInfo
> doGetAuthenticationInfo(AuthenticationToken token) throws
> AuthenticationException {
>         UsernamePasswordToken upToken = (UsernamePasswordToken) token;
>         logger.info("REALM username [{}], password [{}]",
> upToken.getUsername(), upToken.getPassword());
>          return new SimpleAuthenticationInfo(new UserEntity(), null ,
> getName());
>     }
>
> }
>
>
> 4) I tried to use shiro-core + shiro-web, but it seems to be impossible to
> use
> shiro modules in jpms environment, so, I had to take shiro-all.
>
> 5) By the way, I couldn’t find javadoc and sources for shiro-al in maven
> repo
> https://repo1.maven.org/maven2/org/apache/shiro/shiro-all/1.5.3/
>
> Best regards, Alex
>
>
> Среда, 6 мая 2020, 4:09 +03:00 от Brian Demers <brian.demers@gmail.com
> <//...@gmail.com>>:
>
> It depends, we would need to see the full stack trace, it's unclear what
> is setting up your environment.  How are you configuring Shiro?
>
> Also, I'd recommend against using the `shiro-all` and instead use
> `shiro-web`
>
> On Tue, May 5, 2020 at 7:01 PM Alex Sviridov <ooo_saturn7@mail.ru
> <ht...@mail.ru>> wrote:
>
> Hi all,
>
> I am just learning Shiro, but I noticed that onInit method on  on
> AuthenticatingRealm
> is called twice. I have one TestRealm and this is stacktrace:
>
> First call:
>
>     at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>     at
> org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:829)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:288)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41)
> [shiro-all-1.5.3.jar:?]
>
>
> Second call:
>
>     at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>     at
> org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:61)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:292)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41)
> [shiro-all-1.5.3.jar:?]
>
> Could anyone say if it is a bug or it was done intentionally?
>
> --
> Best regards, Alex Sviridov
>
>
>
> --
> Alex Sviridov
>
>
>
>
> --
> Alex Sviridov
>
>

Re: Re[2]: onInit method on AuthenticatingRealm is called twice

Posted by Brian Demers <br...@gmail.com>.
Hi Alex,


1-3.)
Do you also have the Shiro Servlet Filter configured?

4.) We don't currently generate module-info metadata, but if there is
something that isn't working for you please start another thread :)

5.) We don't have sources & Javadoc jars for `shiro-all` we only produce
them for the individual modules.


On Wed, May 6, 2020 at 4:23 AM Alex Sviridov <oo...@mail.ru> wrote:

> Hi Brian,
>
> Thank you for quick answer.
>
> 1) This is my shiro.ini
>
> [main]
> cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
> securityManager.cacheManager = $cacheManager
> realm = com.foo.TestRealm
> securityManager.realms = $realm
>
> 2) This is my init code:
>
>             Environment env = new BasicIniEnvironment(url.toString());
>             final SecurityManager securityManager =
> env.getSecurityManager();
>             SecurityUtils.setSecurityManager(securityManager);
>
> 3) This is my TestRealm
>
> public class TestRealm extends AuthenticatingRealm {
>
>     private static final Logger logger =
> LoggerFactory.getLogger(TestRealm.class);
>     @Override
>     protected void onInit() {
>         logger.info("************************************On INIT");
>         try {
>             throw new Exception();
>         } catch (Exception ex) {
>             logger.error("Error", ex);
>         }
>         setCredentialsMatcher((AuthenticationToken at, AuthenticationInfo
> ai) -> {
>             logger.info("################################ [{}], [{}]",
> at, ai);
>             return false;
>         });
>
>     }
>
>
>     @Override
>     protected AuthenticationInfo
> doGetAuthenticationInfo(AuthenticationToken token) throws
> AuthenticationException {
>         UsernamePasswordToken upToken = (UsernamePasswordToken) token;
>         logger.info("REALM username [{}], password [{}]",
> upToken.getUsername(), upToken.getPassword());
>          return new SimpleAuthenticationInfo(new UserEntity(), null ,
> getName());
>     }
>
> }
>
>
> 4) I tried to use shiro-core + shiro-web, but it seems to be impossible to
> use
> shiro modules in jpms environment, so, I had to take shiro-all.
>
> 5) By the way, I couldn’t find javadoc and sources for shiro-al in maven
> repo
> https://repo1.maven.org/maven2/org/apache/shiro/shiro-all/1.5.3/
>
> Best regards, Alex
>
>
> Среда, 6 мая 2020, 4:09 +03:00 от Brian Demers <br...@gmail.com>:
>
> It depends, we would need to see the full stack trace, it's unclear what
> is setting up your environment.  How are you configuring Shiro?
>
> Also, I'd recommend against using the `shiro-all` and instead use
> `shiro-web`
>
> On Tue, May 5, 2020 at 7:01 PM Alex Sviridov <ooo_saturn7@mail.ru
> <//...@mail.ru>> wrote:
>
> Hi all,
>
> I am just learning Shiro, but I noticed that onInit method on  on
> AuthenticatingRealm
> is called twice. I have one TestRealm and this is stacktrace:
>
> First call:
>
>     at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>     at
> org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:829)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:288)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41)
> [shiro-all-1.5.3.jar:?]
>
>
> Second call:
>
>     at com.foo.TestRealm.onInit(TestRealm.java:37) [classes/:?]
>     at
> org.apache.shiro.realm.AuthenticatingRealm.init(AuthenticatingRealm.java:398)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
> [shiro-all-1.5.3.jar:?]
>     at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:61)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:292)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:37)
> [shiro-all-1.5.3.jar:?]
>     at
> org.apache.shiro.env.BasicIniEnvironment.<init>(BasicIniEnvironment.java:41)
> [shiro-all-1.5.3.jar:?]
>
> Could anyone say if it is a bug or it was done intentionally?
>
> --
> Best regards, Alex Sviridov
>
>
>
> --
> Alex Sviridov
>
>