AjaxProxy.jsp revision 984ea967792540448d05fba2ac6fad5dadf91fd6
2453N/A<%--
3211N/A DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2453N/A
2453N/A Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
2453N/A
2453N/A The contents of this file are subject to the terms
2453N/A of the Common Development and Distribution License
2453N/A (the License). You may not use this file except in
2453N/A compliance with the License.
2453N/A
2453N/A You can obtain a copy of the License at
2453N/A https://opensso.dev.java.net/public/CDDLv1.0.html or
2453N/A opensso/legal/CDDLv1.0.txt
2453N/A See the License for the specific language governing
2453N/A permission and limitations under the License.
2453N/A
2453N/A When distributing Covered Code, include this CDDL
2453N/A Header Notice in each file and include the License file
2453N/A at opensso/legal/CDDLv1.0.txt.
2453N/A If applicable, add the following below the CDDL Header,
2453N/A with the fields enclosed by brackets [] replaced by
2453N/A your own identifying information:
2453N/A "Portions Copyrighted [year] [name of copyright owner]"
2453N/A
2453N/A $Id: AjaxProxy.jsp,v 1.7 2009/08/04 20:50:49 asyhuang Exp $
2453N/A
2453N/A--%>
2453N/A<%@page import="com.iplanet.am.util.SystemProperties"%>
2453N/A<%@page import="com.iplanet.sso.SSOException"%>
2453N/A<%@page import="com.iplanet.sso.SSOToken"%>
2453N/A<%@page import="com.iplanet.sso.SSOTokenManager"%>
2453N/A<%@page import="com.sun.identity.idm.AMIdentity"%>
2453N/A<%@page import="com.sun.identity.idm.IdRepoException"%>
2453N/A<%@page import="com.sun.identity.idm.IdType"%>
2453N/A<%@page import="com.sun.identity.security.AdminTokenAction"%>
2453N/A<%@page import="com.sun.identity.console.base.AMViewBeanBase" %>
2453N/A<%@page import="com.sun.identity.workflow.ITask" %>
2453N/A<%@page import="com.sun.identity.workflow.WorkflowException" %>
2453N/A<%@page import="java.security.AccessController"%>
2453N/A<%@page import="java.util.*" %>
2453N/A
2453N/A<%
2453N/A
2453N/A request.setCharacterEncoding("UTF-8");
2453N/A String locale = request.getParameter("locale");
2453N/A Locale resLocale = null;
3127N/A if ((locale != null) && (locale.length() > 0)) {
3863N/A StringTokenizer st = new StringTokenizer(locale, "|");
2453N/A int cnt = st.countTokens();
2453N/A if (cnt == 1) {
2453N/A resLocale = new Locale(st.nextToken());
2453N/A } else if (cnt == 2) {
2453N/A resLocale = new Locale(st.nextToken(), st.nextToken());
2453N/A } else {
2453N/A resLocale = new Locale(st.nextToken(), st.nextToken(),
2453N/A st.nextToken());
2453N/A }
2453N/A } else {
2453N/A resLocale = Locale.US;
2453N/A }
2453N/A
2453N/A
2453N/A String amadminUUID = null;
2453N/A String adminUser = SystemProperties.get(
2453N/A "com.sun.identity.authentication.super.user");
2453N/A if (adminUser != null) {
2453N/A SSOToken adminToken = (SSOToken) AccessController.doPrivileged(
2453N/A AdminTokenAction.getInstance());
2453N/A AMIdentity adminUserId = new AMIdentity(adminToken, adminUser,
2453N/A IdType.USER, "/", null);
2453N/A amadminUUID = adminUserId.getUniversalId();
2453N/A }
2453N/A
2453N/A try {
2453N/A SSOTokenManager manager = SSOTokenManager.getInstance();
2453N/A SSOToken ssoToken = manager.createSSOToken(request);
2453N/A
2453N/A if (!manager.isValidToken(ssoToken)) {
2453N/A String redirectUrl = request.getScheme() + "://" +
2453N/A request.getServerName() + ":" +
2453N/A request.getServerPort() +
2453N/A request.getContextPath();
2453N/A response.sendRedirect(redirectUrl);
2453N/A return;
2453N/A }
2453N/A
2453N/A AMIdentity user = new AMIdentity(ssoToken);
2453N/A if (!user.getUniversalId().equalsIgnoreCase(amadminUUID)) {
2453N/A
2453N/A ResourceBundle rb = null;
2453N/A String RB_NAME = "workflowMessages";
2453N/A com.sun.identity.shared.debug.Debug debug =
2453N/A com.sun.identity.shared.debug.Debug.getInstance("workflowMessages");
2453N/A rb = ResourceBundle.getBundle(RB_NAME, resLocale);
2453N/A String msg = com.sun.identity.shared.locale.Locale.getString(
2453N/A rb, "ajax.user.privilege.invalid", debug);
2453N/A throw new RuntimeException(msg);
2453N/A }
2453N/A
2453N/A } catch (SSOException ssoe) {
2453N/A String redirectUrl = request.getScheme() + "://" +
2453N/A request.getServerName() + ":" +
2654N/A request.getServerPort() +
2654N/A request.getContextPath();
2654N/A response.sendRedirect(redirectUrl);
2654N/A return;
2654N/A } catch (IdRepoException ex) {
2654N/A String redirectUrl = request.getScheme() + "://" +
2654N/A request.getServerName() + ":" +
2654N/A request.getServerPort() +
2453N/A request.getContextPath() +
2654N/A "/base/AMUncaughtException";
2453N/A response.sendRedirect(redirectUrl);
2453N/A return;
2453N/A }
2453N/A
2453N/A String clazzName = request.getParameter("class");
2453N/A if (clazzName == null) {
2453N/A String redirectUrl = request.getScheme() + "://" +
2453N/A request.getServerName() + ":" +
2453N/A request.getServerPort() +
2453N/A request.getContextPath() +
2453N/A "/base/AMUncaughtException";
2453N/A response.sendRedirect(redirectUrl);
2453N/A return;
2453N/A }
2453N/A try {
2453N/A Class clazz = Class.forName(clazzName);
2453N/A ITask task = (ITask) clazz.newInstance();
2453N/A
2453N/A Map map = new HashMap();
2453N/A for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
2453N/A String n = (String) e.nextElement();
2453N/A if (!n.equals("class") && !n.equals("locale")) {
2453N/A map.put(n, request.getParameter(n));
2654N/A }
2453N/A }
2453N/A
2453N/A map.put("_servlet_context_", getServletConfig().getServletContext());
2453N/A map.put("_request_", request);
2453N/A out.println("0|" + task.execute(resLocale, map));
2453N/A } catch (WorkflowException e) {
2453N/A out.write("1|" + AMViewBeanBase.stringToHex(
2453N/A e.getL10NMessage(resLocale)));
2453N/A } catch (IllegalAccessException e) {
2453N/A out.write("1|" + e.getMessage());
2453N/A } catch (InstantiationException e) {
2453N/A out.write("1|" + e.getMessage());
2453N/A } catch (ClassNotFoundException e) {
2453N/A out.write("1|" + e.getMessage());
2453N/A }
2453N/A
2453N/A%>
2453N/A