Search in sources :

Example 6 with Debug

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

the class JCECrypt method encode.

private static String encode(String clearText, AMEncryption encr) {
    if (clearText == null || clearText.length() == 0) {
        return null;
    }
    // Encrypt the data
    byte[] encData = null;
    try {
        encData = encr.encrypt(clearText.getBytes("utf-8"));
    } catch (UnsupportedEncodingException uee) {
        Debug debug = Debug.getInstance("amSDK");
        debug.error("Crypt:: utf-8 encoding is not supported");
        encData = encryptor.encrypt(clearText.getBytes());
    }
    // BASE64 encode the data
    String str = null;
    // Perf Improvement : Removed the sync block and newed up the Encoder
    // object for every call. Its a trade off b/w CPU and mem usage.
    str = Base64.encode(encData).trim();
    // Serialize the data, i.e., remove \n and \r
    BufferedReader bufReader = new BufferedReader(new StringReader(str));
    StringBuilder strClean = new StringBuilder(str.length());
    String strTemp = null;
    try {
        while ((strTemp = bufReader.readLine()) != null) {
            strClean.append(strTemp);
        }
    } catch (IOException ioe) {
        Debug debug = Debug.getInstance("amSDK");
        debug.error("Crypt:: Error while base64 encoding", ioe);
    }
    return (strClean.toString());
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Debug(com.sun.identity.shared.debug.Debug)

Example 7 with Debug

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

the class EmbeddedOpenDS method hash.

/**
     * Returns a one-way hash for passwd using SSHA512 scheme.
     *
     * @param p Clear password string
     * @return hash value
     */
public static String hash(String p) {
    String str = null;
    try {
        byte[] bb = p.getBytes();
        str = SaltedSHA512PasswordStorageScheme.encodeOffline(bb);
    } catch (Exception ex) {
        Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
        debug.error("EmbeddedOpenDS.hash failed : ex=" + ex);
    }
    return str;
}
Also used : ByteString(org.forgerock.opendj.ldap.ByteString) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException) Debug(com.sun.identity.shared.debug.Debug)

Example 8 with Debug

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

the class EmbeddedOpenDS method getOpenDSVersion.

public static String getOpenDSVersion() {
    Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
    String odsRoot = AMSetupServlet.getBaseDir() + "/" + SetupConstants.SMS_OPENDS_DATASTORE;
    String version = "unknown";
    File configLdif = new File(odsRoot + OPENDS_UPGRADE_DIR);
    File buildInfo = new File(odsRoot + "/" + "config" + "/" + SetupConstants.OPENDJ_BUILDINFO);
    if (configLdif.exists() && configLdif.isDirectory()) {
        String[] configFile = configLdif.list(new FilenameFilter() {

            //@Override -- Not Allowed Here.
            public boolean accept(File dir, String name) {
                return name.startsWith(OPENDS_CONFIG_LDIF);
            }
        });
        if (configFile.length != 0) {
            version = configFile[0].substring(configFile[0].lastIndexOf('.') + 1);
        } else {
            debug.error("Unable to determine OpenDJ version");
        }
    } else if (buildInfo.exists() && buildInfo.canRead() && buildInfo.isFile()) {
        String buildInfoVersionText = getOpenDJBuildInfo(buildInfo);
        if ((buildInfoVersionText != null) && (!buildInfoVersionText.isEmpty())) {
            version = buildInfoVersionText.trim();
        } else {
            debug.error("Unable to determine OpenDJ version");
        }
    } else {
        if (debug.warningEnabled()) {
            debug.warning("Unable to determine OpenDJ version; could be pre-config");
        }
    }
    if (debug.messageEnabled()) {
        debug.message("Found OpenDJ version: " + version);
    }
    return version;
}
Also used : FilenameFilter(java.io.FilenameFilter) ByteString(org.forgerock.opendj.ldap.ByteString) ZipFile(java.util.zip.ZipFile) File(java.io.File) Debug(com.sun.identity.shared.debug.Debug)

Example 9 with Debug

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

the class PooledTaskExecutorTest method testExecute.

