I'm developing a java web application with Netbeans and maven.

I implemented my own Realm extending class org.apache.catalina.realm.DataSourceRealm.

So, I have a parse error in context.xml caused by java.lang.ClassNotFoundException: com.company.authentication.MyRealm

I fixed this by building the JAR with my Realm and putting in tomcat lib folder.

Is there any way to do this automatically? Ie, make the Tomcat in recognizing my Realm in the deploy or make the "Tomcat Class Loader" load my Realm only with WAR file (or by maven).

My Realm

public class MyRealm extends DataSourceRealm{
    @Override
    public Principal authenticate(String username, String credentials) {

        ...

        //Applying encryption
        credentials = MyEncrypt.encrypt(credentials);

        ... 

        return authenticate(dbConnection, username, credentials);
    }
}

My context.xml file

<Resource auth="Container" driverClassName="org.postgresql.Driver" maxActive="10" maxIdle="3" name="jdbc/my_db" password="123456" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/app_web_login" username="postgres" />    
<Realm className="com.company.authentication.MyRealm" dataSourceName="jdbc/my_db" roleNameCol="role_name" userCredCol="user_pass" userNameCol="user_name" userRoleTable="user_roles" userTable="users" localDataSource="true"/>

Part of My pom.xml file

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-catalina</artifactId>
            <version>7.0.42</version>
            <scope>provided</scope>
        </dependency>
        ...
    </dependencies>
有帮助吗?

解决方案

Currently, there is no way to tell Tomcat to look in the web application for your Realm implementation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top