Skip to content

Commit

Permalink
introduce rac v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaminduR committed Oct 22, 2023
1 parent 80502ba commit 113c35f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.wso2.carbon.identity.auth.service.util;

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpHeaders;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.identity.auth.service.AuthenticationContext;
import org.wso2.carbon.identity.auth.service.handler.AuthenticationHandler;
import org.wso2.carbon.identity.auth.service.internal.AuthenticationServiceHolder;
Expand All @@ -13,10 +16,15 @@
import org.wso2.carbon.identity.core.bean.context.MessageContext;
import org.wso2.carbon.identity.core.util.IdentityConfigParser;
import org.wso2.carbon.identity.core.util.IdentityCoreConstants;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.securevault.SecretResolver;
import org.wso2.securevault.SecretResolverFactory;
import org.wso2.securevault.commons.MiscellaneousUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -29,7 +37,9 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;

import static org.wso2.carbon.identity.auth.service.util.Constants.AUTHORIZATION_CONTROL_ELE;
import static org.wso2.carbon.identity.auth.service.util.Constants.AUTH_HANDLER_ELE;
Expand Down Expand Up @@ -78,8 +88,7 @@ public ResourceConfig getSecuredConfig(ResourceConfigKey resourceConfigKey) {
*/
public void buildResourceAccessControlData() {

OMElement resourceAccessControl = IdentityConfigParser.getInstance().getConfigElement(Constants
.RESOURCE_ACCESS_CONTROL_ELE);
OMElement resourceAccessControl = getResourceAccessControlConfigs();
if ( resourceAccessControl != null ) {
defaultAccess = resourceAccessControl.getAttributeValue(new QName(Constants.RESOURCE_DEFAULT_ACCESS));
isScopeValidationEnabled = !Boolean.parseBoolean(resourceAccessControl
Expand Down Expand Up @@ -162,6 +171,34 @@ public void buildResourceAccessControlData() {
}
}

private static OMElement getResourceAccessControlConfigs() {

/*
Check whether legacy authorization runtime is enabled.
Use the legacy resource access control configs if enabled.
*/
if (!CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME) {
return IdentityConfigParser.getInstance().getConfigElement(Constants
.RESOURCE_ACCESS_CONTROL_ELE);
}
try {
InputStream inStream = null;
String configDirPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "identity";
File configFile = new File(configDirPath, FilenameUtils.getName("resource-access-control-v2.xml"));
if (configFile.exists()) {
inStream = new FileInputStream(configFile);
}
if (inStream == null) {
String message = "Identity configuration not found at: " + configFile.getName();
log.error(message);
}
StAXOMBuilder builder = new StAXOMBuilder(inStream);
return builder.getDocumentElement();
} catch (FileNotFoundException | XMLStreamException e) {
throw new RuntimeException(e);
}
}

public List<String> buildAllowedAuthenticationHandlers(String allowedAuthenticationHandlers) {

List<String> allowedAuthHandlersList = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
<osgi.util.tracker.imp.pkg.version.range>[1.5.1, 2.0.0)</osgi.util.tracker.imp.pkg.version.range>

<!-- Carbon Kernel version -->
<carbon.kernel.version>4.9.10</carbon.kernel.version>
<carbon.kernel.version>4.9.15</carbon.kernel.version>
<carbon.kernel.feature.version>4.9.0</carbon.kernel.feature.version>
<carbon.kernel.imp.pkg.version.range>[4.5.0, 5.0.0)</carbon.kernel.imp.pkg.version.range>

Expand Down

0 comments on commit 113c35f

Please sign in to comment.