Creating my first JDBC Realm (Glassfish V3)

I want to create JDBC Realm for my web application. Since my users are very different from each other, I only need to have one table with usernames and passwords for the area, I decided to create a new table in my database named ROLE (oneToOne relationship with another user table).

This is what my user domain model looks like: enter image description here

I follow this guide http://blog.gamatam.com/2009/11/jdbc-realm-setup-with-glassfish-v3.html , but I'm stuck, I don't know how to proceed.

I will post the configuration that I made on the Glassfish server, as well as the sun.resources.xml file, so that you can fix me if I am wrong: 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> 

In the above configuration, I have a few doubts, I really do not understand what I should declare in the Group table and the Column group name.

The im tutorial says that I have to add security roles to the sun-web.xml file, and I wanted to do this, but I don't know what to add to the configuration. This is what I added to this file, but I think this is wrong. Where in this file should I add role mapping and how to 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 textbook guy said he doesn’t need to use web.xml, but I need this file. What should I add to my web.xml?

This is my first area of ​​jdbc, I am very confused :)

+4
source share
1 answer

I assume (from your previous question) that you do not have a group table. In fact, you do not need this. JDBCRealm only works with a user table containing a group column.

In the Glassfish Admin Console, change the following:

Group Table: Role

Group Name Column: userType

Since you used different types (literal cases) for the word “role,” make sure that the configuration values ​​for your kingdom are exactly the same as in the table.

+2
source

Source: https://habr.com/ru/post/1347529/


All Articles