forked from community/device-mgt-core
parent
262e53ddcc
commit
11957f1e47
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.webapp.authenticator.framework.test;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.utils.ServerConstants;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.AuthenticatorFrameworkException;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.config.WebappAuthenticatorConfig;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WebappAuthenticatorConfigTest {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public void init() {
|
||||||
|
System.setProperty(ServerConstants.CARBON_CONFIG_DIR_PATH, "src/test/resources/config");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigInitialization() {
|
||||||
|
try {
|
||||||
|
WebappAuthenticatorConfig.init();
|
||||||
|
|
||||||
|
WebappAuthenticatorConfig config = WebappAuthenticatorConfig.getInstance();
|
||||||
|
Assert.assertNotNull(config);
|
||||||
|
|
||||||
|
List<AuthenticatorConfig> authConfigs = config.getAuthenticators();
|
||||||
|
Assert.assertNotNull(authConfigs);
|
||||||
|
} catch (AuthenticatorFrameworkException e) {
|
||||||
|
Assert.fail("Error occurred while testing webapp authenticator config initialization", e);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Assert.fail("Unexpected error has been encountered while testing webapp authenticator config " +
|
||||||
|
"initialization", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public void cleanup() {
|
||||||
|
System.setProperty(ServerConstants.CARBON_CONFIG_DIR_PATH, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.webapp.authenticator.framework.test;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.commons.pool.ObjectPool;
|
||||||
|
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub;
|
||||||
|
import org.wso2.carbon.webapp.authenticator.framework.Utils.OAuthTokenValidationStubFactory;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class WebappAuthenticatorFrameworkUtilTest {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(WebappAuthenticatorFrameworkUtilTest.class);
|
||||||
|
|
||||||
|
private static final String TOKEN_VALIDATION_SERVICE_URL = "https://localhost:9443";
|
||||||
|
private static final String ADMIN_USERNAME = "admin";
|
||||||
|
private static final String ADMIN_PASSWORD = "admin";
|
||||||
|
private static final Properties PROPERTIES = new Properties();
|
||||||
|
|
||||||
|
static {
|
||||||
|
PROPERTIES.setProperty("MaxTotalConnections", "100");
|
||||||
|
PROPERTIES.setProperty("MaxConnectionsPerHost", "100");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOAuthTokenValidatorStubPool() {
|
||||||
|
ObjectPool stubs = null;
|
||||||
|
OAuth2TokenValidationServiceStub stub = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
stubs = new GenericObjectPool(
|
||||||
|
new OAuthTokenValidationStubFactory(
|
||||||
|
TOKEN_VALIDATION_SERVICE_URL, ADMIN_USERNAME, ADMIN_PASSWORD, PROPERTIES));
|
||||||
|
|
||||||
|
stub = (OAuth2TokenValidationServiceStub) stubs.borrowObject();
|
||||||
|
Assert.assertNotNull(stub);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = "Error occurred while borrowing an oauth validator service stub instance from the pool";
|
||||||
|
log.error(msg, e);
|
||||||
|
Assert.fail(msg, e);
|
||||||
|
} finally {
|
||||||
|
if (stubs != null) {
|
||||||
|
try {
|
||||||
|
if (stub != null) {
|
||||||
|
stubs.returnObject(stub);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Error occurred while returning oauth validator service stub instance to the pool", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Checks if the stub instance used above has been properly returned to the pool */
|
||||||
|
Assert.assertEquals(stubs.getNumIdle(), 1);
|
||||||
|
/* Verifies that there's no hanging connections after the operation performed above */
|
||||||
|
Assert.assertEquals(stubs.getNumActive(), 0);
|
||||||
|
|
||||||
|
try {
|
||||||
|
stubs.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Error occurred while closing the object pool", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testStubFactoryInitWithInvalidHttpClientProperties() {
|
||||||
|
new OAuthTokenValidationStubFactory(TOKEN_VALIDATION_SERVICE_URL, null, ADMIN_PASSWORD, PROPERTIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testStubFactoryInitWithInvalidUsername() {
|
||||||
|
new OAuthTokenValidationStubFactory(TOKEN_VALIDATION_SERVICE_URL, null, ADMIN_PASSWORD, PROPERTIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testStubFactoryInitWithInvalidPassword() {
|
||||||
|
new OAuthTokenValidationStubFactory(TOKEN_VALIDATION_SERVICE_URL, ADMIN_USERNAME, null, PROPERTIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
|
public void testStubFactoryInitWithInvalidUrl() {
|
||||||
|
new OAuthTokenValidationStubFactory(null, ADMIN_USERNAME, ADMIN_PASSWORD, PROPERTIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<WebappAuthenticatorConfig>
|
||||||
|
<Authenticators>
|
||||||
|
<Authenticator>
|
||||||
|
<Name>OAuth</Name>
|
||||||
|
<ClassName>org.wso2.carbon.webapp.authenticator.framework.authenticator.OAuthAuthenticator</ClassName>
|
||||||
|
<Parameters>
|
||||||
|
<Parameter Name="TokenValidationEndpointUrl">https://localhost:9443</Parameter>
|
||||||
|
<Parameter Name="Username">admin</Parameter>
|
||||||
|
<Parameter Name="Password">admin</Parameter>
|
||||||
|
<Parameter Name="IsRemote">true</Parameter>
|
||||||
|
<Parameter Name="MaxConnectionsPerHost">10000</Parameter>
|
||||||
|
<Parameter Name="MaxTotalConnections">10000</Parameter>
|
||||||
|
</Parameters>
|
||||||
|
</Authenticator>
|
||||||
|
<Authenticator>
|
||||||
|
<Name>BasicAuth</Name>
|
||||||
|
<ClassName>org.wso2.carbon.webapp.authenticator.framework.authenticator.BasicAuthAuthenticator</ClassName>
|
||||||
|
</Authenticator>
|
||||||
|
<Authenticator>
|
||||||
|
<Name>JWT</Name>
|
||||||
|
<ClassName>org.wso2.carbon.webapp.authenticator.framework.authenticator.JWTAuthenticator</ClassName>
|
||||||
|
</Authenticator>
|
||||||
|
<Authenticator>
|
||||||
|
<Name>CertificateAuth</Name>
|
||||||
|
<ClassName>org.wso2.carbon.webapp.authenticator.framework.authenticator.CertificateAuthenticator</ClassName>
|
||||||
|
</Authenticator>
|
||||||
|
</Authenticators>
|
||||||
|
</WebappAuthenticatorConfig>
|
@ -0,0 +1,32 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2009 WSO2, Inc. (http://wso2.com)
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# This is the log4j configuration file used by WSO2 Carbon
|
||||||
|
#
|
||||||
|
# IMPORTANT : Please do not remove or change the names of any
|
||||||
|
# of the Appenders defined here. The layout pattern & log file
|
||||||
|
# can be changed using the WSO2 Carbon Management Console, and those
|
||||||
|
# settings will override the settings in this file.
|
||||||
|
#
|
||||||
|
|
||||||
|
log4j.rootLogger=ERROR, STD_OUT
|
||||||
|
|
||||||
|
# Redirect log messages to console
|
||||||
|
log4j.appender.STD_OUT=org.apache.log4j.ConsoleAppender
|
||||||
|
log4j.appender.STD_OUT.Target=System.out
|
||||||
|
log4j.appender.STD_OUT.layout=org.apache.log4j.PatternLayout
|
||||||
|
log4j.appender.STD_OUT.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
~ Version 2.0 (the "License"); you may not use this file except
|
||||||
|
~ in compliance with the License.
|
||||||
|
~ you may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing,
|
||||||
|
~ software distributed under the License is distributed on an
|
||||||
|
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
~ KIND, either express or implied. See the License for the
|
||||||
|
~ specific language governing permissions and limitations
|
||||||
|
~ under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
|
|
||||||
|
<suite name="WebappAuthenticatorFramework">
|
||||||
|
<parameter name="useDefaultListeners" value="false"/>
|
||||||
|
|
||||||
|
<test name="WebappAuthenticatorConfigTests" preserve-order="true">
|
||||||
|
<classes>
|
||||||
|
<class name="org.wso2.carbon.webapp.authenticator.framework.test.WebappAuthenticatorConfigTest"/>
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
|
|
||||||
|
<test name="WebappAuthenticatorUtilTests" preserve-order="true">
|
||||||
|
<classes>
|
||||||
|
<class name="org.wso2.carbon.webapp.authenticator.framework.test.WebappAuthenticatorFrameworkUtilTest"/>
|
||||||
|
</classes>
|
||||||
|
</test>
|
||||||
|
|
||||||
|
</suite>
|
Loading…
Reference in new issue