You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to publish to Liferay 6.2 EE, I have an exception
22:37:11,691 ERROR [http-bio-8080-exec-8][SecureFilter:115] java.lang.StringIndexOutOfBoundsException: String index out of range: 27
java.lang.StringIndexOutOfBoundsException: String index out of range: 27
at java.lang.String.charAt(String.java:658)
at com.liferay.portal.kernel.util.Base64.decode(Base64.java:52)
at com.liferay.portal.util.PortalImpl.getBasicAuthUserId(PortalImpl.java:1175)
at com.liferay.portal.util.PortalImpl.getBasicAuthUserId(PortalImpl.java:1156)
at com.liferay.portal.util.PortalUtil.getBasicAuthUserId(PortalUtil.java:281)
at com.liferay.portal.servlet.filters.secure.SecureFilter.basicAuth(SecureFilter.java:112)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:288)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
After some debugging, Liferay use a specific Base64Encoder... If i use the same, the publish process work.
Add the following code to PostFileUtil
public String encode(byte[] raw) {
return encode(raw, 0, raw.length);
}
public String encode(byte[] raw, int offset, int length) {
int lastIndex = Math.min(raw.length, offset + length);
StringBuilder sb = new StringBuilder(
((lastIndex - offset) / 3 + 1) * 4);
for (int i = offset; i < lastIndex; i += 3) {
sb.append(encodeBlock(raw, i, lastIndex));
}
return sb.toString();
}
protected char[] encodeBlock(byte[] raw, int offset, int lastIndex) {
int block = 0;
int slack = lastIndex - offset - 1;
int end = slack < 2 ? slack : 2;
for (int i = 0; i <= end; i++) {
byte b = raw[offset + i];
int neuter = b >= 0 ? ((int) (b)) : b + 256;
block += neuter << 8 * (2 - i);
}
char[] base64 = new char[4];
for (int i = 0; i < 4; i++) {
int sixbit = block >>> 6 * (3 - i) & 0x3f;
base64[i] = getChar(sixbit);
}
if (slack < 1) {
base64[2] = '=';
}
if (slack < 2) {
base64[3] = '=';
}
return base64;
}
protected static char getChar(int sixbit) {
if ((sixbit >= 0) && (sixbit <= 25)) {
return (char)(65 + sixbit);
}
if ((sixbit >= 26) && (sixbit <= 51)) {
return (char)(97 + (sixbit - 26));
}
if ((sixbit >= 52) && (sixbit <= 61)) {
return (char)(48 + (sixbit - 52));
}
if (sixbit == 62) {
return '+';
}
return sixbit != 63 ? '?' : '/';
}
and replace the line :
String encoding = Base64.encodeBase64URLSafeString((username + ":" + password).getBytes());
by
String encoding = encode((username + ":" + password).getBytes());
The text was updated successfully, but these errors were encountered:
EanDungey
pushed a commit
to EanDungey/liferay-deployer
that referenced
this issue
Aug 19, 2015
When I try to publish to Liferay 6.2 EE, I have an exception
22:37:11,691 ERROR [http-bio-8080-exec-8][SecureFilter:115] java.lang.StringIndexOutOfBoundsException: String index out of range: 27
java.lang.StringIndexOutOfBoundsException: String index out of range: 27
at java.lang.String.charAt(String.java:658)
at com.liferay.portal.kernel.util.Base64.decode(Base64.java:52)
at com.liferay.portal.util.PortalImpl.getBasicAuthUserId(PortalImpl.java:1175)
at com.liferay.portal.util.PortalImpl.getBasicAuthUserId(PortalImpl.java:1156)
at com.liferay.portal.util.PortalUtil.getBasicAuthUserId(PortalUtil.java:281)
at com.liferay.portal.servlet.filters.secure.SecureFilter.basicAuth(SecureFilter.java:112)
at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:288)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:59)
After some debugging, Liferay use a specific Base64Encoder... If i use the same, the publish process work.
Add the following code to PostFileUtil
public String encode(byte[] raw) {
return encode(raw, 0, raw.length);
}
public String encode(byte[] raw, int offset, int length) {
int lastIndex = Math.min(raw.length, offset + length);
and replace the line :
String encoding = Base64.encodeBase64URLSafeString((username + ":" + password).getBytes());
by
String encoding = encode((username + ":" + password).getBytes());
The text was updated successfully, but these errors were encountered: