我試圖實現擴展默認的ActiveDirectoryUserStoreManager用戶存儲的自定義用戶存儲。但是,當我在dropins目錄中安裝生成的osgi包後,服務器啓動時出現錯誤。擴展wso2用戶商店
我在WSO2 API Manager 1.10.0中測試這個自定義用戶存儲。以下是我正在使用的代碼。
文件的pom.xml:
文件MyDomainActiveDirectoryUserStoreManager.java:
package pt.mydomain.wso2.carbon.user.core.ldap;
import java.util.HashMap;
import java.util.Map;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.user.core.UserRealm;
import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.claim.ClaimManager;
import org.wso2.carbon.user.core.config.RealmConfiguration;
import org.wso2.carbon.user.core.ldap.ActiveDirectoryUserStoreManager;
import org.wso2.carbon.user.core.ldap.LDAPConstants;
import org.wso2.carbon.user.core.profile.ProfileConfigurationManager;
import org.wso2.carbon.user.core.util.JNDIUtil;
public class MyDomainActiveDirectoryUserStoreManager extends ActiveDirectoryUserStoreManager {
Log log = LogFactory.getLog(MyDomainActiveDirectoryUserStoreManager.class);
public MyDomainActiveDirectoryUserStoreManager(
RealmConfiguration realmConfig,
ClaimManager claimManager,
ProfileConfigurationManager profileConfigManager) throws UserStoreException {
super(realmConfig, claimManager, profileConfigManager);
}
public MyDomainActiveDirectoryUserStoreManager(
RealmConfiguration realmConfig,
Map<String, Object> properties,
ClaimManager claimManager,
ProfileConfigurationManager profileConfigManager,
UserRealm userRealm,
Integer tenantId) throws UserStoreException {
super(realmConfig, properties, claimManager, profileConfigManager, userRealm, tenantId);
}
public MyDomainActiveDirectoryUserStoreManager() {
super();
}
public Map<String, String> getUserPropertyValues(String userName, String[] propertyNames,
String profileName) throws UserStoreException {
Map<String, String> values = new HashMap<String, String>();
String searchFilter = realmConfig.getUserStoreProperty(LDAPConstants.USER_NAME_LIST_FILTER);
String userNameProperty = realmConfig
.getUserStoreProperty(LDAPConstants.USER_NAME_ATTRIBUTE);
searchFilter = "(&" + searchFilter + "(" + userNameProperty + "=" + userName + "))";
DirContext dirContext = this.connectionSource.getContext();
NamingEnumeration<?> answer = null;
NamingEnumeration<?> attrs = null;
try {
answer = this.searchForUser(searchFilter, propertyNames, dirContext);
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult) answer.next();
Attributes attributes = sr.getAttributes();
if (attributes != null) {
for (String name : propertyNames) {
Attribute attribute = attributes.get(name);
if (attribute != null) {
StringBuffer attrBuffer = new StringBuffer();
for (attrs = attribute.getAll(); attrs.hasMore();) {
String attr = (String) attrs.next();
if (attr != null && attr.trim().length() > 0) {
attrBuffer.append(attr + ",");
}
}
String value = attrBuffer.toString();
/*
* Length needs to be more than one for a valid attribute, since we
* attach ",".
*/
if (value != null && value.trim().length() > 1) {
value = value.substring(0, value.length() - 1);
values.put(name, value);
}
}
}
}
}
} catch (NamingException e) {
log.error(e.getMessage(), e);
throw new UserStoreException(e.getMessage(), e);
} finally {
// close the naming enumeration and free up resources
JNDIUtil.closeNamingEnumeration(attrs);
JNDIUtil.closeNamingEnumeration(answer);
// close directory context
JNDIUtil.closeContext(dirContext);
}
return values;
}
}
文件Activator.java:
package pt.mydomain.wso2.carbon.user.core.ldap;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public void start(BundleContext bundleContext) throws Exception {
System.out.println("Start bundle pt.mydomain.wso2.carbon.user.core.ldap");
}
public void stop(BundleContext bundleContext) throws Exception {
System.out.println("Stop bundle pt.mydomain.wso2.carbon.user.core.ldap");
}
}
這裏是堆棧跟蹤,當服務器啓動我得到:
[2016-03-01 09:59:02,231] INFO - CarbonCoreActivator Starting WSO2 Carbon...
[2016-03-01 09:59:02,234] INFO - CarbonCoreActivator Operating System : Linux 4.3.4-300.fc23.x86_64, amd64
[2016-03-01 09:59:02,234] INFO - CarbonCoreActivator Java Home : /usr/java/jdk1.7.0_79/jre
[2016-03-01 09:59:02,234] INFO - CarbonCoreActivator Java Version : 1.7.0_79
[2016-03-01 09:59:02,234] INFO - CarbonCoreActivator Java VM : Java HotSpot(TM) 64-Bit Server VM 24.79-b02,Oracle Corporation
[2016-03-01 09:59:02,234] INFO - CarbonCoreActivator Carbon Home : /home/mickael/wso2/wso2am-1.10.0
[2016-03-01 09:59:02,234] INFO - CarbonCoreActivator Java Temp Dir : /home/mickael/wso2/wso2am-1.10.0/tmp
[2016-03-01 09:59:02,235] INFO - CarbonCoreActivator User : mickael, en-US, Europe/Lisbon
[2016-03-01 09:59:02,315] WARN - ValidationResultPrinter Carbon is configured to use the default keystore (wso2carbon.jks). To maximize security when deploying to a production environment, configure a new keystore with a unique password in the production server profile.
[2016-03-01 09:59:02,369] INFO - AgentHolder Agent created !
[2016-03-01 09:59:02,384] INFO - AgentDS Successfully deployed Agent Client
[2016-03-01 09:59:03,644] ERROR - DefaultRealm Cannot initialize pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager. Error pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)Type class org.wso2.carbon.user.core.UserStoreException
org.wso2.carbon.user.core.UserStoreException: Cannot initialize pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager. Error pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)Type class org.wso2.carbon.user.core.UserStoreException
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:382)
at org.wso2.carbon.user.core.common.DefaultRealm.initializeObjects(DefaultRealm.java:203)
at org.wso2.carbon.user.core.common.DefaultRealm.init(DefaultRealm.java:108)
at org.wso2.carbon.user.core.common.DefaultRealmService.initializeRealm(DefaultRealmService.java:262)
at org.wso2.carbon.user.core.common.DefaultRealmService.<init>(DefaultRealmService.java:99)
at org.wso2.carbon.user.core.common.DefaultRealmService.<init>(DefaultRealmService.java:112)
at org.wso2.carbon.user.core.internal.Activator.startDeploy(Activator.java:68)
at org.wso2.carbon.user.core.internal.BundleCheckActivator.start(BundleCheckActivator.java:61)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: org.wso2.carbon.user.core.UserStoreException: Cannot initialize pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager. Error pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:374)
... 22 more
Caused by: java.lang.NoSuchMethodException: pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)
at java.lang.Class.getConstructor0(Class.java:2892)
at java.lang.Class.getConstructor(Class.java:1723)
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:365)
... 22 more
[2016-03-01 09:59:03,646] ERROR - Activator Cannot start User Manager Core bundle
org.wso2.carbon.user.core.UserStoreException: Cannot initialize the realm.
at org.wso2.carbon.user.core.common.DefaultRealmService.initializeRealm(DefaultRealmService.java:272)
at org.wso2.carbon.user.core.common.DefaultRealmService.<init>(DefaultRealmService.java:99)
at org.wso2.carbon.user.core.common.DefaultRealmService.<init>(DefaultRealmService.java:112)
at org.wso2.carbon.user.core.internal.Activator.startDeploy(Activator.java:68)
at org.wso2.carbon.user.core.internal.BundleCheckActivator.start(BundleCheckActivator.java:61)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: org.wso2.carbon.user.core.UserStoreException: Cannot initialize pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager. Error pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)Type class org.wso2.carbon.user.core.UserStoreException
at org.wso2.carbon.user.core.common.DefaultRealm.initializeObjects(DefaultRealm.java:303)
at org.wso2.carbon.user.core.common.DefaultRealm.init(DefaultRealm.java:108)
at org.wso2.carbon.user.core.common.DefaultRealmService.initializeRealm(DefaultRealmService.java:262)
... 19 more
Caused by: org.wso2.carbon.user.core.UserStoreException: Cannot initialize pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager. Error pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)Type class org.wso2.carbon.user.core.UserStoreException
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:382)
at org.wso2.carbon.user.core.common.DefaultRealm.initializeObjects(DefaultRealm.java:203)
... 21 more
Caused by: org.wso2.carbon.user.core.UserStoreException: Cannot initialize pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager. Error pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:374)
... 22 more
Caused by: java.lang.NoSuchMethodException: pt.mydomain.wso2.carbon.user.core.ldap.MyDomainActiveDirectoryUserStoreManager.<init>(org.wso2.carbon.user.api.RealmConfiguration, java.util.Map)
at java.lang.Class.getConstructor0(Class.java:2892)
at java.lang.Class.getConstructor(Class.java:1723)
at org.wso2.carbon.user.core.common.DefaultRealm.createObjectWithOptions(DefaultRealm.java:365)
... 22 more
[2016-03-01 09:59:09,517] INFO - TaglibUriRule TLD skipped. URI: http://tiles.apache.org/tags-tiles is already defined
我使用我的pom.xml錯誤的依賴?還是我缺少一些其他課程?歡迎任何幫助。
我嘗試過這些依賴關係,但是我仍然在啓動時遇到同樣的錯誤。這個異常引用了一個缺少的init(RealmConfiguration,Map)方法,但是這個方法似乎並不存在於ActiveDirectoryUserStoreManager類中 – Michael