Glassfish 从应用程序创建 JDBCResources、池和安全领域

发布于 2024-11-25 21:34:14 字数 155 浏览 1 评论 0 原文

如果尚未创建,如何从我的应用程序中在 Glassfish 3.1 服务器中创建 JDBCResources、池和安全领域?我正在编写一个依赖于此资源的应用程序,但是我不想每次将应用程序部署在不同的服务器上时都手动配置服务器。

使用 shell 脚本执行此操作感觉像是一种解决方法。

How can I create JDBCResources, -Pools and Security Realms in a Glassfish 3.1 Server from within my Application, if they are not already created? I am writing an application that relies on this resources, however I don't want to configure the server manually every time the application is deployed on a different server.

Doing this with a shell script feels like a workaround.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一口甜 2024-12-02 21:34:14

Glassfish 提供 REST 接口。您可以在特定配置(例如,本地主机上的 DAS 中的 server-config,管理端口 4848)中创建一个新的安全(身份验证)领域,并使用 POST 到:

http://localhost:4848/management/domain/configs/config/server-config/security-service/auth-realm

对该资源执行 GET 以查看参数。

您可以使用相同的接口来创建连接池。

Glassfish provides a REST interface. You can create a new security (authentication) realm in a certain configuration (say, server-config in a DAS on localhost, admin port 4848) with a POST to:

http://localhost:4848/management/domain/configs/config/server-config/security-service/auth-realm

Do a GET to that resource to see the parameters.

You can use the same interface to create connection pools.

孤独患者 2024-12-02 21:34:14

好的,我找到了一半问题的解决方案。

我在 WEB-INF 文件夹中创建了一个名为 glassfish-resources.xml 的文件,并向其中添加了以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <jdbc-connection-pool
            name="java:app/jdbc/BeerUserPool"
            res-type="javax.sql.DataSource"
            datasource-classname="org.postgresql.ds.PGSimpleDataSource"
            pool-resize-quantity="2"
            max-pool-size="32"
            steady-pool-size="0"
            statement-timeout-in-seconds="30">
        <property name="User" value="USERNAME"></property>
        <property name="Password" value="PASSWORD"></property>
        <property name="PortNumber" value="12345678"></property>
        <property name="dataBaseName" value="DATABASE_NAME"></property>
        <property name="ServerName" value="yourDBUrl.com"></property>
        <property name="Ssl" value="false"></property>
        <property name="ProtocolVersion" value="0"></property>
    </jdbc-connection-pool>
    <jdbc-resource 
        pool-name="java:app/jdbc/BeerUserPool"
        jndi-name="java:app/jdbc/BeerUser"></jdbc-resource>
    <
</resources>

在名称中添加 java:app/ 很重要,没有它就无法工作正确。此连接池也仅是应用程序范围,并在应用程序取消部署后被销毁(除非您添加附加参数)。

现在可以通过 JPA 通过以下 persistence.xml 访问该池。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="jsf-jpa-war" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:app/jdbc/BeerUser</jta-data-source>
        <properties>
            <property name="eclipselink.logging.level" value="FINE"/>
        </properties>
    </persistence-unit>
</persistence>

然而,我没有发现如何以同样的方式定义安全领域。

Ok, I found a solution for half of the Question.

I created a file called glassfish-resources.xml in my WEB-INF folder and added the following content to it:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <jdbc-connection-pool
            name="java:app/jdbc/BeerUserPool"
            res-type="javax.sql.DataSource"
            datasource-classname="org.postgresql.ds.PGSimpleDataSource"
            pool-resize-quantity="2"
            max-pool-size="32"
            steady-pool-size="0"
            statement-timeout-in-seconds="30">
        <property name="User" value="USERNAME"></property>
        <property name="Password" value="PASSWORD"></property>
        <property name="PortNumber" value="12345678"></property>
        <property name="dataBaseName" value="DATABASE_NAME"></property>
        <property name="ServerName" value="yourDBUrl.com"></property>
        <property name="Ssl" value="false"></property>
        <property name="ProtocolVersion" value="0"></property>
    </jdbc-connection-pool>
    <jdbc-resource 
        pool-name="java:app/jdbc/BeerUserPool"
        jndi-name="java:app/jdbc/BeerUser"></jdbc-resource>
    <
</resources>

Addingt the java:app/ to the names is important, without it it won't work correctly. This connection pool is also only application scoped and gets destroyed after the application is undebloyed (except you add an additional argument).

This pool can now be accessed with JPA with the following persistence.xml.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="jsf-jpa-war" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:app/jdbc/BeerUser</jta-data-source>
        <properties>
            <property name="eclipselink.logging.level" value="FINE"/>
        </properties>
    </persistence-unit>
</persistence>

However I found no soultion how I can define the security realms in the same way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文