Search in sources :

Example 11 with SecurityService

use of com.sun.enterprise.config.serverbeans.SecurityService in project Payara by payara.

the class ChangeAdminPassword method preAuthorization.

@Override
public boolean preAuthorization(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // Issue 17513 Fix - Check for null passwords if secureadmin is enabled
    secureAdmin = domain.getSecureAdmin();
    if (SecureAdmin.Util.isEnabled(secureAdmin)) {
        if ((newpassword == null) || (newpassword.isEmpty())) {
            report.setMessage(localStrings.getLocalString("null_empty_password", "The new password is null or empty"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return false;
        }
    }
    final List<Config> configList = configs.getConfig();
    config = configList.get(0);
    SecurityService securityService = config.getSecurityService();
    fileAuthRealm = null;
    for (AuthRealm authRealm : securityService.getAuthRealm()) {
        if (authRealm.getName().equals(adminService.getAuthRealmName())) {
            fileAuthRealm = authRealm;
            break;
        }
    }
    if (fileAuthRealm == null) {
        report.setMessage(localStrings.getLocalString("change.admin.password.adminrealmnotfound", "Server " + "Error: There is no admin realm to perform this operation"));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return false;
    }
    return true;
}
Also used : AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) Config(com.sun.enterprise.config.serverbeans.Config) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) ActionReport(org.glassfish.api.ActionReport)

Example 12 with SecurityService

use of com.sun.enterprise.config.serverbeans.SecurityService in project Payara by payara.

the class CreateAuditModule method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // check if there exists an audit module by the specified name
    // if so return failure.
    List<AuditModule> ams = securityService.getAuditModule();
    for (AuditModule am : ams) {
        if (am.getName().equals(auditModuleName)) {
            report.setMessage(localStrings.getLocalString("create.audit.module.duplicatefound", "AuditModule named {0} exists. " + "Cannot add duplicate AuditModule.", auditModuleName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // No duplicate audit modules found. So add one.
    try {
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                AuditModule newAuditModule = param.createChild(AuditModule.class);
                populateAuditModuleElement(newAuditModule);
                param.getAuditModule().add(newAuditModule);
                return newAuditModule;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("create.audit.module.fail", "Creation of AuditModule {0} failed", auditModuleName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
// report.setMessage(localStrings.getLocalString("create.audit.module.success",
// "Creation of AuditModule {0} completed successfully", auditModuleName));
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) AuditModule(com.sun.enterprise.config.serverbeans.AuditModule) ActionReport(org.glassfish.api.ActionReport)

Example 13 with SecurityService

use of com.sun.enterprise.config.serverbeans.SecurityService in project Payara by payara.

the class CreateAuthRealm 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();
    // No duplicate auth realms found. So add one.
    try {
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                AuthRealm newAuthRealm = param.createChild(AuthRealm.class);
                populateAuthRealmElement(newAuthRealm);
                param.getAuthRealm().add(newAuthRealm);
                // In case of cluster instances, this is required to
                // avoid issues with the listener's callback method
                SecurityConfigListener.authRealmCreated(config, newAuthRealm);
                return newAuthRealm;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("create.auth.realm.fail", "Creation of Authrealm {0} failed", authRealmName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AuthRealm(com.sun.enterprise.config.serverbeans.AuthRealm) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) ActionReport(org.glassfish.api.ActionReport)

Example 14 with SecurityService

use of com.sun.enterprise.config.serverbeans.SecurityService in project Payara by payara.

the class CreateJACCProvider method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    // No duplicate auth realms found. So add one.
    try {
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                JaccProvider newJacc = param.createChild(JaccProvider.class);
                newJacc.setName(jaccProviderName);
                newJacc.setPolicyConfigurationFactoryProvider(polConfFactoryClass);
                newJacc.setPolicyProvider(polProviderClass);
                configureProperties(newJacc);
                param.getJaccProvider().add(newJacc);
                return newJacc;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("create.auth.realm.fail", "Creation of Authrealm {0} failed", jaccProviderName) + "  " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JaccProvider(com.sun.enterprise.config.serverbeans.JaccProvider) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) ActionReport(org.glassfish.api.ActionReport)

Aggregations

SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)14 ActionReport (org.glassfish.api.ActionReport)10 PropertyVetoException (java.beans.PropertyVetoException)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 Property (org.jvnet.hk2.config.types.Property)4 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)3 AuditModule (com.sun.enterprise.config.serverbeans.AuditModule)2 Config (com.sun.enterprise.config.serverbeans.Config)2 JaccProvider (com.sun.enterprise.config.serverbeans.JaccProvider)2 BadRealmException (com.sun.enterprise.security.auth.realm.BadRealmException)2 FileRealm (com.sun.enterprise.security.auth.realm.file.FileRealm)2 File (java.io.File)2 MessageSecurityConfig (com.sun.enterprise.config.serverbeans.MessageSecurityConfig)1 ProviderConfig (com.sun.enterprise.config.serverbeans.ProviderConfig)1 BaseAuditModule (com.sun.enterprise.security.BaseAuditModule)1 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)1 String (java.lang.String)1 Properties (java.util.Properties)1 NamingException (javax.naming.NamingException)1 DigestAuthenticator (org.apache.catalina.authenticator.DigestAuthenticator)1