在 WSO2 身份服务器中创建服务提供者时出现 302 错误
302 Error while creating service provider in WSO2 Identity Server
我正在尝试通过 Java 程序在 WSO2 Identity Server 中创建一个服务提供者。创建服务提供者的代码块如下。
public static OAuthKeySecret createOAuthServiceProvider(OAuthAppDetails oauthApp, String authType) {
OAuthKeySecret oauthKeySecret = new OAuthKeySecret();
try {
IdentityApplicationManagementServiceStub IAMStub = new IdentityApplicationManagementServiceStub(
null, oauthApp.getSERVER_URL() + "IdentityApplicationManagementService");
ServiceClient IAMClient = IAMStub._getServiceClient();
Authenticate.authenticate(IAMClient);
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(oauthApp.getAppName());
serviceProvider.setDescription(oauthApp.getAppDescription());
IAMStub.createApplication(serviceProvider);
System.out.println("Service Provider created");
} catch (Exception e) {
e.printStackTrace();
}
return oauthKeySecret;
}
当 运行 程序出现以下错误可追溯到以下代码行
IAMStub.createApplication(serviceProvider);
完整跟踪
org.apache.axis2.AxisFault: Transport error: 302 Error: Found
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:311)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:451)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:278)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:430)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceStub.createApplication(IdentityApplicationManagement
ServiceStub.java:601)
at com.xxxxx.identity.wso2.IdentityServerAdapter.IDManagementClient.createOAuthServiceProvider(IDManagementClient.java:52)
at com.xxxxx.identity.wso2.IdentityServerAdapter.IdentityServerRest.handle(IdentityServerRest.java:37)
at com.xxxxx.identity.wso2.IdentityServerAdapter.IdentityServerRest.handle(IdentityServerRest.java:19)
at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:138)
at spark.webserver.JettyHandler.doHandle(JettyHandler.java:54)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:179)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:451)
at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:252)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:266)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:240)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:527)
at java.lang.Thread.run(Unknown Source)
这是怎么回事?请帮我。
在 Identity Server 5.1.0 中,"createApplication" 操作没有任何问题。你能 post 完整的示例源代码和 Authenticate.authenticate 的实现吗?记录 "oauthApp.getAppName()" 的值。下面的代码对我有用。
try {
String authCookie = null;
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
AuthenticationAdminStub authstub = new AuthenticationAdminStub(ctx, "https://localhost:9443/services`enter code here`/AuthenticationAdmin");
ServiceClient client = authstub._getServiceClient();
Options options = client.getOptions();`enter code here`
options.setManageSession(true);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, authCookie);
//set trust store properties required in SSL communication.
System.setProperty("javax.net.ssl.trustStore", RemoteUMSampleConstants.TRUST_STORE_PATH);
System.setProperty("javax.net.ssl.trustStorePassword", RemoteUMSampleConstants.TRUST_STORE_PASSWORD);
authstub.login("admin", "admin", "localhost");
authCookie = (String) authstub._getServiceClient().getServiceContext().getProperty(
HTTPConstants.COOKIE_STRING);
IdentityApplicationManagementServiceStub stub = new IdentityApplicationManagementServiceStub(
"https://localhost:9443/services/IdentityApplicationManagementService");
ServiceClient e = stub._getServiceClient();
Options option = e.getOptions();
option.setManageSession(true);
option.setProperty("Cookie", authCookie);
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName("testName");
serviceProvider.setDescription("testDescription");
stub.createApplication(serviceProvider);
}catch (Exception e){
System.out.print(e);
}
我正在尝试通过 Java 程序在 WSO2 Identity Server 中创建一个服务提供者。创建服务提供者的代码块如下。
public static OAuthKeySecret createOAuthServiceProvider(OAuthAppDetails oauthApp, String authType) {
OAuthKeySecret oauthKeySecret = new OAuthKeySecret();
try {
IdentityApplicationManagementServiceStub IAMStub = new IdentityApplicationManagementServiceStub(
null, oauthApp.getSERVER_URL() + "IdentityApplicationManagementService");
ServiceClient IAMClient = IAMStub._getServiceClient();
Authenticate.authenticate(IAMClient);
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName(oauthApp.getAppName());
serviceProvider.setDescription(oauthApp.getAppDescription());
IAMStub.createApplication(serviceProvider);
System.out.println("Service Provider created");
} catch (Exception e) {
e.printStackTrace();
}
return oauthKeySecret;
}
当 运行 程序出现以下错误可追溯到以下代码行
IAMStub.createApplication(serviceProvider);
完整跟踪
org.apache.axis2.AxisFault: Transport error: 302 Error: Found
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:311)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:451)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:278)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:430)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceStub.createApplication(IdentityApplicationManagement
ServiceStub.java:601)
at com.xxxxx.identity.wso2.IdentityServerAdapter.IDManagementClient.createOAuthServiceProvider(IDManagementClient.java:52)
at com.xxxxx.identity.wso2.IdentityServerAdapter.IdentityServerRest.handle(IdentityServerRest.java:37)
at com.xxxxx.identity.wso2.IdentityServerAdapter.IdentityServerRest.handle(IdentityServerRest.java:19)
at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:138)
at spark.webserver.JettyHandler.doHandle(JettyHandler.java:54)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:179)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:451)
at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:252)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:266)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:240)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:527)
at java.lang.Thread.run(Unknown Source)
这是怎么回事?请帮我。
在 Identity Server 5.1.0 中,"createApplication" 操作没有任何问题。你能 post 完整的示例源代码和 Authenticate.authenticate 的实现吗?记录 "oauthApp.getAppName()" 的值。下面的代码对我有用。
try {
String authCookie = null;
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
AuthenticationAdminStub authstub = new AuthenticationAdminStub(ctx, "https://localhost:9443/services`enter code here`/AuthenticationAdmin");
ServiceClient client = authstub._getServiceClient();
Options options = client.getOptions();`enter code here`
options.setManageSession(true);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, authCookie);
//set trust store properties required in SSL communication.
System.setProperty("javax.net.ssl.trustStore", RemoteUMSampleConstants.TRUST_STORE_PATH);
System.setProperty("javax.net.ssl.trustStorePassword", RemoteUMSampleConstants.TRUST_STORE_PASSWORD);
authstub.login("admin", "admin", "localhost");
authCookie = (String) authstub._getServiceClient().getServiceContext().getProperty(
HTTPConstants.COOKIE_STRING);
IdentityApplicationManagementServiceStub stub = new IdentityApplicationManagementServiceStub(
"https://localhost:9443/services/IdentityApplicationManagementService");
ServiceClient e = stub._getServiceClient();
Options option = e.getOptions();
option.setManageSession(true);
option.setProperty("Cookie", authCookie);
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName("testName");
serviceProvider.setDescription("testDescription");
stub.createApplication(serviceProvider);
}catch (Exception e){
System.out.print(e);
}