Refactoring

revert-70aa11f8
megala21 7 years ago
parent 29896fd9b5
commit a838590e31

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

@ -16,13 +16,11 @@
* under the License.
*/
package org.wso2.carbon.webapp.authenticator.framework.Utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService;
@ -105,7 +103,6 @@ public class Utils {
throw new IllegalArgumentException(
"Username to connect to the OAuth token validation endpoint is not provided");
}
String adminPassword = properties.getProperty("Password");
if (adminPassword == null) {
throw new IllegalArgumentException(
@ -134,7 +131,6 @@ public class Utils {
if (oAuthValidationResponse.isValid()) {
String username = oAuthValidationResponse.getUserName();
String tenantDomain = oAuthValidationResponse.getTenantDomain();
authenticationInfo.setUsername(username);
authenticationInfo.setTenantDomain(tenantDomain);
authenticationInfo.setTenantId(getTenantIdOFUser(username + "@" + tenantDomain));
@ -144,7 +140,6 @@ public class Utils {
authenticationInfo.setMessage(oAuthValidationResponse.getErrorMsg());
}
return authenticationInfo;
}
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;
import org.testng.annotations.BeforeSuite;
@ -44,7 +62,6 @@ public class BaseWebAppAuthenticatorFrameworkTest {
.getTenantUserRealm(MultitenantConstants.SUPER_TENANT_ID).getUserStoreManager();
Permission adminPermission = new Permission(PermissionUtils.ADMIN_PERMISSION_REGISTRY_PATH,
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 org.apache.coyote.Request coyoteRequest;
private MessageBytes bytes;
private final String BASIC_HEADER = "basic ";
@BeforeTest
public void init() throws NoSuchFieldException {
@ -73,13 +74,12 @@ public class BasicAuthAuthenticatorTest {
"Without proper Authentication headers request can be handled by BasicAuthAuthenticator.");
coyoteRequest = new org.apache.coyote.Request();
mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue("Authorization");
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("test");
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
Assert.assertFalse(basicAuthAuthenticator.canHandle(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 "
@ -90,8 +90,8 @@ public class BasicAuthAuthenticatorTest {
context.addParameter("basicAuth", "true");
request.setContext(context);
mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue("Authorization");
bytes.setString("basic ");
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString(BASIC_HEADER);
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
Assert.assertTrue(basicAuthAuthenticator.canHandle(request),
@ -108,7 +108,7 @@ public class BasicAuthAuthenticatorTest {
request.setContext(context);
mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("basic " + encodedString);
bytes.setString(BASIC_HEADER + encodedString);
coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
@ -131,7 +131,7 @@ public class BasicAuthAuthenticatorTest {
String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":test" + ADMIN_USER).getBytes()));
mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("basic " + encodedString);
bytes.setString(BASIC_HEADER + encodedString);
coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
@ -142,13 +142,12 @@ public class BasicAuthAuthenticatorTest {
encodedString = new String(Base64.getEncoder().encode((ADMIN_USER).getBytes()));
mimeHeaders = new MimeHeaders();
bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
bytes.setString("basic " + encodedString);
bytes.setString(BASIC_HEADER + encodedString);
coyoteRequest = new org.apache.coyote.Request();
headersField.set(coyoteRequest, mimeHeaders);
request.setCoyoteRequest(coyoteRequest);
authenticationInfo = basicAuthAuthenticator.authenticate(request, null);
Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.FAILURE,
"For a request with missing password authentication succeeded.");
}
}

Loading…
Cancel
Save