2011-04-11 34 views
4

我想爲我的Web應用程序創建JDBC領域。由於我的用戶彼此非常不同,我需要只有一個表,用戶名和密碼爲領域,我決定在我的數據庫中創建一個名爲ROLE(與其他用戶表的onetoOne關係)的新表。創建我的第一個JDBC領域(GlassFish V3)

這是我的用戶的域模型的樣子: enter image description here

我下面這個教程http://blog.gamatam.com/2009/11/jdbc-realm-setup-with-glassfish-v3.html但我堅持,我不知道如何繼續。

我會後我在GlassFish服務器製成,也是我的文件sun.resources.xml這樣你就可以糾正我,如果我作出任何錯誤的配置: enter image description here

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd"> 
<resources> 
<jdbc-resource enabled="true" jndi-name="jdbc/myDatasource" object-type="user" pool- name="Derby_grupovina_grupovinauserPool"/> 
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.apache.derby.jdbc.ClientDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="Derby_grupovina_grupovinauserPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false"> 
<property name="serverName" value="localhost"/> 
    <property name="PortNumber" value="1527"/> 
    <property name="DatabaseName" value="grupovina"/> 
    <property name="User" value="grupovinauser"/> 
    <property name="Password" value="grupovina"/> 
    <property name="URL" value="jdbc:derby://localhost:1527/grupovina;create=true"/> 
    <property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/> 
    </jdbc-connection-pool> 
    </resources> 

在上面comfiguration我有一些疑問,我真的不明白什麼,我應該在組表名和組名。

下面的教程說,我應該在文件sun-web.xml中添加安全角色,並且我想這樣做,但是我不知道要在configuratio中放置什麼。這只是我添加到該文件,但我認爲這是不正確的。我應該在那個文件中添加角色映射,我應該如何配置它?

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd"> 
<sun-web-app error-url=""> 
<context-root>/GroupBuySystem</context-root> 
<class-loader delegate="true"/> 
<jsp-config> 
<property name="keepgenerated" value="true"> 
    <description>Keep a copy of the generated servlet class java code.</description> 
</property> 
</jsp-config>  
<security-role-mapping> 
<role-name> </role-name> 
<group-name> </group-name> 
</security-role-mapping> 
</sun-web-app> 

該教程的傢伙說他不需要web.xml,但我確實需要該文件。我應該添加我的web.xml?

這是我的第一個JDBC領域,我很困惑:)

回答

2

我想(從你前面的問題),你沒有一組表。實際上你不一定需要一個。 JDBCRealm僅與包含組列的用戶表一起使用。

在Glassfish的管理控制檯中的變化如下:

組表:角色

組名稱列:USERTYPE

既然你單詞「角色」使用不同的分型(字母大小寫),確保您領域的配置值與表中的配置值完全相同。

相關問題