为 Apache Shiro 配置 JTDS 数据源
Configure JTDS datasource for Apache Shiro
我最近开始编写 JSF 应用程序。我将 ecplise neon 与 maven3 和 jetty webserver 一起用于快速测试部署。到目前为止一切都很好,但现在我想尝试 apache shiro,因为它似乎是一个非常酷且很好的安全框架。
现在,因为我使用 ms sql 服务器,所以我使用 jtds 数据库驱动程序。但不幸的是,由于以下错误,我无法让 shiro 工作:
[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@6ea04618{/,[file:///E:/Dev/JSF/Lister/Lister/src/main/webapp/, jar:file:///C:/Users/Dethrall/.m2/repository/com/sun/faces/jsf-impl/2.2.2/jsf-impl-2.2.2.jar!/META-INF/resources],UNAVAILABLE}{file:///E:/Dev/JSF/Lister/Lister/src/main/webapp/}
org.apache.shiro.config.ConfigurationException: Property 'database' does not exist for object of type net.sourceforge.jtds.jdbcx.JtdsDataSource.
特别有趣的部分是 "Property 'database' does not exist..."
所以我查看了相应的 javadoc,确实没有 属性 数据库。
这让我们回到我的问题。我应该如何在 shiro.ini 中配置 jtds 数据源。如果有人有任何建议,将不胜感激!
抱歉顺便说一句,因为我对所有这些新东西有点不知所措,比如 maven、jsf、shiro、jetty 等等...
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
</web-app>
pom.xml
...
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>${shiro.version}</version>
</dependency>
...
shiro.ini
[main]
#authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
authc.loginUrl = /faces/login.xhtml
authc.successUrl = /faces/users.xhtml
logout.redirectUrl = /faces/users.xhtml
ds = net.sourceforge.jtds.jdbcx.JtdsDataSource
ds.serverName = localhost
ds.portNumber = 1434
ds.user = lister
ds.password = 1234
ds.database = Lister
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.authenticationQuery = SELECT password FROM trs_sec_t_users WHERE username = ?
jdbcRealm.userRolesQuery = SELECT role FROM trs_sec_t_roles WHERE username = ?
#jdbcRealm.credentialsMatcher = $sha256Matcher
[users]
#admin = admin, ROLE_ADMIN
#root = 1234, ROLE_ADMIN
[roles]
#ROLE_ADMIN = *
[urls]
/faces/users.xhtml = authc
在你的 shiro.ini 中尝试:'ds.databaseName = Lister'
我最近开始编写 JSF 应用程序。我将 ecplise neon 与 maven3 和 jetty webserver 一起用于快速测试部署。到目前为止一切都很好,但现在我想尝试 apache shiro,因为它似乎是一个非常酷且很好的安全框架。
现在,因为我使用 ms sql 服务器,所以我使用 jtds 数据库驱动程序。但不幸的是,由于以下错误,我无法让 shiro 工作:
[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@6ea04618{/,[file:///E:/Dev/JSF/Lister/Lister/src/main/webapp/, jar:file:///C:/Users/Dethrall/.m2/repository/com/sun/faces/jsf-impl/2.2.2/jsf-impl-2.2.2.jar!/META-INF/resources],UNAVAILABLE}{file:///E:/Dev/JSF/Lister/Lister/src/main/webapp/} org.apache.shiro.config.ConfigurationException: Property 'database' does not exist for object of type net.sourceforge.jtds.jdbcx.JtdsDataSource.
特别有趣的部分是 "Property 'database' does not exist..." 所以我查看了相应的 javadoc,确实没有 属性 数据库。
这让我们回到我的问题。我应该如何在 shiro.ini 中配置 jtds 数据源。如果有人有任何建议,将不胜感激!
抱歉顺便说一句,因为我对所有这些新东西有点不知所措,比如 maven、jsf、shiro、jetty 等等...
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
</web-app>
pom.xml
...
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>${shiro.version}</version>
</dependency>
...
shiro.ini
[main]
#authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
authc.loginUrl = /faces/login.xhtml
authc.successUrl = /faces/users.xhtml
logout.redirectUrl = /faces/users.xhtml
ds = net.sourceforge.jtds.jdbcx.JtdsDataSource
ds.serverName = localhost
ds.portNumber = 1434
ds.user = lister
ds.password = 1234
ds.database = Lister
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.authenticationQuery = SELECT password FROM trs_sec_t_users WHERE username = ?
jdbcRealm.userRolesQuery = SELECT role FROM trs_sec_t_roles WHERE username = ?
#jdbcRealm.credentialsMatcher = $sha256Matcher
[users]
#admin = admin, ROLE_ADMIN
#root = 1234, ROLE_ADMIN
[roles]
#ROLE_ADMIN = *
[urls]
/faces/users.xhtml = authc
在你的 shiro.ini 中尝试:'ds.databaseName = Lister'