/* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * * U.S. Government Rights - Commercial software. Government users * are subject to the Sun Microsystems, Inc. standard license agreement * and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. * Sun, Sun Microsystems, the Sun logo, Java and Project Identity * Connectors are trademarks or registered trademarks of Sun * Microsystems, Inc. or its subsidiaries in the U.S. and other * countries. * * UNIX is a registered trademark in the U.S. and other countries, * exclusively licensed through X/Open Company, Ltd. * * ----------- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of the Common Development * and Distribution License(CDDL) (the License). You may not use this file * except in compliance with the License. * * You can obtain a copy of the License at * http://identityconnectors.dev.java.net/CDDLv1.0.html * See the License for the specific language governing permissions and * limitations under the License. * * When distributing the Covered Code, include this CDDL Header Notice in each * file and include the License file at identityconnectors/legal/license.txt. * If applicable, add the following below this CDDL Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * ----------- * * Portions Copyrighted 2012 ForgeRock Inc. * */ package org.forgerock.openicf.connectors.googleapps; import org.identityconnectors.common.StringUtil; import org.identityconnectors.framework.common.objects.Attribute; import org.identityconnectors.framework.common.objects.AttributeUtil; import org.identityconnectors.framework.common.objects.Name; import org.identityconnectors.framework.common.objects.Uid; import org.identityconnectors.framework.common.objects.filter.AbstractFilterTranslator; import org.identityconnectors.framework.common.objects.filter.ContainsFilter; import org.identityconnectors.framework.common.objects.filter.EndsWithFilter; import org.identityconnectors.framework.common.objects.filter.EqualsFilter; import org.identityconnectors.framework.common.objects.filter.GreaterThanFilter; import org.identityconnectors.framework.common.objects.filter.GreaterThanOrEqualFilter; import org.identityconnectors.framework.common.objects.filter.LessThanFilter; import org.identityconnectors.framework.common.objects.filter.LessThanOrEqualFilter; import org.identityconnectors.framework.common.objects.filter.StartsWithFilter; /** * This is an implementation of AbstractFilterTranslator that gives a concrete * representation of which filters can be applied at the connector level * (natively). If the GoogleApps doesn't support a certain expression type, that * factory method should return null. This level of filtering is present only to * allow any native constructs that may be available to help reduce the result * set for the framework, which will (strictly) reapply all filters specified * after the connector does the initial filtering. * <p> * <p> * Note: The generic query type is most commonly a String, but does not have to * be. * * @author $author$ * @version $Revision$ $Date$ */ public class GoogleAppsFilterTranslator extends AbstractFilterTranslator<String> { /** * {@inheritDoc} */ @Override protected String createContainsExpression(ContainsFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createEndsWithExpression(EndsWithFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createStartsWithExpression(StartsWithFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createEqualsExpression(EqualsFilter filter, boolean not) { if (not) { // no way (natively) to search for "NotEquals" return null; } Attribute attr = filter.getAttribute(); if (!attr.is(Name.NAME) && !attr.is(Uid.NAME)) { return null; } String name = attr.getName(); String value = AttributeUtil.getAsStringValue(attr); if (checkSearchValue(value) == null) { return null; } else { return value; } } /** * {@inheritDoc} */ @Override protected String createAndExpression(String leftExpression, String rightExpression) { return null; } /** * {@inheritDoc} */ @Override protected String createOrExpression(String leftExpression, String rightExpression) { return null; } /** * {@inheritDoc} */ @Override protected String createGreaterThanExpression(GreaterThanFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createGreaterThanOrEqualExpression(GreaterThanOrEqualFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createLessThanExpression(LessThanFilter filter, boolean not) { return null; } /** * {@inheritDoc} */ @Override protected String createLessThanOrEqualExpression(LessThanOrEqualFilter filter, boolean not) { return null; } private String checkSearchValue(String value) { if (StringUtil.isEmpty(value)) { return null; } if (value.contains("*") || value.contains("&") || value.contains("|")) { throw new IllegalArgumentException( "Value of search attribute contains illegal character(s)."); } return value; } }