Search in sources :

Example 1 with Props

use of org.apache.directory.fortress.core.model.Props in project directory-fortress-core by apache.

the class ConfigMgrRestImpl method add.

/**
 * {@inheritDoc}
 */
@Override
public Properties add(String name, Properties inProperties) throws SecurityException {
    VUtil.assertNotNull(name, GlobalErrIds.FT_CONFIG_NAME_NULL, CLS_NM + ".add");
    VUtil.assertNotNull(inProperties, GlobalErrIds.FT_CONFIG_PROPS_NULL, CLS_NM + ".add");
    Properties retProperties;
    FortRequest request = new FortRequest();
    Props inProps = RestUtils.getProps(inProperties);
    request.setEntity(inProps);
    request.setValue(name);
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.CFG_ADD);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        Props outProps = (Props) response.getEntity();
        retProperties = RestUtils.getProperties(outProps);
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retProperties;
}
Also used : FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) Properties(java.util.Properties) Props(org.apache.directory.fortress.core.model.Props) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 2 with Props

use of org.apache.directory.fortress.core.model.Props in project directory-fortress-core by apache.

the class ConfigMgrRestImpl method read.

/**
 * {@inheritDoc}
 */
@Override
public Properties read(String name) throws SecurityException {
    VUtil.assertNotNull(name, GlobalErrIds.FT_CONFIG_NAME_NULL, CLS_NM + ".readRole");
    Properties retProps;
    FortRequest request = new FortRequest();
    request.setValue(name);
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.CFG_READ);
    FortResponse response = RestUtils.unmarshall(szResponse);
    Props props;
    if (response.getErrorCode() == 0) {
        props = (Props) response.getEntity();
        retProps = RestUtils.getProperties(props);
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retProps;
}
Also used : FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) Properties(java.util.Properties) Props(org.apache.directory.fortress.core.model.Props) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Example 3 with Props

use of org.apache.directory.fortress.core.model.Props in project directory-fortress-core by apache.

the class RestUtils method getProps.

/**
 * @param properties
 * @return Prop contains name value pairs.
 */
public static Props getProps(Properties properties) {
    Props props = null;
    if (properties != null) {
        props = new ObjectFactory().createProps();
        for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements(); ) {
            String key = (String) e.nextElement();
            String val = properties.getProperty(key);
            Props.Entry entry = new Props.Entry();
            entry.setKey(key);
            entry.setValue(val);
            props.getEntry().add(entry);
        }
    }
    return props;
}
Also used : ObjectFactory(org.apache.directory.fortress.core.model.ObjectFactory) Props(org.apache.directory.fortress.core.model.Props)

Example 4 with Props

use of org.apache.directory.fortress.core.model.Props in project directory-fortress-core by apache.

the class RestUtils method getProperties.

/**
 * @param inProps
 * @return Properties
 */
public static Properties getProperties(Props inProps) {
    Properties properties = null;
    List<Props.Entry> props = inProps.getEntry();
    if (props.size() > 0) {
        properties = new Properties();
        // int size = props.size();
        for (Props.Entry entry : props) {
            String key = entry.getKey();
            String val = entry.getValue();
            properties.setProperty(key, val);
        }
    }
    return properties;
}
Also used : Properties(java.util.Properties) Props(org.apache.directory.fortress.core.model.Props)

Example 5 with Props

use of org.apache.directory.fortress.core.model.Props in project directory-fortress-core by apache.

the class ConfigMgrRestImpl method update.

/**
 * {@inheritDoc}
 */
@Override
public Properties update(String name, Properties inProperties) throws SecurityException {
    VUtil.assertNotNull(name, GlobalErrIds.FT_CONFIG_NAME_NULL, CLS_NM + ".update");
    VUtil.assertNotNull(inProperties, GlobalErrIds.FT_CONFIG_PROPS_NULL, CLS_NM + ".update");
    Properties retProperties;
    FortRequest request = new FortRequest();
    Props inProps = RestUtils.getProps(inProperties);
    request.setEntity(inProps);
    request.setValue(name);
    String szRequest = RestUtils.marshal(request);
    String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.CFG_UPDATE);
    FortResponse response = RestUtils.unmarshall(szResponse);
    if (response.getErrorCode() == 0) {
        Props outProps = (Props) response.getEntity();
        retProperties = RestUtils.getProperties(outProps);
    } else {
        throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
    }
    return retProperties;
}
Also used : FortResponse(org.apache.directory.fortress.core.model.FortResponse) SecurityException(org.apache.directory.fortress.core.SecurityException) Properties(java.util.Properties) Props(org.apache.directory.fortress.core.model.Props) FortRequest(org.apache.directory.fortress.core.model.FortRequest)

Aggregations

Props (org.apache.directory.fortress.core.model.Props)6 Properties (java.util.Properties)4 SecurityException (org.apache.directory.fortress.core.SecurityException)4 FortRequest (org.apache.directory.fortress.core.model.FortRequest)4 FortResponse (org.apache.directory.fortress.core.model.FortResponse)4 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)1