62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste/*
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * The contents of this file are subject to the terms of the Common Development and
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Distribution License (the License). You may not use this file except in compliance with the
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * License.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * specific language governing permission and limitations under the License.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * When distributing Covered Software, include this CDDL Header Notice in each file and include
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Header, with the fields enclosed by brackets [] replaced by your own identifying
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * information: "Portions copyright [year] [name of copyright owner]".
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Copyright 2015 ForgeRock AS.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joostepackage com.sun.identity.console.audit.model;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport static com.sun.identity.console.audit.AuditConsoleConstants.AUDIT_SERVICE;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Joosteimport static java.util.Arrays.asList;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport static java.util.Collections.*;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Joosteimport static org.forgerock.openam.utils.StringUtils.isNotEmpty;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.iplanet.sso.SSOException;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.base.model.AMAdminUtils;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.base.model.AMConsoleException;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.base.model.AMResBundleCacher;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.base.model.AMServiceProfileModelImpl;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.base.model.SMSubConfig;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.base.model.SMSubConfigComparator;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.delegation.model.DelegationConfig;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.console.property.PropertyXMLBuilder;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.shared.locale.Locale;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.sm.AttributeSchema;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.sm.SMSException;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Joosteimport com.sun.identity.sm.SchemaType;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.sm.ServiceConfig;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport com.sun.identity.sm.ServiceSchema;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport javax.servlet.http.HttpServletRequest;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.text.Collator;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.util.ArrayList;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Joosteimport java.util.Collections;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Joosteimport java.util.Enumeration;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.util.HashMap;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.util.HashSet;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Joosteimport java.util.LinkedHashSet;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.util.List;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.util.Map;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.util.ResourceBundle;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport java.util.Set;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste/**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Abstract Audit configuration UI model.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @since 13.0.0
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joostepublic abstract class AbstractAuditModel extends AMServiceProfileModelImpl {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste private static final String AUDIT_BUNDLE_NAME = "audit";
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste private static final String SECTION_FILE_NAME_SUFFIX = ".section.properties";
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste protected ResourceBundle handlerResourceBundle;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Create a new {@code AbstractAuditModel}.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param request The {@code HttpServletRequest}
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param sessionAttributes The session attributes.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If construction fails.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public AbstractAuditModel(HttpServletRequest request, Map sessionAttributes) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste super(request, AUDIT_SERVICE, sessionAttributes);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * The service schema for the configuration represented by this model.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return The service schema.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws SMSException If an SMS error occurred.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws SSOException If an SSO error occurred.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste protected abstract ServiceSchema getServiceSchema() throws SMSException, SSOException;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * The service config for the configuration represented by this model.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return The service config.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws SMSException If an SMS error occurred.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws SSOException If an SSO error occurred.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste protected abstract ServiceConfig getServiceConfig() throws SMSException, SSOException;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste @Override
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste protected void initialize(HttpServletRequest req, String rbName) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste super.initialize(req, rbName);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste handlerResourceBundle = AMResBundleCacher.getBundle(AUDIT_BUNDLE_NAME, locale);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste @Override
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public String getLocalizedString(String key) {
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste if (handlerResourceBundle.containsKey(key)) {
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste return Locale.getString(handlerResourceBundle, key, debug);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } else {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return super.getLocalizedString(key);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste @Override
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public String getPropertySheetXML(String realmName, String viewBeanName, String viewBeanClassName) throws
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste DelegationConfig dc = DelegationConfig.getInstance();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste boolean readOnly = !dc.hasPermission(realmName, serviceName, PERMISSION_MODIFY, this, viewBeanClassName);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste xmlBuilder.setAllAttributeReadOnly(readOnly);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste xmlBuilder.setSupportSubConfig(true);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste xmlBuilder.setViewBeanName(viewBeanName);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return xmlBuilder.getXML();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the JATO XML configuration for generation the UI used to edit event handlers.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param realmName The current realm.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param handlerName The audit event handler name.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param viewBeanClassName The view bean class name.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return The JATO XML configuration for generation the UI.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If an error occurs during the XML creation.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public String getEditEventHandlerPropertyXML(String realmName, String handlerName, String viewBeanClassName)
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste DelegationConfig dc = DelegationConfig.getInstance();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste boolean readOnly = !dc.hasPermission(realmName, serviceName, PERMISSION_MODIFY, this, viewBeanClassName);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste String schemaId = getServiceConfig().getSubConfig(handlerName).getSchemaID();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(schemaId);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste updateHandlerResourceBundle(handlerSchema);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste xmlBuilder = new PropertyXMLBuilder(handlerSchema, this, handlerResourceBundle,
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste getSectionsForHandler(schemaId), schemaId + SECTION_FILE_NAME_SUFFIX);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste xmlBuilder.setAllAttributeReadOnly(readOnly);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste xmlBuilder.setSupportSubConfig(false);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return xmlBuilder.getXML();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SMSException | SSOException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the JATO XML configuration for generation the UI used to add event handlers.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param schemaId The event handler schema ID.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return The JATO XML configuration for generation the UI.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If an error occurs during the XML creation.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public String getAddEventHandlerPropertyXML(String schemaId) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(schemaId);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste updateHandlerResourceBundle(handlerSchema);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste xmlBuilder = new PropertyXMLBuilder(handlerSchema, this, handlerResourceBundle,
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste getSectionsForHandler(schemaId), schemaId + SECTION_FILE_NAME_SUFFIX);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste xmlBuilder.setSupportSubConfig(false);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste String xml = xmlBuilder.getXML();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste String attributeNameXML = AMAdminUtils.getStringFromInputStream(getClass().getClassLoader()
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste .getResourceAsStream("com/sun/identity/console/propertyAuditEventHandlerName.xml"));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return PropertyXMLBuilder.prependXMLProperty(xml, attributeNameXML);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SMSException | SSOException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the configuration properties of all the audit event handlers.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return A list of config objects.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public List<SMSubConfig> getEventHandlerConfigurations() throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste List<SMSubConfig> subConfigModelList = new ArrayList<>();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (serviceConfig == null) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return subConfigModelList;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set<String> auditHandlerNames = serviceConfig.getSubConfigNames();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste for (String name : auditHandlerNames) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig conf = serviceConfig.getSubConfig(name);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste subConfigModelList.add(new SMSubConfig(conf.getComponentName(), name, conf.getSchemaID()));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste sort(subConfigModelList, new SMSubConfigComparator(Collator.getInstance(getUserLocale())));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SMSException | SSOException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return subConfigModelList;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the type names (schema ID) for all the event handlers.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return A set of event handler type names.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste @SuppressWarnings("unchecked")
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public Set<String> getEventHandlerTypeNames() throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return getServiceSchema().getSubSchemaNames();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SMSException | SSOException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Delete the event handlers specified.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param names Set of event handler names that are to be deleted.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException if sub configurations cannot be deleted.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public void deleteEventHandles(Set<String> names) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (serviceConfig != null) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste for (String name : names) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste serviceConfig.removeSubConfig(name);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste @Override
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public void setAttributeValues(Map map) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (serviceConfig == null) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste serviceConfig.setAttributes(map);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste @Override
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public Map getAttributeValues() {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (serviceConfig == null) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return emptyMap();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return serviceConfig.getAttributes();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste debug.error("AbstractAuditModel.getAttributeValues", e);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return emptyMap();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the attribute values for the specified event handler.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param eventHandlerName The name of the event handler.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return A map of event handler attribute values.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If an error occurs whilst reading the attributes.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public Map<?, ?> getEventHandlerAttributeValues(String eventHandlerName) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (serviceConfig == null) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return emptyMap();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set<String> subConfigNames = serviceConfig.getSubConfigNames();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (!subConfigNames.contains(eventHandlerName)) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return emptyMap();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return serviceConfig.getSubConfig(eventHandlerName).getAttributes();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Set the attribute values for the specified event handler.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param eventHandlerName The name of the event handler.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param values The attribute values.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If an error occurs whilst writing the attributes.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public void setEventHandlerAttributeValues(String eventHandlerName, Map<?, ?> values) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (serviceConfig == null) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set<String> subConfigNames = serviceConfig.getSubConfigNames();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (!subConfigNames.contains(eventHandlerName)) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste serviceConfig.getSubConfig(eventHandlerName).setAttributes(values);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the default attribute values for the specified event handler type (schema ID).
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param eventHandlerType The name of the event handler type.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return A map of default event handler attribute values.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If an error occurs whilst reading the attributes.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public Map<String, Set<?>> getEventHandlerDefaultValues(String eventHandlerType) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Map<String, Set<?>> defaultValues = new HashMap<>();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(eventHandlerType);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set attributeSchemas = handlerSchema.getAttributeSchemas();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste for (Object value : attributeSchemas) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste AttributeSchema as = (AttributeSchema) value;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set values = as.getDefaultValues();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (values != null) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste defaultValues.put(as.getName(), values);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return defaultValues;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the attribute names for the specified event handler type (schema ID).
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param eventHandlerType The name of the event handler type.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return A set of attribute type names.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If an error occurs whilst reading the attributes.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public Set<String> getEventHandlerAttributeNames(String eventHandlerType) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(eventHandlerType);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set attributeSchemas = handlerSchema.getAttributeSchemas();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set<String> attrNames = new HashSet<>();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste for (Object as : attributeSchemas) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste attrNames.add(((AttributeSchema) as).getName());
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return attrNames;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste /**
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Create a new event handler with the given attributes.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste *
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param eventHandlerName The name of the new event handler.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param eventHandlerType The name of the event handler type.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param attributeValues The attribute values.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If an error occurs whilst creating the event handler.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste */
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public void createEventHandler(String eventHandlerName, String eventHandlerType,
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Map<String, Set<String>> attributeValues) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste try {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste getServiceConfig().addSubConfig(eventHandlerName, eventHandlerType, 0, attributeValues);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste } catch (SSOException | SMSException e) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste }
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste private void updateHandlerResourceBundle(ServiceSchema handlerSchema) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste String handlerBundleName = handlerSchema.getI18NFileName();
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste if (isNotEmpty(handlerBundleName) && !AUDIT_BUNDLE_NAME.equals(handlerBundleName)) {
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste handlerResourceBundle = new MultiResourceBundle(locale, handlerBundleName, AUDIT_BUNDLE_NAME);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste private Map<SchemaType, List<String>> getSectionsForHandler(String schemaId) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste Map<SchemaType, List<String>> sectionMap = new HashMap<>();
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste String sections = getLocalizedString("sections." + schemaId);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste if (isNotEmpty(sections)) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste List<String> sectionList = asList(sections.split(" "));
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste sectionMap.put(SchemaType.GLOBAL, sectionList);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste sectionMap.put(SchemaType.ORGANIZATION, sectionList);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste return sectionMap;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste private static final class MultiResourceBundle extends ResourceBundle {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste private Set<ResourceBundle> resourceBundles = new LinkedHashSet<>();
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste private MultiResourceBundle(java.util.Locale locale, String... rbNames) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste for (String rbName : rbNames) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste ResourceBundle rb = AMResBundleCacher.getBundle(rbName, locale);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste if (rb != null) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste resourceBundles.add(rb);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste @Override
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste protected Object handleGetObject(String key) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste for (ResourceBundle rb : resourceBundles) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste if (rb.containsKey(key)) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste return rb.getObject(key);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste return null;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste @Override
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste public Enumeration<String> getKeys() {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste List<String> keys = new ArrayList<>();
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste for (ResourceBundle rb : resourceBundles) {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste keys.addAll(Collections.list(rb.getKeys()));
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste return Collections.enumeration(keys);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste }
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste}