FileUpload.jsp revision 9740fa737ef2ed9453ab46d145777dbbbf6a747b
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%--
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync The contents of this file are subject to the terms
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync of the Common Development and Distribution License
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (the License). You may not use this file except in
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync You can obtain a copy of the License at
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync https://opensso.dev.java.net/public/CDDLv1.0.html or
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync opensso/legal/CDDLv1.0.txt
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync See the License for the specific language governing
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync permission and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync When distributing Covered Code, include this CDDL
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Header Notice in each file and include the License file
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync at opensso/legal/CDDLv1.0.txt.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync If applicable, add the following below the CDDL Header,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync with the fields enclosed by brackets [] replaced by
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync your own identifying information:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "Portions Copyrighted [year] [name of copyright owner]"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync $Id: FileUpload.jsp,v 1.4 2009/08/07 23:39:08 asyhuang Exp $
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync--%>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%--
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Portions Copyrighted 2012-2013 ForgeRock AS
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Portions Copyrighted 2012 Open Source Solution Technology Corporation
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync--%>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%@page import="com.iplanet.sso.SSOException"%>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%@page import="com.iplanet.sso.SSOToken"%>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%@page import="com.iplanet.sso.SSOTokenManager"%>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%@page import="java.io.*" %>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%@page import="java.util.*" %>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%@ page import="org.owasp.esapi.ESAPI" %>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync<%
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync request.setCharacterEncoding("UTF-8");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync response.setContentType("text/html; charset=UTF-8");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Locale resLocale = request.getLocale();
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (resLocale == null) {
resLocale = Locale.US;
}
try {
SSOTokenManager manager = SSOTokenManager.getInstance();
SSOToken ssoToken = manager.createSSOToken(request);
if (!manager.isValidToken(ssoToken)) {
return;
}
} catch (SSOException ssoe) {
String redirectUrl = request.getScheme() + "://" +
request.getServerName() + ":" +
request.getServerPort() +
request.getContextPath();
response.sendRedirect(redirectUrl);
return;
}
InputStream is = null;
BufferedReader bos = null;
try {
boolean limitExceeded = false;
StringBuffer buff = new StringBuffer();
is = request.getInputStream();
bos = new BufferedReader(new InputStreamReader(is));
String line = bos.readLine();
while (line != null) {
buff.append(line).append("\n");
line = bos.readLine();
if (buff.length() > (1024 * 50)) {
limitExceeded = true;
break;
}
}
if (limitExceeded) {
ResourceBundle rb = null;
String RB_NAME = "workflowMessages";
com.sun.identity.shared.debug.Debug debug =
com.sun.identity.shared.debug.Debug.getInstance("workflowMessages");
rb = ResourceBundle.getBundle(RB_NAME, resLocale);
String data = com.sun.identity.shared.locale.Locale.getString(
rb, "file.upload.size.limit.exceeded", debug);
out.println("<div id=\"data\">" + "Error: " + ESAPI.encoder().encodeForHTML(data) + "</div>");
} else {
// Parses a content-type String for the boundary.
String contentType = request.getContentType();
if (contentType == null) {
contentType = request.getHeader("Content-Type");
}
String boundary = "";
if (contentType != null && contentType.lastIndexOf("boundary=") != -1) {
boundary = contentType.substring(contentType.lastIndexOf("boundary=") + 9);
if (boundary.endsWith("\n")) {
boundary = boundary.substring(0, boundary.length()-1);
}
}
String data = buff.toString();
int idx = data.indexOf("filename=\"");
idx = data.indexOf("\n\n", idx);
data = data.substring(idx + 2);
idx = data.lastIndexOf("\n--" + boundary);
data = data.substring(0, idx);
data = data.replace("<", "&lt;");
data = data.replace(">", "&gt;");
out.println("<div id=\"data\">" + ESAPI.encoder().encodeForHTML(data) + "</div>");
}
} catch (IOException e) {
} finally {
try {
if (bos != null) {
bos.close();
}
} catch (IOException e) {
//ignore
}
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
//ignore
}
}
%>