Search in sources :

Example 1 with RealmConfigXMLProcessor

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;
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) RealmConfigXMLProcessor(org.wso2.carbon.user.core.config.RealmConfigXMLProcessor) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) File(java.io.File) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)

Example 2 with RealmConfigXMLProcessor

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;
    }
}
Also used : RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) RealmConfigXMLProcessor(org.wso2.carbon.user.core.config.RealmConfigXMLProcessor) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Aggregations

RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)2 RealmConfigXMLProcessor (org.wso2.carbon.user.core.config.RealmConfigXMLProcessor)2 File (java.io.File)1 ResourceFile (org.wso2.carbon.apimgt.api.model.ResourceFile)1 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1