Search in sources :

Example 16 with Debug

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

the class AMIdentityMembershipConditionTest method setUp.

@BeforeMethod
public void setUp() {
    Debug debug = mock(Debug.class);
    coreWrapper = mock(CoreWrapper.class);
    condition = new AMIdentityMembershipCondition(debug, coreWrapper);
    adminToken = mock(SSOToken.class);
    given(coreWrapper.getAdminToken()).willReturn(adminToken);
}
Also used : CoreWrapper(org.forgerock.openam.core.CoreWrapper) SSOToken(com.iplanet.sso.SSOToken) Debug(com.sun.identity.shared.debug.Debug) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 17 with Debug

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

the class OpenAMTokenStoreTest method setUp.

@BeforeMethod
public void setUp() {
    tokenStore = mock(OAuthTokenStore.class);
    providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
    oAuth2UrisFactory = mock(OAuth2UrisFactory.class);
    clientRegistrationStore = mock(OpenIdConnectClientRegistrationStore.class);
    realmNormaliser = mock(RealmNormaliser.class);
    ssoTokenManager = mock(SSOTokenManager.class);
    request = mock(Request.class);
    cookieExtractor = mock(CookieExtractor.class);
    auditLogger = mock(OAuth2AuditLogger.class);
    debug = mock(Debug.class);
    failureFactory = mock(ClientAuthenticationFailureFactory.class);
    oAuth2RequestFactory = new RestletOAuth2RequestFactory(new JacksonRepresentationFactory(new ObjectMapper()));
    ClientAuthenticationFailureFactory failureFactory = mock(ClientAuthenticationFailureFactory.class);
    InvalidClientException expectedResult = mock(InvalidClientException.class);
    when(expectedResult.getError()).thenReturn(new String("invalid_client"));
    when(failureFactory.getException()).thenReturn(expectedResult);
    when(failureFactory.getException(anyString())).thenReturn(expectedResult);
    when(failureFactory.getException(any(OAuth2Request.class), anyString())).thenReturn(expectedResult);
    openAMtokenStore = new OpenAMTokenStore(tokenStore, providerSettingsFactory, oAuth2UrisFactory, clientRegistrationStore, realmNormaliser, ssoTokenManager, cookieExtractor, auditLogger, debug, new SecureRandom(), failureFactory);
}
Also used : OAuth2UrisFactory(org.forgerock.oauth2.core.OAuth2UrisFactory) SSOTokenManager(com.iplanet.sso.SSOTokenManager) JacksonRepresentationFactory(org.forgerock.openam.rest.representations.JacksonRepresentationFactory) RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) SecureRandom(java.security.SecureRandom) BDDMockito.anyString(org.mockito.BDDMockito.anyString) OpenIdConnectClientRegistrationStore(org.forgerock.openidconnect.OpenIdConnectClientRegistrationStore) ClientAuthenticationFailureFactory(org.forgerock.oauth2.core.exceptions.ClientAuthenticationFailureFactory) RealmNormaliser(org.forgerock.openam.utils.RealmNormaliser) RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) InvalidClientException(org.forgerock.oauth2.core.exceptions.InvalidClientException) RestletOAuth2RequestFactory(org.forgerock.oauth2.restlet.RestletOAuth2RequestFactory) Debug(com.sun.identity.shared.debug.Debug) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 18 with Debug

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

the class JCEEncryption method pbeEncrypt.

/**
     * Method declaration
     * 
     * @param clearText
     */
private byte[] pbeEncrypt(final byte[] clearText) {
    byte[] result = null;
    if (clearText == null || clearText.length == 0) {
        return null;
    }
    if (_initialized) {
        try {
            byte[] type = new byte[2];
            type[1] = (byte) DEFAULT_ENC_ALG_INDEX;
            type[0] = (byte) DEFAULT_KEYGEN_ALG_INDEX;
            final Cipher pbeCipher = cipherProvider.getCipher();
            if (pbeCipher != null) {
                pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParameterSpec);
                result = pbeCipher.doFinal(clearText);
                byte[] iv = pbeCipher.getIV();
                result = addPrefix(type, iv, result);
            } else {
                Debug debug = Debug.getInstance("amSDK");
                if (debug != null) {
                    debug.error("JCEEncryption: Failed to obtain Cipher");
                }
            }
        } catch (Exception ex) {
            Debug debug = Debug.getInstance("amSDK");
            if (debug != null) {
                debug.error("JCEEncryption:: failed to encrypt data", ex);
            }
        }
    } else {
        Debug debug = Debug.getInstance("amSDK");
        if (debug != null) {
            debug.error("JCEEncryption:: not yet initialized");
        }
    }
    return result;
}
Also used : Cipher(javax.crypto.Cipher) Debug(com.sun.identity.shared.debug.Debug)

Example 19 with Debug

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

the class JCEEncryption method pbeDecrypt.

/**
     * Method declaration
     * 
     * @param cipherText
     */
private byte[] pbeDecrypt(byte[] cipherText) {
    byte[] result = null;
    if (_initialized) {
        try {
            byte[] share = cipherText;
            if (share[0] != VERSION) {
                Debug debug = Debug.getInstance("amSDK");
                if (debug != null) {
                    debug.error("JCEEncryption:: Unsupported version: " + share[0]);
                }
                return null;
            }
            byte[] raw = getRaw(share);
            final Cipher pbeCipher = cipherProvider.getCipher();
            if (pbeCipher != null) {
                pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParameterSpec);
                result = pbeCipher.doFinal(raw);
            } else {
                Debug debug = Debug.getInstance("amSDK");
                if (debug != null) {
                    debug.error("JCEEncryption: Failed to obtain Cipher");
                }
            }
        } catch (Exception ex) {
            Debug debug = Debug.getInstance("amSDK");
            if (debug != null) {
                debug.error("JCEEncryption:: failed to decrypt data", ex);
            }
        }
    } else {
        Debug debug = Debug.getInstance("amSDK");
        if (debug != null) {
            debug.error("JCEEncryption:: not yet initialized");
        }
    }
    return result;
}
Also used : Cipher(javax.crypto.Cipher) Debug(com.sun.identity.shared.debug.Debug)

Example 20 with Debug

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

the class CLIUtil method getFileContent.

/**
     * Returns content of a file.
     *
     * @param mgr Command Line Manager.
     * @param fileName Name of file.
     * @param singleLine <code>true</code> to only read one line from the file.
     * @return content of a file.
     * @throws CLIException if file content cannot be returned.
     */
public static String getFileContent(CommandManager mgr, String fileName, boolean singleLine) throws CLIException {
    File test = new File(fileName);
    if (!test.exists()) {
        Object[] param = { fileName };
        throw new CLIException(MessageFormat.format(mgr.getResourceBundle().getString("error-message-file-does-not-exist"), param), ExitCodes.CANNOT_READ_FILE);
    }
    StringBuilder buff = new StringBuilder();
    BufferedReader in = null;
    try {
        in = new BufferedReader(new FileReader(fileName));
        if (in.ready()) {
            String line = in.readLine();
            while (line != null) {
                buff.append(line);
                if (singleLine) {
                    break;
                } else {
                    buff.append("\n");
                    line = in.readLine();
                }
            }
        }
    } catch (IOException e) {
        throw new CLIException(e.getMessage(), ExitCodes.CANNOT_READ_FILE);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
                Debug debugger = CommandManager.getDebugger();
                if (debugger.warningEnabled()) {
                    debugger.warning("cannot close file, " + fileName, e);
                }
            }
        }
    }
    return buff.toString();
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) SSOException(com.iplanet.sso.SSOException) Debug(com.sun.identity.shared.debug.Debug)

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