Hi Alex,

Thanks for your explanation.

Although I read your referenced posts in stackoverflow before asking this 
question, I didn't understand it well.

Now I understand it now and my problem is resolved.

I'm new user for shiro and I could continue to dive into shiro.


Thanks again.

Jared
________________________________
From: Alexander Openkowski <[email protected]>
Sent: Saturday, June 3, 2017 10:26:26 PM
To: [email protected]
Subject: Re: Errors when tried to configure shiro.ini to work with tomcat 
database connection pool

Hi,

the shiro.ini allows you to configure objects via their setters. Look at the 
JndiObjectFactory class: 
https://shiro.apache.org/static/latest/apidocs/org/apache/shiro/jndi/JndiObjectFactory.html.
 As you can see, there is no setUser() method etc. to configure the data source 
directly. You instead use the setResourceName(String resourceName) method to 
supply a JNDI URL with which the data source can be looked up. The data source 
itself must be configured somewhere else when using the JndiObjectFactory. 
Maybe in Tomcat's config in your case? I really don't know, but maybe it at 
least gets you on the right track. Also have a look at this question on SO 
maybe: 
https://stackoverflow.com/questions/17441019/how-to-configure-jdbcrealm-to-obtain-its-datasource-from-jndi

Regards
Alex

On Sat, Jun 3, 2017 at 4:03 PM, Yu Wei 
<[email protected]<mailto:[email protected]>> wrote:

Hi guys,

I tried to configure shiro.ini to make shiro using tomcat database connection 
pool.
The configuration is as below,
datasrc = org.apache.shiro.jndi.JndiObjectFactory
datasrc.requiredType = javax.sql.DataSource
datasrc.resourceName = mysql/ustudy
datasrc.resourceRef = true
datasrc.user = root
datasrc.password = mysql
datasrc.url = 
jdbc:mysql://192.168.0.107:13306/ustudy?characterEncoding=UTF-8<http://192.168.0.107:13306/ustudy?characterEncoding=UTF-8>
datasrc.driverClassName = com.mysql.jdbc.Driver

realm = org.apache.shiro.realm.jdbc.JdbcRealm
realm.permissionsLookupEnabled = true
realm.dataSource = $datasrc
realm.authenticationQuery = select usr_passwd from sec_users where loginname = ?
realm.credentialsMatcher = $pwMatcher

securityManager.realms = $realm

tomcat failed to enable shiro  and I got following errors:
03-Jun-2017 11:41:52.930 INFO [main] 
org.apache.catalina.core.ApplicationContext.log Initializing Shiro environment
03-Jun-2017 11:41:53.130 SEVERE [main] 
org.apache.catalina.core.StandardContext.listenerStart Exception sending 
context initialized event to listener instance of class 
[org.apache.shiro.web.env.EnvironmentLoaderListener]
 org.apache.shiro.config.ConfigurationException: Property 'user' does not exist 
for object of type org.apache.shiro.jndi.JndiObjectFactory.
        at 
org.apache.shiro.config.ReflectionBuilder.isTypedProperty(ReflectionBuilder.java:255)
        at 
org.apache.shiro.config.ReflectionBuilder.applyProperty(ReflectionBuilder.java:544)
        at 
org.apache.shiro.config.ReflectionBuilder.applySingleProperty(ReflectionBuilder.java:206)
        at 
org.apache.shiro.config.ReflectionBuilder.applyProperty(ReflectionBuilder.java:167)
        at 
org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:124)
        at 
org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:161)
        at 
org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:124)
        at 
org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:102)
        at 
org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:88)
        at 
org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:46)
        at 
org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:123)
        at 
org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)
        at 
org.apache.shiro.web.env.IniWebEnvironment.createWebSecurityManager(IniWebEnvironment.java:203)
        at 
org.apache.shiro.web.env.IniWebEnvironment.configure(IniWebEnvironment.java:99)
        at 
org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:92)
        at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
        at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
        at 
org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:221)
        at 
org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:133)
        at 
org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
        at 
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4734)

Maybe this is only configuration problem.
Could you please help to have a look?


Thanks,

Jared, (韦煜)
Software developer
Interested in open source software, big data, Linux

Reply via email to