Search in sources :

Example 1 with SettingsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsDTO in project carbon-apimgt by wso2.

the class SettingsApiServiceImpl method settingsGet.

/**
 * Retrieves admin portal related server settings
 *
 * @param messageContext
 * @return settings list
 * @throws APIManagementException
 */
@Override
public Response settingsGet(MessageContext messageContext) throws APIManagementException {
    String username = RestApiCommonUtil.getLoggedInUsername();
    boolean isUserAvailable = false;
    if (!APIConstants.WSO2_ANONYMOUS_USER.equalsIgnoreCase(username)) {
        isUserAvailable = true;
    }
    SettingsMappingUtil settingsMappingUtil = new SettingsMappingUtil();
    SettingsDTO settingsDTO = settingsMappingUtil.fromSettingsToDTO(isUserAvailable);
    return Response.ok().entity(settingsDTO).build();
}
Also used : SettingsDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.SettingsDTO) SettingsMappingUtil(org.wso2.carbon.apimgt.rest.api.admin.v1.utils.mappings.SettingsMappingUtil)

Example 2 with SettingsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsDTO in project carbon-apimgt by wso2.

the class SettingsMappingUtil method fromSettingsToDTO.

/**
 * This method feeds data into the settingsDTO
 *
 * @param isUserAvailable check if user is logged in
 * @return SettingsDTO
 * @throws APIManagementException
 */
public SettingsDTO fromSettingsToDTO(Boolean isUserAvailable) throws APIManagementException {
    SettingsDTO settingsDTO = new SettingsDTO();
    if (isUserAvailable) {
        settingsDTO.setAnalyticsEnabled(APIUtil.isAnalyticsEnabled());
        settingsDTO.setKeyManagerConfiguration(getSettingsKeyManagerConfigurationDTOList());
    }
    settingsDTO.setScopes(getScopeList());
    return settingsDTO;
}
Also used : SettingsDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.SettingsDTO)

Example 3 with SettingsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsDTO in project carbon-apimgt by wso2.

the class SettingsMappingUtil method fromSettingsToDTO.

/**
 * This method feeds data into the settingsDTO
 *
 * @return SettingsDTO
 * @throws APIManagementException
 */
public SettingsDTO fromSettingsToDTO() throws APIManagementException {
    SettingsDTO settingsDTO = new SettingsDTO();
    settingsDTO.setScopes(getScopeList());
    return settingsDTO;
}
Also used : SettingsDTO(org.wso2.carbon.apimgt.rest.api.service.catalog.dto.SettingsDTO)

Example 4 with SettingsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsDTO in project carbon-apimgt by wso2.

the class SettingsMappingUtil method fromSettingstoDTO.

