WSO2 版本 5.0.0 自定义用户存储管理器引发 NoClassDefFoundError

WSO2 version 5.0.0 Custom User Store Manager Raising NoClassDefFoundError

我正在尝试在 WSO2IS 5.0.0 版中设置自定义主用户商店管理器。

根据 WSO2IS 5.0.0 版的文档,我必须扩展 UserStoreManager:

import org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager;

public class CustomUserStoreManager extends JDBCUserStoreManager {
...

在 user-mgmt.xml 中,我将 UserStoreManager 更改为引用此 class:

<UserStoreManager class="com.abc.identity.CustomUserStoreManager">
...

在 pom.xml 中,我将其构建为一个包:

<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.abc.asset</groupId>
<artifactId>asset-identity</artifactId>
<packaging>bundle</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>asset-identity</name>
<description>asset-identity</description>

<dependencies>
    <dependency>
        <groupId>org.wso2.carbon</groupId>
        <artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
        <version>4.2.7</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.carbon</groupId>
        <artifactId>org.wso2.carbon.user.core</artifactId>
        <version>4.4.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>1.4.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.5.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Name>${project.artifactId}</Bundle-Name>
                    <Bundle-Version>0.0.1</Bundle-Version>
                    <Private-Package>com.abc.ecommerce.identity</Private-Package>
                    <Import-Package>
                        *
                    </Import-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

但是当我启动 WSO2IS 时,出现以下异常:

[2015-09-29 14:55:07,805] ERROR {org.wso2.carbon.user.core.common.DefaultRealm} -  Cannot create com.abc.identity.CustomUserStoreManager
java.lang.NoClassDefFoundError: org/wso2/carbon/user/core/jdbc/JDBCUserStoreManager

WSO2IS 5.0.0 版的文档没有详细说明如何设置 pom.xml。

请尝试添加插件配置的导出部分

<build>
<plugins>
    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.5.0</version>
        <extensions>true</extensions>
        <configuration>
            <instructions>
                <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                <Bundle-Name>${project.artifactId}</Bundle-Name>
                <Bundle-Version>0.0.1</Bundle-Version>
                <Private-Package>com.peplink.ecommerce.identity</Private-Package>
                <Import-Package>
                    *
                </Import-Package>
                <Export-Package>
                    org.wso2.carbon.user.core.*
                </Export-Package>
            </instructions>
        </configuration>
    </plugin>
</plugins>

这个pom.xml可以解决NoClassDefFoundError异常。关键是要匹配 WSO2IS 5.0.0 附带的捆绑包版本。

<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.abc.asset</groupId>
<artifactId>asset-identity</artifactId>
<packaging>bundle</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>asset-identity</name>
<description>asset-identity</description>

<dependencies>
    <dependency>
        <groupId>org.wso2.carbon</groupId>
        <artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
        <version>4.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.carbon</groupId>
        <artifactId>org.wso2.carbon.user.core</artifactId>
        <version>4.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.felix</groupId>
        <artifactId>org.osgi.core</artifactId>
        <version>1.4.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.5.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Name>${project.artifactId}</Bundle-Name>
                    <Bundle-Version>0.0.1</Bundle-Version>
                    <Export-Package>com.abc.asset.identity</Export-Package>
                    <Import-Package>
                        *
                    </Import-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>wso2-nexus</id>
        <name>WSO2 internal Repository</name>
        <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
        </releases>
    </repository>
</repositories>
</project>