diff --git a/services/src/main/java/org/exoplatform/mfa/notifications/plugin/MfaAdminRevocationRequestPlugin.java b/services/src/main/java/org/exoplatform/mfa/notifications/plugin/MfaAdminRevocationRequestPlugin.java index 8e7a1235..fd7508a2 100644 --- a/services/src/main/java/org/exoplatform/mfa/notifications/plugin/MfaAdminRevocationRequestPlugin.java +++ b/services/src/main/java/org/exoplatform/mfa/notifications/plugin/MfaAdminRevocationRequestPlugin.java @@ -33,6 +33,10 @@ import org.exoplatform.services.log.Log; import org.exoplatform.services.organization.OrganizationService; import org.exoplatform.services.organization.User; +import org.exoplatform.social.core.identity.model.Identity; +import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider; +import org.exoplatform.social.notification.LinkProviderUtils; +import org.exoplatform.social.notification.Utils; public class MfaAdminRevocationRequestPlugin extends BaseNotificationPlugin { @@ -58,11 +62,19 @@ public String getId() { @Override public NotificationInfo makeNotification(NotificationContext ctx) { String userId = ctx.value(MfaNotificationUtils.MFA_REVOCATION_REQUEST_REQUESTER); + Identity identity = + Utils.getIdentityManager().getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId); try { + List recipients = getRecipients(); + + recipients.remove(userId); return NotificationInfo.instance().key(getId()) .with("username", userId) + .with("fullname", identity.getProfile().getFullName()) + .with("avatar", LinkProviderUtils.getUserAvatarUrl(identity.getProfile())) + .with("url", MfaNotificationUtils.getMfaAdminURL()) .to(recipients); } catch (Exception e) { ctx.setException(e); diff --git a/services/src/main/java/org/exoplatform/mfa/notifications/provider/PushTemplateProvider.java b/services/src/main/java/org/exoplatform/mfa/notifications/provider/PushTemplateProvider.java index bc78aeed..afaf63d3 100644 --- a/services/src/main/java/org/exoplatform/mfa/notifications/provider/PushTemplateProvider.java +++ b/services/src/main/java/org/exoplatform/mfa/notifications/provider/PushTemplateProvider.java @@ -20,36 +20,45 @@ import org.exoplatform.commons.api.notification.annotation.TemplateConfig; import org.exoplatform.commons.api.notification.annotation.TemplateConfigs; import org.exoplatform.commons.api.notification.channel.template.AbstractTemplateBuilder; +import org.exoplatform.commons.api.notification.channel.template.TemplateProvider; import org.exoplatform.commons.api.notification.model.MessageInfo; +import org.exoplatform.commons.api.notification.model.NotificationInfo; import org.exoplatform.commons.api.notification.model.PluginKey; +import org.exoplatform.commons.api.notification.service.template.TemplateContext; import org.exoplatform.container.xml.InitParams; import org.exoplatform.mfa.notifications.plugin.MfaAdminRevocationRequestPlugin; import org.exoplatform.mfa.notifications.utils.MfaNotificationUtils; +import org.exoplatform.social.core.identity.model.Identity; +import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider; +import org.exoplatform.social.notification.Utils; import java.io.Writer; -import java.util.HashMap; -import java.util.Map; @TemplateConfigs(templates = { @TemplateConfig(pluginId = MfaAdminRevocationRequestPlugin.ID, template = "war:/notifications/templates/push/MfaAdminRevocationRequestPlugin.gtmpl") }) -public class PushTemplateProvider extends WebTemplateProvider { - - private final Map webTemplateBuilders = new HashMap<>(); +public class PushTemplateProvider extends TemplateProvider { public PushTemplateProvider(InitParams initParams) { super(initParams); - this.webTemplateBuilders.putAll(this.templateBuilders); - this.templateBuilders.put(PluginKey.key(MfaAdminRevocationRequestPlugin.ID), mfaRevocationRequest); + this.templateBuilders.put(PluginKey.key(MfaAdminRevocationRequestPlugin.ID), new TemplateBuilder()); } /** Defines the template builder for MfaRevocationRequestPlugin*/ - private AbstractTemplateBuilder mfaRevocationRequest = new AbstractTemplateBuilder() { - + private class TemplateBuilder extends AbstractTemplateBuilder { @Override protected MessageInfo makeMessage(NotificationContext ctx) { - MessageInfo messageInfo = webTemplateBuilders.get(new PluginKey(MfaAdminRevocationRequestPlugin.ID)).buildMessage(ctx); + NotificationInfo notification = ctx.getNotificationInfo(); + String language = getLanguage(notification); + TemplateContext + templateContext = TemplateContext.newChannelInstance(getChannelKey(), notification.getKey().getId(), language); + Identity identity = + Utils.getIdentityManager().getOrCreateIdentity(OrganizationIdentityProvider.NAME, notification.getValueOwnerParameter( + "username")); + templateContext.put("USER", Utils.addExternalFlag(identity)); + ctx.setException(templateContext.getException()); + MessageInfo messageInfo = new MessageInfo(); return messageInfo.subject(MfaNotificationUtils.getMfaAdminURL()).end(); } @@ -57,5 +66,5 @@ protected MessageInfo makeMessage(NotificationContext ctx) { protected boolean makeDigest(NotificationContext ctx, Writer writer) { return false; } - }; + } } diff --git a/services/src/main/java/org/exoplatform/mfa/notifications/provider/WebTemplateProvider.java b/services/src/main/java/org/exoplatform/mfa/notifications/provider/WebTemplateProvider.java deleted file mode 100644 index 7618c846..00000000 --- a/services/src/main/java/org/exoplatform/mfa/notifications/provider/WebTemplateProvider.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2003-2014 eXo Platform SAS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.exoplatform.mfa.notifications.provider; - -import java.io.Writer; -import java.util.Calendar; -import java.util.Locale; - - -import org.exoplatform.commons.api.notification.NotificationContext; -import org.exoplatform.commons.api.notification.NotificationMessageUtils; -import org.exoplatform.commons.api.notification.annotation.TemplateConfig; -import org.exoplatform.commons.api.notification.annotation.TemplateConfigs; -import org.exoplatform.commons.api.notification.channel.template.AbstractTemplateBuilder; -import org.exoplatform.commons.api.notification.channel.template.TemplateProvider; -import org.exoplatform.commons.api.notification.model.MessageInfo; -import org.exoplatform.commons.api.notification.model.NotificationInfo; -import org.exoplatform.commons.api.notification.model.PluginKey; -import org.exoplatform.commons.api.notification.service.template.TemplateContext; -import org.exoplatform.commons.notification.template.TemplateUtils; -import org.exoplatform.container.xml.InitParams; -import org.exoplatform.mfa.notifications.plugin.MfaAdminRevocationRequestPlugin; -import org.exoplatform.mfa.notifications.utils.MfaNotificationUtils; -import org.exoplatform.social.core.identity.model.Identity; -import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider; -import org.exoplatform.social.notification.LinkProviderUtils; -import org.exoplatform.social.notification.Utils; -import org.exoplatform.webui.utils.TimeConvertUtils; - -/** - * Created by The eXo Platform SAS - * Author : eXoPlatform - * thanhvc@exoplatform.com - * Dec 14, 2014 - */ - - -@TemplateConfigs ( - templates = { - @TemplateConfig(pluginId = MfaAdminRevocationRequestPlugin.ID, template = "war:/notifications/templates/web/MfaAdminRevocationRequestPlugin.gtmpl") - } -) -public class WebTemplateProvider extends TemplateProvider { - - /** - * Defines the template builder for MfaAdminRevocationRequestPlugin - */ - private AbstractTemplateBuilder mfaAdminRevocationRequest = new AbstractTemplateBuilder() { - - @Override - protected MessageInfo makeMessage(NotificationContext ctx) { - NotificationInfo notification = ctx.getNotificationInfo(); - - String language = getLanguage(notification); - - TemplateContext templateContext = TemplateContext.newChannelInstance(getChannelKey(), notification.getKey().getId(), language); - - Identity identity = - Utils.getIdentityManager().getOrCreateIdentity(OrganizationIdentityProvider.NAME,notification.getValueOwnerParameter( - "username")); - - templateContext.put("isIntranet", "true"); - Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(notification.getLastModifiedDate()); - templateContext.put("READ", Boolean.parseBoolean(notification.getValueOwnerParameter(NotificationMessageUtils.READ_PORPERTY.getKey())) ? "read" : "unread"); - templateContext.put("NOTIFICATION_ID", notification.getId()); - templateContext.put("LAST_UPDATED_TIME", TimeConvertUtils.convertXTimeAgoByTimeServer(cal.getTime(), "EE, dd yyyy", new Locale(language), TimeConvertUtils.YEAR)); - templateContext.put("USERNAME", notification.getValueOwnerParameter("username")); - templateContext.put("USER", Utils.addExternalFlag(identity)); - templateContext.put("AVATAR", LinkProviderUtils.getUserAvatarUrl(identity.getProfile())); - templateContext.put("MFA_ADMIN_PAGE_URL", MfaNotificationUtils.getMfaAdminURL()); - - // - String body = TemplateUtils.processGroovy(templateContext); - //binding the exception throws by processing template - ctx.setException(templateContext.getException()); - MessageInfo messageInfo = new MessageInfo(); - return messageInfo.body(body).end(); - } - - @Override - protected boolean makeDigest(NotificationContext ctx, Writer writer) { - return false; - } - - - }; - - - public WebTemplateProvider(InitParams initParams) { - super(initParams); - this.templateBuilders.put(PluginKey.key(MfaAdminRevocationRequestPlugin.ID), mfaAdminRevocationRequest); - } - -} diff --git a/webapps/src/main/resources/locale/notifications/template/Notifications_en.properties b/webapps/src/main/resources/locale/notifications/template/Notifications_en.properties index c64e1d4e..58a1730c 100644 --- a/webapps/src/main/resources/locale/notifications/template/Notifications_en.properties +++ b/webapps/src/main/resources/locale/notifications/template/Notifications_en.properties @@ -10,3 +10,5 @@ Notification.mail.MfaAdminRevocationRequestPlugin.Hello=Hello Notification.intranet.message.MfaAdminRevocationRequestPlugin={0} has sent a request to revoke his authentification key Notification.mail.MfaAdminRevocationRequestPlugin.administration=MFA Administration page Notification.mail.MfaAdminRevocationRequestPlugin.footer=eXo Platform + +Notification.label.types.security=Security diff --git a/webapps/src/main/resources/locale/notifications/template/Notifications_fr.properties b/webapps/src/main/resources/locale/notifications/template/Notifications_fr.properties index 536bea50..e455eca9 100644 --- a/webapps/src/main/resources/locale/notifications/template/Notifications_fr.properties +++ b/webapps/src/main/resources/locale/notifications/template/Notifications_fr.properties @@ -10,3 +10,4 @@ Notification.mail.MfaAdminRevocationRequestPlugin.Hello=Bonjour Notification.intranet.message.MfaAdminRevocationRequestPlugin={0} a envoy\u00E9 une demande de r\u00E9vocation de sa cl\u00E9 d'authentification Notification.mail.MfaAdminRevocationRequestPlugin.administration=Page d'administration de MFA Notification.mail.MfaAdminRevocationRequestPlugin.footer=eXoPlatform +Notification.label.types.security=S\u00E9curit\u00E9 diff --git a/webapps/src/main/webapp/WEB-INF/conf/multifactor-authentication/mfa-notifications-configuration.xml b/webapps/src/main/webapp/WEB-INF/conf/multifactor-authentication/mfa-notifications-configuration.xml index c5e78880..6cd2a155 100644 --- a/webapps/src/main/webapp/WEB-INF/conf/multifactor-authentication/mfa-notifications-configuration.xml +++ b/webapps/src/main/webapp/WEB-INF/conf/multifactor-authentication/mfa-notifications-configuration.xml @@ -75,17 +75,6 @@ org.exoplatform.commons.api.notification.channel.ChannelManager - - web.channel.mfa.template - registerTemplateProvider - org.exoplatform.mfa.notifications.provider.WebTemplateProvider - - - channel-id - WEB_CHANNEL - - - mail.channel.mfa.template registerTemplateProvider diff --git a/webapps/src/main/webapp/WEB-INF/gatein-resources.xml b/webapps/src/main/webapp/WEB-INF/gatein-resources.xml index b58d991c..3f47d37e 100644 --- a/webapps/src/main/webapp/WEB-INF/gatein-resources.xml +++ b/webapps/src/main/webapp/WEB-INF/gatein-resources.xml @@ -84,4 +84,24 @@ + + + mfaNotificationExtension + notificationGRP + + + vue + + + vuetify + + + eXoVueI18n + + + extensionRegistry + + diff --git a/webapps/src/main/webapp/WEB-INF/notifications/templates/web/MfaAdminRevocationRequestPlugin.gtmpl b/webapps/src/main/webapp/WEB-INF/notifications/templates/web/MfaAdminRevocationRequestPlugin.gtmpl deleted file mode 100644 index 98430e9b..00000000 --- a/webapps/src/main/webapp/WEB-INF/notifications/templates/web/MfaAdminRevocationRequestPlugin.gtmpl +++ /dev/null @@ -1,18 +0,0 @@ -
  • -
    -
    - <%=_ctx.escapeHTML(USER)%> -
    -
    - <% - String profileUrl = "" + _ctx.escapeHTML(USER) + ""; - - %> -
    -
    <%=_ctx.appRes("Notification.intranet.message.MfaAdminRevocationRequestPlugin", profileUrl)%>
    -
    $LAST_UPDATED_TIME
    -
    -
    -
    - -
  • diff --git a/webapps/src/main/webapp/vue-apps/mfa-notifications/components/MfaAdminRevocationRequestPlugin.vue b/webapps/src/main/webapp/vue-apps/mfa-notifications/components/MfaAdminRevocationRequestPlugin.vue new file mode 100644 index 00000000..21dd9eb4 --- /dev/null +++ b/webapps/src/main/webapp/vue-apps/mfa-notifications/components/MfaAdminRevocationRequestPlugin.vue @@ -0,0 +1,50 @@ + + + diff --git a/webapps/src/main/webapp/vue-apps/mfa-notifications/extensions.js b/webapps/src/main/webapp/vue-apps/mfa-notifications/extensions.js new file mode 100644 index 00000000..9e211e6c --- /dev/null +++ b/webapps/src/main/webapp/vue-apps/mfa-notifications/extensions.js @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2023 eXo Platform SAS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +extensionRegistry.registerExtension('WebNotification', 'notification-group-extension', { + rank: 100, + name: 'security', + plugins: [ + 'MfaAdminRevocationRequestPlugin', + ], + icon: 'fa-shield-alt', +}); +extensionRegistry.registerExtension('WebNotification', 'notification-content-extension', { + type: 'MfaAdminRevocationRequestPlugin', + rank: 10, + vueComponent: Vue.options.components['user-notification-mfa-revocation'], +}); diff --git a/webapps/src/main/webapp/vue-apps/mfa-notifications/initComponents.js b/webapps/src/main/webapp/vue-apps/mfa-notifications/initComponents.js new file mode 100644 index 00000000..ca4fa2fd --- /dev/null +++ b/webapps/src/main/webapp/vue-apps/mfa-notifications/initComponents.js @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2023 eXo Platform SAS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import MfaAdminRevocationRequestPlugin from './components/MfaAdminRevocationRequestPlugin.vue'; + +const components = { + 'user-notification-mfa-revocation': MfaAdminRevocationRequestPlugin, +}; + +for (const key in components) { + Vue.component(key, components[key]); +} diff --git a/webapps/src/main/webapp/vue-apps/mfa-notifications/main.js b/webapps/src/main/webapp/vue-apps/mfa-notifications/main.js new file mode 100644 index 00000000..ff4ec080 --- /dev/null +++ b/webapps/src/main/webapp/vue-apps/mfa-notifications/main.js @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2023 eXo Platform SAS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import './initComponents.js'; +import './extensions.js'; + +const lang = eXo.env.portal.language; +const url = `${eXo.env.portal.context}/${eXo.env.portal.rest}/i18n/bundle/locale.notifications.template.Notifications-${lang}.json`; + +export function init() { + return exoi18n.loadLanguageAsync(lang, url) + .then(() => { + new Vue({ + i18n: exoi18n.i18n, + }); + }); +} diff --git a/webapps/webpack.common.js b/webapps/webpack.common.js index 2721c726..767b1ae0 100644 --- a/webapps/webpack.common.js +++ b/webapps/webpack.common.js @@ -8,7 +8,8 @@ let config = { // can use multiple entry entry: { multifactorAuthentication : './src/main/webapp/vue-apps/multi-factor-authentication/main.js', - mfaAccess : './src/main/webapp/vue-apps/mfa-access/main.js' + mfaAccess : './src/main/webapp/vue-apps/mfa-access/main.js', + notificationExtension : './src/main/webapp/vue-apps/mfa-notifications/main.js' }, plugins: [ new ESLintPlugin({