55minutes / fiftyfive-wicket

Bootstrap Apache Wicket with testing utilities, Apache Shiro security, JS dep management, and more
Apache License 2.0
68 stars 24 forks source link

shiro with database #25

Open frodrigues opened 12 years ago

frodrigues commented 12 years ago

Hello, I setup shiro.ini to connect with database (mysql) by gives me the following error:

Last cause: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.

my shiro.ini

[main] jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm jdbcRealm.authenticationQuery = select password from user where username = ? jdbcRealm.userRolesQuery = select role_id from user_role where user_id = ?

ds = com.mysql.jdbc.Driver ds.jdbcUrl = jdbc:mysql://localhost:3306/database ds.username = root ds.password = **** ds.databaseName = database jdbcRealm.dataSource = $ds

mattbrictson commented 12 years ago

@frodrigues, I would have to see the full stack trace to be sure, but that error usually means you are accessing Shiro-related code in your application before the Shiro servlet filter has executed.

Make sure the ShiroFilter is present in your web.xml and that the <filter-mapping> for ShiroFilter it is declared before any other filters that have to do with your application code, like Wicket-, Spring- or Hibernate-related filters.

The Shiro web.xml declarations should look like this:

<filter>
  <filter-name>ShiroFilter</filter-name>
  <filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
  <init-param>
    <param-name>configPath</param-name>
    <param-value>classpath:shiro.ini</param-value>
  </init-param>
</filter>

<filter-mapping>
  <filter-name>ShiroFilter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping>