通过Kotin使用OpenAM SDK时发现“没有类def”错误
我正在尝试使用OpenAM SDK进行一些任务。 当使用任何SDK类时,我得到“没有类def找不到”的错误! 我已经检查并确认gradle.build,并确保我有正确的外部jar(客户端SDK)。 可能是什么问题?
buildscript { ext.kotlin_version = '1.1.3' repositories { mavenCentral() flatDir { dirs 'lib' } } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath group: 'com.sun.identity', name: 'openam-clientsdk', version: '13.0.0' classpath group: 'com.iplanet.am', name: 'openam-clientsdk', version: '13.0.0' } } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" compile group: 'org.forgerock.openam', name: 'openam-clientsdk', version: '13.0.0' runtime group: 'com.sun.identity', name: 'openam-clientsdk', version: '13.0.0' }
这是Kotlin代码:
import com.iplanet.sso.SSOTokenManager import com.iplanet.sso.SSOException import com.iplanet.sso.SSOToken import com.sun.identity.idm.IdConstants import com.sun.identity.sm.* import com.sun.identity.authentication.* import com.sun.identity.authentication.spi.AuthLoginException import com.sun.identity.authentication.share.AuthXMLTags import java.util.* import javax.security.auth.callback.*` @Throws(SSOException::class, AuthLoginException::class, Exception::class) fun realmLogin(userid: String, password: String, realm: String):SSOToken? { val mgr: SSOTokenManager val adminDN: String val adminPassword: String val ssoToken: SSOToken? val authType = AuthContext.IndexType.MODULE_INSTANCE val lc: AuthContext try { lc = AuthContext(realm) } catch (le: AuthLoginException) { System.err.println( "IdRepoSampleUtils: could not get AuthContext for realm " + realm) throw le } try { lc.login() } catch (le: AuthLoginException) { System.err.println("IdRepoSampleUtils: Failed to start login " + "for default authmodule") throw le } var callbacks: Array<Callback>? val values = Hashtable<String, String>() values.put(AuthXMLTags.NAME_CALLBACK, userid) values.put(AuthXMLTags.PASSWORD_CALLBACK, password) while (lc.hasMoreRequirements()) { callbacks = lc.getRequirements() try { fillCallbacks(callbacks, values) lc.submitRequirements(callbacks) } catch (e: Exception) { System.err.println("Failed to submit callbacks!") e.printStackTrace() return null } } val istat = lc.getStatus() if (istat === AuthContext.Status.SUCCESS) { println("==>Authentication SUCCESSFUL for user " + userid) } else if (istat === AuthContext.Status.COMPLETED) { println("==>Authentication Status for user " + userid + " = " + istat) return null } try { ssoToken = lc.getSSOToken() } catch (e: Exception) { System.err.println("Failed to get SSO token! " + e.message) throw e } return ssoToken } fun main(args: Array<String>) { realmLogin("amAdmin", "MyPassword", "") } Exception in thread "main" java.lang.NoClassDefFoundError: org/forgerock/guava/common/collect/ImmutableMap at com.iplanet.am.util.SystemProperties.<clinit>(SystemProperties.java:121) at com.sun.identity.configuration.FedSystemProperties.isServerMode(FedSystemProperties.java:115) at com.sun.identity.configuration.FedSystemProperties.get(FedSystemProperties.java:90) at com.sun.identity.shared.configuration.SystemPropertiesManager.get(SystemPropertiesManager.java:137) at com.sun.identity.shared.debug.Debug.initialize(Debug.java:262) at com.sun.identity.shared.debug.Debug.<clinit>(Debug.java:754) at com.sun.identity.sm.SMSEntry.<clinit>(SMSEntry.java:96) at com.sun.identity.sm.ServiceManager.<clinit>(ServiceManager.java:78) at com.sun.identity.sm.ServiceConfigManager.<init>(ServiceConfigManager.java:93) at MainKt.main(Main.kt:145) Caused by: java.lang.ClassNotFoundException:org.forgerock.guava.common.collect.ImmutableMap at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 10 more`
正如@KoheiTAMURA提到的,我通过从OpenAM安装文件夹中添加需要的jar(forgerock-guava-collect-18.0.1.jar)来修复错误。
不要在新的应用程序中使用ClientSDK。 ClientSDK已弃用,不会在较新版本的OpenAM中发布。
您应该使用您选择的http-client的REST API。