Search in sources :

Example 61 with Property

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

the class CreateAuditModule method populateAuditModuleElement.

private void populateAuditModuleElement(AuditModule newAuditModule) throws PropertyVetoException, TransactionFailure {
    newAuditModule.setName(auditModuleName);
    newAuditModule.setClassname(className);
    if (properties != null) {
        for (Object propname : properties.keySet()) {
            Property newprop = newAuditModule.createChild(Property.class);
            newprop.setName((String) propname);
            newprop.setValue(properties.getProperty((String) propname));
            newAuditModule.getProperty().add(newprop);
        }
    }
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 62 with Property

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

the class CreateFileUser 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("create.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 kf = keyFile;
    if (keyFile == null) {
        report.setMessage(localStrings.getLocalString("create.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(kf)).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[] { kf, authRealmName }));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Now get all inputs ready. userid and groups are straightforward but
    // password is tricky. It is stored in the file passwordfile passed
    // through the CLI options. It is stored under the name
    // AS_ADMIN_USERPASSWORD. Fetch it from there.
    // fetchPassword(report);
    final String password = userpassword;
    if (password == null) {
        report.setMessage(localStrings.getLocalString("create.file.user.keyfilenotreadable", "Password for user {0} " + "has to be specified in --userpassword option or supplied " + "through AS_ADMIN_USERPASSWORD property in the file specified " + "in --passwordfile option", userName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Issue 17525 Fix - Check for null passwords for admin-realm if secureadmin is enabled
    secureAdmin = domain.getSecureAdmin();
    if ((SecureAdmin.Util.isEnabled(secureAdmin)) && (authRealmName.equals(adminService.getAuthRealmName()))) {
        if (password.isEmpty()) {
            report.setMessage(localStrings.getLocalString("null_empty_password", "The admin user password is null or empty"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // now adding user
    try {
        // even though create-file-user is not an update to the security-service
        // do we need to make it transactional by referncing the securityservice
        // hypothetically ?.
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                try {
                    realmsManager.createRealms(config);
                    // If the (shared) keyfile is updated by an external process, load the users first
                    refreshRealm(config.getName(), authRealmName);
                    final FileRealm fr = (FileRealm) realmsManager.getFromLoadedRealms(config.getName(), authRealmName);
                    CreateFileUser.handleAdminGroup(authRealmName, groups);
                    String[] groups1 = groups.toArray(new String[groups.size()]);
                    try {
                        fr.addUser(userName, password.toCharArray(), groups1);
                    } catch (BadRealmException br) {
                        if (se != null && se.isDas()) {
                            throw new BadRealmException(br);
                        }
                    }
                    fr.persist();
                    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                } catch (Exception e) {
                    String localalizedErrorMsg = (e.getLocalizedMessage() == null) ? "" : e.getLocalizedMessage();
                    report.setMessage(localStrings.getLocalString("create.file.user.useraddfailed", "Adding User {0} to the file realm {1} failed", userName, authRealmName) + "  " + localalizedErrorMsg);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(e);
                }
                return null;
            }
        }, securityService);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("create.file.user.useraddfailed", "Adding User {0} to the file realm {1} failed", userName, authRealmName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) 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) 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)

Example 63 with Property

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

the class CreateProfilerTest method testExecuteSuccess.

/**
 * Test of execute method, of class CreateProfiler.
 * asadmin create-profiler --nativelibrarypath "myNativeLibraryPath"
 *          --enabled=true --classpath "myProfilerClasspath" testProfiler
 */
@Test
public void testExecuteSuccess() {
    // Set the options and operand to pass to the command
    parameters.set("classpath", "myProfilerClasspath");
    parameters.set("enabled", "true");
    parameters.set("nativelibrarypath", "myNativeLibraryPath");
    parameters.set("property", "a=x:b=y:c=z");
    parameters.set("DEFAULT", "testProfiler");
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("create-profiler", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check that the profiler is created
    boolean isCreated = false;
    int propertyCount = 0;
    Profiler profiler = javaConfig.getProfiler();
    if (profiler.getName().equals("testProfiler")) {
        assertEquals("myProfilerClasspath", profiler.getClasspath());
        assertEquals("true", profiler.getEnabled());
        assertEquals("myNativeLibraryPath", profiler.getNativeLibraryPath());
        List<Property> properties = profiler.getProperty();
        for (Property property : properties) {
            if (property.getName().equals("a"))
                assertEquals("x", property.getValue());
            if (property.getName().equals("b"))
                assertEquals("y", property.getValue());
            if (property.getName().equals("c"))
                assertEquals("z", property.getValue());
            propertyCount++;
        }
        isCreated = true;
        logger.fine("Profiler element myProfiler is created.");
    }
    assertTrue(isCreated);
    assertEquals(propertyCount, 3);
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
    // Check the success message
    // assertEquals("Command create-profiler executed successfully.", context.getActionReport().getMessage());
    logger.fine("msg: " + context.getActionReport().getMessage());
}
Also used : Profiler(com.sun.enterprise.config.serverbeans.Profiler) Property(org.jvnet.hk2.config.types.Property) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 64 with Property

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

the class LogManagerService method generateAttributeChangeEvent.

public void generateAttributeChangeEvent(String property, String propertyDetail, Map props) {
    PropertyChangeEvent pce = new PropertyChangeEvent(this, property, propertyDetail, props.get(property));
    UnprocessedChangeEvents ucel = new UnprocessedChangeEvents(new UnprocessedChangeEvent(pce, "server log file attribute " + property + " changed."));
    List<UnprocessedChangeEvents> b = new ArrayList();
    b.add(ucel);
    ucl.unprocessedTransactedEvents(b);
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent)

Example 65 with Property

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

the class ConfigConfigSource method setValue.

public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
    boolean success = false;
    Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
    if (config != null) {
        Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
        if (p == null) {
            ConfigSupport.apply(new SingleConfigCode<Config>() {

                @Override
                public Object run(Config config) throws TransactionFailure, PropertyVetoException {
                    Property prop = config.createChild(Property.class);
                    prop.setName(PROPERTY_PREFIX + propertyName);
                    prop.setValue(propertyValue);
                    config.getProperty().add(prop);
                    return null;
                }
            }, config);
        } else {
            ConfigSupport.apply(new SingleConfigCode<Property>() {

                @Override
                public Object run(Property config) throws TransactionFailure, PropertyVetoException {
                    config.setValue(propertyValue);
                    return null;
                }
            }, p);
        }
        success = true;
    }
    return success;
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) Config(com.sun.enterprise.config.serverbeans.Config) Property(org.jvnet.hk2.config.types.Property)

Aggregations

Property (org.jvnet.hk2.config.types.Property)149 PropertyVetoException (java.beans.PropertyVetoException)30 HashMap (java.util.HashMap)27 Properties (java.util.Properties)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 ArrayList (java.util.ArrayList)18 ActionReport (org.glassfish.api.ActionReport)17 Map (java.util.Map)15 File (java.io.File)13 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)12 Config (com.sun.enterprise.config.serverbeans.Config)11 List (java.util.List)11 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)10 HttpService (com.sun.enterprise.config.serverbeans.HttpService)9 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)9 Server (com.sun.enterprise.config.serverbeans.Server)8 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 Application (com.sun.enterprise.config.serverbeans.Application)7 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)7