Search in sources :

Example 1 with LicenseSet

use of org.forgerock.openam.license.LicenseSet 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());
    }
}
Also used : LicenseSet(org.forgerock.openam.license.LicenseSet) License(org.forgerock.openam.license.License) IOException(java.io.IOException) File(java.io.File) IOUtils.writeToFile(org.forgerock.openam.utils.IOUtils.writeToFile)

Example 2 with LicenseSet

use of org.forgerock.openam.license.LicenseSet 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;
}
Also used : LicenseSet(org.forgerock.openam.license.LicenseSet) ConfigMonitoring(com.sun.identity.common.ConfigMonitoring) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) LicenseSet(org.forgerock.openam.license.LicenseSet) HashSet(java.util.HashSet) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) EntitlementConfiguration(com.sun.identity.entitlement.EntitlementConfiguration) License(org.forgerock.openam.license.License) MissingResourceException(java.util.MissingResourceException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) MalformedURLException(java.net.MalformedURLException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) DirUserObject(com.sun.identity.common.configuration.ServerConfigXML.DirUserObject) ServerObject(com.sun.identity.common.configuration.ServerConfigXML.ServerObject) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 3 with LicenseSet

use of org.forgerock.openam.license.LicenseSet 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);
}
Also used : LicenseSet(org.forgerock.openam.license.LicenseSet) License(org.forgerock.openam.license.License) Test(org.testng.annotations.Test)

Example 4 with LicenseSet

use of org.forgerock.openam.license.LicenseSet 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);
}
Also used : LicenseSet(org.forgerock.openam.license.LicenseSet) DebugLog(org.forgerock.openam.install.tools.logs.DebugLog) LicenseLog(org.forgerock.openam.license.LicenseLog) User(org.forgerock.openam.license.User) License(org.forgerock.openam.license.License) LicenseLocator(org.forgerock.openam.license.LicenseLocator) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

License (org.forgerock.openam.license.License)4 LicenseSet (org.forgerock.openam.license.LicenseSet)4 IOException (java.io.IOException)2 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 ConfigMonitoring (com.sun.identity.common.ConfigMonitoring)1 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)1 DirUserObject (com.sun.identity.common.configuration.ServerConfigXML.DirUserObject)1 ServerObject (com.sun.identity.common.configuration.ServerConfigXML.ServerObject)1 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)1 EntitlementConfiguration (com.sun.identity.entitlement.EntitlementConfiguration)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 PolicyException (com.sun.identity.policy.PolicyException)1 SMSException (com.sun.identity.sm.SMSException)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1