use of org.forgerock.openam.license.License in project OpenAM by OpenRock.
the class UpgradeServices method writeReport.
/**
* Writes the detailed upgrade report to a file.
*
* @param adminToken Valid admin SSOToken.
* @throws UpgradeException If there was an error while writing the report file.
*/
protected void writeReport(final SSOToken adminToken) throws UpgradeException {
try {
final LicenseSet licenses = AMSetupServlet.getLicenseLocator().getRequiredLicenses();
final StringBuilder sb = new StringBuilder();
/*
* As we have got this far then the user must have accepted the license, so we log this implicitly.
*/
for (final License license : licenses) {
sb.append(String.format("License, %s, has been accepted.%n", license.getFilename()));
final String licenseHash = Hash.hash(license.toString());
sb.append(String.format("License Hash: %s.%n", licenseHash));
}
String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
String reportFile = baseDir + File.separator + "upgrade" + File.separator + REPORT_FILENAME + "." + createdDate;
File f = new File(reportFile);
// if exists then there has been an error
if (f.exists()) {
throw new UpgradeException("File " + f.getName() + " already exist!");
}
sb.append(generateDetailedUpgradeReport(adminToken, false));
writeToFile(reportFile, sb.toString());
} catch (IOException ioe) {
throw new UpgradeException(ioe.getMessage());
}
}
use of org.forgerock.openam.license.License in project OpenAM by OpenRock.
the class AMSetupServlet method processRequest.
public static boolean processRequest(IHttpServletRequest request, IHttpServletResponse response) {
// Only continue if we are not already configured
if (isConfigured()) {
return true;
}
setLocale(request);
final InstallLog installLog = InstallLog.getInstance();
installLog.open((String) request.getParameterMap().get(SetupConstants.CONFIG_VAR_BASE_DIR));
/*
* This logic needs refactoring later. setServiceConfigValues()
* attempts to check if directory is up and makes a call
* back to this class. The implementation'd
* be cleaner if classes&methods are named better and separated than
* intertwined together.
*/
ServicesDefaultValues.setServiceConfigValues(request);
// set debug directory
Map<String, Object> map = ServicesDefaultValues.getDefaultValues();
String basedir = (String) map.get(SetupConstants.CONFIG_VAR_BASE_DIR);
String uri = (String) map.get(SetupConstants.CONFIG_VAR_SERVER_URI);
SystemProperties.initializeProperties(Constants.SERVICES_DEBUG_DIRECTORY, basedir + uri + "/debug");
// used for site configuration later
Map<String, Object> siteMap = (Map<String, Object>) map.remove(SetupConstants.CONFIG_VAR_SITE_CONFIGURATION);
Map<String, Object> userRepo = (Map<String, Object>) map.remove(SetupConstants.USER_STORE);
try {
// Check for click-through license acceptance before processing the request.
SetupProgress.reportStart("configurator.progress.license.check", new Object[0]);
if (!isLicenseAccepted(request)) {
SetupProgress.reportEnd("configurator.progress.license.rejected", new Object[] { SetupConstants.ACCEPT_LICENSE_PARAM });
return false;
}
SetupProgress.reportEnd("configurator.progress.license.accepted", new Object[0]);
/*
* As we have got this far then the user must have accepted the license, so we log this implicitly.
*/
LicenseSet licenses = getLicenseLocator().getRequiredLicenses();
for (License license : licenses) {
installLog.write(String.format("License, %s, has been accepted.%n", license.getFilename()));
String licenseHash = Hash.hash(license.toString());
installLog.write(String.format("License Hash: %s.%n", licenseHash));
}
isConfiguredFlag = configure(request, map, userRepo);
if (isConfiguredFlag) {
FQDNUtils.getInstance().init();
//postInitialize was called at the end of configure????
postInitialize(getAdminSSOToken());
}
LoginLogoutMapping.setProductInitialized(isConfiguredFlag);
registerListeners();
if (isConfiguredFlag) {
String fileBootstrap = getBootstrapLocator();
if (fileBootstrap != null) {
writeToFileEx(fileBootstrap, basedir);
}
// this will write bootstrap file after configuration is
// done; and also register the observer.
ServerConfigXMLObserver.getInstance().update(true);
// register our other observers
SMSPropertiesObserver.getInstance().notifyChanges();
DebugPropertiesObserver.getInstance().notifyChanges();
Map<String, Set<String>> mapBootstrap = new HashMap<String, Set<String>>(2);
Set<String> set = new HashSet<String>(2);
set.add(fileBootstrap);
mapBootstrap.put(BOOTSTRAP_FILE_LOC, set);
if (fileBootstrap == null) {
set.add(getPresetConfigDir());
} else {
set.add(fileBootstrap);
}
// this is to store the bootstrap location
String serverInstanceName = SystemProperties.getServerInstanceName();
SSOToken adminToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
ServerConfiguration.setServerInstance(adminToken, serverInstanceName, mapBootstrap);
// store the ds admin port if we are running in embedded mode
String dataStore = (String) map.get(SetupConstants.CONFIG_VAR_DATA_STORE);
if (dataStore.equals(SetupConstants.SMS_EMBED_DATASTORE)) {
String dsAdminPort = (String) map.get(SetupConstants.CONFIG_VAR_DIRECTORY_ADMIN_SERVER_PORT);
Map<String, Set<String>> mapAdminPort = new HashMap<String, Set<String>>(2);
Set<String> set2 = new HashSet<String>(2);
set2.add(dsAdminPort);
mapAdminPort.put(Constants.DS_ADMIN_PORT, set2);
ServerConfiguration.setServerInstance(adminToken, serverInstanceName, mapAdminPort);
}
// setup site configuration information
if (siteMap != null && !siteMap.isEmpty()) {
String site = (String) siteMap.get(SetupConstants.LB_SITE_NAME);
String primaryURL = (String) siteMap.get(SetupConstants.LB_PRIMARY_URL);
Boolean isSessionHASFOEnabled = Boolean.valueOf((String) siteMap.get(SetupConstants.LB_SESSION_HA_SFO));
/*
* If primary url is null that means we are adding
* to an existing site. we don't need to create it
* first.
*/
if (primaryURL != null && primaryURL.length() > 0) {
Set<String> sites = SiteConfiguration.getSites(adminToken);
if (!sites.contains(site)) {
SiteConfiguration.createSite(adminToken, site, primaryURL, Collections.EMPTY_SET);
}
}
if (!ServerConfiguration.belongToSite(adminToken, serverInstanceName, site)) {
ServerConfiguration.addToSite(adminToken, serverInstanceName, site);
}
//configure SFO (enabled/disabled) by creating a subconfiguration for the site
Map<String, Set<String>> values = new HashMap<String, Set<String>>(1);
values.put(CoreTokenConstants.IS_SFO_ENABLED, asSet(isSessionHASFOEnabled.toString()));
createSFOSubConfig(adminToken, site, values);
}
if (EmbeddedOpenDS.isMultiServer(map)) {
// Setup Replication port in SMS for each server
updateReplPortInfo(map);
}
EntitlementConfiguration ec = EntitlementConfiguration.getInstance(SubjectUtils.createSuperAdminSubject(), "/");
ec.reindexApplications();
}
} catch (Exception e) {
installLog.write("AMSetupServlet.processRequest: error", e);
Debug.getInstance(SetupConstants.DEBUG_NAME).error("AMSetupServlet.processRequest: error", e);
Object[] params = { e.getMessage(), basedir };
throw new ConfiguratorException("configuration.failed", params, configLocale);
} finally {
installLog.write("\n\nDumping all configuration parameters...\n");
installLog.write("\nRequest Parameters:\n");
dumpConfigurationProperties(installLog, request.getParameterMap());
if (siteMap != null && !siteMap.isEmpty()) {
installLog.write("\nSite configuration items:\n");
dumpConfigurationProperties(installLog, siteMap);
}
if (userRepo != null && !userRepo.isEmpty()) {
installLog.write("\nExternal user repo configuration items:\n");
dumpConfigurationProperties(installLog, userRepo);
}
if (map != null && !map.isEmpty()) {
installLog.write("\nMain configuration items:\n");
dumpConfigurationProperties(installLog, map);
}
installLog.write("\nFinished dumping all configuration parameters\n");
installLog.close();
SetupProgress.closeOutputStream();
}
if (WebtopNaming.configMonitoring() >= 0) {
ConfigMonitoring cm = new ConfigMonitoring();
cm.configureMonitoring();
} else {
Debug.getInstance(SetupConstants.DEBUG_NAME).error("WebtopNaming.configMonitoring returned error.");
}
return isConfiguredFlag;
}
use of org.forgerock.openam.license.License in project OpenAM by OpenRock.
the class LicenseCheckerTest method shouldDisplayLicenseHeader.
@Test
public void shouldDisplayLicenseHeader() {
// Given
given(mockLocator.getRequiredLicenses()).willReturn(new LicenseSet(Collections.<License>emptyList()));
// When
checker.checkLicenseAcceptance();
// Then
verify(mockUser).tell(LicenseChecker.MSG_LICENSE_HEADER);
}
use of org.forgerock.openam.license.License in project OpenAM by OpenRock.
the class LicenseCheckerTest method setup.
@BeforeMethod
public void setup() {
mockLocator = mock(LicenseLocator.class);
mockLog = mock(LicenseLog.class);
mockUser = mock(User.class);
mockDebug = mock(DebugLog.class);
// Defaults
given(mockUser.getName()).willReturn(USER);
license = new License("aaa", "aaa");
given(mockLocator.getRequiredLicenses()).willReturn(new LicenseSet(Collections.singletonList(license)));
checker = new LicenseChecker(mockLocator, mockLog, mockUser, mockDebug);
}
Aggregations