Hilly B
Hilly B

Reputation: 1

Shiro environment initialization failed: org.apache.shiro.config.ConfigurationException

We are running an existing application using wildfly-10.0.0.Final with Shiro 1.2.2 We have upgraded our application from using mysql 5.6 to 8.0.40 and we are now using the latest mysql drivers. The other parts of the application are working with the new mysql besides this section that uses apache.shiro.

see https://mvnrepository.com/artifact/com.mysql/mysql-connector-j/9.1.0

From our pom.xml
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>9.1.0</version>
</dependency>

From our keep.shiro.ini

[main]  
authc.loginUrl = /index.xhtml
authc.successUrl  = /hello
logout.redirectUrl = /hello

# ------------------------  
# Database  

# Own Realm  
#jdbcRealm = com.jjoe64.shiroexample.auth.MyCustomRealm
#jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm = com.ecomm.messages.security.JdbcReferenceRealm

# Sha256  
sha256Matcher = 
 org.apache.shiro.authc.credential.Sha256CredentialsMatcher
# base64 encoding, not hex in this example:  
sha256Matcher.storedCredentialsHexEncoded = false  
sha256Matcher.hashIterations = 1024  
  # User Query  
 jdbcRealm.authenticationQuery = select pr.password from 
 principals 
 pr,clientdetails cd where pr.clientid = cd.clientid and username 
 = ? and cd.clientref     
 = ? and pr.active = 1

# permissions  
#jdbcRealm.permissionsLookupEnabled = true
#jdbcRealm.userRolesQuery = select roleName from UserRole where 
  userName = ?
  jdbcRealm.userRolesQuery = select rl.roles, rl.rolegroups from 
 roles rl,     
 principals pr, clientdetails cd where pr.clientid = cd.clientid 
 and 
 rl.userid=pr.userid and pr.username = ? and cd.clientref = ?

# Connection   
ds = com.mysql.cj.jdbc.MysqlDataSource
ds.driverClass=com.mysql.cj.jdbc.Driver
ds.serverName = localhost
ds.user = 
ds.password = 
ds.databaseName = dbname
jdbcRealm.dataSource=$ds

# Use Built-in Chache Manager
builtInCacheManager = 
org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $builtInCacheManager

securityManager.realms = $jdbcRealm

# -----------------------------------------------------------------------------  
[urls]  
#/hello = authc
/index.xhtml = authc
/app/** = authc
/admin.jsp = authc, perms["admin:access"]

In Wildfly we updated ./jboss-cli.sh --connect [standalone@localhost:9990 /]

[standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=com.mysql:add(driver-name=com.mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.cj.jdbc.MysqlXADataSource {"outcome" => "success"}

We checked our application and all the references for object ds have been changed from com.mysql.jdbc.jdbc2.optional to com.mysql.cj.jdbc.MysqlDataSource based on the changes mentioned here https://dev.mysql.com/doc/connector-j/en/connector-j-api-changes.html

We are still getting the errors: 2025-01-14 09:07:27,509 ERROR [org.apache.shiro.web.env.EnvironmentLoader] (ServerService Thread Pool -- 197) Shiro environment initialization failed: org.apache.shiro.config.ConfigurationException: Unable to instantiate class [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] for object named 'ds'. Please ensure you've specified the fully qualified class name correctly. 2025-01-14 09:07:27,510 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 197) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./message: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./message: java.lang.RuntimeException: org.apache.shiro.config.ConfigurationException: Unable to instantiate class [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] for object named 'ds'. Please ensure you've specified the fully qualified class name correctly. 2025-01-14 09:07:27,522 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "messageapp.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./message" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./messsage: java.lang.RuntimeException: org.apache.shiro.config.ConfigurationException: Unable to instantiate class [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] for object named 'ds'. Please ensure you've specified the fully qualified class name correctly.

Any suggestions where we can look to find out where apache.shiro could be setting the object ds to com.mysql.jdbc.jdbc2.optional.MysqlDataSource so we can change it to com.mysql.cj.jdbc.MysqlDataSource and fix this part of the application.

Thanks for any help.

Upvotes: 0

Views: 44

Answers (0)

Related Questions