Example usage for org.apache.wicket.util.crypt ICrypt decryptUrlSafe

List of usage examples for org.apache.wicket.util.crypt ICrypt decryptUrlSafe

Introduction

In this page you can find the example usage for org.apache.wicket.util.crypt ICrypt decryptUrlSafe.

Prototype

String decryptUrlSafe(final String text);

Source Link

Document

Decrypts a string using URL and filename safe Base64 decoding.

Usage

From source file:com.servoy.j2db.server.headlessclient.dataui.InlineScriptExecutorBehavior.java

License:Open Source License

@Override
protected void respond(AjaxRequestTarget target) {
    Page page = component.getPage();// w w w  .  j av a  2s .com
    String scriptName = RequestCycle.get().getRequest().getParameter("snenc");

    ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
    scriptName = urlCrypt.decryptUrlSafe(scriptName).replace("\\\"", "\"");

    String argValue;
    for (String browserArgument : getBrowserArguments(scriptName)) {
        argValue = RequestCycle.get().getRequest().getParameter(browserArgument);
        if (argValue == null)
            argValue = "";
        boolean isString = true;
        try {
            Double.parseDouble(argValue);
            isString = false;
        } catch (NumberFormatException ex) {
        }
        if (isString && ("true".equals(argValue) || "false".equals(argValue)))
            isString = false;
        String browserParamWithArgument = BROWSER_PARAM + browserArgument;

        // make sure we ignore user quoting if isString 
        if (isString) {
            scriptName = scriptName.replace("\"" + browserParamWithArgument + "\"", browserParamWithArgument);
            scriptName = scriptName.replace("'" + browserParamWithArgument + "'", browserParamWithArgument);
        }

        scriptName = scriptName.replace(browserParamWithArgument, isString ? "'" + argValue + "'" : argValue);
    }

    WebForm wf = component.findParent(WebForm.class);
    if (wf != null) {
        try {
            wf.getController().eval(scriptName);
        } catch (Exception e) {
            if (!(e instanceof ExitScriptException)) {
                Debug.error("Exception evaluating: " + scriptName, e); //$NON-NLS-1$
            }
        }
        WebEventExecutor.generateResponse(target, page);
    }
    target.appendJavascript("clearDoubleClickId('" + component.getMarkupId() + "')"); //$NON-NLS-1$ //$NON-NLS-2$      
}

From source file:com.servoy.j2db.server.headlessclient.dataui.StripHTMLTagsConverter.java

License:Open Source License

public static String getBlobLoaderUrlPart(Request request) {
    String url = request.getParameter(BLOB_LOADER_PARAM);
    if (url != null) {
        // old url
        if (url.equals("true")) //$NON-NLS-1$
        {/* w  w w  . j a  v a2s  . c om*/
            url = request.getURL();
        } else {
            // encrypted
            if (Application.exists()) {
                try {
                    ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
                    url = urlCrypt.decryptUrlSafe(url);
                    url = url.replace("&", "&"); //$NON-NLS-1$ //$NON-NLS-2$
                } catch (Exception e) {
                    Debug.error("Error decrypting blobloader url: " + url, e);
                }
            }
        }
    }
    return url;
}

From source file:sf.wicklet.ext.test.application.TestCrypt01.java

License:Apache License

@Test
public void test01() {
    final int COUNT = 1000;
    final String[] data = new String[COUNT];
    for (int i = 0; i < COUNT; ++i) {
        data[i] = randUtil.getString(0, 40);
    }// w w  w. ja va 2  s  .c o  m
    final ICrypt crypt = new DefaultWickletCrypt();
    for (int i = 0; i < COUNT; ++i) {
        final String e = crypt.encryptUrlSafe(data[i]);
        final String ret = crypt.decryptUrlSafe(e);
        if (DEBUG) {
            System.out.println("# " + i);
            System.out.println(data[i]);
            System.out.println(e);
            System.out.println(ret);
        }
        assertEquals(data[i], ret);
    }
}