通过Kotin使用OpenAM SDK时“没有找到类def”错误

时间:2017-07-02 22:44:31

标签: java kotlin openam

我正在尝试使用OpenAM SDK执行某项任务。当使用任何SDK类时,我得到“No class def found”错误!我检查并确认了gradle.build并确保我有正确的外部jar(Client 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`

2 个答案:

答案 0 :(得分:0)

正如@KoheiTAMURA所提到的,我通过将所需的jar(forgerock-guava-collect-18.0.1.jar)从OpenAM安装文件夹添加到我的项目中来修复错误。

答案 1 :(得分:-1)

不要在新应用程序中使用ClientSDK。 ClientSDK已弃用,并未在较新版本的OpenAM中发布。

您应该将REST API与您选择的http-client一起使用。