@Test
public void testExecute() throws Exception {
    // Given
    ConnectionConfigFactory configFactory = mock(ConnectionConfigFactory.class);
    ConnectionConfig config = mock(ConnectionConfig.class);
    when(configFactory.getConfig(any(ConnectionType.class))).thenReturn(config);
    when(config.getMaxConnections()).thenReturn(2);
    Debug debug = mock(Debug.class);
    when(debug.messageEnabled()).thenReturn(true);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) throws Throwable {
            System.out.println(Thread.currentThread().getName() + ":: " + invocation.getArguments()[0]);
            return null;
        }
    }).when(debug).message(anyString());
    Provider<SimpleTaskExecutor> simpleTaskExecutorProvider = mock(Provider.class);
    when(simpleTaskExecutorProvider.get()).thenAnswer(new Answer<SimpleTaskExecutor<?>>() {

        public SimpleTaskExecutor<?> answer(InvocationOnMock invocation) throws Throwable {
            return new SimpleTaskExecutor<Object>(mock(ConnectionFactory.class), null, null);
        }
    });
    Semaphore semaphore = new Semaphore(2, true);
    // When
    final TaskExecutor executor = new PooledTaskExecutor(simpleTaskExecutorProvider, debug, ConnectionType.RESOURCE_SETS, configFactory, semaphore);
    LongTask longTask1 = new LongTask();
    TaskThread task1 = new TaskThread(1, executor, longTask1);
    LongTask longTask2 = new LongTask();
    TaskThread task2 = new TaskThread(2, executor, longTask2);
    TaskThread task3 = new TaskThread(3, executor, mock(Task.class));
    debug("Starting task 1");
    task1.start();
    debug("Starting task 2");
    task2.start();
    while (semaphore.availablePermits() > 0) {
        debug("Waiting for no available permits. Currently got: {0}", semaphore.availablePermits());
        Thread.sleep(50);
    }
    debug("Tasks 1 and 2 should now be executing and will shortly be blocked - starting task 3");
    task3.start();
    long timeout = System.currentTimeMillis() + 5000;
    while (!semaphore.hasQueuedThreads()) {
        debug("Waiting for task 3 to be queued on semaphore");
        Thread.sleep(50);
        if (System.currentTimeMillis() > timeout) {
            fail("Where did my thread go?");
        }
    }
    debug("Task 3 now queued on semaphore");
    // Then
    verifyZeroInteractions(task3.task);
    // When
    debug("Unblocking task 2");
    longTask2.unblock();
    debug("Unblocking task 1");
    longTask1.unblock();
    // Then
    debug("Waiting for tasks to complete");
    task1.join(TimeUnit.SECONDS.toMillis(10));
    task2.join(TimeUnit.SECONDS.toMillis(10));
    task3.join(TimeUnit.SECONDS.toMillis(10));
    assertThat(task1.isAlive()).as("Task 1 thread running").isFalse();
    assertThat(task2.isAlive()).as("Task 2 thread running").isFalse();
    assertThat(task3.isAlive()).as("Task 3 thread running").isFalse();
    verify(task3.task).execute(null, null);
    verify(simpleTaskExecutorProvider, times(2)).get();
    assertThat(semaphore.availablePermits()).isEqualTo(2);
}
Also used : Task(org.forgerock.openam.sm.datalayer.api.Task) ConnectionType(org.forgerock.openam.sm.datalayer.api.ConnectionType) ConnectionConfigFactory(org.forgerock.openam.sm.ConnectionConfigFactory) Semaphore(java.util.concurrent.Semaphore) TaskExecutor(org.forgerock.openam.sm.datalayer.api.TaskExecutor) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConnectionConfig(org.forgerock.openam.sm.ConnectionConfig) Debug(com.sun.identity.shared.debug.Debug) Test(org.testng.annotations.Test)

Example 10 with Debug

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

the class MailServerImplTest method setup.

@BeforeMethod
public void setup() {
    ServiceConfigManager serviceConfigManagerMock = PowerMockito.mock(ServiceConfigManager.class);
    ServiceConfig serviceConfigMock = PowerMockito.mock(ServiceConfig.class);
    Debug debugMock = PowerMockito.mock(Debug.class);
    sendMailMock = PowerMockito.mock(AMSendMail.class);
    Map<String, Set<String>> options = createOptionsMap();
    try {
        Mockito.doNothing().when(sendMailMock).postMail(eq(recipients), anyString(), anyString(), anyString());
        Mockito.doNothing().when(sendMailMock).postMail(eq(recipients), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyBoolean());
    } catch (MessagingException e) {
        assert (false);
    }
    mailServerMock = new MailServerImpl(serviceConfigManagerMock, serviceConfigMock, debugMock, sendMailMock, options);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) MessagingException(javax.mail.MessagingException) AMSendMail(com.iplanet.am.util.AMSendMail) Matchers.anyString(org.mockito.Matchers.anyString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) Debug(com.sun.identity.shared.debug.Debug) 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