Refactoring

4.x.x
megala21 7 years ago
parent 29896fd9b5
commit a838590e31

@ -138,7 +138,6 @@ public class UtilsTest {
ComplianceFeature complianceFeature = new ComplianceFeature(); ComplianceFeature complianceFeature = new ComplianceFeature();
complianceFeature.setCompliance(true); complianceFeature.setCompliance(true);
complianceFeatures.add(complianceFeature); complianceFeatures.add(complianceFeature);
ComplianceFeature nonCompliant = new ComplianceFeature(); ComplianceFeature nonCompliant = new ComplianceFeature();
nonCompliant.setCompliance(false); nonCompliant.setCompliance(false);
complianceFeatures.add(nonCompliant); complianceFeatures.add(nonCompliant);

@ -16,13 +16,11 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.webapp.authenticator.framework.Utils; package org.wso2.carbon.webapp.authenticator.framework.Utils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.user.api.TenantManager; import org.wso2.carbon.user.api.TenantManager;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.service.RealmService;
@ -105,7 +103,6 @@ public class Utils {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Username to connect to the OAuth token validation endpoint is not provided"); "Username to connect to the OAuth token validation endpoint is not provided");
} }
String adminPassword = properties.getProperty("Password"); String adminPassword = properties.getProperty("Password");
if (adminPassword == null) { if (adminPassword == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -134,7 +131,6 @@ public class Utils {
if (oAuthValidationResponse.isValid()) { if (oAuthValidationResponse.isValid()) {
String username = oAuthValidationResponse.getUserName(); String username = oAuthValidationResponse.getUserName();
String tenantDomain = oAuthValidationResponse.getTenantDomain(); String tenantDomain = oAuthValidationResponse.getTenantDomain();
authenticationInfo.setUsername(username); authenticationInfo.setUsername(username);
authenticationInfo.setTenantDomain(tenantDomain); authenticationInfo.setTenantDomain(tenantDomain);
authenticationInfo.setTenantId(getTenantIdOFUser(username + "@" + tenantDomain)); authenticationInfo.setTenantId(getTenantIdOFUser(username + "@" + tenantDomain));
@ -144,7 +140,6 @@ public class Utils {
authenticationInfo.setMessage(oAuthValidationResponse.getErrorMsg()); authenticationInfo.setMessage(oAuthValidationResponse.getErrorMsg());
} }
return authenticationInfo; return authenticationInfo;
} }
private static String replaceSystemProperty(String urlWithPlaceholders) { private static String replaceSystemProperty(String urlWithPlaceholders) {

@ -1,3 +1,21 @@
/*
* Copyright (c) 2017, 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; package org.wso2.carbon.webapp.authenticator.framework;
import org.testng.annotations.BeforeSuite; import org.testng.annotations.BeforeSuite;
@ -45,6 +63,5 @@ public class BaseWebAppAuthenticatorFrameworkTest {
Permission adminPermission = new Permission(PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH, Permission adminPermission = new Permission(PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH,
CarbonConstants.UI_PERMISSION_ACTION); CarbonConstants.UI_PERMISSION_ACTION);
userStoreManager.addRole(ADMIN_ROLE + "t", new String[] { ADMIN_USER }, new Permission[] { adminPermission }); userStoreManager.addRole(ADMIN_ROLE + "t", new String[] { ADMIN_USER }, new Permission[] { adminPermission });
} }
} }

@ -49,6 +49,7 @@ public class BasicAuthAuthenticatorTest {
private MimeHeaders mimeHeaders; private MimeHeaders mimeHeaders;
private org.apache.coyote.Request coyoteRequest; private org.apache.coyote.Request coyoteRequest;
private MessageBytes bytes; private MessageBytes bytes;
private final String BASIC_HEADER = "basic ";
@BeforeTest @BeforeTest
public void init() throws NoSuchFieldException { public void init() throws NoSuchFieldException {
@ -73,13 +74,12 @@ public class BasicAuthAuthenticatorTest {
"Without proper Authentication headers request can be handled by BasicAuthAuthenticator."); "Without proper Authentication headers request can be handled by BasicAuthAuthenticator.");
coyoteRequest = new org.apache.coyote.Request(); coyoteRequest = new org.apache.coyote.Request();
mimeHeaders = new MimeHeaders(); mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue("Authorization"); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("test"); bytes.setString("test");
headersField.set(coyoteRequest, mimeHeaders); headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest); request.setCoyoteRequest(coyoteRequest);
Assert.assertFalse(basicAuthAuthenticator.canHandle(request), Assert.assertFalse(basicAuthAuthenticator.canHandle(request),
"With a different authorization header Basic Authenticator can handle the request"); "With a different authorization header Basic Authenticator can handle the request");
} }
@Test(description = "This method tests the canHandle method when all the required parameters are given with the " @Test(description = "This method tests the canHandle method when all the required parameters are given with the "
@ -90,8 +90,8 @@ public class BasicAuthAuthenticatorTest {
context.addParameter("basicAuth", "true"); context.addParameter("basicAuth", "true");
request.setContext(context); request.setContext(context);
mimeHeaders = new MimeHeaders(); mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue("Authorization"); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("basic "); bytes.setString(BASIC_HEADER);
headersField.set(coyoteRequest, mimeHeaders); headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest); request.setCoyoteRequest(coyoteRequest);
Assert.assertTrue(basicAuthAuthenticator.canHandle(request), Assert.assertTrue(basicAuthAuthenticator.canHandle(request),
@ -108,7 +108,7 @@ public class BasicAuthAuthenticatorTest {
request.setContext(context); request.setContext(context);
mimeHeaders = new MimeHeaders(); mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("basic " + encodedString); bytes.setString(BASIC_HEADER + encodedString);
coyoteRequest = new org.apache.coyote.Request(); coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders); headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest); request.setCoyoteRequest(coyoteRequest);
@ -131,7 +131,7 @@ public class BasicAuthAuthenticatorTest {
String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":test" + ADMIN_USER).getBytes())); String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":test" + ADMIN_USER).getBytes()));
mimeHeaders = new MimeHeaders(); mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("basic " + encodedString); bytes.setString(BASIC_HEADER + encodedString);
coyoteRequest = new org.apache.coyote.Request(); coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders); headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest); request.setCoyoteRequest(coyoteRequest);
@ -142,13 +142,12 @@ public class BasicAuthAuthenticatorTest {
encodedString = new String(Base64.getEncoder().encode((ADMIN_USER).getBytes())); encodedString = new String(Base64.getEncoder().encode((ADMIN_USER).getBytes()));
mimeHeaders = new MimeHeaders(); mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER); bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("basic " + encodedString); bytes.setString(BASIC_HEADER + encodedString);
coyoteRequest = new org.apache.coyote.Request(); coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders); headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest); request.setCoyoteRequest(coyoteRequest);
authenticationInfo = basicAuthAuthenticator.authenticate(request, null); authenticationInfo = basicAuthAuthenticator.authenticate(request, null);
Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.FAILURE, Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.FAILURE,
"For a request with missing password authentication succeeded."); "For a request with missing password authentication succeeded.");
} }
} }

Loading…
Cancel
Save