Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Christoph Jahn
committed
Jun 16, 2021
1 parent
fabc56f
commit 79bc69b
Showing
5 changed files
with
75 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
WxPassword/code/source/com/softwareag/wx/is/password/DefaultAccountUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.softwareag.wx.is.password; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import com.wm.app.b2b.server.ServiceException; | ||
|
||
/** | ||
* Controls automated password update for default accounts | ||
*/ | ||
public class DefaultAccountUpdater { | ||
|
||
/** | ||
* List of default accounts to be updated | ||
*/ | ||
private enum DefaultUser { | ||
Administrator, Replicator, Developer | ||
} | ||
|
||
/** | ||
* Name of environment variable that enables (if set to "true") the automated | ||
* password update for default accounts | ||
*/ | ||
public static final String ENVVAR_UPDATE_DEFAULT_ACCOUNTS = "SAG_WXPASSWORD_UPDATE_DEFAULT_ACCOUNTS"; | ||
|
||
/** | ||
* Perform the update, if enabled | ||
* | ||
* @throws ServiceException | ||
*/ | ||
public static void execute() throws ServiceException { | ||
|
||
if (isEnabled()) { | ||
WorkDir workDir = new WorkDir(); | ||
File workDirFile = workDir.get(); | ||
|
||
for (DefaultUser defaultUser : DefaultUser.values()) { | ||
String userName = defaultUser.toString(); | ||
PasswordSetter pws = new PasswordSetter(workDirFile, userName); | ||
try { | ||
pws.execute(); | ||
} catch (IOException e) { | ||
throw new ServiceException(e); | ||
} | ||
} | ||
} else { | ||
System.out.println("WxPassword : Automated update of passwords for default accounts is disabled"); | ||
} | ||
} | ||
|
||
/** | ||
* Check if automated update is enabled | ||
* | ||
* @return true if enabled, false otherwise | ||
*/ | ||
private static boolean isEnabled() { | ||
String envVarIsEnabled = System.getenv(ENVVAR_UPDATE_DEFAULT_ACCOUNTS); | ||
return Boolean.valueOf(envVarIsEnabled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters