ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni/*
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: DNOrIPAddressListTokenRestriction.java,v 1.7 2009/10/29 17:33:29 ericow Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni * Portions Copyrighted 2011-2016 ForgeRock AS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.dpro.session;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.net.InetAddress;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.net.UnknownHostException;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport java.util.ArrayList;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Collections;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.List;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.StringTokenizer;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.fasterxml.jackson.annotation.JsonIgnore;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.iplanet.am.util.Misc;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.iplanet.sso.SSOToken;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.sun.identity.shared.datastruct.CollectionHelper;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.sun.identity.shared.debug.Debug;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.sun.identity.shared.encode.Hash;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.sun.identity.sm.ServiceSchema;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoniimport com.sun.identity.sm.ServiceSchemaManager;
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>DNOrIPAddressListTokenRestriction</code> implements
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * {@link TokenRestriction} interface and handles the restriction of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the <code>DN</code> or <code>IPAddress</code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class DNOrIPAddressListTokenRestriction implements TokenRestriction {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final long serialVersionUID = 8352965917649287133L;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String dn;
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major private static final Debug DEBUG = Debug.getInstance("amSession");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Set<InetAddress> addressList = new HashSet<InetAddress>();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
e6ff5d36907b3336d3ab0316cbfa6cdd781a20eeJon Jonthomas /** SHA-1 hash of the concatenated string of DN and/or Host Name/IP Address.*/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String asString;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * boolean to indicate if the restriction checking is strictly based on DN
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * or not during cookie hijacking mitigation mode.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * By default if DN is absent or cannot be determined,restriction is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * set to IP address of the client. This property if not defined in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is assumed false.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If strict DN checking is desired this property needs to be defined
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with value "true"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean dnRestrictionOnly;
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major private static volatile boolean isInitialized = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String SESSION_DNRESTRICTIONONLY_ATTR_NAME =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iplanet-am-session-dnrestrictiononly";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni @JsonIgnore
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni private transient ServiceSchemaManager serviceSchemaManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major /**
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major * Default constructor for InternalSession deserialization.
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major */
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major public DNOrIPAddressListTokenRestriction() {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs <code>DNOrIPAddressListTokenRestriction</code> object based on
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the <code>DN</code> and list of host names to be restricted.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param dn the <code>DN</code> of the user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param hostNames list of host names.
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni * @param serviceSchemaManager the service's schema manager.
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni * @exception UnknownHostException if the host cannot be resolved.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni public DNOrIPAddressListTokenRestriction(
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni String dn,
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni Set<String> hostNames,
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni ServiceSchemaManager serviceSchemaManager) throws UnknownHostException {
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni this.serviceSchemaManager = serviceSchemaManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder buf = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dn.indexOf('|') > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer st = new StringTokenizer(dn, "|");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (st.hasMoreTokens()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (buf == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buf = new StringBuilder(Misc.canonicalize(st.nextToken()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buf.append('|').append(Misc.canonicalize(st.nextToken()));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buf = new StringBuilder(Misc.canonicalize(dn));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.dn = buf.toString();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (!isDNRestrictionOnly()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean hostmatch = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator<String> it = hostNames.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (it.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String val = it.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addressList.add(InetAddress.getByName(val));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster hostmatch = true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (UnknownHostException e) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.warningEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.warning("DNOrIPAddressListTokenRestriction.constructor: failure resolving host " + val);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!it.hasNext() && !hostmatch) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new UnknownHostException(val);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buf.append('\n');
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni List<String> hostNamesList = new ArrayList<>(hostNames);
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni Collections.sort(hostNamesList);
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni for (String hostName : hostNamesList) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster buf.append(hostName).append('\n');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster asString = buf.toString();
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.messageEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("DNOrIPAddressListTokenRestriction.new " + asString);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
e6ff5d36907b3336d3ab0316cbfa6cdd781a20eeJon Jonthomas asString = Hash.hash(asString);
e6ff5d36907b3336d3ab0316cbfa6cdd781a20eeJon Jonthomas if (asString == null){
e6ff5d36907b3336d3ab0316cbfa6cdd781a20eeJon Jonthomas throw new IllegalStateException("DNOrIPAddressListTokenRestriction.hashcode error creating SHA-1 hash, hash was null");
e6ff5d36907b3336d3ab0316cbfa6cdd781a20eeJon Jonthomas }
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.messageEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("DNOrIPAddressListTokenRestriction.hashCode " + asString);
e6ff5d36907b3336d3ab0316cbfa6cdd781a20eeJon Jonthomas }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method returns the restriction as a string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
e6ff5d36907b3336d3ab0316cbfa6cdd781a20eeJon Jonthomas * @return A SHA-1 hash of the concatenated string of DN and/or Host Name/IP Address.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String toString() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return asString;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a hash code for this object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a hash code value for this object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int hashCode() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return toString().hashCode();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a true if the restriction matches the context for which it was
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param context The context from which the restriction needs to be
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * checked. The context can be any from the following - the Single
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sign on token of the Application against which the restriction
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is being compared - the IP Address/Host Name of the Application
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * against which the restriction is being compared
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if the restriction is satisfied.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws Exception is thrown if the there was an error.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean isSatisfied(Object context) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (context == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (context instanceof SSOToken) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.messageEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("DNOrIPAddressListTokenRestriction.isSatisfied(): context is instance of SSOToken");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOToken usedBy = (SSOToken) context;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String udn = Misc.canonicalize(usedBy.getPrincipal().getName());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer st = new StringTokenizer(dn, "|");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while(st.hasMoreTokens()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (st.nextToken().equals(udn)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.messageEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("DNOrIPAddressListTokenRestriction:isSatisfied SSOToken of " + udn
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major + " does not match with restriction " + dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (context instanceof InetAddress) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (isDNRestrictionOnly()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //returning true here lessens the security, but truth to be told
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //sessionservice endpoint should not be accessible externally
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.warningEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.warning("DNOrIPAddressListTokenRestriction.isSatisfied():dnRestrictionOnly is true, but IP "
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major + "has been received as the restriction context, this could be a suspicious activity. "
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major + "Received InetAddress is: " + ((InetAddress) context).toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.messageEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("DNOrIPAddressListTokenRestriction.isSatisfied(): dnRestrictionOnly is false");
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("DNOrIPAddressListTokenRestriction.isSatisfied(): IP based restriction received and "
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major + "accepted");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return addressList.contains((InetAddress) context);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.warningEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.warning("Unknown context type:" + context);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns true of <code>other</code> meets these criteria.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <ol type="1">
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>it is not null
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>it is an instance of {@link DNOrIPAddressListTokenRestriction}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>it has the same distinguished name as this object and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>it has the same set of IP addresses as this object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * </ol>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param other the object to be used for comparison.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if <code>other</code> meets the above criteria.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean equals(Object other) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return other != null
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster && (other instanceof DNOrIPAddressListTokenRestriction)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster && other.toString().equals(this.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major * Gets the value of the "iplanet-am-session-dnrestrictiononly" session global attribute.
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major * NOTE: It may be possible that this setting gets initialized more than once, but that should be fine as it
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major * shouldn't be a too expensive operation.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major * @return Whether the DN restriction only is enabled.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni private boolean isDNRestrictionOnly() {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (!isInitialized) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major try {
ea342a784cd8d924a42a5721a4b0c42b4d644a93Diego Colantoni ServiceSchema schema = serviceSchemaManager.getGlobalSchema();
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major Map attrs = schema.getAttributeDefaults();
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major dnRestrictionOnly = Boolean.parseBoolean(CollectionHelper.getMapAttr(attrs,
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major SESSION_DNRESTRICTIONONLY_ATTR_NAME, "false"));
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.messageEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("DN restriction enabled: " + dnRestrictionOnly);
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major }
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major isInitialized = true;
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major } catch (Exception e) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major if (DEBUG.messageEnabled()) {
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major DEBUG.message("Failed to get the default dnRestrictionOnly setting. => Setting to false", e);
1f7d36d655f5d4d021b4dd67ca200ac503f5a25ePeter Major }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return dnRestrictionOnly;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}