Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.8.x] Admin advisory banner component #3566

Open
wants to merge 17 commits into
base: 4.8.x
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
~
~ WSO2 LLC. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.wso2.carbon</groupId>
<artifactId>admin-advisory-mgt</artifactId>
<version>4.8.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.admin.advisory.mgt.ui</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Admin Advisory Mgt UI</name>
<description>org.wso2.carbon.admin.advisory.mgt.ui represent the UI aspects of
org.wso2.carbon.admin.advisory.mgt bundle
</description>
<url>http://wso2.org</url>

<dependencies>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.admin.advisory.mgt.stub</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>
org.wso2.carbon.admin.advisory.mgt.ui.*,
</Export-Package>
<Import-Package>
!org.wso2.carbon.admin.advisory.mgt.ui.i18n,
org.wso2.carbon.admin.advisory.mgt.stub.*;version="${carbon.kernel.imp.pkg.version}",
*;resolution:=optional
</Import-Package>
<Carbon-Component>UIBundle</Carbon-Component>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.admin.advisory.mgt.ui;

import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.wso2.carbon.admin.advisory.mgt.stub.AdminAdvisoryManagementServiceStub;
import org.wso2.carbon.admin.advisory.mgt.stub.dto.AdminAdvisoryBannerDTO;

/**
* This class is used to call the AdminAdvisoryManagementService.
*/
public class AdminAdvisoryBannerClient {

protected AdminAdvisoryManagementServiceStub stub;
private static final String ADMIN_ADVISORY_MANAGEMENT_SERVICE = "AdminAdvisoryManagementService";

/**
* AdminAdvisoryBannerClient constructor.
*
* @param url URL.
* @param configContext Configuration context.
* @throws AxisFault Error while creating AdminAdvisoryManagementServiceStub instance.
*/
public AdminAdvisoryBannerClient(String url, ConfigurationContext configContext) throws AxisFault {

try {
stub = new AdminAdvisoryManagementServiceStub(configContext, url
+ ADMIN_ADVISORY_MANAGEMENT_SERVICE);
} catch (AxisFault e) {
handleException(e.getMessage(), e);
}
}

/**
* AdminAdvisoryBannerClient constructor.
*
* @param cookie Cookie.
* @param url URL.
* @param configContext Configuration context.
* @throws AxisFault Error while creating AdminAdvisoryManagementServiceStub instance.
*/
public AdminAdvisoryBannerClient(String cookie, String url, ConfigurationContext configContext) throws AxisFault {

try {
stub = new AdminAdvisoryManagementServiceStub(configContext, url
+ ADMIN_ADVISORY_MANAGEMENT_SERVICE);
ServiceClient client = stub._getServiceClient();
Options option = client.getOptions();
option.setManageSession(true);
option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
} catch (AxisFault e) {
handleException(e.getMessage(), e);
}
}

/**
* Saves the banner configuration.
*
* @param adminAdvisoryBannerDTO AdminAdvisoryBannerDTO.
* @throws AxisFault Error while saving the banner configuration.
*/
public void saveBannerConfig(AdminAdvisoryBannerDTO adminAdvisoryBannerDTO) throws AxisFault {

try {
stub.saveAdminAdvisoryConfig(adminAdvisoryBannerDTO);
} catch (Exception e) {
handleException(e.getMessage(), e);
}
}

/**
* Loads the banner configuration.
*
* @return adminAdvisoryBannerDTO AdminAdvisoryBannerDTO.
* @throws AxisFault Error while loading the banner configuration.
*/
public AdminAdvisoryBannerDTO loadBannerConfig() throws AxisFault {

try {
return stub.getAdminAdvisoryConfig();
} catch (Exception e) {
handleException(e.getMessage(), e);
}
return null;
}

/**
* Handle exception.
*
* @throws AxisFault To handle the exception.
*/
private void handleException(String msg, Exception e) throws AxisFault {

throw new AxisFault(msg, e);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
~ Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
~
~ WSO2 LLC. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<component xmlns="http://products.wso2.org/carbon">
<menus>
<menu>
<id>identity_admin_advisory_banner_menu</id>
<i18n-key>admin.session.advisory.banner</i18n-key>
<i18n-bundle>org.wso2.carbon.admin.advisory.mgt.ui.i18n.Resources</i18n-bundle>
<parent-menu>configure_menu</parent-menu>
<link>../admin-advisory-mgt/admin-advisory-banner.jsp</link>
<region>region1</region>
<order>1</order>
<style-class>manage</style-class>
<icon>../admin-advisory-mgt/images/admin-adv.png</icon>
<require-permission>/permission/admin</require-permission>
<require-super-tenant>true</require-super-tenant>
</menu>
</menus>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
#
# WSO2 LLC. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

error.while.loading.admin.advisory.banner.data=Error while loading admin advisory banner data
admin.session.advisory.banner=Admin Advisory
admin.session.advisory.banner.heading=Admin Session Advisory Banner
admin.session.advisory.banner.set=Admin Session Advisory Banner
admin.session.advisory.banner.enable.banner=Enable Banner
admin.session.advisory.banner.enable.banner.hint=Enable banner to be displayed in the login page
admin.session.advisory.banner.banner.content=Banner Content
admin.session.advisory.banner.banner.content.hint=Banner content to be displayed in the login page

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!--
~ Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved.
~
~ WSO2 LLC. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
<%@ page import="org.apache.axis2.context.ConfigurationContext"%>
<%@ page import="org.wso2.carbon.CarbonConstants"%>
<%@ page import="org.wso2.carbon.admin.advisory.mgt.stub.dto.AdminAdvisoryBannerDTO"%>
<%@ page import="org.wso2.carbon.admin.advisory.mgt.ui.AdminAdvisoryBannerClient" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@ page import="org.wso2.carbon.utils.ServerConstants"%>

<script type="text/javascript" src="extensions/js/vui.js"></script>
<script type="text/javascript" src="../admin/js/main.js"></script>

<jsp:include page="../dialog/display_messages.jsp"/>

<%
String httpMethod = request.getMethod();
if (!"post".equalsIgnoreCase(httpMethod)) {
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}

String enableBanner = request.getParameter("enableBanner");
String bannerContent = request.getParameter("bannerContent").trim();

AdminAdvisoryBannerDTO adminAdvisoryBannerConfig = new AdminAdvisoryBannerDTO();

adminAdvisoryBannerConfig.setEnableBanner(Boolean.parseBoolean(enableBanner));
if (bannerContent != null && bannerContent.length() > 0) {
adminAdvisoryBannerConfig.setBannerContent(bannerContent);
}

try {
String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
ConfigurationContext configContext = (ConfigurationContext) config
.getServletContext()
.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
AdminAdvisoryBannerClient configClient =
new AdminAdvisoryBannerClient(cookie, backendServerURL, configContext);

// Save the new configuration.
configClient.saveBannerConfig(adminAdvisoryBannerConfig);

%>
<script type="text/javascript">
location.href = "admin-advisory-banner.jsp";
</script>
<%
} catch (Exception e) {
CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request);
%>
<script type="text/javascript">
location.href = "admin-advisory-banner.jsp";
</script>
<%
return;
}
%>
Loading