Search in sources :

Example 36 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class AMSetupServlet method createOpenDJBackup.

private static void createOpenDJBackup() {
    try {
        UpgradeDirectoryUtils.createUpgradeDirectories(getBaseDir());
    } catch (UpgradeException ue) {
        Debug.getInstance(SetupConstants.DEBUG_NAME).error("Upgrade cannot create backup directory", ue);
        return;
    }
    ZipOutputStream zOut = null;
    String baseDir = getBaseDir();
    String backupDir = baseDir + "/backups/";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    String dateStamp = dateFormat.format(new Date());
    File backupFile = new File(backupDir + "opendj.backup." + dateStamp + ".zip");
    if (backupFile.exists()) {
        Debug.getInstance(SetupConstants.DEBUG_NAME).error("Upgrade cannot continue as backup file exists! " + backupFile.getName());
        return;
    }
    File opendjDirectory = new File(baseDir + OPENDS_DIR);
    if (opendjDirectory.exists() && opendjDirectory.isDirectory()) {
        final String[] filenames = opendjDirectory.list();
        try {
            zOut = new ZipOutputStream(new FileOutputStream(backupFile));
            // Compress the files
            for (String filename : filenames) {
                zipDir(new File(baseDir + OPENDS_DIR + File.separator + filename), baseDir + OPENDS_DIR + File.separator, zOut, (baseDir + File.separator).length());
            }
            zOut.close();
        } catch (IOException ioe) {
            Debug.getInstance(SetupConstants.DEBUG_NAME).error("IOException", ioe);
        } finally {
            if (zOut != null) {
                try {
                    zOut.close();
                } catch (IOException ioe) {
                // do nothing
                }
            }
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) IOUtils.writeToFile(org.forgerock.openam.utils.IOUtils.writeToFile) Date(java.util.Date)

Example 37 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class BootstrapData method initSMS.

public void initSMS(boolean startDS) throws UnsupportedEncodingException, LDAPServiceException, MalformedURLException {
    String serverConfigXML = getServerConfigXML(false);
    Properties prop = getBootstrapProperties();
    SystemProperties.initializeProperties(prop, true);
    Crypt.reinitialize();
    loadServerConfigXML(serverConfigXML);
    if (startDS) {
        startEmbeddedDS(basedir + AMSetupServlet.OPENDS_DIR);
        if (AMSetupServlet.isOpenDJUpgraded()) {
            try {
                new DirectoryContentUpgrader(basedir, dsbasedn).upgrade(true);
            } catch (UpgradeException ue) {
                throw new IllegalStateException("An error occurred while upgrading directory content", ue);
            }
        }
    } else {
        EmbeddedOpenDS.initializeForClientUse();
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SystemProperties(com.iplanet.am.util.SystemProperties) Properties(java.util.Properties) DirectoryContentUpgrader(org.forgerock.openam.upgrade.DirectoryContentUpgrader)

Example 38 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class ServiceSchemaModifications method parseExistingServiceDefinition.

private void parseExistingServiceDefinition() throws UpgradeException {
    //we should only fetch these once to prevent performance problems, also in case of fetchNew to prevent
    //encrypting passwords multiple times.
    Map<String, ServiceSchemaImpl> newSchemaMap = fetchNewServiceAttributes(serviceSchemaDoc);
    Map<String, ServiceSchemaImpl> existingSchemaMap = null;
    try {
        existingSchemaMap = fetchExistingServiceAttributes(serviceName, adminToken);
    } catch (SMSException smse) {
        UpgradeUtils.debug.error("unable to fetch existing service attributes", smse);
        throw new UpgradeException(smse.getMessage());
    } catch (SSOException ssoe) {
        UpgradeUtils.debug.error("unable to fetch existing service attributes", ssoe);
        throw new UpgradeException(ssoe.getMessage());
    }
    if (calculateSchemaChanges(newSchemaMap, existingSchemaMap)) {
        if (UpgradeUtils.debug.messageEnabled()) {
            UpgradeUtils.debug.message("service " + serviceName + " has new/deleted schema");
        }
        hasSchemaChanges = true;
    }
    // sub schemas added or removed?
    if (calculateSubSchemaChanges(newSchemaMap, existingSchemaMap)) {
        if (UpgradeUtils.debug.messageEnabled()) {
            UpgradeUtils.debug.message("service " + serviceName + " has a modified sub schema");
        }
        hasSubSchemaChanges = true;
    }
    // has the service changed
    if (calculateServiceModifications(newSchemaMap, existingSchemaMap)) {
        if (UpgradeUtils.debug.messageEnabled()) {
            UpgradeUtils.debug.message("service " + serviceName + " has changes in schemas");
        }
        isServiceModified = true;
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SSOException(com.iplanet.sso.SSOException)

Example 39 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class ServiceSchemaModifications method calculateServiceModifications.

private boolean calculateServiceModifications(Map<String, ServiceSchemaImpl> newSchemaMap, Map<String, ServiceSchemaImpl> existingSchemaMap) throws UpgradeException {
    modifications = new HashMap<String, ServiceSchemaUpgradeWrapper>();
    try {
        for (Map.Entry<String, ServiceSchemaImpl> newAttrSchemaEntry : newSchemaMap.entrySet()) {
            ServiceSchemaImpl schema = existingSchemaMap.get(newAttrSchemaEntry.getKey());
            if (schema == null) {
                //calculateSchemaChanges
                continue;
            }
            ServiceSchemaModificationWrapper attrsAdded = getServiceAdditionsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
            ServiceSchemaModificationWrapper attrsModified = getServiceModificationsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
            ServiceSchemaModificationWrapper attrsDeleted = getServiceDeletionsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue(), schema);
            if (attrsAdded.hasBeenModified() || attrsModified.hasBeenModified() || attrsDeleted.hasBeenModified()) {
                modifications.put(newAttrSchemaEntry.getKey(), new ServiceSchemaUpgradeWrapper(attrsAdded, attrsModified, attrsDeleted));
            }
        }
    } catch (SMSException smse) {
        UpgradeUtils.debug.error("error whilst determining schema changes for service: " + serviceName, smse);
        throw new UpgradeException(smse.getMessage());
    }
    if (UpgradeUtils.debug.messageEnabled()) {
        UpgradeUtils.debug.message("calculateServiceModifications returning " + (!(modifications.isEmpty())));
    }
    return !(modifications.isEmpty());
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceSchemaModificationWrapper(org.forgerock.openam.upgrade.ServiceSchemaModificationWrapper) ServiceSchemaUpgradeWrapper(org.forgerock.openam.upgrade.ServiceSchemaUpgradeWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class ServiceSchemaModifications method createServiceModifications.

/**
     * This will use the service schemas to find any upgrade handlers registered for the service and
     * populate the NewServiceWrapper's ServiceSchemaModificationWrappers.
     * @param newSchemaMap The service schemas representing the service.
     * @throws UpgradeException If an upgrade error occurs.
     */
private void createServiceModifications(Map<String, ServiceSchemaImpl> newSchemaMap) throws UpgradeException {
    try {
        final Map<String, ServiceSchemaModificationWrapper> serviceSchemaMap = new HashMap<String, ServiceSchemaModificationWrapper>();
        for (Map.Entry<String, ServiceSchemaImpl> newAttrSchemaEntry : newSchemaMap.entrySet()) {
            final ServiceSchemaModificationWrapper attributesAdded = getServiceModificationsRecursive(newAttrSchemaEntry.getKey(), newAttrSchemaEntry.getValue());
            if (attributesAdded.hasBeenModified()) {
                serviceSchemaMap.put(newAttrSchemaEntry.getKey(), attributesAdded);
            }
        }
        newServiceWrapper = new NewServiceWrapper(serviceName, serviceSchemaMap, serviceSchemaDoc);
    } catch (SMSException smse) {
        UpgradeUtils.debug.error("Error whilst determining schema changes for service: " + serviceName, smse);
        throw new UpgradeException(smse.getMessage(), smse);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceSchemaModificationWrapper(org.forgerock.openam.upgrade.ServiceSchemaModificationWrapper) HashMap(java.util.HashMap) NewServiceWrapper(org.forgerock.openam.upgrade.NewServiceWrapper) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

UpgradeException (org.forgerock.openam.upgrade.UpgradeException)81 SSOException (com.iplanet.sso.SSOException)29 HashMap (java.util.HashMap)27 SMSException (com.sun.identity.sm.SMSException)25 Set (java.util.Set)25 HashSet (java.util.HashSet)22 Map (java.util.Map)22 ServiceConfig (com.sun.identity.sm.ServiceConfig)21 EntitlementException (com.sun.identity.entitlement.EntitlementException)16 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)14 Application (com.sun.identity.entitlement.Application)10 IOException (java.io.IOException)10 PolicyManager (com.sun.identity.policy.PolicyManager)8 PolicyException (com.sun.identity.policy.PolicyException)6 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)6 EntitlementUtils.resourceTypeFromMap (org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)6 Node (org.w3c.dom.Node)5 ServiceSchema (com.sun.identity.sm.ServiceSchema)4 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)4 Properties (java.util.Properties)4