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 * 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 * 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 * Copyright 2015 ForgeRock AS.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joosteimport static com.sun.identity.console.audit.AuditConsoleConstants.AUDIT_SERVICE;
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Joosteimport static org.forgerock.openam.utils.StringUtils.isNotEmpty;
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 Jooste * Abstract Audit configuration UI model.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @since 13.0.0
62639ee1329be2d687701dfa01fc006314440bf7Jaco Joostepublic abstract class AbstractAuditModel extends AMServiceProfileModelImpl {
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste private static final String AUDIT_BUNDLE_NAME = "audit";
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste private static final String SECTION_FILE_NAME_SUFFIX = ".section.properties";
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Create a new {@code AbstractAuditModel}.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param request The {@code HttpServletRequest}
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @param sessionAttributes The session attributes.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @throws AMConsoleException If construction fails.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public AbstractAuditModel(HttpServletRequest request, Map sessionAttributes) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste super(request, AUDIT_SERVICE, sessionAttributes);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * The service schema for the configuration represented by this model.
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 protected abstract ServiceSchema getServiceSchema() throws SMSException, SSOException;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * The service config for the configuration represented by this model.
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 protected abstract ServiceConfig getServiceConfig() throws SMSException, SSOException;
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste protected void initialize(HttpServletRequest req, String rbName) {
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste handlerResourceBundle = AMResBundleCacher.getBundle(AUDIT_BUNDLE_NAME, locale);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste return Locale.getString(handlerResourceBundle, key, debug);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public String getPropertySheetXML(String realmName, String viewBeanName, String viewBeanClassName) throws
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste DelegationConfig dc = DelegationConfig.getInstance();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste boolean readOnly = !dc.hasPermission(realmName, serviceName, PERMISSION_MODIFY, this, viewBeanClassName);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the JATO XML configuration for generation the UI used to edit event handlers.
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 public String getEditEventHandlerPropertyXML(String realmName, String handlerName, String viewBeanClassName)
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste DelegationConfig dc = DelegationConfig.getInstance();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste boolean readOnly = !dc.hasPermission(realmName, serviceName, PERMISSION_MODIFY, this, viewBeanClassName);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste String schemaId = getServiceConfig().getSubConfig(handlerName).getSchemaID();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(schemaId);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste xmlBuilder = new PropertyXMLBuilder(handlerSchema, this, handlerResourceBundle,
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste getSectionsForHandler(schemaId), schemaId + SECTION_FILE_NAME_SUFFIX);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the JATO XML configuration for generation the UI used to add event handlers.
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 public String getAddEventHandlerPropertyXML(String schemaId) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(schemaId);
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste xmlBuilder = new PropertyXMLBuilder(handlerSchema, this, handlerResourceBundle,
11ddc496a78229c9c3e6f48a12f743e2d16d5180Jaco Jooste getSectionsForHandler(schemaId), schemaId + SECTION_FILE_NAME_SUFFIX);
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 throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the configuration properties of all the audit event handlers.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return A list of config objects.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public List<SMSubConfig> getEventHandlerConfigurations() throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste List<SMSubConfig> subConfigModelList = new ArrayList<>();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set<String> auditHandlerNames = serviceConfig.getSubConfigNames();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig conf = serviceConfig.getSubConfig(name);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste subConfigModelList.add(new SMSubConfig(conf.getComponentName(), name, conf.getSchemaID()));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste sort(subConfigModelList, new SMSubConfigComparator(Collator.getInstance(getUserLocale())));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the type names (schema ID) for all the event handlers.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * @return A set of event handler type names.
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public Set<String> getEventHandlerTypeNames() throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Delete the event handlers specified.
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 public void deleteEventHandles(Set<String> names) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste public void setAttributeValues(Map map) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste debug.error("AbstractAuditModel.getAttributeValues", e);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the attribute values for the specified event handler.
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 public Map<?, ?> getEventHandlerAttributeValues(String eventHandlerName) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set<String> subConfigNames = serviceConfig.getSubConfigNames();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (!subConfigNames.contains(eventHandlerName)) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste return serviceConfig.getSubConfig(eventHandlerName).getAttributes();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Set the attribute values for the specified event handler.
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 public void setEventHandlerAttributeValues(String eventHandlerName, Map<?, ?> values) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceConfig serviceConfig = getServiceConfig();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set<String> subConfigNames = serviceConfig.getSubConfigNames();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste if (!subConfigNames.contains(eventHandlerName)) {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste serviceConfig.getSubConfig(eventHandlerName).setAttributes(values);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the default attribute values for the specified event handler type (schema ID).
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 public Map<String, Set<?>> getEventHandlerDefaultValues(String eventHandlerType) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Map<String, Set<?>> defaultValues = new HashMap<>();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(eventHandlerType);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set attributeSchemas = handlerSchema.getAttributeSchemas();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Get the attribute names for the specified event handler type (schema ID).
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 public Set<String> getEventHandlerAttributeNames(String eventHandlerType) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste ServiceSchema handlerSchema = getServiceSchema().getSubSchema(eventHandlerType);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Set attributeSchemas = handlerSchema.getAttributeSchemas();
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste attrNames.add(((AttributeSchema) as).getName());
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste * Create a new event handler with the given attributes.
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 public void createEventHandler(String eventHandlerName, String eventHandlerType,
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste Map<String, Set<String>> attributeValues) throws AMConsoleException {
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste getServiceConfig().addSubConfig(eventHandlerName, eventHandlerType, 0, attributeValues);
62639ee1329be2d687701dfa01fc006314440bf7Jaco Jooste throw new AMConsoleException(getErrorString(e));
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 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 List<String> sectionList = asList(sections.split(" "));
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste sectionMap.put(SchemaType.ORGANIZATION, sectionList);
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste private static final class MultiResourceBundle extends ResourceBundle {
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste private Set<ResourceBundle> resourceBundles = new LinkedHashSet<>();
c423fd5d4f121413c5e72c134412b6ce5daa0dd9Jaco Jooste private MultiResourceBundle(java.util.Locale locale, String... rbNames) {