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"));
}
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)
}
}
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);
}
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;
}
Aggregations