Search in sources :

Example 1 with ICrypt

use of org.apache.wicket.util.crypt.ICrypt in project wicket by apache.

the class CryptTest method noCrypt.

/**
 */
@Test
public void noCrypt() {
    // The NoCrypt implementation does not modify the string at all
    final ICrypt crypt = new NoCrypt();
    assertEquals("test", crypt.encryptUrlSafe("test"));
    assertEquals("test", crypt.decryptUrlSafe("test"));
}
Also used : ICrypt(org.apache.wicket.util.crypt.ICrypt) NoCrypt(org.apache.wicket.util.crypt.NoCrypt) Test(org.junit.Test)

Example 2 with ICrypt

use of org.apache.wicket.util.crypt.ICrypt in project wicket by apache.

the class CryptTest method crypt.

@Test
public void crypt() {
    final ICrypt crypt = new SunJceCrypt();
    crypt.setKey("someStableKey");
    try {
        if (crypt.encryptUrlSafe("test") != null) {
            final String text = "abcdefghijkABC: A test which creates a '/' and/or a '+'";
            final String expectedUrlSafeEncrypted = "xXMS3UMELV--qVINGVFaYaiqUPOtryc_E4x0MyMFgYl-TgTGKxczTzPvwJrE-4YEVMpl-F3eDAg";
            final String encrypted = crypt.encryptUrlSafe(text);
            assertEquals(expectedUrlSafeEncrypted, encrypted);
            assertEquals(text, crypt.decryptUrlSafe(expectedUrlSafeEncrypted));
            assertNull(crypt.decryptUrlSafe("style.css"));
        }
    } catch (Exception ex) {
    // fails on JVMs without security provider (e.g. seems to be on
    // MAC in US)
    }
}
Also used : ICrypt(org.apache.wicket.util.crypt.ICrypt) SunJceCrypt(org.apache.wicket.util.crypt.SunJceCrypt) Test(org.junit.Test)

Example 3 with ICrypt

use of org.apache.wicket.util.crypt.ICrypt in project wicket by apache.

the class CryptoMapperTest method before.

/**
 * Creates the {@link CryptoMapper}
 *
 * @throws Exception
 */
@Before
public void before() throws Exception {
    tester = new WicketTester(HomePage.class);
    WebApplication application = tester.getApplication();
    application.mountPage(MOUNTED_URL, Page1.class);
    /**
     * Use explicit crypt provider to prevent crypt warning output, see
     * SecuritySettings#getCryptFactory()
     */
    Supplier<ICrypt> cryptProvider = new Supplier<ICrypt>() {

        private ICryptFactory cryptFactory = new CachingSunJceCryptFactory(SecuritySettings.DEFAULT_ENCRYPTION_KEY);

        @Override
        public ICrypt get() {
            return cryptFactory.newCrypt();
        }
    };
    mapper = new CryptoMapper(application.getRootRequestMapper(), cryptProvider);
}
Also used : ICryptFactory(org.apache.wicket.util.crypt.ICryptFactory) ICrypt(org.apache.wicket.util.crypt.ICrypt) CachingSunJceCryptFactory(org.apache.wicket.util.crypt.CachingSunJceCryptFactory) Supplier(java.util.function.Supplier) WicketTester(org.apache.wicket.util.tester.WicketTester) WebApplication(org.apache.wicket.protocol.http.WebApplication) Before(org.junit.Before)

Example 4 with ICrypt

use of org.apache.wicket.util.crypt.ICrypt in project wicket by apache.

the class KeyInSessionSunJceCryptFactory method newCrypt.

@Override
public ICrypt newCrypt() {
    Session session = Session.get();
    session.bind();
    // retrieve or generate encryption key from session
    String key = session.getMetaData(KEY);
    if (key == null) {
        // generate new key
        key = session.getId() + "." + UUID.randomUUID().toString();
        session.setMetaData(KEY, key);
    }
    // build the crypt based on session key
    ICrypt crypt = createCrypt();
    crypt.setKey(key);
    return crypt;
}
Also used : ICrypt(org.apache.wicket.util.crypt.ICrypt) Session(org.apache.wicket.Session)

Aggregations

ICrypt (org.apache.wicket.util.crypt.ICrypt)4 Test (org.junit.Test)2 Supplier (java.util.function.Supplier)1 Session (org.apache.wicket.Session)1 WebApplication (org.apache.wicket.protocol.http.WebApplication)1 CachingSunJceCryptFactory (org.apache.wicket.util.crypt.CachingSunJceCryptFactory)1 ICryptFactory (org.apache.wicket.util.crypt.ICryptFactory)1 NoCrypt (org.apache.wicket.util.crypt.NoCrypt)1 SunJceCrypt (org.apache.wicket.util.crypt.SunJceCrypt)1 WicketTester (org.apache.wicket.util.tester.WicketTester)1 Before (org.junit.Before)1