Skip to content

Commit

Permalink
[#1119] api security check: requests all allow when security policy i…
Browse files Browse the repository at this point in the history
…s not setting (#1120)
  • Loading branch information
chengyouling authored Dec 5, 2023
1 parent e9f205b commit 3de36f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package com.huaweicloud.governance.authentication.securityPolicy;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -49,6 +49,9 @@ public boolean isAllowed(AuthRequestExtractor extractor) throws Exception {
if (StringUtils.isEmpty(currentServiceName)) {
currentServiceName = authenticationAdapter.getServiceName(extractor.serviceId());
}
if (StringUtils.isEmpty(securityPolicyProperties.getMode())) {
return true;
}
return checkAllowAndDeny(currentServiceName, extractor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.huaweicloud.governance.authentication.AuthRequestExtractor;
import com.huaweicloud.governance.authentication.AuthRequestExtractorUtils;
import com.huaweicloud.governance.authentication.AuthenticationAdapter;
import com.huaweicloud.governance.authentication.Const;
import com.huaweicloud.governance.authentication.securityPolicy.SecurityPolicyProperties.Action;
import com.huaweicloud.governance.authentication.securityPolicy.SecurityPolicyProperties.ConfigurationItem;

Expand Down Expand Up @@ -554,6 +555,19 @@ public void testUriSuffixNotMatch() throws Exception {
.isAllowed(extractor));
}

@Test
public void testPolicyIsNull() throws Exception {
AuthRequestExtractor extractor = createAuthRequestExtractor("/checkTokenPer/security/checkTokenSfu");
Assertions.assertTrue(getNoSettingAccessController()
.isAllowed(extractor));
}

private SecurityPolicyAccessController getNoSettingAccessController() {
securityPolicyProperties.setAction(null);
securityPolicyProperties.setMode(null);
return new SecurityPolicyAccessController(authenticationAdapter, securityPolicyProperties);
}

private SecurityPolicyAccessController getAllowAccessController(String mode) {
Action action = new Action();
action.setAllow(buildAllow());
Expand Down

0 comments on commit 3de36f7

Please sign in to comment.