bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: AMDynamicGroupImpl.java,v 1.5 2009/01/28 05:34:47 ww203982 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyrighted 2011-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.am.sdk;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.DN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The <code>AMDynamicGroupImpl</code> implements interface
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>AMDynamicGroup</code> dynamic group.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @deprecated As of Sun Java System Access Manager 7.1.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass AMDynamicGroupImpl extends AMGroupImpl implements AMDynamicGroup {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public AMDynamicGroupImpl(SSOToken ssoToken, String dn) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster super(ssoToken, dn, DYNAMIC_GROUP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the filter for the dynamic group.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the filter for the dynamic group.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws AMException if an error is encountered when trying to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * access/retrieve data from the data store.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the single sign on token is no longer valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getFilter() throws AMException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] array = dsServices.getGroupFilterAndScope(token, entryDN,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster profileType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (array[2]);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the the filter for the dynamic group.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param filter the dynamic group filter.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws AMException if an error is encountered when trying to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * access/retrieve data from the data store.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the single sign on token is no longer valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setFilter(String filter) throws AMException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dsServices.setGroupFilter(token, entryDN, filter);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster setACI();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the aci and the role aci value for the dynamic group.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void setACI() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington DN thisDN = DN.valueOf(entryDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String orgDN = this.getOrganizationDN();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String roleDN = AMNamingAttrManager.getNamingAttr(AMObject.ROLE)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "=" + thisDN.toString().replace(',', '_') + "," + orgDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMStoreConnection amsc = new AMStoreConnection(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMRole gRole = amsc.getRole(roleDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set aciValue = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster aciValue = gRole.getAttribute("iplanet-am-role-aci-list");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator iter = aciValue.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set newACIValue = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (iter.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String aci = (String) iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int indx = aci.indexOf("iplanet-am-static-group-dn=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (indx < 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster newACIValue.add(aci);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String targetFilter = aci.substring(0, indx);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String restACI = aci.substring(aci.indexOf("(|(nsroledn"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder sb = new StringBuilder();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sb.append(targetFilter).append(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iplanet-am-static-group-dn=*").append(entryDN)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(")").append(this.getFilter()).append("))")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(restACI);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster newACIValue.add(sb.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster HashMap avPairs = new HashMap(1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster avPairs.put("iplanet-am-role-aci-list", newACIValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster gRole.setAttributes(avPairs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster gRole.store();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (AMException ame) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.warningEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("error setting attribute ", ame);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException soe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Error in SSO Token");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (AMException amex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.warningEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Could not set aci " + amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException soe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Error in SSO Token" + soe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}