commit | author | age
|
7e5ee5
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
package com.gitblit.wicket;
|
|
17 |
|
70b492
|
18 |
import java.text.MessageFormat;
|
JM |
19 |
|
|
20 |
import org.apache.wicket.IRequestTarget;
|
7e5ee5
|
21 |
import org.apache.wicket.Page;
|
70b492
|
22 |
import org.apache.wicket.PageParameters;
|
JM |
23 |
import org.apache.wicket.request.RequestParameters;
|
7e5ee5
|
24 |
import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;
|
70b492
|
25 |
import org.slf4j.Logger;
|
JM |
26 |
import org.slf4j.LoggerFactory;
|
7e5ee5
|
27 |
|
JM |
28 |
import com.gitblit.GitBlit;
|
|
29 |
import com.gitblit.Keys;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Simple subclass of mixed parameter url coding strategy that works around the
|
|
33 |
* encoded forward-slash issue that is present in some servlet containers.
|
|
34 |
*
|
|
35 |
* https://issues.apache.org/jira/browse/WICKET-1303
|
|
36 |
* http://tomcat.apache.org/security-6.html
|
|
37 |
*
|
|
38 |
* @author James Moger
|
|
39 |
*
|
|
40 |
*/
|
|
41 |
public class GitblitParamUrlCodingStrategy extends MixedParamUrlCodingStrategy {
|
70b492
|
42 |
|
JM |
43 |
private Logger logger = LoggerFactory.getLogger(GitblitParamUrlCodingStrategy.class);
|
7e5ee5
|
44 |
|
JM |
45 |
/**
|
|
46 |
* Construct.
|
|
47 |
*
|
|
48 |
* @param <C>
|
|
49 |
* @param mountPath
|
|
50 |
* mount path (not empty)
|
|
51 |
* @param bookmarkablePageClass
|
|
52 |
* class of mounted page (not null)
|
|
53 |
* @param parameterNames
|
|
54 |
* the parameter names (not null)
|
|
55 |
*/
|
|
56 |
public <C extends Page> GitblitParamUrlCodingStrategy(String mountPath,
|
|
57 |
Class<C> bookmarkablePageClass, String[] parameterNames) {
|
|
58 |
super(mountPath, bookmarkablePageClass, parameterNames);
|
|
59 |
}
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Url encodes a string that is mean for a URL path (e.g., between slashes)
|
|
63 |
*
|
|
64 |
* @param string
|
|
65 |
* string to be encoded
|
|
66 |
* @return encoded string
|
|
67 |
*/
|
|
68 |
protected String urlEncodePathComponent(String string) {
|
|
69 |
char altChar = GitBlit.getChar(Keys.web.forwardSlashCharacter, '/');
|
|
70 |
if (altChar != '/') {
|
|
71 |
string = string.replace('/', altChar);
|
|
72 |
}
|
|
73 |
return super.urlEncodePathComponent(string);
|
|
74 |
}
|
|
75 |
|
|
76 |
/**
|
|
77 |
* Returns a decoded value of the given value (taken from a URL path
|
|
78 |
* section)
|
|
79 |
*
|
|
80 |
* @param value
|
|
81 |
* @return Decodes the value
|
|
82 |
*/
|
|
83 |
protected String urlDecodePathComponent(String value) {
|
|
84 |
char altChar = GitBlit.getChar(Keys.web.forwardSlashCharacter, '/');
|
|
85 |
if (altChar != '/') {
|
|
86 |
value = value.replace(altChar, '/');
|
|
87 |
}
|
|
88 |
return super.urlDecodePathComponent(value);
|
|
89 |
}
|
70b492
|
90 |
|
JM |
91 |
/**
|
|
92 |
* Gets the decoded request target.
|
|
93 |
*
|
|
94 |
* @param requestParameters
|
|
95 |
* the request parameters
|
|
96 |
* @return the decoded request target
|
|
97 |
*/
|
|
98 |
@Override
|
|
99 |
public IRequestTarget decode(RequestParameters requestParameters) {
|
|
100 |
final String parametersFragment = requestParameters.getPath().substring(
|
|
101 |
getMountPath().length());
|
|
102 |
logger.debug(MessageFormat
|
|
103 |
.format("REQ: {0} PARAMS {1}", getMountPath(), parametersFragment));
|
|
104 |
|
|
105 |
final PageParameters parameters = new PageParameters(decodeParameters(parametersFragment,
|
|
106 |
requestParameters.getParameters()));
|
|
107 |
return super.decode(requestParameters);
|
|
108 |
}
|
7e5ee5
|
109 |
} |