Appboard/2.4/admin/provisioning/custom jsp
Overview
Another way to manage domains, users, roles, and role assignments is through the creation of a custom Java Server Page (JSP) that is run on the AppBoard server and exposed an web interface for management purposes.
This document covers an example JSP implementation.
![Template-warning.png](/docs/images/0/07/Template-warning.png)
Installation and Configuration
Perform the following steps to install the Custom JSP for direct provisioning:
- Save the code shown in the "JSP Code" section below into a text file with the file name: selfProvisioning.jsp
- Modify the code as appropriate to meet the needs of the customer.
- Save the file in to [INSTALL_HOME]/server/webapps/enportal/pkg/system/selfProvisioning.jsp
- Invoke the self-provisioning options through the URL. See details and examples provided below under Applying Provisioning Updates
- After creating the desired Users in the system, delete the selfProvisioning.jsp file from the system, so that users do not access the provisioning capabilities.
![Template-warning.png](/docs/images/0/07/Template-warning.png)
JSP Code
[xml,N]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page import="java.util.*"
import="com.edgetech.eportal.component.*"
import="com.edgetech.eportal.user.*"
import="com.edgetech.eportal.session.*"
import="com.edgetech.eportal.util.*"
import="com.edgetech.eportal.user.impl.*"
import="com.edgetech.util.logger.*"
import="com.edgetech.eportal.directory.*"
import="com.edgetech.eportal.executive.impl.PrivilegedServiceRegistry"
import="com.edgetech.eportal.executive.ServiceRegistry"
import="com.edgetech.eportal.session.impl.SessionServiceImpl"
import="com.edgetech.eportal.web.JSPUtilities"
import="com.edgetech.eportal.config.Config" %>
<jsp:useBean id="JspConfigBean" scope="application" class="com.edgetech.util.config.JspConfig" />
<%@ taglib uri="/PortalTagLibrary" prefix="portal" %>
<%
String username = request.getParameter("uid");
String password = "ChangeMe"; // Note: the initial password is set to "ChangeMe"!
String domainName = request.getParameter("domain");
String rolePath = request.getParameter("rolePath");
String errorMessage = "";
if (username != null && domainName != null && rolepath != null) {
SessionServiceImpl sessionService = null;
AuthenticationToken systemSession = null;
try{
sessionService = (SessionServiceImpl)PrivilegedServiceRegistry.getSessionService();
systemSession = sessionService.createSystemSession();
UserService userService = ServiceRegistry.getUserService(systemSession);
Domain domain = UserPackageToolkit.makeDomain(domainName);
Role role = UserPackageToolkit.makeRoleFromAbsoluteString(rolePath);
String[] roleArray = rolePath.substring(1).split("/"); // Ignore the leading '/'
userService.createRole(roleArray);
String[] userArray = username.split(",");
for (int i=0; i< userArray.length; i++) {
User user = UserPackageToolkit.makeUser(domainName, userArray[i].trim());
userService.createUser(domain, userArray[i].trim(), password);
userService.assignUserToRole(user, role);
}
} catch (Exception exp) {
errorMessage = exp.getMessage();
exp.printStackTrace();
} finally {
// Terminate the system session.
sessionService.terminateSession(systemSession, SessionService.TERMCODE_LOGOUT);
}
if (errorMessage.equals("")) {
%>
<html>
<head>
<LINK href='<%=JSPUtilities.out(URLUtil.getPortalContext(), true)%>/framework/styles/editors.css' type=text/css rel=stylesheet>
<script type="text/javascript" src='<%=JSPUtilities.out(URLUtil.getPortalContext(), true)%>/framework/js/browser.js'></script>
</head>
<body>
<%
out.println("User Creation successful. Please login to Portal.");
%>
<button onClick="return cancel();" class=fixedWidth>Ok</button>
</body>
</html>
<%
return;
} else {
// re-write errorMessage here.//
}
}
%>
<html>
<head>
<title>Self Provisioning Form</title>
<LINK href='<%=JSPUtilities.out(URLUtil.getPortalContext(), true)%>/framework/styles/editors.css' type=text/css rel=stylesheet>
<script type="text/javascript" src='<%=JSPUtilities.out(URLUtil.getPortalContext(), true)%>/framework/js/browser.js'></script>
<script type="text/javascript">
var warned="";
function saveChanges(actionType)
{
if (validateInput(document.inputForm))
{
document.inputForm.actionType.value = actionType;
document.inputForm.submit();
}
return false;
}
function validateInput(workerForm)
{
if ( ! isValidUsernameFieldType(workerForm.uid, "User Name", true, false))
{
workerForm.uid.focus();
return false;
}
else if ( emptyString.test(workerForm.rolePath.value))
{
alert('Role cannot be empty.');
workerForm.rolePath.focus();
return false;
}
else if (emptyString.test(workerForm.domain.value))
{
alert('domain cannot be empty.');
workerForm.domain.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name="inputForm" method="POST" action="">
<input type="hidden" name="actionType">
Self Provisioning
<%=JSPUtilities.out(errorMessage)%>
<tbody>
</tbody>
New User Name
<input value="" name="uid" size="200" maxlength="2000" type="text">
role
<input value="" name="rolePath" size="15" type="text">
domain
<input value="" name="domain" size="15" type="text" >
</form>
<button onClick="return saveChanges('Ok');" class=fixedWidth>Continue</button>
<button onClick="return cancel();" class=fixedWidth>Cancel</button>
</body>
</html>
Usage
- uid, domain, and rolePath are required parameters in order for the provisioning code to run.
- Each new User's password is defaulted to "ChangeMe".
Applying Provisioning Updates
Perform the following steps to apply provisioning updates using the Custom JSP:
- Follow the steps above under Installation and Configuration to save the JSP code into the system.
- Enter a URL into the browser to invoke the self-provisioning command. The URL will have the following format:
- http://<serverhost>:<port>/enportal/pkg/system/selfProvisioning.jsp?uid=<userid01>,<userid02>,...,<userid_n>&domain=<DomainName>&rolePath=<RoleName>
- Each user will be added to the system under the indicated Domain, and will be assigned the indicated Role.
Examples:
- http://localhost:8080/enportal/pkg/system/selfProvisioning.jsp?uid=jMurphy ,rJohnson ,bAckerman&domain=SafeCo&rolePath=/NOC
- http://rimagicor.com:8081/enportal/pkg/system/selfProvisioning.jsp?uid=INM18483 ,INM20170 ,INM05057 ,INM02642 ,INM05166 ,INM02642 ,INM31735 ,INM20170&domain=CustomerA&rolePath=/Users/East/Home
- http://myservername/enportal/pkg/system/selfProvisioning.jsp?uid=bill.thompson,amy.dobson,yolanda.pence&domain=North&rolePath=/SystemAdmin