001package org.apache.archiva.redback.users.ldap;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.archiva.redback.common.ldap.LdapUtils;
023import org.apache.archiva.redback.common.ldap.user.UserMapper;
024import org.apache.archiva.redback.users.AbstractUserQuery;
025
026public class LdapUserQuery
027    extends AbstractUserQuery
028{
029
030    public void setFirstResult( int firstResult )
031    {
032        super.setFirstResult( firstResult );
033        throw new UnsupportedOperationException( "Result limiting is not yet supported for LDAP." );
034    }
035
036    public void setMaxResults( int maxResults )
037    {
038        super.setMaxResults( maxResults );
039        throw new UnsupportedOperationException( "Result limiting is not yet supported for LDAP." );
040    }
041
042    public void setOrderBy( String orderBy )
043    {
044        super.setOrderBy( orderBy );
045        throw new UnsupportedOperationException( "Free-form ordering is not yet supported for LDAP." );
046    }
047    
048    public String getLdapFilter( UserMapper mapper )
049    {
050        String filter = "";
051        if (this.getEmail() != null )
052        {
053            filter += "(" + mapper.getEmailAddressAttribute() + "=" + LdapUtils.encodeFilterValue( this.getEmail() ) + ")";
054        }
055        if ( this.getFullName() != null )
056        {
057            filter += "(" + mapper.getUserFullNameAttribute() + "=" + LdapUtils.encodeFilterValue( this.getFullName() ) + ")";
058        }
059        filter += "(" + mapper.getUserIdAttribute() + "=" + ( this.getUsername() != null ? LdapUtils.encodeFilterValue( this.getUsername() ) : "*" ) + ")";
060        
061        return filter;
062    }
063
064}