【问题标题】:Can't authentication with WSO2 IS on webapp无法在 webapp 上使用 WSO2 IS 进行身份验证
【发布时间】:2016-08-26 16:04:00
【问题描述】:

我正在尝试在 WSO2 IS 上创建身份验证机制,但遇到以下问题: - 我按照下面的链接实现了 remote_user,结果没问题。我可以从控制台登录和访问 WSO API

https://svn.wso2.org/repos/wso2/people/asela/user-mgt/remote-user-api/4.2.X/

但是当我在网页上尝试时,我无法向 WSO IS 进行身份验证。以下是我的代码:

public void init() throws AxisFault{
        userName = HDConstants.USER_NAME;
        password = HDConstants.PASSWORD;
        backEndServerURL = HDConstants.SERVER_URL;

    setKeyStore();
    configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
}

public void setKeyStore() {
    System.setProperty("javax.net.ssl.trustStore", HDConstants.TRUST_STORE_PATH);
    System.setProperty("javax.net.ssl.trustStorePassword", HDConstants.TRUST_STORE_PASSWORD);
    System.setProperty("javax.net.ssl.trustStoreType", HDConstants.TRUST_STORE_TYPE);
}

public boolean authenticateUser(String userName, String password) throws Exception {
    String serviceURL = null;
    ServiceClient client = null;
    Options option = null;
    boolean isAuthenticated = false;
    AuthenticationAdminStub authStub = null;

    serviceURL = backEndServerURL + "AuthenticationAdmin";
    authStub = new AuthenticationAdminStub(configCtx, serviceURL);
    client = authStub._getServiceClient();
    option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, authCookie);
    isAuthenticated = authStub.login(userName, password, HDConstants.APP_ID);
    authCookie = (String) authStub._getServiceClient().getServiceContext()
            .getProperty(HTTPConstants.COOKIE_STRING);
    System.out.println(" Auth Cookie ==== " + authCookie);
    return isAuthenticated;
}
`

在控制器中我使用下面的代码来调用验证方法:

AuthenticationServiceClient authenticationServiceClient = new AuthenticationServiceClient();
           authenticationServiceClient.init();
           authenticationServiceClient.authenticateUser("admin", "admin");

但结果并不好。系统提示:

at org.apache.axis2.deployment.AxisConfigBuilder.processTransportSenders(AxisConfigBuilder.java:688)
at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:124)
at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:887)
at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210)
at com.home.hduser.wsois.AuthenticationServiceClient.init(AuthenticationServiceClient.java:29)

我不知道为什么我可以在控制台上进行身份验证,但不能在 webapp 上进行验证

以及以下文件中附加的完整跟踪错误: https://drive.google.com/open?id=0B9zEqmu0HBunSlp3X0dpWC1YU0E

感谢您在这种情况下的帮助。 谢谢

【问题讨论】:

  • 发布您的完整错误跟踪。
  • 嗨 Bhathiya,我在上面的链接中附加了完整的错误。
  • 你的 IS 版本是多少?
  • 我正在使用最新版本的 WSO IS (5.1.0)
  • 作为在 WSO2 AS 5.3.0 中部署 webapp 的解决方法,请先删除此 jar:tomcat-annotations-api-7.0.59.jar tomcat-api-7.0.59.jar tomcat-catalina -7.0.59.jar tomcat-catalina-ha-7.0.59.jar tomcat-jdbc-7.0.47.jar tomcat-juli-7.0.59.jar tomcat-tribes-7.0.59.jar tomcat-util-7.0。 59.jar

标签: spring-mvc authentication wso2 wso2is


【解决方案1】:

只需在 pom.xml 文件中更改此依赖项,设置提供的范围:

     <dependency>
        <groupId>org.wso2.carbon.identity</groupId>
        <artifactId>org.wso2.carbon.um.ws.api</artifactId>
        <version>${carbon.identity.version}</version>
         <scope>provided</scope>
    </dependency>

移除tomcat依赖:

[INFO] +- org.wso2.carbon.identity:org.wso2.carbon.um.ws.api:jar:4.5.4:provided
[INFO] |  +- org.wso2.carbon:org.wso2.carbon.user.core:jar:4.4.1:provided
[INFO] |  |  +- org.wso2.carbon:javax.cache.wso2:jar:4.4.1:provided
[INFO] |  |  |  \- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1:provided
[INFO] |  |  +- commons-dbcp.wso2:commons-dbcp:jar:1.4.0.wso2v1:provided
[INFO] |  |  +- org.apache.tomcat.wso2:jdbc-pool:jar:7.0.34.wso2v2:provided
[INFO] |  |  |  \- org.apache.tomcat:tomcat-jdbc:jar:7.0.47:provided
[INFO] |  |  \- commons-collections.wso2:commons-collections:jar:3.2.0.wso2v1:provided
[INFO] |  +- org.wso2.carbon.identity:org.wso2.carbon.user.mgt.common:jar:4.5.4:provided
[INFO] |  +- org.wso2.carbon:org.wso2.carbon.core:jar:4.4.1:provided
[INFO] |  |  +- org.wso2.orbit.com.hazelcast:hazelcast:jar:3.5.0.wso2v1:provided
[INFO] |  |  |  \- com.hazelcast:hazelcast-all:jar:3.5:provided
[INFO] |  |  |     +- com.eclipsesource.minimal-json:minimal-json:jar:0.9.2:provided
[INFO] |  |  |     \- org.freemarker:freemarker:jar:2.3.22:provided
[INFO] |  |  +- org.eclipse.equinox:org.eclipse.equinox.http.helper:jar:1.1.0.wso2v1:provided
[INFO] |  |  \- org.apache.tomcat:tomcat-catalina-ha:jar:7.0.59:provided
[INFO] |  |     +- org.apache.tomcat:tomcat-juli:jar:7.0.59:provided
[INFO] |  |     +- org.apache.tomcat:tomcat-tribes:jar:7.0.59:provided
[INFO] |  |     +- org.apache.tomcat:tomcat-catalina:jar:7.0.59:provided
[INFO] |  |     |  +- org.apache.tomcat:tomcat-annotations-api:jar:7.0.59:provided
[INFO] |  |     |  \- org.apache.tomcat:tomcat-api:jar:7.0.59:provided
[INFO] |  |     \- org.apache.tomcat:tomcat-util:jar:7.0.59:provided
[INFO] |  +- org.wso2.carbon:org.wso2.carbon.authenticator.proxy:jar:4.4.1:provided
[INFO] |  |  \- org.wso2.carbon:org.wso2.carbon.core.common:jar:4.4.1:provided
[INFO] |  +- org.wso2.carbon:org.wso2.carbon.registry.core:jar:4.4.1:provided
[INFO] |  |  +- commons-io.wso2:commons-io:jar:2.0.0.wso2v2:provided
[INFO] |  |  +- net.sourceforge.findbugs:annotations:jar:1.3.2:provided
[INFO] |  |  +- org.wso2.carbon:org.wso2.carbon.registry.xboot:jar:4.4.1:provided
[INFO] |  |  +- org.compass-project.wso2:compass:jar:2.0.1.wso2v2:provided
[INFO] |  |  +- org.apache.abdera.wso2:abdera:jar:1.0.0.wso2v3:provided
[INFO] |  |  +- org.apache.poi.wso2:poi-scratchpad:jar:3.9.0.wso2v1:provided
[INFO] |  |  |  \- org.apache.poi:poi-scratchpad:jar:3.9:provided
[INFO] |  |  |     \- org.apache.poi:poi:jar:3.9:provided
[INFO] |  |  \- commons-pool.wso2:commons-pool:jar:1.5.6.wso2v1:provided
[INFO] |  |     \- commons-pool:commons-pool:jar:1.5.6:provided
[INFO] |  \- org.wso2.carbon.identity:org.wso2.carbon.um.ws.api.stub:jar:4.5.4:provided

编辑:我必须设置 IS_HOME 绝对路径。

编辑 2:使用相对路径:

此方法返回 wso2carbon.jks 文件的路径:

public String setKeyStorePath(){
    String path = System.getProperty("carbon.home") + File.separator +
            "repository" + File.separator + "resources" +
            File.separator + "security" +
            File.separator + "wso2carbon.jks";
    System.out.println("wso2carbon.jks path: " + path);
    return path;
}

修改 setKeyStore 以使用 setKeyStorePath()

public void setKeyStore() {
    System.setProperty("javax.net.ssl.trustStore", setKeyStorePath());
    System.setProperty("javax.net.ssl.trustStorePassword", HDConstants.TRUST_STORE_PASSWORD);
    System.setProperty("javax.net.ssl.trustStoreType", HDConstants.TRUST_STORE_TYPE);
}

【讨论】:

  • 感谢 Jorge,但目前我在身份验证方面遇到了麻烦。例外是“java.security.NoSuchAlgorithmException:构造实现时出错(算法:默认,提供者:SunJSSE,类:sun.security.ssl.SSLContextImpl$DefaultSSLContext)”,而我将trustStore,trustStorePassword设置为上面的代码:
  • 如果问题与信任锚有关,则与 public static final String IS_HOME = ".." + File.separator + ".." + File.separator 中的相对路径有关;
  • 我尝试使用以下代码从项目的资源文件夹中获取 TRUST_STORE_PATH,但结果相同。类加载器 classLoader = getClass().getClassLoader();文件 file = new File(classLoader.getResource("wso2carbon.jks").getFile()); System.setProperty("javax.net.ssl.trustStore", file.getAbsolutePath());
  • 不,我设置了绝对路径来尝试并且它可以工作。现在的问题是相对路径。
  • 请检查我的第二次更新。它现在可以使用相对路径:-D
【解决方案2】:

我假设您在 IS 本身中部署您的 webapp。我可以看到你的战争文件中包含了很多罐子。它们中的大多数已经在 IS 服务器中可用。

由于依赖冲突,可能会发生上述错误。 See this 了解更多信息。

要消除错误,您可以尝试将&lt;scope&gt;provided&lt;/scope&gt; 设置为服务器中已经可用的依赖项。

【讨论】:

  • 哦,我正在尝试构建一种网关方式来帮助从我们的客户端访问 ---> my Gate --> IS 。假设当我们的客户端使用登录功能时。我们将在我的 Gate 中调用 login 方法,然后它将重定向到 IS 上的身份验证功能。我尝试在我的 pom 文件中添加 provided 但结果与之前相同。
  • 能否请您为我提供正确的 wso2 存储库或编辑我项目中的 pom 文件?
  • wso2-nexus 你在 pom 中的 repo 是正确的。要查找 IS 有哪些版本的 jars,您可以查看 &lt;IS_HOME&gt;/repository/components/plugins/ 目录。
  • 我明白你提到的。我想知道我们的代码不正确或者我的 pom 中的 wso2 版本不正确,所以它导致了我上面提到的错误。
  • 什么是my gate?雄猫?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-30
  • 2017-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多