Skip to content

Commit 79bc69b

Browse files
author
Christoph Jahn
committed
Require explicit activation of automated update
The environment variable `SAG_WXPASSWORD_UPDATE_DEFAULT_ACCOUNTS=true` must be set, to enable the automated update. This is a protection against accidental execution, e.g. on a CI system.
1 parent fabc56f commit 79bc69b

File tree

5 files changed

+75
-40
lines changed

5 files changed

+75
-40
lines changed

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ in a container.
66

77
## Usage
88

9-
Installing the package is all that needs to be done. The service
10-
`wx.password.pub:nonDefaultPasswordsForStandardAccounts` is defined
11-
as a start-up service and therefore gets executed automatically.
9+
To enable the automated update of passwords the environment variable
10+
`SAG_WXPASSWORD_UPDATE_DEFAULT_ACCOUNTS` must be set to `true`.
11+
This mechanism protects against accidental execution and by that
12+
a potential lock-out.
13+
1214

1315
### Specific passwords
1416

@@ -19,7 +21,7 @@ the variable `SAG_WXPASSWORD_SET_Administrator` must be defined.
1921

2022
### Random passwords
2123

22-
If no password is defined a random one will be generated and saved in
24+
If no password is defined, a random one will be generated and saved in
2325
clear text in the working directory. For each user a separate file will
2426
be created and its name matches the user name.
2527

@@ -34,12 +36,6 @@ is `$IS_HOME/config/WxPassword`. In both cases, the directory will
3436
be created, if it does not exist. If the creation fails, a
3537
`ServiceException` is thrown and now further activities performed.
3638

37-
### Disable execution
38-
39-
To disable the execution from the outside you need to create a semaphore
40-
file (name: `disable_WxPassword`) in the working directory. If this is
41-
found, WxPassword will effectively be completely disabled.
42-
4339
## Getting Started
4440

4541
You can use this package in multiple ways.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.softwareag.wx.is.password;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
6+
import com.wm.app.b2b.server.ServiceException;
7+
8+
/**
9+
* Controls automated password update for default accounts
10+
*/
11+
public class DefaultAccountUpdater {
12+
13+
/**
14+
* List of default accounts to be updated
15+
*/
16+
private enum DefaultUser {
17+
Administrator, Replicator, Developer
18+
}
19+
20+
/**
21+
* Name of environment variable that enables (if set to "true") the automated
22+
* password update for default accounts
23+
*/
24+
public static final String ENVVAR_UPDATE_DEFAULT_ACCOUNTS = "SAG_WXPASSWORD_UPDATE_DEFAULT_ACCOUNTS";
25+
26+
/**
27+
* Perform the update, if enabled
28+
*
29+
* @throws ServiceException
30+
*/
31+
public static void execute() throws ServiceException {
32+
33+
if (isEnabled()) {
34+
WorkDir workDir = new WorkDir();
35+
File workDirFile = workDir.get();
36+
37+
for (DefaultUser defaultUser : DefaultUser.values()) {
38+
String userName = defaultUser.toString();
39+
PasswordSetter pws = new PasswordSetter(workDirFile, userName);
40+
try {
41+
pws.execute();
42+
} catch (IOException e) {
43+
throw new ServiceException(e);
44+
}
45+
}
46+
} else {
47+
System.out.println("WxPassword : Automated update of passwords for default accounts is disabled");
48+
}
49+
}
50+
51+
/**
52+
* Check if automated update is enabled
53+
*
54+
* @return true if enabled, false otherwise
55+
*/
56+
private static boolean isEnabled() {
57+
String envVarIsEnabled = System.getenv(ENVVAR_UPDATE_DEFAULT_ACCOUNTS);
58+
return Boolean.valueOf(envVarIsEnabled);
59+
}
60+
}

