use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class AuthenticateToServiceConditionTest method setUp.
@BeforeMethod
public void setUp() {
Debug debug = mock(Debug.class);
coreWrapper = mock(CoreWrapper.class);
entitlementCoreWrapper = mock(EntitlementCoreWrapper.class);
condition = new AuthenticateToServiceCondition(debug, coreWrapper, entitlementCoreWrapper);
}
use of com.sun.identity.shared.debug.Debug in project OpenAM by OpenRock.
the class DebugLogTest method testDebug.
@Test
public void testDebug() {
Debug debug = Debug.getInstance("debugtest");
try {
String s = null;
s.equals("test");
} catch (NullPointerException e) {
debug.error("DebugLogTest.testDebug", e);
}
}
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.
}
}
}
}
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 });
}
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;
}
}
Aggregations