0N/A/*
2362N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
0N/A * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the License). You may not use this file except in
0N/A * compliance with the License.
0N/A *
0N/A * You can obtain a copy of the License at
0N/A * https://opensso.dev.java.net/public/CDDLv1.0.html or
0N/A * opensso/legal/CDDLv1.0.txt
0N/A * See the License for the specific language governing
0N/A * permission and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * Header Notice in each file and include the License file
2362N/A * at opensso/legal/CDDLv1.0.txt.
2362N/A * If applicable, add the following below the CDDL Header,
2362N/A * with the fields enclosed by brackets [] replaced by
0N/A * your own identifying information:
0N/A * "Portions Copyrighted [year] [name of copyright owner]"
0N/A *
0N/A * $Id: RMRealmViewBean.java,v 1.3 2008/07/07 20:39:20 veiming Exp $
0N/A *
0N/A * Portions Copyrighted 2011-2015 ForgeRock AS.
0N/A */
0N/Apackage com.sun.identity.console.realm;
0N/A
0N/Aimport static com.sun.identity.console.XuiRedirectHelper.*;
0N/A
0N/Aimport javax.servlet.http.HttpServletRequest;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Collection;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.List;
0N/Aimport java.util.Set;
0N/A
2230N/Aimport com.iplanet.jato.model.ModelControlException;
2230N/Aimport com.iplanet.jato.view.View;
0N/Aimport com.iplanet.jato.view.event.DisplayEvent;
0N/Aimport com.iplanet.jato.view.event.RequestInvocationEvent;
0N/Aimport com.sun.identity.console.base.AMViewBeanBase;
0N/Aimport com.sun.identity.console.base.AMViewConfig;
2230N/Aimport com.sun.identity.console.base.model.AMAdminConstants;
2230N/Aimport com.sun.identity.console.base.model.AMConsoleException;
2230N/Aimport com.sun.identity.console.base.model.AMFormatUtils;
2230N/Aimport com.sun.identity.console.base.model.AMModel;
2230N/Aimport com.sun.identity.console.components.view.html.SerializedField;
2230N/Aimport com.sun.identity.console.realm.model.RMRealmModel;
2230N/Aimport com.sun.identity.console.realm.model.RMRealmModelImpl;
2230N/Aimport com.sun.identity.sm.SMSSchema;
2230N/Aimport com.sun.web.ui.model.CCActionTableModel;
2230N/Aimport com.sun.web.ui.model.CCPageTitleModel;
2230N/Aimport com.sun.web.ui.view.alert.CCAlert;
2230N/Aimport com.sun.web.ui.view.html.CCButton;
2230N/Aimport com.sun.web.ui.view.html.CCTextField;
0N/Aimport com.sun.web.ui.view.pagetitle.CCPageTitle;
0N/Aimport com.sun.web.ui.view.table.CCActionTable;
0N/A
0N/Apublic class RMRealmViewBean
0N/A extends RMRealmViewBeanBase
0N/A implements HasEntitiesTabs
0N/A{
0N/A public static final String DEFAULT_DISPLAY_URL =
0N/A "/console/realm/RMRealm.jsp";
0N/A
0N/A private static final String TBL_SEARCH = "tblSearch";
0N/A private static final String TF_FILTER = "tfFilter";
0N/A private static final String BTN_SEARCH = "btnSearch";
0N/A private static final String TBL_BUTTON_ADD = "tblButtonAdd";
0N/A private static final String TBL_BUTTON_DELETE = "tblButtonDelete";
0N/A
0N/A // name column
0N/A private static final String TBL_COL_NAME = "tblColName";
0N/A private static final String TBL_DATA_ACTION_HREF = "tblDataActionHref";
0N/A private static final String TBL_DATA_NAME = "tblDataName";
0N/A
0N/A // location column
0N/A private static final String TBL_COL_PATH = "tblColPath";
0N/A private static final String TBL_DATA_PATH = "tblDataPath";
0N/A
0N/A private static final String PAGETITLE = "pgtitle";
0N/A
0N/A private CCActionTableModel tblModel = null;
0N/A private CCPageTitleModel ptModel;
0N/A
0N/A /**
0N/A * Creates a authentication domains view bean.
0N/A */
0N/A public RMRealmViewBean() {
0N/A super("RMRealm");
0N/A setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
0N/A createTableModel();
0N/A ptModel = new CCPageTitleModel(
0N/A getClass().getClassLoader().getResourceAsStream(
0N/A "com/sun/identity/console/simplePageTitle.xml"));
0N/A registerChildren();
0N/A }
0N/A
0N/A protected void registerChildren() {
0N/A super.registerChildren();
0N/A registerChild(TF_FILTER, CCTextField.class);
0N/A registerChild(BTN_SEARCH, CCButton.class);
0N/A registerChild(PAGETITLE, CCPageTitle.class);
0N/A registerChild(TBL_SEARCH, CCActionTable.class);
0N/A ptModel.registerChildren(this);
0N/A tblModel.registerChildren(this);
0N/A }
0N/A
0N/A protected View createChild(String name) {
0N/A View view = null;
0N/A
0N/A if (name.equals(TBL_SEARCH)) {
0N/A SerializedField szCache = (SerializedField)getChild(SZ_CACHE);
0N/A populateTableModel((List)szCache.getSerializedObj());
0N/A view = new CCActionTable(this, tblModel, name);
0N/A } else if (name.equals(PAGETITLE)) {
0N/A view = new CCPageTitle(this, ptModel, name);
0N/A } else if (tblModel.isChildSupported(name)) {
0N/A view = tblModel.createChild(this, name);
0N/A } else {
0N/A view = super.createChild(name);
0N/A }
0N/A
0N/A return view;
0N/A }
0N/A
0N/A public void beginDisplay(DisplayEvent event) throws ModelControlException {
0N/A if (!isJatoSessionRequestFromXUI(getRequestContext().getRequest()) && isXuiAdminConsoleEnabled()) {
0N/A String redirectRealm = getAdministeredRealm(this);
0N/A String authenticationRealm = getAuthenticationRealm(this);
0N/A redirectToXui(getRequestContext().getRequest(), redirectRealm, authenticationRealm, "realms/");
0N/A return;
2612N/A }
0N/A super.beginDisplay(event);
0N/A resetButtonState(TBL_BUTTON_DELETE);
2612N/A getRealmNames();
2612N/A }
0N/A
0N/A protected AMModel getModelInternal() {
0N/A HttpServletRequest req = getRequestContext().getRequest();
0N/A return new RMRealmModelImpl(req, getPageSessionAttributes());
0N/A }
0N/A
0N/A private void createTableModel() {
0N/A tblModel = new CCActionTableModel(
0N/A getClass().getClassLoader().getResourceAsStream(
0N/A "com/sun/identity/console/tblRMRealm.xml"));
0N/A tblModel.setTitleLabel("label.items");
0N/A tblModel.setActionValue(TBL_BUTTON_ADD, "table.realm.button.new");
0N/A tblModel.setActionValue(TBL_BUTTON_DELETE, "table.realm.button.delete");
0N/A tblModel.setActionValue(TBL_COL_NAME, "table.realm.name.column.name");
0N/A tblModel.setActionValue(TBL_COL_PATH, "table.realm.path.column.name");
0N/A }
0N/A
0N/A private void getRealmNames() {
0N/A RMRealmModel model = (RMRealmModel)getModel();
0N/A String filter = ((String)getDisplayFieldValue(TF_FILTER));
0N/A
0N/A if ((filter == null) || (filter.length() == 0)) {
0N/A filter = "*";
0N/A setDisplayFieldValue(TF_FILTER, "*");
0N/A } else {
0N/A filter = filter.trim();
0N/A }
0N/A
0N/A try {
0N/A String curRealm = (String)getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
0N/A populateTableModel(model.getRealmNames(curRealm, filter));
0N/A } catch (AMConsoleException e) {
0N/A setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error",
0N/A e.getMessage());
0N/A }
0N/A }
0N/A
0N/A private void populateTableModel(Collection realmNames) {
0N/A tblModel.clearAll();
0N/A SerializedField szCache = (SerializedField)getChild(SZ_CACHE);
0N/A RMRealmModel model = (RMRealmModel)getModel();
0N/A tblModel.setMaxRows(model.getPageSize());
0N/A
0N/A if ((realmNames != null) && !realmNames.isEmpty()) {
0N/A String curRealm = (String)getPageSessionAttribute(
0N/A AMAdminConstants.CURRENT_REALM);
0N/A List cache = new ArrayList(realmNames.size());
0N/A boolean firstEntry = true;
0N/A String startDN = model.getStartDN();
0N/A int counter = 0;
0N/A
0N/A for (Iterator iter = realmNames.iterator(); iter.hasNext();
0N/A counter++
0N/A ) {
0N/A if (firstEntry) {
0N/A firstEntry = false;
0N/A } else {
0N/A tblModel.appendRow();
0N/A }
0N/A
0N/A String name = (String)iter.next();
0N/A String fqName = null;
0N/A String displayName = null;
0N/A
0N/A if (name.equals(startDN)) {
0N/A tblModel.setSelectionVisible(counter, false);
0N/A fqName = name;
0N/A displayName = AMFormatUtils.DNToName(
0N/A model, model.getStartDSDN());
0N/A } else {
0N/A int idx = name.lastIndexOf('/');
0N/A displayName = (idx == -1) ? name : name.substring(idx+1);
0N/A tblModel.setSelectionVisible(counter, true);
0N/A fqName = name;
0N/A }
0N/A
0N/A
0N/A /*
0N/A * Set name column info. Need to unescape the value as it
0N/A * may contain a '/' character.
0N/A */
0N/A tblModel.setValue(TBL_DATA_ACTION_HREF, stringToHex(fqName));
0N/A tblModel.setValue(TBL_DATA_NAME,
0N/A SMSSchema.unescapeName(displayName));
0N/A
0N/A // set location column info
0N/A tblModel.setValue(TBL_DATA_PATH, getPath(name));
0N/A
0N/A cache.add(name);
0N/A }
0N/A szCache.setValue((ArrayList)cache);
0N/A } else {
0N/A szCache.setValue(null);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Handles search request.
0N/A *
0N/A * @param event Request Invocation Event.
0N/A */
0N/A public void handleBtnSearchRequest(RequestInvocationEvent event) {
0N/A forwardTo();
0N/A }
0N/A
0N/A /**
0N/A * Forwards request to creation view bean.
0N/A *
0N/A * @param event Request Invocation Event.
2557N/A */
2557N/A public void handleTblButtonAddRequest(RequestInvocationEvent event) {
0N/A RMRealmAddViewBean vb = (RMRealmAddViewBean)getViewBean(
0N/A RMRealmAddViewBean.class);
0N/A unlockPageTrail();
0N/A passPgSessionMap(vb);
0N/A vb.forwardTo(getRequestContext());
0N/A }
0N/A
0N/A /**
0N/A * Deletes realms.
0N/A *
0N/A * @param event Request Invocation Event.
2230N/A * @throws ModelControlException if table model cannot be restored.
2230N/A */
2230N/A public void handleTblButtonDeleteRequest(RequestInvocationEvent event)
2230N/A throws ModelControlException
2230N/A {
2230N/A CCActionTable table = (CCActionTable)getChild(TBL_SEARCH);
2230N/A table.restoreStateData();
2230N/A String curRealm = (String)getPageSessionAttribute(
2230N/A AMAdminConstants.CURRENT_REALM);
0N/A
0N/A Integer[] selected = tblModel.getSelectedRows();
0N/A SerializedField szCache = (SerializedField)getChild(SZ_CACHE);
0N/A List list = (List)szCache.getSerializedObj();
0N/A Set names = new HashSet(selected.length *2);
0N/A
0N/A for (int i = 0; i < selected.length; i++) {
0N/A String name = (String)list.get(selected[i].intValue());
0N/A /*
0N/A * make sure the realm name starts with / to give it a
0N/A * fully qualified look. This value will be set in the log file
0N/A */
0N/A if (!name.startsWith("/")) {
0N/A name = "/" + name;
0N/A }
0N/A names.add(name);
0N/A }
0N/A
0N/A try {
0N/A RMRealmModel model = (RMRealmModel)getModel();
0N/A model.deleteSubRealms(curRealm, names);
0N/A
0N/A if (selected.length == 1) {
0N/A setInlineAlertMessage(CCAlert.TYPE_INFO, "message.information",
0N/A "realm.message.deleted");
0N/A } else {
0N/A setInlineAlertMessage(CCAlert.TYPE_INFO, "message.information",
0N/A "realm.message.deleted.pural");
0N/A }
0N/A } catch (AMConsoleException e) {
0N/A setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error",
0N/A e.getMessage());
0N/A }
0N/A
0N/A forwardTo();
0N/A }
0N/A
0N/A /**
0N/A * Handles edit realm request.
0N/A *
0N/A * @param event Request Invocation Event.
0N/A * @throws ModelControlException if table model cannot be restored.
0N/A */
0N/A public void handleTblDataActionHrefRequest(RequestInvocationEvent event)
0N/A throws ModelControlException
0N/A {
0N/A // store the current realm name and the current selected tab
0N/A // in the page session. Need to do this so after returning
0N/A // from profile object we get placed in the correct location.
0N/A String prevRealm = (String)getPageSessionAttribute(
0N/A AMAdminConstants.CURRENT_REALM);
0N/A setPageSessionAttribute(AMAdminConstants.PREVIOUS_REALM, prevRealm);
0N/A
0N/A String newRealm = hexToString(
0N/A (String)getDisplayFieldValue(TBL_DATA_ACTION_HREF));
0N/A setPageSessionAttribute(AMAdminConstants.CURRENT_REALM, newRealm);
0N/A setCurrentLocation(newRealm);
0N/A
0N/A // store the current selected tab in the page session
0N/A String tmp = (String)getPageSessionAttribute(getTrackingTabIDName());
0N/A setPageSessionAttribute(AMAdminConstants.PREVIOUS_TAB_ID, tmp);
0N/A
0N/A AMViewConfig config = AMViewConfig.getInstance();
0N/A RMRealmModel model = (RMRealmModel)getModel();
0N/A unlockPageTrail();
0N/A
0N/A try {
0N/A AMViewBeanBase vb = config.getTabViewBean(
0N/A this, newRealm, model, "realms", -1, -1);
0N/A passPgSessionMap(vb);
0N/A vb.forwardTo(getRequestContext());
0N/A } catch (AMConsoleException e) {
0N/A setPageSessionAttribute(AMAdminConstants.CURRENT_REALM, prevRealm);
0N/A removePageSessionAttribute(AMAdminConstants.PREVIOUS_TAB_ID);
0N/A setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error",
0N/A e.getMessage());
0N/A forwardTo();
0N/A }
0N/A }
0N/A
0N/A protected String getBreadCrumbDisplayName() {
0N/A return "breadcrumbs.realms";
0N/A }
0N/A}
0N/A