Search in sources :

Example 76 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class MonitoredAttributeBagResource method put.

/**
 * Creates new monitored-attributes. This method deletes all of the existing
 * monitored-attributes.
 *
 * @param attributes the list of monitored-attributes to be created.
 * @return a list of the monitored-attributes after the transaction.
 */
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ActionReportResult put(List<Map<String, String>> attributes) {
    RestActionReporter ar = new RestActionReporter();
    ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ar.setActionDescription("monitored-attribute");
    try {
        setMonitoredAttributes(attributes);
        List monitoredAttributes = getMonitoredAttributes();
        Properties extraProperties = new Properties();
        extraProperties.put("monitoredAttributes", monitoredAttributes);
        ar.setExtraProperties(extraProperties);
    } catch (TransactionFailure ex) {
        ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
        ar.setMessage(ex.getMessage());
    }
    return new ActionReportResult(tagName, ar, new OptionsResult(Util.getResourceName(uriInfo)));
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 77 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class ModuleInfo method save.

/**
 * Saves its state to the configuration. this method must be called within a transaction
 * to the configured module instance.
 *
 * @param module the module being persisted
 */
public void save(Module module) throws TransactionFailure, PropertyVetoException {
    // write out the module properties only for composite app
    if (Boolean.valueOf(moduleProps.getProperty(ServerTags.IS_COMPOSITE))) {
        moduleProps.remove(ServerTags.IS_COMPOSITE);
        for (Iterator itr = moduleProps.keySet().iterator(); itr.hasNext(); ) {
            String propName = (String) itr.next();
            Property prop = module.createChild(Property.class);
            module.getProperty().add(prop);
            prop.setName(propName);
            prop.setValue(moduleProps.getProperty(propName));
        }
    }
    for (EngineRef ref : _getEngineRefs()) {
        Engine engine = module.createChild(Engine.class);
        module.getEngines().add(engine);
        ref.save(engine);
    }
}
Also used : Iterator(java.util.Iterator) Property(org.jvnet.hk2.config.types.Property) Engine(com.sun.enterprise.config.serverbeans.Engine)

Example 78 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class CreateJACCProvider method configureProperties.

private void configureProperties(JaccProvider newJacc) throws PropertyVetoException, TransactionFailure {
    if (properties != null) {
        for (Object key : properties.keySet()) {
            Object value = properties.get(key);
            Property property = newJacc.createChild(Property.class);
            property.setName(key.toString());
            property.setValue(value.toString());
            newJacc.getProperty().add(property);
        }
    }
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 79 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class CreateMessageSecurityProvider method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are parameter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    List<MessageSecurityConfig> mscs = secService.getMessageSecurityConfig();
    // Let's find the correct MessageSecurityConfig. As of now,
    // there can be only two of them - one for SOAP and one for
    // HttpServlet
    MessageSecurityConfig msgSecCfg = null;
    for (MessageSecurityConfig msc : mscs) {
        if (msc.getAuthLayer().equals(authLayer)) {
            msgSecCfg = msc;
        }
    }
    // then, add a new provider config under it provided it is not duplicate
    if (msgSecCfg != null) {
        // check if there exists a provider config by the
        // specified provider name; if so return failure.
        List<ProviderConfig> pcs = msgSecCfg.getProviderConfig();
        for (ProviderConfig pc : pcs) {
            if (pc.getProviderId().equals(providerId)) {
                report.setMessage(localStrings.getLocalString("create.message.security.provider.duplicatefound", "Message security provider named {0} exists. " + "Cannot add duplicate.", providerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        // No duplicate message security providers found. So add one.
        try {
            ConfigSupport.apply(new SingleConfigCode<MessageSecurityConfig>() {

                public Object run(MessageSecurityConfig param) throws PropertyVetoException, TransactionFailure {
                    ProviderConfig newPC = param.createChild(ProviderConfig.class);
                    populateProviderConfigElement(newPC);
                    param.getProviderConfig().add(newPC);
                    // security config object
                    if (isDefaultProvider) {
                        if (providerType.equals(SERVER) || providerType.equals(CLIENT_SERVER))
                            param.setDefaultProvider(providerId);
                        if (providerType.equals(CLIENT) || providerType.equals(CLIENT_SERVER))
                            param.setDefaultClientProvider(providerId);
                    }
                    return newPC;
                }
            }, msgSecCfg);
        } catch (TransactionFailure e) {
            report.setMessage(localStrings.getLocalString("create.message.security.provider.fail", "Creation of message security provider named {0} failed", providerId));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        report.setMessage(localStrings.getLocalString("create.message.security.provider.success", "Creation of message security provider named {0} completed " + "successfully", providerId));
    } else // Now if there is NO message security config for this type of layer
    // then, first add a message security config for the layer and then
    // add a provider config under this message security config
    {
        try {
            ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

                public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                    MessageSecurityConfig newMSC = param.createChild(MessageSecurityConfig.class);
                    newMSC.setAuthLayer(authLayer);
                    param.getMessageSecurityConfig().add(newMSC);
                    ProviderConfig newPC = newMSC.createChild(ProviderConfig.class);
                    populateProviderConfigElement(newPC);
                    newMSC.getProviderConfig().add(newPC);
                    // security config object
                    if (isDefaultProvider) {
                        if (providerType.equals(SERVER) || providerType.equals(CLIENT_SERVER))
                            newMSC.setDefaultProvider(providerId);
                        if (providerType.equals(CLIENT) || providerType.equals(CLIENT_SERVER))
                            newMSC.setDefaultClientProvider(providerId);
                    }
                    return newMSC;
                }
            }, secService);
        } catch (TransactionFailure e) {
            report.setMessage(localStrings.getLocalString("create.message.security.provider.fail", "Creation of message security provider named {0} failed", providerId));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    /* report.setMessage(localStrings.getLocalString(
                "create.message.security.provider.success",
                "Creation of message security provider named {0} completed " +
                "successfully", providerId));  */
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ProviderConfig(com.sun.enterprise.config.serverbeans.ProviderConfig) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) MessageSecurityConfig(com.sun.enterprise.config.serverbeans.MessageSecurityConfig) ActionReport(org.glassfish.api.ActionReport)

Example 80 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class DeleteFileUser method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // Get FileRealm class name, match it with what is expected.
    String fileRealmClassName = fileAuthRealm.getClassname();
    // Report error if provided impl is not the one expected
    if (fileRealmClassName != null && !fileRealmClassName.equals("com.sun.enterprise.security.auth.realm.file.FileRealm")) {
        report.setMessage(localStrings.getLocalString("delete.file.user.realmnotsupported", "Configured file realm {0} is not supported.", fileRealmClassName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we have the file associated with the authrealm
    String keyFile = null;
    for (Property fileProp : fileAuthRealm.getProperty()) {
        if (fileProp.getName().equals("file"))
            keyFile = fileProp.getValue();
    }
    final String kFile = keyFile;
    if (keyFile == null) {
        report.setMessage(localStrings.getLocalString("delete.file.user.keyfilenotfound", "There is no physical file associated with this file realm {0} ", authRealmName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    boolean exists = (new File(kFile)).exists();
    if (!exists) {
        report.setMessage(localStrings.getLocalString("file.realm.keyfilenonexistent", "The specified physical file {0} associated with the file realm {1} does not exist.", new Object[] { kFile, authRealmName }));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // hypothetically ?.
    try {
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                try {
                    realmsManager.createRealms(config);
                    final FileRealm fr = (FileRealm) realmsManager.getFromLoadedRealms(config.getName(), authRealmName);
                    fr.removeUser(userName);
                    fr.persist();
                    CreateFileUser.refreshRealm(config.getName(), authRealmName);
                    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                } catch (NoSuchUserException e) {
                    report.setMessage(localStrings.getLocalString("delete.file.user.usernotfound", "There is no such existing user {0} in the file realm {1}.", userName, authRealmName) + "  " + e.getLocalizedMessage());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(e);
                } catch (BadRealmException e) {
                    report.setMessage(localStrings.getLocalString("delete.file.user.realmcorrupted", "Configured file realm {0} is corrupted.", authRealmName) + "  " + e.getLocalizedMessage());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(e);
                } catch (Exception e) {
                    e.printStackTrace();
                    report.setMessage(localStrings.getLocalString("delete.file.user.userdeletefailed", "Removing User {0} from file realm {1} failed", userName, authRealmName) + "  " + e.getLocalizedMessage());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(e);
                }
                return null;
            }
        }, securityService);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("delete.file.user.userdeletefailed", "Removing User {0} from file realm {1} failed", userName, authRealmName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException) ActionReport(org.glassfish.api.ActionReport) FileRealm(com.sun.enterprise.security.auth.realm.file.FileRealm) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) PropertyVetoException(java.beans.PropertyVetoException) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException) PropertyVetoException(java.beans.PropertyVetoException) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) Property(org.jvnet.hk2.config.types.Property) File(java.io.File)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)191 PropertyVetoException (java.beans.PropertyVetoException)132 ActionReport (org.glassfish.api.ActionReport)86 Property (org.jvnet.hk2.config.types.Property)61 Config (com.sun.enterprise.config.serverbeans.Config)52 HashMap (java.util.HashMap)30 Test (org.junit.Test)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 Map (java.util.Map)25 List (java.util.List)21 CommandTarget (org.glassfish.config.support.CommandTarget)21 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Target (org.glassfish.internal.api.Target)21 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)20 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 ConfigBean (org.jvnet.hk2.config.ConfigBean)20 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)18 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)16 ParameterMap (org.glassfish.api.admin.ParameterMap)14