static class SecurityWarningsPanel extends Panel {
public SecurityWarningsPanel(String id) {
super(id);
GeoServerSecurityManager manager = GeoServerApplication.get().getSecurityManager();
// warn in case of an existing masterpw.info
File mpInfo = null;
Label mpInfoLabel=null;
try {
mpInfo = new File (manager.getSecurityRoot(),
GeoServerSecurityManager.MASTER_PASSWD_INFO_FILENAME);
mpInfoLabel=new Label("mpfile", new StringResourceModel("masterPasswordFile", (Component)this, null,
new Object[] {mpInfo.getCanonicalFile()}));
mpInfoLabel.setEscapeModelStrings(false);
add(mpInfoLabel);
mpInfoLabel.setVisible(mpInfo.exists());
} catch (Exception ex) {
throw new RuntimeException (ex);
}
// warn in case of an existing user.properties.old
File userprops = null;
Label userpropsLabel=null;
try {
userprops = new File (manager.getSecurityRoot(),
"users.properties.old");
userpropsLabel=new Label("userpropsold", new StringResourceModel("userPropertiesOldFile", (Component)this, null,
new Object[] {userprops.getCanonicalFile()}));
userpropsLabel.setEscapeModelStrings(false);
add(userpropsLabel);
userpropsLabel.setVisible(userprops.exists());
} catch (Exception ex) {
throw new RuntimeException (ex);
}
// check for default master password
boolean visibility = manager.checkMasterPassword( DEFAULT_ADMIN_PASSWD);
Label label=new Label("mpmessage", new StringResourceModel("changeMasterPassword", (Component)this, null));
label.setEscapeModelStrings(false);
add(label);
Link link=null;;
add(link=new Link("mplink") {
@Override
public void onClick() {
setResponsePage(new MasterPasswordChangePage());
}
});
label.setVisible(visibility);
link.setVisible(visibility);
// check for default admin password
visibility= manager.checkForDefaultAdminPassword();
Page changeItPage = null;
String passwordEncoderName=null;
try {
GeoServerUserGroupService ugService = manager.loadUserGroupService(XMLUserGroupService.DEFAULT_NAME);
if (ugService != null) {
passwordEncoderName = ugService.getPasswordEncoderName();
GeoServerUser user = ugService.getUserByUsername(ADMIN_USERNAME);
if (user != null) {
changeItPage = new EditUserPage(ugService.getName(), user);
}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Error looking up admin user", e);
}
if (changeItPage == null) {
changeItPage = new UserGroupRoleServicesPage();
}
final Page linkPage = changeItPage;
label=new Label("adminmessage", new StringResourceModel("changeAdminPassword", (Component)this, null));
label.setEscapeModelStrings(false);
add(label);
add(link=new Link("adminlink") {
@Override
public void onClick() {
setResponsePage(linkPage);
}
});
label.setVisible(visibility);
link.setVisible(visibility);
// inform about strong encryption
if (manager.isStrongEncryptionAvailable()) {
add(new Label("strongEncryptionMsg", new StringResourceModel("strongEncryption", new SecuritySettingsPage(), null))
.add(new AttributeAppender("class", new Model("info-link"), " ")));
}
else {
add(new Label("strongEncryptionMsg", new StringResourceModel("noStrongEncryption", new SecuritySettingsPage(), null))
.add(new AttributeAppender("class", new Model("warning-link"), " ")));
}
// check for password encoding in the default user group service
visibility=false;
if (passwordEncoderName!=null) {
GeoServerPasswordEncoder encoder = manager.loadPasswordEncoder(passwordEncoderName);
if (encoder!=null) {
visibility = encoder.isReversible();
}
}