public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, Boolean moneatizationEnabled, boolean recommendationEnabled, boolean anonymousEnabled, String organization) throws APIManagementException {
    SettingsDTO settingsDTO = new SettingsDTO();
    settingsDTO.setScopes(GetScopeList());
    settingsDTO.setApplicationSharingEnabled(APIUtil.isMultiGroupAppSharingEnabled());
    settingsDTO.setRecommendationEnabled(recommendationEnabled);
    settingsDTO.setMapExistingAuthApps(APIUtil.isMapExistingAuthAppsEnabled());
    settingsDTO.setMonetizationEnabled(moneatizationEnabled);
    SettingsIdentityProviderDTO identityProviderDTO = new SettingsIdentityProviderDTO();
    identityProviderDTO.setExternal(APIUtil.getIdentityProviderConfig() != null);
    settingsDTO.setIdentityProvider(identityProviderDTO);
    settingsDTO.setIsAnonymousModeEnabled(anonymousEnabled);
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    boolean enableChangePassword = Boolean.parseBoolean(config.getFirstProperty(APIConstants.ENABLE_CHANGE_PASSWORD));
    settingsDTO.setIsPasswordChangeEnabled(enableChangePassword);
    String username = RestApiCommonUtil.getLoggedInUsername();
    String tenantDomain = MultitenantUtils.getTenantDomain(username);
    int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
    String userStorePasswordPattern = null;
    String passwordPolicyPattern = null;
    int passwordPolicyMinLength = -1;
    int passwordPolicyMaxLength = -1;
    try {
        // Get password pattern from the UserStoreManager configuration
        RealmConfiguration realmConfiguration = null;
        RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
        if (realmService != null && tenantId != MultitenantConstants.INVALID_TENANT_ID) {
            UserStoreManager userStoreManager = null;
            userStoreManager = (UserStoreManager) realmService.getTenantUserRealm(tenantId).getUserStoreManager();
            realmConfiguration = userStoreManager.getRealmConfiguration();
        }
        if (realmConfiguration != null) {
            String passwordJavaRegEx = realmConfiguration.getUserStoreProperty(APIConstants.PASSWORD_JAVA_REGEX_PROPERTY);
            if (passwordJavaRegEx != null && !passwordJavaRegEx.trim().isEmpty()) {
                userStorePasswordPattern = passwordJavaRegEx;
            }
        }
        // Get password pattern from the Password policy
        Property passwordPolicyEnabledProperty = FrameworkUtils.getResidentIdpConfiguration(APIConstants.IS_PASSWORD_POLICY_ENABLED_PROPERTY, tenantDomain);
        boolean isPasswordPolicyEnabled = Boolean.parseBoolean(passwordPolicyEnabledProperty.getValue());
        if (isPasswordPolicyEnabled) {
            passwordPolicyPattern = FrameworkUtils.getResidentIdpConfiguration(APIConstants.PASSWORD_POLICY_PATTERN_PROPERTY, tenantDomain).getValue();
            passwordPolicyMinLength = Integer.parseInt(FrameworkUtils.getResidentIdpConfiguration(APIConstants.PASSWORD_POLICY_MIN_LENGTH_PROPERTY, tenantDomain).getValue());
            passwordPolicyMaxLength = Integer.parseInt(FrameworkUtils.getResidentIdpConfiguration(APIConstants.PASSWORD_POLICY_MAX_LENGTH_PROPERTY, tenantDomain).getValue());
        }
    } catch (UserStoreException e) {
        String errorMessage = "Error occurred in getting userRealm for the tenant: " + tenantId;
        throw new APIManagementException(errorMessage, e);
    } catch (FrameworkException e) {
        String errorMessage = "Error occurred in getting Resident Idp Configurations for tenant: " + tenantId;
        throw new APIManagementException(errorMessage, e);
    }
    settingsDTO.setUserStorePasswordPattern(userStorePasswordPattern);
    settingsDTO.setPasswordPolicyPattern(passwordPolicyPattern);
    settingsDTO.setPasswordPolicyMinLength(passwordPolicyMinLength);
    settingsDTO.setPasswordPolicyMaxLength(passwordPolicyMaxLength);
    if (isUserAvailable) {
        settingsDTO.setGrantTypes(APIUtil.getGrantTypes());
        Map<String, Environment> environments = APIUtil.getEnvironments(organization);
        if (environments.isEmpty()) {
            settingsDTO.apiGatewayEndpoint("http://localhost:8280, https://localhost:8243");
        } else {
            for (Map.Entry<String, Environment> entry : environments.entrySet()) {
                Environment environment = environments.get(entry.getKey());
                if (environment.isDefault()) {
                    settingsDTO.apiGatewayEndpoint(environment.getApiGatewayEndpoint());
                    break;
                }
            }
            if (settingsDTO.getApiGatewayEndpoint() == null) {
                Map.Entry<String, Environment> entry = environments.entrySet().iterator().next();
                Environment environment = environments.get(entry.getKey());
                settingsDTO.apiGatewayEndpoint(environment.getApiGatewayEndpoint());
            }
        }
    }
    return settingsDTO;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) SettingsIdentityProviderDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsIdentityProviderDTO) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) SettingsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreException(org.wso2.carbon.user.api.UserStoreException) Environment(org.wso2.carbon.apimgt.api.model.Environment) Property(org.wso2.carbon.identity.application.common.model.Property) Map(java.util.Map)

Example 5 with SettingsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsDTO in project carbon-apimgt by wso2.

the class SettingsMappingUtil method fromSettingstoDTO.

/**
 * This method feeds data into the settingsDTO.
 *
 * @param isUserAvailable check if user is logged in
 * @return SettingsDTO
 * @throws APIManagementException,IOException
 */
public SettingsDTO fromSettingstoDTO(Boolean isUserAvailable, String organization) throws APIManagementException, IOException {
    SettingsDTO settingsDTO = new SettingsDTO();
    EnvironmentListDTO environmentListDTO = new EnvironmentListDTO();
    if (isUserAvailable) {
        Map<String, Environment> environments = APIUtil.getEnvironments(organization);
        if (environments != null) {
            environmentListDTO = EnvironmentMappingUtil.fromEnvironmentCollectionToDTO(environments.values());
        }
        settingsDTO.setEnvironment(environmentListDTO.getList());
        String storeUrl = APIUtil.getStoreUrl();
        String loggedInUserTenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
        Map<String, String> domainMappings = APIUtil.getDomainMappings(loggedInUserTenantDomain, APIConstants.API_DOMAIN_MAPPINGS_STORE);
        if (domainMappings.size() != 0) {
            Iterator entries = domainMappings.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry thisEntry = (Map.Entry) entries.next();
                storeUrl = "https://" + thisEntry.getValue();
                break;
            }
        }
        settingsDTO.setDevportalUrl(storeUrl);
        settingsDTO.setMonetizationAttributes(getMonetizationAttributes());
        settingsDTO.setSecurityAuditProperties(getSecurityAuditProperties());
        settingsDTO.setExternalStoresEnabled(APIUtil.isExternalStoresEnabled(RestApiCommonUtil.getLoggedInUserTenantDomain()));
        settingsDTO.setDocVisibilityEnabled(APIUtil.isDocVisibilityLevelsEnabled());
        settingsDTO.setCrossTenantSubscriptionEnabled(APIUtil.isCrossTenantSubscriptionsEnabled());
        Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
        String authorizationHeader = APIUtil.getOAuthConfiguration(loggedInUserTenantDomain, APIConstants.AUTHORIZATION_HEADER);
        if (authorizationHeader == null) {
            authorizationHeader = APIConstants.AUTHORIZATION_HEADER_DEFAULT;
        }
        settingsDTO.setAuthorizationHeader(authorizationHeader);
    }
    return settingsDTO;
}
Also used : SettingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SettingsDTO) EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentListDTO) Iterator(java.util.Iterator) Environment(org.wso2.carbon.apimgt.api.model.Environment) Map(java.util.Map)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 Map (java.util.Map)2 Environment (org.wso2.carbon.apimgt.api.model.Environment)2 SettingsDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.SettingsDTO)2 SettingsDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SettingsDTO)2 SettingsDTO (org.wso2.carbon.apimgt.rest.api.service.catalog.dto.SettingsDTO)2 SettingsDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsDTO)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 SettingsMappingUtil (org.wso2.carbon.apimgt.rest.api.admin.v1.utils.mappings.SettingsMappingUtil)1 SettingsMappingUtil (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.mappings.SettingsMappingUtil)1 EnvironmentListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentListDTO)1 SettingsMappingUtil (org.wso2.carbon.apimgt.rest.api.service.catalog.utils.SettingsMappingUtil)1 SettingsIdentityProviderDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.SettingsIdentityProviderDTO)1 SettingsMappingUtil (org.wso2.carbon.apimgt.rest.api.store.v1.mappings.SettingsMappingUtil)1 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)1 Property (org.wso2.carbon.identity.application.common.model.Property)1 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)1