JNDI Shiro PostgreSQL - 无法在Apache Isis中使用jndi名称'jdbc / postgres'查找javax.sql.DataSource

时间:2017-11-01 16:35:02

标签: postgresql jndi shiro isis

我已经下载了Apache Isis的simple-app原型1.15.0。我希望在此documentation之后将其与Apache Shiro集成。但我得到了这样的错误:

java.lang.IllegalStateException: Unable to look up javax.sql.DataSource with jndi name 'jdbc/postgres'.

在我的 web.xml

中查看我的内容
<resource-ref>
<description>db</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

和我的 shiro.ini

jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm        

jof = org.apache.shiro.jndi.JndiObjectFactory          
jof.resourceName = jdbc/postgres
jof.requiredType = javax.sql.DataSource
jof.resourceRef = true

jdbcRealm.dataSource = $jof

jdbcRealm.authenticationQuery =         \
        select password                 \
          from users                    \
         where username = ?

jdbcRealm.userRolesQuery =              \
        select r.label                  \
          from users_roles ur           \
    inner join roles r                  \
            on ur.role_id = r.id        \
         where user_id = (              \
            select id                   \
             from users                 \
            where username = ?);        \

jdbcRealm.permissionsQuery=             \
        select p.permission             \
          from roles_permissions rp     \
    inner join permissions p            \
            on rp.permission_id = p.id  \
         where rp.role_id = (           \
            select id                   \
             from roles                 \
            where label = ?);

jdbcRealm.permissionsLookupEnabled=true

dps = org.apache.shiro.authc.credential.DefaultPasswordService
pm = org.apache.shiro.authc.credential.PasswordMatcher
pm.passwordService = $dps
jdbcRealm.credentialsMatcher = $pm

securityManager.realms = $jdbcRealm

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

这取决于你的容器。 Apache-Isis doc确实有一个如何在Tomcat上配置它的链接:

  

使用上述配置,您还需要设置DataSource。细节因servlet容器而异,例如how to do the setup on Tomcat 8.0