Search in sources :

Example 81 with TransactionFailure

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

the class DeleteMessageSecurityProvider 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) {
    ActionReport report = context.getActionReport();
    List<ProviderConfig> pcs = msgSecCfg.getProviderConfig();
    for (ProviderConfig pc : pcs) {
        if (pc.getProviderId().equals(providerId)) {
            thePC = pc;
            try {
                ConfigSupport.apply(new SingleConfigCode<MessageSecurityConfig>() {

                    public Object run(MessageSecurityConfig param) throws PropertyVetoException, TransactionFailure {
                        if ((param.getDefaultProvider() != null) && param.getDefaultProvider().equals(thePC.getProviderId())) {
                            param.setDefaultProvider(null);
                        }
                        if ((param.getDefaultClientProvider() != null) && param.getDefaultClientProvider().equals(thePC.getProviderId())) {
                            param.setDefaultClientProvider(null);
                        }
                        param.getProviderConfig().remove(thePC);
                        return null;
                    }
                }, msgSecCfg);
            } catch (TransactionFailure e) {
                e.printStackTrace();
                report.setMessage(localStrings.getLocalString("delete.message.security.provider.fail", "Deletion of message security provider named {0} failed", providerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                report.setFailureCause(e);
                return;
            }
            /*report.setMessage(localStrings.getLocalString(
                    "delete.message.security.provider.success", 
                    "Deletion of message security provider {0} completed " +
                    "successfully", providerId));*/
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
            return;
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ProviderConfig(com.sun.enterprise.config.serverbeans.ProviderConfig) MessageSecurityConfig(com.sun.enterprise.config.serverbeans.MessageSecurityConfig) ActionReport(org.glassfish.api.ActionReport)

Example 82 with TransactionFailure

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

the class DeleteAuthRealm 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) {
    ActionReport report = context.getActionReport();
    try {
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                param.getAuthRealm().remove(authRealm);
                // temporary fix - since the SecurityConfigListener is  not being called on an realm delete.
                SecurityConfigListener.authRealmDeleted(authRealm);
                return null;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("delete.auth.realm.fail", "Deletion 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) SecurityService(com.sun.enterprise.config.serverbeans.SecurityService) ActionReport(org.glassfish.api.ActionReport)

Example 83 with TransactionFailure

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

the class DeleteJaccProvider method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        List<JaccProvider> jaccProviders = securityService.getJaccProvider();
        JaccProvider jprov = null;
        for (JaccProvider jaccProv : jaccProviders) {
            if (jaccProv.getName().equals(jaccprovider)) {
                jprov = jaccProv;
                break;
            }
        }
        final JaccProvider jaccprov = jprov;
        ConfigSupport.apply(new SingleConfigCode<SecurityService>() {

            public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure {
                param.getJaccProvider().remove(jaccprov);
                return null;
            }
        }, securityService);
    } catch (TransactionFailure e) {
        report.setMessage(localStrings.getLocalString("delete.jacc.provider.fail", "Deletion of JaccProvider {0} failed", jaccprovider) + "  " + 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)

Example 84 with TransactionFailure

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

the class LDAPAdminAccessConfigurator method createLDAPRealm.

// this had been called renameRealm, but in the SecurityConfigListener, the method authRealmUpdated actually does a create...
/*    private void createBackupRealm(final StringBuilder sb, AuthRealm realm, final String to) throws PropertyVetoException, TransactionFailure {
        SingleConfigCode<AuthRealm> scc = new SingleConfigCode<AuthRealm>() {
            @Override
            public Object run(AuthRealm realm) throws PropertyVetoException, TransactionFailure {
                appendNL(sb, lsm.getString("config.to.ldap", FIXED_ADMIN_REALM_NAME, to));
                realm.setName(to);
                return realm;
            }
        };
        ConfigSupport.apply(scc, realm);
    }*/
private AuthRealm createLDAPRealm(SecurityService ss) throws TransactionFailure, PropertyVetoException {
    AuthRealm ar = ss.createChild(AuthRealm.class);
    ar.setClassname(LDAPRealm.class.getName());
    ar.setName(FIXED_ADMIN_REALM_NAME);
    List<Property> props = ar.getProperty();
    Property p = ar.createChild(Property.class);
    p.setName(DIR_P);
    p.setValue(url);
    props.add(p);
    p = ar.createChild(Property.class);
    p.setName(BASEDN_P);
    p.setValue(basedn);
    props.add(p);
    p = ar.createChild(Property.class);
    p.setName(JAAS_P);
    p.setValue(JAAS_V);
    props.add(p);
    if (ldapGroupName != null) {
        p = ar.createChild(Property.class);
        p.setName(Realm.PARAM_GROUP_MAPPING);
        // appears as gfdomain1->asadmin in domain.xml
        p.setValue(ldapGroupName + "->asadmin");
        props.add(p);
    }
    return ar;
}
Also used : LDAPRealm(com.sun.enterprise.security.auth.realm.ldap.LDAPRealm) Property(org.jvnet.hk2.config.types.Property)

Example 85 with TransactionFailure

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

the class LDAPAdminAccessConfigurator method updateSecurityProvider.

/*    private String getNewRealmName(SecurityService ss) {
        List<AuthRealm> realms = ss.getAuthRealm();
        String pref = ORIG_ADMIN_REALM_NAME + "-";
        int index = 0;  //last one
        for (AuthRealm realm : realms) {
            if (realm.getName().indexOf(pref) >= 0) {
                index = Integer.parseInt(realm.getName().substring(pref.length()));
            }
        }
        return pref + (index+1);
    }*/
private void updateSecurityProvider(final Transaction t, final SecurityProvider w_sp, final StringBuilder sb) throws TransactionFailure, PropertyVetoException {
    for (SecurityProviderConfig spc : w_sp.getSecurityProviderConfig()) {
        if ((spc instanceof LoginModuleConfig) && spc.getName().equals(ADMIN_FILE_LM_NAME)) {
            final LoginModuleConfig w_lmConfig = t.enroll((LoginModuleConfig) spc);
            w_lmConfig.setModuleClass(LDAPLoginModule.class.getName());
            sb.append(lsm.getString("ldap.authProviderConfigOK", w_sp.getName()));
            return;
        }
    }
    throw new TransactionFailure(lsm.getString("ldap.noAuthProviderConfig", w_sp.getName(), ADMIN_FILE_LM_NAME));
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) LoginModuleConfig(org.glassfish.security.services.config.LoginModuleConfig) LDAPLoginModule(com.sun.enterprise.security.auth.login.LDAPLoginModule) SecurityProviderConfig(org.glassfish.security.services.config.SecurityProviderConfig)

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