use of org.wso2.carbon.user.core.config.RealmConfigXMLProcessor in project carbon-apimgt by wso2.
the class APIUtil method replaceSystemProperty.
/**
* Resolves system properties and replaces in given in text
*
* @param text
* @return System properties resolved text
*/
public static String replaceSystemProperty(String text) {
int indexOfStartingChars = -1;
int indexOfClosingBrace;
// 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 = ServiceReferenceHolder.getContextService().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;
}
use of org.wso2.carbon.user.core.config.RealmConfigXMLProcessor in project carbon-apimgt by wso2.
the class RegistrationServiceImpl method isUserSuperAdmin.
private boolean isUserSuperAdmin(String username) {
try {
RealmConfiguration realmConfig = new RealmConfigXMLProcessor().buildRealmConfigurationFromFile();
String adminUserName = realmConfig.getAdminUserName();
return adminUserName.equalsIgnoreCase(username);
} catch (UserStoreException e) {
log.error("Error while retrieving super admin username", e);
return false;
}
}
Aggregations