Custom Glassfish Security Realm does not work (unable to find LoginModule)

前端 未结 2 1111

I\'m trying to get a Custom Security Realm in Glassfish working (i tried 3.0.1 final and 3.1 B33). I read nearly all tutorials about this, but it doesn\'t not work on my Sys

相关标签:
2条回答
  • 2020-12-16 05:14

    Got it. Seems like newer Glassfish versions require that the Security Realm and the LoginModule are packaged as an OSGi module, which should then be copied into glassfish/modules.

    Therefore i changed my pom.xml to create an OSGi bundle, which contains both the CustomRealm and the CustomLoginModule.

    Here it is:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.mycompany</groupId>
        <artifactId>security.realm</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>bundle</packaging>
    
        <name>Custom JDBCRealm OSGi</name>
        <url>http://maven.apache.org</url>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.glassfish.security</groupId>
                <artifactId>security</artifactId>
                <version>3.1-b33</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <optimise>true</optimise>
                        <debug>true</debug>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <extensions>true</extensions>
                    <configuration>
                        <instructions>
                            <Export-Package>
                                ${project.groupId}.${project.artifactId};version=${project.version}
                            </Export-Package>
                            <Import-Package>
                                com.sun.appserv.security,
                                org.glassfish.security.common,
                                com.sun.enterprise.security.auth.realm,
                                com.sun.enterprise.security.auth.login.common,
                                java.util,
                                javax.security.auth
                            </Import-Package>
                        </instructions>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    EDIT

    Found a good additional resource here: http://blogs.oracle.com/nithya/entry/modularized_osgi_custom_realms_in , where the Realm and it's LoginModule is build as a hk2-jar.

    0 讨论(0)
  • 2020-12-16 05:16

    This was driving me crazy, I've finally cracked creating a custom realm in glassfish 3.1, turns out that of course its really easy. The following documentation is the key: http://docs.oracle.com/cd/E18930_01/html/821-2418/beabo.html ... note that it has changed somewhat from the answers above.

    0 讨论(0)
提交回复
热议问题