added scripts and updated config reading

kernel-4.6.x
Amalka Subasinghe 3 years ago
parent bdb01a0098
commit f3720e49ff

@ -17,6 +17,8 @@
*/
package org.wso2.carbon.device.mgt.core.config.identity;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@ -31,7 +33,7 @@ public class IdentityConfigurations {
@XmlElement(name = "AdminUsername", required = true)
public String getAdminUsername() {
return adminUsername;
return DeviceManagerUtil.replaceSystemProperty(adminUsername);
}
public void setAdminUsername(String adminUsername) {
@ -40,7 +42,7 @@ public class IdentityConfigurations {
@XmlElement(name = "AdminPassword", required = true)
public String getAdminPassword() {
return adminPassword;
return DeviceManagerUtil.replaceSystemProperty(adminPassword);
}
public void setAdminPassword(String adminPassword) {

@ -17,6 +17,8 @@
*/
package org.wso2.carbon.device.mgt.core.config.keymanager;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@ -31,7 +33,7 @@ public class KeyManagerConfigurations {
@XmlElement(name = "AdminUsername", required = true)
public String getAdminUsername() {
return adminUsername;
return DeviceManagerUtil.replaceSystemProperty(adminUsername);
}
public void setAdminUsername(String adminUsername) {
@ -40,7 +42,7 @@ public class KeyManagerConfigurations {
@XmlElement(name = "AdminPassword", required = true)
public String getAdminPassword() {
return adminPassword;
return DeviceManagerUtil.replaceSystemProperty(adminPassword);
}
public void setAdminPassword(String adminPassword) {

@ -96,10 +96,12 @@ import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
import org.wso2.carbon.user.api.RealmConfiguration;
import org.wso2.carbon.user.api.TenantManager;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.config.RealmConfigXMLProcessor;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ConfigurationContextService;
import org.wso2.carbon.utils.NetworkUtils;
@ -1165,4 +1167,55 @@ public final class DeviceManagerUtil {
.getUserStoreManager();
return userStoreManager.getUserClaimValue(username, claimUri, null);
}
public static String replaceSystemProperty(String text) {
int indexOfStartingChars = -1;
int indexOfClosingBrace;
// The following condition deals with properties.
// Properties are specified as ${system.property},
// and are assumed to be System properties
while (indexOfStartingChars < text.indexOf("${")
&& (indexOfStartingChars = text.indexOf("${")) != -1
&& (indexOfClosingBrace = text.indexOf('}')) != -1) { // Is a
// property
// used?
String sysProp = text.substring(indexOfStartingChars + 2,
indexOfClosingBrace);
String propValue = System.getProperty(sysProp);
if (propValue == null) {
if ("carbon.context".equals(sysProp)) {
propValue = DeviceManagementDataHolder.getInstance().getConfigurationContextService()
.getServerConfigContext().getContextRoot();
} else if ("admin.username".equals(sysProp) || "admin.password".equals(sysProp)) {
try {
RealmConfiguration realmConfig =
new RealmConfigXMLProcessor().buildRealmConfigurationFromFile();
if ("admin.username".equals(sysProp)) {
propValue = realmConfig.getAdminUserName();
} else {
propValue = realmConfig.getAdminPassword();
}
} catch (UserStoreException e) {
// Can't throw an exception because the server is
// starting and can't be halted.
log.error("Unable to build the Realm Configuration", e);
return null;
}
}
}
//Derive original text value with resolved system property value
if (propValue != null) {
text = text.substring(0, indexOfStartingChars) + propValue
+ text.substring(indexOfClosingBrace + 1);
}
if ("carbon.home".equals(sysProp) && propValue != null
&& ".".equals(propValue)) {
text = new File(".").getAbsolutePath() + File.separator + text;
}
}
return text;
}
}

@ -21,6 +21,7 @@ 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.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.user.api.TenantManager;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService;
@ -98,12 +99,12 @@ public class Utils {
if ((url == null) || (url.isEmpty())) {
throw new IllegalArgumentException("OAuth token validation endpoint url is not provided");
}
String adminUsername = properties.getProperty("Username");
String adminUsername = DeviceManagerUtil.replaceSystemProperty(properties.getProperty("Username"));
if (adminUsername == null) {
throw new IllegalArgumentException(
"Username to connect to the OAuth token validation endpoint is not provided");
}
String adminPassword = properties.getProperty("Password");
String adminPassword = DeviceManagerUtil.replaceSystemProperty(properties.getProperty("Password"));
if (adminPassword == null) {
throw new IllegalArgumentException(
"Password to connect to the OAuth token validation endpoint is not provided");

@ -42,13 +42,13 @@
</PullNotificationConfiguration>
<IdentityConfiguration>
<ServerUrl>https://localhost:9443</ServerUrl>
<AdminUsername>admin</AdminUsername>
<AdminPassword>admin</AdminPassword>
<AdminUsername>${admin.username}</AdminUsername>
<AdminPassword>${admin.username}</AdminPassword>
</IdentityConfiguration>
<KeyManagerConfiguration>
<ServerUrl>https://localhost:9443</ServerUrl>
<AdminUsername>admin</AdminUsername>
<AdminPassword>admin</AdminPassword>
<AdminUsername>${admin.username}</AdminUsername>
<AdminPassword>${admin.username}</AdminPassword>
</KeyManagerConfiguration>
<PolicyConfiguration>
<MonitoringClass>org.wso2.carbon.policy.mgt</MonitoringClass>

@ -63,8 +63,8 @@
<AdminPassword>{{device_mgt_conf.identity_conf.admin_password}}</AdminPassword>
{% else %}
<ServerUrl>https://localhost:9443</ServerUrl>
<AdminUsername>admin</AdminUsername>
<AdminPassword>admin</AdminPassword>
<AdminUsername>${admin.username}</AdminUsername>
<AdminPassword>${admin.username}</AdminPassword>
{% endif %}
</IdentityConfiguration>
<KeyManagerConfiguration>
@ -74,8 +74,8 @@
<AdminPassword>{{device_mgt_conf.key_manager_conf.admin_password}}</AdminPassword>
{% else %}
<ServerUrl>https://localhost:9443</ServerUrl>
<AdminUsername>admin</AdminUsername>
<AdminPassword>admin</AdminPassword>
<AdminUsername>${admin.username}</AdminUsername>
<AdminPassword>${admin.username}</AdminPassword>
{% endif %}
</KeyManagerConfiguration>
<PolicyConfiguration>

@ -6,8 +6,8 @@
<Parameters>
<Parameter Name="IsRemote">false</Parameter>
<Parameter Name="TokenValidationEndpointUrl">https://${iot.keymanager.host}:${iot.keymanager.https.port}</Parameter>
<Parameter Name="Username">admin</Parameter>
<Parameter Name="Password">admin</Parameter>
<Parameter Name="Username">${admin.username}</Parameter>
<Parameter Name="Password">${admin.username}</Parameter>
<Parameter Name="MaxTotalConnections">100</Parameter>
<Parameter Name="MaxConnectionsPerHost">100</Parameter>
</Parameters>
@ -41,8 +41,8 @@
<Parameters>
<Parameter Name="IsRemote">false</Parameter>
<Parameter Name="TokenValidationEndpointUrl">https://${iot.keymanager.host}:${iot.keymanager.https.port}</Parameter>
<Parameter Name="Username">admin</Parameter>
<Parameter Name="Password">admin</Parameter>
<Parameter Name="Username">${admin.username}</Parameter>
<Parameter Name="Password">${admin.username}</Parameter>
<Parameter Name="MaxTotalConnections">100</Parameter>
<Parameter Name="MaxConnectionsPerHost">100</Parameter>
</Parameters>

@ -14,8 +14,8 @@
<Parameters>
<Parameter Name="IsRemote">false</Parameter>
<Parameter Name="TokenValidationEndpointUrl">https://${iot.keymanager.host}:${iot.keymanager.https.port}</Parameter>
<Parameter Name="Username">admin</Parameter>
<Parameter Name="Password">admin</Parameter>
<Parameter Name="Username">${admin.username}</Parameter>
<Parameter Name="Password">${admin.username}</Parameter>
<Parameter Name="MaxTotalConnections">100</Parameter>
<Parameter Name="MaxConnectionsPerHost">100</Parameter>
</Parameters>
@ -94,8 +94,8 @@
<Parameters>
<Parameter Name="IsRemote">false</Parameter>
<Parameter Name="TokenValidationEndpointUrl">https://${iot.keymanager.host}:${iot.keymanager.https.port}</Parameter>
<Parameter Name="Username">admin</Parameter>
<Parameter Name="Password">admin</Parameter>
<Parameter Name="Username">${admin.username}</Parameter>
<Parameter Name="Password">${admin.username}</Parameter>
<Parameter Name="MaxTotalConnections">100</Parameter>
<Parameter Name="MaxConnectionsPerHost">100</Parameter>
</Parameters>

Loading…
Cancel
Save