WxPassword/code/source/com/softwareag/wx/is/password/PasswordSetter.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,10 @@ public class PasswordSetter {
2424
public static final String ENVVAR_PASSWORD_PREFIX = "SAG_WXPASSWORD_SET_";
2525

2626
/**
27-
* Name of semaphore file to indicate that password should not be updated. The
28-
* existence of this file disables any changes, regardless of whether the
29-
* passwords are specified as environment variables or should be created
30-
* randomly.
27+
* Set of characters from which the random password is generated
3128
*/
32-
public static final String SEMAPHOR_DISABLE = "disable_WxPassword";
33-
34-
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
35-
static SecureRandom rnd = new SecureRandom();
29+
private static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
30+
private static SecureRandom rnd = new SecureRandom();
3631

3732
File workDir = null;
3833
String userName = null;
@@ -66,7 +61,7 @@ public void execute() throws IOException, ServiceException {
6661
// an IO issue
6762
if (!isPasswordDefinedByEnvVar) {
6863
Files.write(fileWithPlainTextPassword(), password.getBytes());
69-
System.out.println("New password for user '" + userName + "' can be found at '"
64+
System.out.println("WxPassword : New password for user '" + userName + "' can be found at '"
7065
+ fileWithPlainTextPassword().getCanonicalPath() + "'");
7166
}
7267

WxPassword/code/source/wx/password/pub.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import java.io.IOException;
1515
import java.security.SecureRandom;
1616
import java.util.Iterator;
17-
import com.softwareag.wx.is.password.PasswordSetter;
18-
import com.softwareag.wx.is.password.WorkDir;
17+
import com.softwareag.wx.is.password.DefaultAccountUpdater;
1918
// --- <<IS-END-IMPORTS>> ---
2019

2120
public final class pub
@@ -39,29 +38,16 @@ public static final void nonDefaultPasswordsForStandardAccounts (IData pipeline)
3938
{
4039
// --- <<IS-START(nonDefaultPasswordsForStandardAccounts)>> ---
4140
// @sigtype java 3.5
42-
WorkDir workDir = new WorkDir();
43-
File workDirFile = workDir.get();
44-
45-
for (DefaultUser defaultUser : DefaultUser.values()) {
46-
String userName = defaultUser.toString();
47-
PasswordSetter pws = new PasswordSetter(workDirFile, userName);
48-
try {
49-
pws.execute();
50-
} catch (IOException e) {
51-
throw new ServiceException(e);
52-
}
53-
}
41+
DefaultAccountUpdater.execute();
5442

5543
// --- <<IS-END>> ---
5644

5745

5846
}
5947

6048
// --- <<IS-START-SHARED>> ---
49+
6150

62-
private enum DefaultUser { Administrator, Replicator, Developer }
63-
64-
6551
// --- <<IS-END-SHARED>> ---
6652
}
6753

WxPassword/ns/wx/password/pub/node.idf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
<value name="node_nsName">wx.password.pub</value>
77
<value name="is_public">false</value>
88
<value name="encodeutf8">true</value>
9-
<value name="shared">CnByaXZhdGUgZW51bSBEZWZhdWx0VXNlciB7IEFkbWluaXN0cmF0b3IsIFJlcGxpY2F0b3IsIERl
10-
dmVsb3BlciB9CgoJ</value>
9+
<value name="shared">Cgk=</value>
1110
<value name="extends"></value>
1211
<array name="implements" type="value" depth="1">
1312
</array>
@@ -19,7 +18,6 @@ dmVsb3BlciB9CgoJ</value>
1918
<value>java.io.IOException</value>
2019
<value>java.security.SecureRandom</value>
2120
<value>java.util.Iterator</value>
22-
<value>com.softwareag.wx.is.password.PasswordSetter</value>
23-
<value>com.softwareag.wx.is.password.WorkDir</value>
21+
<value>com.softwareag.wx.is.password.DefaultAccountUpdater</value>
2422
</array>
2523
</Values>

0 commit comments

Comments
 (0)