本文介绍了创建我的第一个JDBC Realm(Glassfish V3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的web应用程序创建一个JDBC Realm。由于我的用户彼此非常不同,我需要只有一个表,用户名和密码为领域,我决定在我的数据库中创建一个名为ROLE(与其他用户表的onetoOne关系)的新表。



这就是我的用户域模型的样子:


我正在学习本教程但是我我坚持,我不知道如何继续。



我会发布我在glassfish服务器和我的文件sun.resources.xml中所做的配置,以便您可以纠正我如果我犯了什么错误:

 <?xml version =1.0encoding =UTF-8?> 
<资源>
< property name =serverNamevalue =localhost/>
< property name =PortNumbervalue =1527/>
< property name =DatabaseNamevalue =grupovina/>
< property name =Uservalue =grupovinauser/>
< property name =Passwordvalue =grupovina/>
< property name =URLvalue =jdbc:derby:// localhost:1527 / grupovina; create = true/>
< property name =driverClassvalue =org.apache.derby.jdbc.ClientDriver/>
< / jdbc-connection-pool>
< /资源>

在上面的配置中我有一些疑惑,我真的不明白我应该在Group table上做什么广告和组名称列。



接下来的教程说我应该在文件sun-web.xml中添加安全角色,并且我想这样做但我不知道在配置中放什么。这只是我添加到该文件,但我认为这是不正确的。

 <?xml version =1.0我应该在那个文件中添加角色映射,并且应该如何配置它?编码= UTF-8 >?; 
<!DOCTYPE sun-web-app PUBLIC - // Sun Microsystems,Inc. //DTD Application Server 9.0 Servlet 2.5 // ENhttp://www.sun.com/software/appserver/的DTD /太阳网络app_2_5-0.dtd>
< sun-web-app error-url =>
< context-root> / GroupBuySystem< / context-root>
< class-loader delegate =true/>
< jsp-config>
< property name =keepgeneratedvalue =true>
< description>保留生成的servlet类java代码的副本。< / description>
< / property>
< / jsp-config>
< security-role-mapping>
<角色名称> < /角色的名称>
< group-name> < /组名称>
< / security-role-mapping>
< / sun-web-app>

本教程的人说他不需要web.xml,但我确实需要文件。我应该添加我的web.xml文件?



这是我的第一个jdbc领域,我很困惑:)

解决方案

我假设(从你以前的问题),你没有一个组表。实际上你不一定需要一个。 JDBCRealm仅适用于包含组列的用户表。



在Glassfish管理控制台中更改以下内容:

组表:角色

组名称列:userType



由于您使用了不同的类型)为角色一词,请确保您领域的配置值与表中的完全相同。


I want to create a JDBC Realm for my web app. Since my users are very different from each other i need to have just one table, with the usernames and passwords for the realm, i decided to create a new table in my database called ROLE(oneToOne relationship with the other users table).

This is how my users domain model looks like:

I am following this tutorial http://blog.gamatam.com/2009/11/jdbc-realm-setup-with-glassfish-v3.html but i am stuck, i dont know how to continue.

I will post the configuration i made at the glassfish server and also my file sun.resources.xml so you can correct me if i am making any mistake:

<?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>

In the above comfiguration i have a few doubts, I dont really understand what should i ad at Group table and Group name Column.

The tutorial im following says that i should add security roles at the file sun-web.xml, and i wanted to do it but i dont know what to put in the configuratio. This is just what i added to that file but i think it is not correct. Where in that file should i add the role mapping and how should i configure it?

<?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>

The guy of the tutorial said he had not need for a web.xml, but i do need that file. What should i add my web.xml?

This is my first jdbc realm, i am very confused :)

解决方案

I assume (from your previous question) that you don't have a group table. In fact you don't necessarily need one. JDBCRealm works with only a user table containing a group column as well.

In your Glassfish admin console change the following:

Group Table: Role

Group Name Column: userType

Since you used different typings (letter cases) for the word "role", make sure that the configuration values for your realm are exactly the same as in the table.

这篇关于创建我的第一个JDBC Realm(Glassfish V3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:57