Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
我正在尝试使用 ADAL 与 REST API 通信。低于错误
Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.microsoft.aad.adal4j.AuthenticationContext.acquireToken(AuthenticationContext.java:382)
at edu.stanford.test.AccToken.main(AccToken.java:40)
使用的代码是:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import com.microsoft.aad.adal4j.AsymmetricKeyCredential;
import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
public class AcceToken {
public static void main(String[] args) {
String authority = "https://login.microsoftonline.com/tenant-id/oauth2/authorize";
ExecutorService service = null;
service = Executors.newFixedThreadPool(1);
try {
AuthenticationContext authenticationContext = new AuthenticationContext(
authority, false, service);
System.out.println("Authentication Context is "+ authenticationContext.getAuthority() );
String certfile = "D:\Microsoft-tools\Samples\Final\test.pfx";
InputStream pkcs12Certificate = new FileInputStream(certfile);
String token = "";
AsymmetricKeyCredential credential = AsymmetricKeyCredential
.create("id", pkcs12Certificate, "password");
System.out.println("X509 is fine!");
Future<AuthenticationResult> future = authenticationContext.acquireToken("https://outlook.office365.com",(AsymmetricKeyCredential) credential, null);
token = future.get().getAccessToken();
Long uuid = UUID.randomUUID().getMostSignificantBits();
URL url = new URL(
"https://outlook.office365.com/api/v1.0/emailaddress/folders/inbox/messages");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("User-Agent", "Testing/1.0 abc/1.1");
Date date = new Date();
SimpleDateFormat ft = new SimpleDateFormat(
"E, dd MM yyyy hh:mm:ss zzz");
System.out.println("Current Date: " + ft.format(date));
String dateString = ft.format(date);
con.setRequestProperty("Authorization", "Bearer " + token);
if (con.getResponseCode() != 200) {
System.out.println(con.getHeaderFields());
throw new RuntimeException("Failed : HTTP error code : "
+ con.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(con.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
con.disconnect();
service.shutdown();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我在以下行收到错误消息:
Future<AuthenticationResult> future = authenticationContext.acquireToken("https://outlook.office365.com",(AsymmetricKeyCredential) credential, null);
当我查看它时,我发现在 AuthenticationContext.java 的第 382 行。我们正在调用 JwtHelper class 的 buildJwt 方法,它正在调用 AdalJWTClaimsSet class,它正在扩展 JWTClaimsSet class.
JWTClaimsSet class 不再是 public 现在是最终的。
我使用早期版本的 JWT jar,但我不断收到其他错误。
ADAL 依赖于 oauth2-oidc-sdk 版本 4.5,它依赖于 nimbus-jose-jwt 版本 3.1.2。它有 JWTClaimsSet class 作为 public。您是否在 pom.xml 中覆盖了这些库的版本?您可以在 https://github.com/AzureAD/azure-activedirectory-library-for-java/tree/master/src/samples 试用示例并查看 adal4j 按预期工作。
我正在尝试使用 ADAL 与 REST API 通信。低于错误
Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.microsoft.aad.adal4j.AuthenticationContext.acquireToken(AuthenticationContext.java:382)
at edu.stanford.test.AccToken.main(AccToken.java:40)
使用的代码是:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import com.microsoft.aad.adal4j.AsymmetricKeyCredential;
import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
public class AcceToken {
public static void main(String[] args) {
String authority = "https://login.microsoftonline.com/tenant-id/oauth2/authorize";
ExecutorService service = null;
service = Executors.newFixedThreadPool(1);
try {
AuthenticationContext authenticationContext = new AuthenticationContext(
authority, false, service);
System.out.println("Authentication Context is "+ authenticationContext.getAuthority() );
String certfile = "D:\Microsoft-tools\Samples\Final\test.pfx";
InputStream pkcs12Certificate = new FileInputStream(certfile);
String token = "";
AsymmetricKeyCredential credential = AsymmetricKeyCredential
.create("id", pkcs12Certificate, "password");
System.out.println("X509 is fine!");
Future<AuthenticationResult> future = authenticationContext.acquireToken("https://outlook.office365.com",(AsymmetricKeyCredential) credential, null);
token = future.get().getAccessToken();
Long uuid = UUID.randomUUID().getMostSignificantBits();
URL url = new URL(
"https://outlook.office365.com/api/v1.0/emailaddress/folders/inbox/messages");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("User-Agent", "Testing/1.0 abc/1.1");
Date date = new Date();
SimpleDateFormat ft = new SimpleDateFormat(
"E, dd MM yyyy hh:mm:ss zzz");
System.out.println("Current Date: " + ft.format(date));
String dateString = ft.format(date);
con.setRequestProperty("Authorization", "Bearer " + token);
if (con.getResponseCode() != 200) {
System.out.println(con.getHeaderFields());
throw new RuntimeException("Failed : HTTP error code : "
+ con.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(con.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
con.disconnect();
service.shutdown();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我在以下行收到错误消息:
Future<AuthenticationResult> future = authenticationContext.acquireToken("https://outlook.office365.com",(AsymmetricKeyCredential) credential, null);
当我查看它时,我发现在 AuthenticationContext.java 的第 382 行。我们正在调用 JwtHelper class 的 buildJwt 方法,它正在调用 AdalJWTClaimsSet class,它正在扩展 JWTClaimsSet class.
JWTClaimsSet class 不再是 public 现在是最终的。
我使用早期版本的 JWT jar,但我不断收到其他错误。
ADAL 依赖于 oauth2-oidc-sdk 版本 4.5,它依赖于 nimbus-jose-jwt 版本 3.1.2。它有 JWTClaimsSet class 作为 public。您是否在 pom.xml 中覆盖了这些库的版本?您可以在 https://github.com/AzureAD/azure-activedirectory-library-for-java/tree/master/src/samples 试用示例并查看 adal4j 按预期工作。