AjaxProxy.jsp revision 76ca7aa420bce98964cdb3245393b1c8416fa938
11e9368a226272085c337e9e74b79808c16fbdbaTinderbox User DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews The contents of this file are subject to the terms
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews of the Common Development and Distribution License
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (the License). You may not use this file except in
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews compliance with the License.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews You can obtain a copy of the License at
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews https://opensso.dev.java.net/public/CDDLv1.0.html or
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews See the License for the specific language governing
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews permission and limitations under the License.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews When distributing Covered Code, include this CDDL
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Header Notice in each file and include the License file
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews If applicable, add the following below the CDDL Header,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User with the fields enclosed by brackets [] replaced by
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt your own identifying information:
cd32f419a8a5432fbb139f56ee73cbf68b9350ccTinderbox User "Portions Copyrighted [year] [name of copyright owner]"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews $Id: AjaxProxy.jsp,v 1.7 2009/08/04 20:50:49 asyhuang Exp $
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Portions Copyrighted 2012-2014 ForgeRock AS
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews Portions Copyrighted 2012 Open Source Solution Technology Corporation
0c6ada0a814f3c5417daa1654129bc2af56ed504Automatic Updater<%@page import="com.iplanet.am.util.SystemProperties"%>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@page import="com.iplanet.sso.SSOToken"%>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@page import="com.iplanet.sso.SSOTokenManager"%>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@page import="com.sun.identity.idm.AMIdentity"%>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@page import="com.sun.identity.idm.IdRepoException"%>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@page import="com.sun.identity.security.AdminTokenAction"%>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<%@page import="com.sun.identity.console.base.AMViewBeanBase" %>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@page import="com.sun.identity.workflow.ITask" %>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<%@page import="com.sun.identity.workflow.WorkflowException" %>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@page import="java.security.AccessController"%>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<%@page import="java.util.*" %>
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews<%@ page import="org.owasp.esapi.ESAPI" %>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User<%@ page import="com.sun.identity.shared.debug.Debug" %>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User response.setContentType("text/plain; charset=UTF-8");
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User String locale = request.getParameter("locale");
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User if (!ESAPI.validator().isValidInput("HTTP Parameter Value: " + locale, locale, "HTTPParameterValue", 200,
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt locale = null;
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt Locale resLocale = null;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if ((locale != null) && (!locale.isEmpty())) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews StringTokenizer st = new StringTokenizer(locale, "|");
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (cnt == 1) {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User resLocale = new Locale(st.nextToken());
b2f07642fd712c8fda81a116bcdde229ab291f33Tinderbox User } else if (cnt == 2) {
b2f07642fd712c8fda81a116bcdde229ab291f33Tinderbox User resLocale = new Locale(st.nextToken(), st.nextToken());
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt resLocale = new Locale(st.nextToken(), st.nextToken(),
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews String amadminUUID = null;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews String adminUser = SystemProperties.get(
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User "com.sun.identity.authentication.super.user");
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if (adminUser != null) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews SSOToken adminToken = (SSOToken) AccessController.doPrivileged(
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews AMIdentity adminUserId = new AMIdentity(adminToken, adminUser,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User SSOTokenManager manager = SSOTokenManager.getInstance();
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User SSOToken ssoToken = manager.createSSOToken(request);
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User if (!manager.isValidToken(ssoToken)) {
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User String redirectUrl = request.getScheme() + "://" +
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews AMIdentity user = new AMIdentity(ssoToken);
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User if (!user.getUniversalId().equalsIgnoreCase(amadminUUID)) {
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User ResourceBundle rb = null;
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User String RB_NAME = "workflowMessages";
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User com.sun.identity.shared.debug.Debug.getInstance("workflowMessages");
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User rb = ResourceBundle.getBundle(RB_NAME, resLocale);
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User String msg = com.sun.identity.shared.locale.Locale.getString(
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews throw new RuntimeException(msg);
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User } catch (SSOException ssoe) {
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt String redirectUrl = request.getScheme() + "://" +
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User } catch (IdRepoException ex) {
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User String redirectUrl = request.getScheme() + "://" +
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User String clazzName = request.getParameter("class");
6d45011a65dfc43f476ca15c3fd9ee5227eb968fTinderbox User if (clazzName == null || !ESAPI.validator().isValidInput("HTTP Parameter Value: " + clazzName,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User clazzName, "HTTPParameterValue", 2000, false)) {
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt String redirectUrl = request.getScheme() + "://" +
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User Class clazz = Class.forName(clazzName);
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User ITask task = (ITask) clazz.newInstance();
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User Map map = new HashMap();
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt String n = (String) e.nextElement();
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User if (!n.equals("class") && !n.equals("locale")) {
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User map.put("_servlet_context_", getServletConfig().getServletContext());
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User map.put("_request_", request);
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User out.println("0|" + task.execute(resLocale, map));
659d063f23a35d77ad5826e6556d3137672bb937Tinderbox User } catch (WorkflowException e) {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User ESAPI.encoder().encodeForHTML(e.getL10NMessage(resLocale))));
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews } catch (IllegalAccessException e) {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User out.write("1|" + ESAPI.encoder().encodeForHTML(e.getMessage()));
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User } catch (InstantiationException e) {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User out.write("1|" + ESAPI.encoder().encodeForHTML(e.getMessage()));
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User } catch (ClassNotFoundException e) {
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt out.write("1|" + ESAPI.encoder().encodeForHTML(e.getMessage()));
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt } catch (ClassCastException e) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews out.write("1|" + ESAPI.encoder().encodeForHTML(e.getMessage()));
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User } catch (Exception e) {
0ccb0e98c77a9b9636a036f8f64f5679a430aaf4Tinderbox User Debug.getInstance("workflow").error("Uncaught exception in AjaxProxy", e);