Search in sources :

Example 21 with Debug

use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.

the class ImportMetaData method importSAML2Metadata.

private List<String> importSAML2Metadata(SAML2MetaManager metaManager) throws SAML2MetaException, CLIException {
    List<String> result = null;
    InputStream is = null;
    String out = (webAccess) ? "web" : metadata;
    Object[] objs = { out };
    try {
        Document doc;
        Debug debug = CommandManager.getDebugger();
        if (webAccess) {
            doc = XMLUtils.toDOMDocument(metadata, debug);
        } else {
            is = new FileInputStream(metadata);
            doc = XMLUtils.toDOMDocument(is, debug);
        }
        if (doc == null) {
            throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-descriptor-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        result = SAML2MetaUtils.importSAML2Document(metaManager, realm, doc);
        if (result.isEmpty()) {
            throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-descriptor-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        return result;
    } catch (FileNotFoundException e) {
        throw new CLIException(MessageFormat.format(getResourceString("file-not-found"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (JAXBException e) {
        debugWarning("ImportMetaData.importMetaData", e);
        throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-descriptor-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IllegalArgumentException e) {
        debugWarning("ImportMetaData.importMetaData", e);
        throw new CLIException(MessageFormat.format(getResourceString("import-entity-exception-invalid-descriptor-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            //do not if the file cannot be closed.
            }
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) CLIException(com.sun.identity.cli.CLIException) Debug(com.sun.identity.shared.debug.Debug)

Example 22 with Debug

use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.

the class DefaultDebugRecorderTest method tryOneRecord.

@Test
public void tryOneRecord() throws RecordException, InvalidDebugConfigurationException, IOException {
    int issueID = 1;
    String referenceID = "first_record";
    //message ID, it helps to check which message are printed on logs
    int messageNb = 0;
    //Maps for checking the test results. We store every message ID by category
    Set<String> shouldBeInRootLogName = new HashSet<String>();
    Set<String> shouldBeInIssueIDLogName = new HashSet<String>();
    Set<String> shouldBeNotPrint = new HashSet<String>();
    JsonValue jsonRecordProperties = JsonValueBuilder.toJsonValue(IOUtils.getFileContentFromClassPath(DefaultDebugRecorderTest.class, RecordPropertiesTest.RECORD_DIRECTORY + "oneRecordFirstRecord.json"));
    //Initialize the debugger
    Debug debugTest = Debug.getInstance(logName);
    debugTest.setDebug(DebugLevel.ERROR.toString());
    // try some logs first, that should not be recorded
    shouldBeInRootLogName.add(messageNb + " -");
    debugTest.error(messageNb++ + " - Error not recorded");
    shouldBeNotPrint.add(messageNb + " -");
    debugTest.message(messageNb++ + " - message not recorded");
    //We start recording the issue
    recordDebugController.startRecording(jsonRecordProperties);
    //try some logs that should be recorded
    shouldBeInIssueIDLogName.add(messageNb + " -");
    debugTest.error(messageNb++ + " - Error recorded");
    shouldBeInIssueIDLogName.add(messageNb + " -");
    debugTest.message(messageNb++ + " - message recorded");
    // We stop recording
    recordDebugController.stopRecording();
    // try some logs after, that should not be recorded
    shouldBeInRootLogName.add(messageNb + " -");
    debugTest.error(messageNb++ + " - Error not recorded");
    shouldBeNotPrint.add(messageNb + " -");
    debugTest.message(messageNb++ + " - message not recorded");
    //Check everything is correctly generated
    Assert.assertTrue(checkRecordFolderIsCreated(issueID + ""), "Record folder '" + issueID + "' doesn't exist.");
    //We check now that every messages are in the right log file.
    String issueIDDebuglogFile = RecordConstants.RECORD_FOLDER_NAME + File.separator + issueID + File.separator + referenceID + File.separator + RecordConstants.DEBUG_FOLDER_NAME + File.separator + logName;
    checkLogMessagesAreInTheRightLogFiles(shouldBeInRootLogName, new String[] { logName }, new String[] { issueIDDebuglogFile });
    checkLogMessagesAreInTheRightLogFiles(shouldBeInIssueIDLogName, new String[] { issueIDDebuglogFile }, new String[] { logName });
    checkLogMessagesAreInTheRightLogFiles(shouldBeNotPrint, new String[] {}, new String[] { logName, issueIDDebuglogFile });
}
Also used : JsonValue(org.forgerock.json.JsonValue) Debug(com.sun.identity.shared.debug.Debug) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 23 with Debug

use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.

the class AMSetupServlet method getBootstrapLocator.

// this is the file which contains the base dir.
// this file is not created if configuration directory is 
// preset in bootstrap.properties
private static String getBootstrapLocator() throws ConfiguratorException {
    String configDir = getPresetConfigDir();
    if (configDir != null && configDir.length() > 0) {
        return null;
    }
    if (servletCtx != null) {
        String path = getNormalizedRealPath(servletCtx);
        if (path != null) {
            String home = System.getProperty("user.home");
            File newPath = new File(home + "/" + SetupConstants.CONFIG_VAR_BOOTSTRAP_BASE_DIR);
            File oldPath = new File(home + "/" + SetupConstants.CONFIG_VAR_BOOTSTRAP_LEGACY_BASE_DIR);
            String fullOldPath = oldPath.getPath() + "/" + SetupConstants.CONFIG_VAR_BOOTSTRAP_BASE_PREFIX + path;
            String fullNewPath = newPath.getPath() + "/" + SetupConstants.CONFIG_VAR_BOOTSTRAP_BASE_PREFIX + path;
            Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
            String bootstrapLocatorResult;
            // Simple case where just the old path exists.
            if (oldPath.exists() && !newPath.exists()) {
                bootstrapLocatorResult = fullOldPath;
                if (debug.messageEnabled()) {
                    debug.message("AMSetupServlet.getBootstrapLocator: only old path exists, returning old " + bootstrapLocatorResult);
                }
            // There is a chance that both new and old path locations exist when newer installations have been done
            // from scratch but the instance to consider is in the old path, double check for an old config before
            // returning the new path when finding both.
            } else if (oldPath.exists() && newPath.exists()) {
                // Test if we have a config file in the old path
                File testOldPath = new File(fullOldPath);
                if (testOldPath.exists()) {
                    bootstrapLocatorResult = fullOldPath;
                    if (debug.messageEnabled()) {
                        debug.message("AMSetupServlet.getBootstrapLocator: both old and new paths exist, found a " + "config in the old path, returning old " + bootstrapLocatorResult);
                    }
                } else {
                    bootstrapLocatorResult = fullNewPath;
                    if (debug.messageEnabled()) {
                        debug.message("AMSetupServlet.getBootstrapLocator: both old and new paths exist but did " + "not find a config in old path, returning new " + bootstrapLocatorResult);
                    }
                }
            } else {
                bootstrapLocatorResult = fullNewPath;
                if (debug.messageEnabled()) {
                    debug.message("AMSetupServlet.getBootstrapLocator: only new path exists, returning new " + bootstrapLocatorResult);
                }
            }
            return bootstrapLocatorResult;
        } else {
            throw new ConfiguratorException("Cannot read the bootstrap path");
        }
    } else {
        return null;
    }
}
Also used : File(java.io.File) IOUtils.writeToFile(org.forgerock.openam.utils.IOUtils.writeToFile) Debug(com.sun.identity.shared.debug.Debug)

Example 24 with Debug

use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.

the class SessionUtils method checkPermissionToSetProperty.

/**
     * Helper method to check if client has taken permission to
     * set value to it. If
     * @param clientToken Token of the client setting protected property.
     * @param key Property key
     * @param value Property value.
     * @throws SessionException if the key is protected property.
     */
public static void checkPermissionToSetProperty(SSOToken clientToken, String key, String value) throws SessionException {
    Debug sessionDebug = InjectorHolder.getInstance(Key.get(Debug.class, Names.named(SESSION_DEBUG)));
    if (InternalSession.isProtectedProperty(key)) {
        if (clientToken == null) {
            // Throw Ex. Client should identify itself.
            if (sessionDebug.warningEnabled()) {
                sessionDebug.warning("SessionUtils.checkPermissionToSetProperty(): " + "Attempt to set protected property without client " + "token [" + key + "=" + value + "]");
            }
            throw new SessionException(SessionBundle.getString("protectedPropertyNoClientToken") + " " + key);
        }
        SSOTokenManager ssoTokenManager = null;
        try {
            ssoTokenManager = SSOTokenManager.getInstance();
        } catch (SSOException ssoEx) {
            // Throw Ex. Not able to get SSOTokenManager instance.
            sessionDebug.error("SessionUtils.checkPermissionToSetProperty(): " + "Cannot get instance of SSOTokenManager.");
            throw new SessionException(SessionBundle.getString("protectedPropertyNoSSOTokenMgrInstance") + " " + key);
        }
        if (!ssoTokenManager.isValidToken(clientToken)) {
            // Throw Ex. Client should identify itself.
            if (sessionDebug.warningEnabled()) {
                sessionDebug.warning("SessionUtils.checkPermissionToSetProperty(): " + "Attempt to set protected property with invalid client" + " token [" + key + "=" + value + "]");
            }
            throw new SessionException(SessionBundle.getString("protectedPropertyInvalidClientToken") + " " + key);
        }
        SSOToken admToken = null;
        try {
            admToken = SessionUtils.getAdminToken();
        } catch (SSOException ssoEx) {
            // Throw Ex. Server not able to get Admin Token.
            sessionDebug.error("SessionUtils.checkPermissionToSetProperty(): " + "Cannot get Admin Token for validation to set protected " + "property [" + key + "=" + value + "]");
            throw new SessionException(SessionBundle.getString("protectedPropertyNoAdminToken") + " " + key);
        }
        if (!SessionUtils.isAdmin(admToken, clientToken)) {
            // Throw Ex. Client not authorized to set this property.
            sessionDebug.error("SessionUtils.checkPermissionToSetProperty(): " + "Client does not have permission to set protected " + "property" + key + "=" + value + "]");
            throw new SessionException(SessionBundle.getString("protectedPropertyNoPermission") + " " + key);
        }
    }
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) SessionException(com.iplanet.dpro.session.SessionException) SSOException(com.iplanet.sso.SSOException) Debug(com.sun.identity.shared.debug.Debug)

Example 25 with Debug

use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.

the class CTSMonitoringStoreImplTest method setUp.

@BeforeMethod
public void setUp() {
    tokenOperationsStore = mock(TokenOperationsStore.class);
    final ExecutorService executorService = mock(ExecutorService.class);
    final Debug debug = mock(Debug.class);
    reaperMonitor = mock(ReaperMonitor.class);
    connectionStore = mock(ConnectionStore.class);
    ctsOperationsMonitoringStore = new CTSMonitoringStoreImpl(executorService, tokenOperationsStore, reaperMonitor, connectionStore, debug);
    ctsReaperMonitoringStore = (CTSReaperMonitoringStore) ctsOperationsMonitoringStore;
    given(executorService.submit(any(Callable.class))).will(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) throws Throwable {
            Callable r = (Callable) invocation.getArguments()[0];
            r.call();
            return null;
        }
    });
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) ExecutorService(java.util.concurrent.ExecutorService) CTSMonitoringStoreImpl(org.forgerock.openam.cts.monitoring.impl.CTSMonitoringStoreImpl) TokenOperationsStore(org.forgerock.openam.cts.monitoring.impl.operations.TokenOperationsStore) ConnectionStore(org.forgerock.openam.cts.monitoring.impl.connections.ConnectionStore) ReaperMonitor(org.forgerock.openam.cts.monitoring.impl.reaper.ReaperMonitor) Debug(com.sun.identity.shared.debug.Debug) Callable(java.util.concurrent.Callable) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Debug (com.sun.identity.shared.debug.Debug)50 BeforeMethod (org.testng.annotations.BeforeMethod)15 IOException (java.io.IOException)14 ByteString (org.forgerock.opendj.ldap.ByteString)10 FileNotFoundException (java.io.FileNotFoundException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)7 HashSet (java.util.HashSet)6 LdapException (org.forgerock.opendj.ldap.LdapException)6 BufferedReader (java.io.BufferedReader)5 File (java.io.File)5 Subject (javax.security.auth.Subject)5 CoreWrapper (org.forgerock.openam.core.CoreWrapper)5 Test (org.testng.annotations.Test)5 StringReader (java.io.StringReader)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 SSOToken (com.iplanet.sso.SSOToken)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 ZipFile (java.util.zip.ZipFile)3