Skip to content

Commit a937ddc

Browse files
committed
initial commit
1 parent 8f723d2 commit a937ddc

File tree

8 files changed

+242
-0
lines changed

8 files changed

+242
-0
lines changed

DEPENDENCIES

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
JDK Version:
2+
openjdk 17.0.2 2022-01-18
3+
OpenJDK Runtime Environment (build 17.0.2+8-86)
4+
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)
5+
6+
Compilation Flags:
7+
--release 11
8+
9+
Runtime Dependencies:
10+
addonsupport-api-addon-1.7.0
11+
alarmmanager-api-addon-1.7.0
12+
bacnet-api-addon-1.7.012
13+
directaccess-api-addon-1.7.0
14+
tomcat-embed-core-9.0.37
15+
webaccess-api-addon-1.7.0
16+
xdatabase-api-addon-1.7.0
17+
commonbaseutils-1.0.6
18+
core-8.0.002
19+
datatable-8.0.002
20+
extensionsupport-api-8.0.002
21+
spring-context-5.2.8.RELEASE
22+
webaccess-api-8.0.002
23+
webserver-api-8.0.002
24+
25+
Packaged Dependencies:

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ForeignOperatorTest
2+
3+
WebCTRL is a trademark of Automated Logic Corporation. Any other trademarks mentioned herein are the property of their respective owners.
4+
5+
## General Information
6+
7+
For demonstration and testing purposes, this add-on creates a single foreign operator with administrative privileges.
8+
9+
## Instructions
10+
11+
1. If your server requires signed add-ons, copy the authenticating certificate [*ACES.cer*](https://github.com/automatic-controls/addon-dev-script/blob/main/ACES.cer?raw=true) to the *./addons* directory of your WebCTRL installation folder.
12+
13+
2. Install [*ForeignOperatorTest.addon*](https://github.com/automatic-controls/foreign-operator-test/releases/latest/download/ForeignOperatorTest.addon) using the WebCTRL interface.
14+
15+
3. Use the manual command `rebootserver`. Note: this step won't be necessary when ALC fixes [one of the bugs I found](http://alcshare.com/content/webctrl80-foreign-operators-not-working).
16+
17+
4. Login to your WebCTRL server using credentials provided in the following table. If you receive an HTTP error upon logging in (this is a result of a WebCTRL bug), remove all add-ons except this one, and go back to step 3.
18+
19+
| Username | Password |
20+
| - | - |
21+
| foreign | 12345678 |

root/info.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<extension version="1">
2+
<name>ForeignOperatorTest</name>
3+
<description>For demonstration and testing purposes, this add-on creates a single foreign operator with administrative privileges.</description>
4+
<version>1.0.0</version>
5+
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
6+
<web-operator-provider>aces.webctrl.test.operators.ForeignProvider</web-operator-provider>
7+
</extension>

root/webapp/WEB-INF/web.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<web-app>
4+
5+
<listener>
6+
<listener-class>aces.webctrl.test.operators.Initializer</listener-class>
7+
</listener>
8+
9+
<security-constraint>
10+
<web-resource-collection>
11+
<web-resource-name>WEB</web-resource-name>
12+
<url-pattern>/*</url-pattern>
13+
</web-resource-collection>
14+
</security-constraint>
15+
16+
<filter>
17+
<filter-name>RoleFilterAJAX</filter-name>
18+
<filter-class>com.controlj.green.addonsupport.web.RoleFilter</filter-class>
19+
<init-param>
20+
<param-name>roles</param-name>
21+
<param-value>view_administrator_only</param-value>
22+
</init-param>
23+
</filter>
24+
<filter-mapping>
25+
<filter-name>RoleFilterAJAX</filter-name>
26+
<url-pattern>/*</url-pattern>
27+
</filter-mapping>
28+
29+
</web-app>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
BSD 3-Clause License
3+
Copyright (c) 2022, Automatic Controls Equipment Systems, Inc.
4+
Contributors: Cameron Vogt (@cvogt729)
5+
*/
6+
package aces.webctrl.test.operators;
7+
import java.util.*;
8+
import com.controlj.green.addonsupport.web.*;
9+
import com.controlj.green.addonsupport.web.auth.*;
10+
public class ForeignOperator implements WebOperator {
11+
@Override public int getNavigationTimeout(){
12+
return -1;
13+
}
14+
@Override public String getDisplayName(){
15+
return Initializer.DISPLAY_NAME;
16+
}
17+
@Override public String getLoginName(){
18+
return Initializer.USERNAME;
19+
}
20+
@Override public Link getStartLocation(){
21+
return null;
22+
}
23+
@Override public Locale getLocale(){
24+
return Locale.getDefault();
25+
}
26+
@Override public boolean isSystem(){
27+
return false;
28+
}
29+
@Override public Set<String> getPrivilegeSet(com.controlj.green.addonsupport.access.Location loc){
30+
return priv;
31+
}
32+
@Override public com.controlj.green.addonsupport.access.PrivilegeTester getFunctionalPrivilegeTester(){
33+
return tester;
34+
}
35+
@Override public com.controlj.green.addonsupport.access.PrivilegeTester getLocationPrivilegeTester(com.controlj.green.addonsupport.access.Location loc){
36+
return tester;
37+
}
38+
private final static com.controlj.green.addonsupport.access.PrivilegeTester tester = new com.controlj.green.addonsupport.access.PrivilegeTester(){
39+
@Override public boolean hasPrivilege(String str){
40+
return true;
41+
}
42+
};
43+
private volatile static Set<String> priv;
44+
static {
45+
Set<String> priv = new HashSet<String>();
46+
priv.add("administrator");
47+
ForeignOperator.priv = Collections.unmodifiableSet(priv);
48+
}
49+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
BSD 3-Clause License
3+
Copyright (c) 2022, Automatic Controls Equipment Systems, Inc.
4+
Contributors: Cameron Vogt (@cvogt729)
5+
*/
6+
package aces.webctrl.test.operators;
7+
import com.controlj.green.addonsupport.web.auth.*;
8+
public class ForeignProvider extends StandardWebOperatorProvider {
9+
private final static char[] PASSWORD = Initializer.PASSWORD.toCharArray();
10+
@Override public WebOperator validate(String username, char[] password, String host) throws ValidationException {
11+
if (Initializer.USERNAME.equalsIgnoreCase(username) && java.util.Arrays.equals(PASSWORD, password)){
12+
return new ForeignOperator();
13+
}
14+
return super.validate(username, password, host);
15+
}
16+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
BSD 3-Clause License
3+
Copyright (c) 2022, Automatic Controls Equipment Systems, Inc.
4+
Contributors: Cameron Vogt (@cvogt729)
5+
*/
6+
package aces.webctrl.test.operators;
7+
import com.controlj.green.addonsupport.web.auth.AuthenticationManager;
8+
import com.controlj.green.extensionsupport.Extension;
9+
import com.controlj.green.core.ui.UserSession;
10+
/**
11+
* Namespace which contains methods to access small sections of a few internal WebCTRL APIs.
12+
*/
13+
public class HelperAPI {
14+
/**
15+
* Specifies whether methods of this API should log stack traces generated from errors.
16+
*/
17+
public static volatile boolean logErrors = true;
18+
/**
19+
* Terminates sessions for all foreign operators.
20+
* @return whether this method executed successfully.
21+
*/
22+
public static boolean logoutAllForeign(){
23+
try{
24+
for (final UserSession session:UserSession.getAllUserSessions()){
25+
if (session.getOperator().isForeign()){
26+
session.close();
27+
}
28+
}
29+
return true;
30+
}catch(Throwable t){
31+
if (logErrors){ t.printStackTrace(); }
32+
return false;
33+
}
34+
}
35+
/**
36+
* Activates the specified {@code WebOperatorProvider}.
37+
* @param addon specifies the name of the addon to activate.
38+
* @return an {@code Extension} object matching the given addon, or {@code null} if the addon cannot be found or if any error occurs.
39+
*/
40+
public static Extension activateWebOperatorProvider(String addon){
41+
try{
42+
AuthenticationManager auth = new AuthenticationManager();
43+
for (Extension e:auth.findWebOperatorProviders()){
44+
if (addon.equals(e.getName())){
45+
auth.activateProvider(e);
46+
return e;
47+
}
48+
}
49+
}catch(Throwable t){}
50+
return null;
51+
}
52+
/**
53+
* Activates the default {@code WebOperatorProvider}.
54+
* @return whether this method executed successfully.
55+
*/
56+
public static boolean activateDefaultWebOperatorProvider(){
57+
try{
58+
new AuthenticationManager().activateProvider(null);
59+
return true;
60+
}catch(Throwable t){
61+
if (logErrors){ t.printStackTrace(); }
62+
return false;
63+
}
64+
}
65+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
BSD 3-Clause License
3+
Copyright (c) 2022, Automatic Controls Equipment Systems, Inc.
4+
Contributors: Cameron Vogt (@cvogt729)
5+
*/
6+
package aces.webctrl.test.operators;
7+
import javax.servlet.*;
8+
import com.controlj.green.addonsupport.*;
9+
public class Initializer implements ServletContextListener {
10+
public final static String DISPLAY_NAME = "Foreign";
11+
public final static String USERNAME = "foreign";
12+
public final static String PASSWORD = "12345678";
13+
static {
14+
// Temporary workaround for bug until ALC releases a patch for WebCTRL
15+
try{
16+
Class.forName("com.controlj.green.directaccess.DirectAccessInternal").getMethod("getDirectAccessInternal").invoke(null);
17+
com.controlj.green.addonsupport.access.DirectAccess.getDirectAccess();
18+
}catch (Throwable t){
19+
System.err.println("Failed to enforce temporary workaround.");
20+
}
21+
}
22+
@Override public void contextInitialized(ServletContextEvent sce){
23+
HelperAPI.logoutAllForeign();
24+
HelperAPI.activateWebOperatorProvider(AddOnInfo.getAddOnInfo().getName());
25+
}
26+
@Override public void contextDestroyed(ServletContextEvent sce){
27+
HelperAPI.activateDefaultWebOperatorProvider();
28+
HelperAPI.logoutAllForeign();
29+
}
30+
}

0 commit comments

Comments
 (0)