*/
import org.apache.archiva.redback.authentication.AbstractAuthenticator;
-import org.apache.archiva.redback.authentication.AuthenticationConstants;
-import org.apache.archiva.redback.common.ldap.UserMapper;
+import org.apache.archiva.redback.common.ldap.user.UserMapper;
import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
-import java.util.HashMap;
-import java.util.Map;
/**
* LdapBindAuthenticator:
<property name="userConf" ref="userConfiguration#default"/>
</bean>
- <bean name="userMapper#ldap" class="org.apache.archiva.redback.common.ldap.LdapUserMapper">
+ <bean name="userMapper#ldap" class="org.apache.archiva.redback.common.ldap.user.LdapUserMapper">
<property name="emailAttribute" value="mail"/>
<property name="fullNameAttribute" value="givenName"/>
<property name="passwordAttribute" value="userPassword"/>
+++ /dev/null
-package org.apache.archiva.redback.common.ldap;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.redback.users.User;
-
-import javax.naming.directory.Attributes;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-// TODO this class should be able to be replaced with a model
-public class LdapUser
- implements User, Serializable
-{
-
- private String username;
-
- private String fullName;
-
- private String email;
-
- private String encodedPassword;
-
- private List<String> previousEncodedPasswords;
-
- private boolean locked = false;
-
- private boolean requiresPasswordChange = false;
-
- private boolean permanent = true;
-
- private boolean valid = true;
-
- private Date creationDate = null;
-
- private int failedLoginAttempts;
-
- private Date lastLoginDate = null;
-
- private Date lastPasswordChange = null;
-
- // DO NOT STORE AS SUCH!!!
- private String newPassword;
-
- private Attributes originalAttributes;
-
- /**
- * @since 2.1
- */
- private String userManagerId = "ldap";
-
- public LdapUser( String username )
- {
- this.username = username;
- this.previousEncodedPasswords = new ArrayList<String>( 0 );
- this.failedLoginAttempts = 0;
- }
-
- public LdapUser( String username, String fullName, String email )
- {
- this( username );
- this.fullName = fullName;
- this.email = email;
- }
-
- public LdapUser()
- {
- previousEncodedPasswords = new ArrayList<String>( 0 );
- failedLoginAttempts = Integer.MIN_VALUE;
- }
-
- public void addPreviousEncodedPassword( String encodedPassword )
- {
- previousEncodedPasswords.add( encodedPassword );
- }
-
- public Date getAccountCreationDate()
- {
- return creationDate;
- }
-
- public int getCountFailedLoginAttempts()
- {
- return failedLoginAttempts;
- }
-
- public String getEmail()
- {
- return email;
- }
-
- public String getEncodedPassword()
- {
- return encodedPassword;
- }
-
- public String getFullName()
- {
- return fullName;
- }
-
- public Date getLastLoginDate()
- {
- return lastLoginDate;
- }
-
- public Date getLastPasswordChange()
- {
- return lastPasswordChange;
- }
-
- public String getPassword()
- {
- return newPassword;
- }
-
- public List<String> getPreviousEncodedPasswords()
- {
- return previousEncodedPasswords;
- }
-
-
- public String getUsername()
- {
- return username;
- }
-
- public boolean isLocked()
- {
- return locked;
- }
-
- public boolean isPasswordChangeRequired()
- {
- return requiresPasswordChange;
- }
-
- public boolean isPermanent()
- {
- return permanent;
- }
-
- public boolean isValidated()
- {
- return valid;
- }
-
- public void setCountFailedLoginAttempts( int count )
- {
- failedLoginAttempts = count;
- }
-
- public void setEmail( String address )
- {
- email = address;
- }
-
- public void setEncodedPassword( String encodedPassword )
- {
- this.encodedPassword = encodedPassword;
- }
-
- public void setFullName( String name )
- {
- fullName = name;
- }
-
- public void setAccountCreationDate( Date date )
- {
- creationDate = date;
- }
-
- public void setLastLoginDate( Date date )
- {
- lastLoginDate = date;
- }
-
- public void setLastPasswordChange( Date passwordChangeDate )
- {
- lastPasswordChange = passwordChangeDate;
- }
-
- public void setLocked( boolean locked )
- {
- this.locked = locked;
- }
-
- public void setPassword( String rawPassword )
- {
- newPassword = rawPassword;
- }
-
- public void setPasswordChangeRequired( boolean changeRequired )
- {
- requiresPasswordChange = changeRequired;
- }
-
- public void setPermanent( boolean permanent )
- {
- this.permanent = permanent;
- }
-
- public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
- {
- previousEncodedPasswords = new ArrayList<String>( encodedPasswordList );
- }
-
- public void setUsername( String name )
- {
- username = name;
- }
-
- public void setValidated( boolean valid )
- {
- this.valid = valid;
- }
-
- public Attributes getOriginalAttributes()
- {
- return originalAttributes;
- }
-
- public void setOriginalAttributes( Attributes originalAttributes )
- {
- this.originalAttributes = originalAttributes;
- }
-
- public String getUserManagerId()
- {
- return userManagerId;
- }
-
-}
+++ /dev/null
-package org.apache.archiva.redback.common.ldap;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.redback.configuration.UserConfiguration;
-import org.apache.archiva.redback.configuration.UserConfigurationKeys;
-import org.apache.archiva.redback.users.User;
-import org.apache.commons.lang.StringUtils;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
-import java.util.Date;
-
-/**
- * @author <a href="jesse@codehaus.org"> jesse
- */
-@Service("userMapper#ldap")
-public class LdapUserMapper
- implements UserMapper
-{
- /**
- *
- */
- String emailAttribute = "mail";
-
- /**
- *
- */
- String fullNameAttribute = "givenName";
-
- /**
- *
- */
- String passwordAttribute = "userPassword";
-
- /**
- *
- */
- String userIdAttribute = "cn";
-
- /**
- *
- */
- String userBaseDn;
-
- /**
- *
- */
- String userObjectClass = "inetOrgPerson";
-
- /**
- *
- */
- String userFilter;
-
- /**
- *
- */
- int maxResultCount = 0;
-
- @Inject
- @Named(value = "userConfiguration#default")
- private UserConfiguration userConf;
-
- @PostConstruct
- public void initialize()
- {
- emailAttribute = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_EMAIL, emailAttribute );
- fullNameAttribute =
- userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_FULLNAME, fullNameAttribute );
- passwordAttribute =
- userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_PASSWORD, passwordAttribute );
- userIdAttribute = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_ID, userIdAttribute );
- userBaseDn = userConf.getConcatenatedList( "ldap.config.mapper.attribute.user.base.dn",
- userConf.getConcatenatedList( "ldap.config.base.dn", userBaseDn ) );
- userObjectClass =
- userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_OBJECT_CLASS, userObjectClass );
- userFilter = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_FILTER, userFilter );
- maxResultCount = userConf.getInt( UserConfigurationKeys.LDAP_MAX_RESULT_COUNT, maxResultCount );
- }
-
- public Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
- throws MappingException
- {
- Attributes userAttrs = new BasicAttributes();
-
- boolean passwordSet = false;
-
- if ( !passwordSet && ( user.getEncodedPassword() != null ) )
- {
- userAttrs.put( getPasswordAttribute(), user.getEncodedPassword() );
- }
-
- if ( !StringUtils.isEmpty( user.getFullName() ) )
- {
- userAttrs.put( getUserFullNameAttribute(), user.getFullName() );
- }
-
- if ( !StringUtils.isEmpty( user.getEmail() ) )
- {
- userAttrs.put( getEmailAddressAttribute(), user.getEmail() );
- }
-
- return userAttrs;
- }
-
- public String getEmailAddressAttribute()
- {
- return emailAttribute;
- }
-
- public String getUserFullNameAttribute()
- {
- return fullNameAttribute;
- }
-
- public String getPasswordAttribute()
- {
- return passwordAttribute;
- }
-
- public String[] getUserAttributeNames()
- {
- return new String[]{ emailAttribute, fullNameAttribute, passwordAttribute, userIdAttribute };
- }
-
- public int getMaxResultCount()
- {
- return maxResultCount;
- }
-
- public UserUpdate getUpdate( LdapUser user )
- throws MappingException
- {
-
- Attributes addAttrs = new BasicAttributes();
-
- Attributes modAttrs = new BasicAttributes();
-
- if ( !StringUtils.isEmpty( user.getFullName() ) )
- {
- if ( user.getFullName() == null )
- {
- addAttrs.put( getUserFullNameAttribute(), user.getFullName() );
- }
- else if ( !user.getFullName().equals( user.getFullName() ) )
- {
- modAttrs.put( getUserFullNameAttribute(), user.getFullName() );
- }
- }
-
- if ( !StringUtils.isEmpty( user.getEmail() ) )
- {
- if ( user.getEmail() == null )
- {
- addAttrs.put( getEmailAddressAttribute(), user.getEmail() );
- }
- else if ( !user.getEmail().equals( user.getEmail() ) )
- {
- modAttrs.put( getEmailAddressAttribute(), user.getEmail() );
- }
- }
-
- return null;
- }
-
- public LdapUser getUser( Attributes attributes )
- throws MappingException
- {
- String userIdAttribute = getUserIdAttribute();
- String emailAddressAttribute = getEmailAddressAttribute();
- String nameAttribute = getUserFullNameAttribute();
- String passwordAttribute = getPasswordAttribute();
-
- String userId = LdapUtils.getAttributeValue( attributes, userIdAttribute, "username" );
-
- LdapUser user = new LdapUser( userId );
- user.setOriginalAttributes( attributes );
-
- user.setEmail( LdapUtils.getAttributeValue( attributes, emailAddressAttribute, "email address" ) );
- user.setFullName( LdapUtils.getAttributeValue( attributes, nameAttribute, "name" ) );
-
- String encodedPassword = LdapUtils.getAttributeValueFromByteArray( attributes, passwordAttribute, "password" );
-
- // it seems to be a common convention for the password to come back prepended with the encoding type..
- // however we deal with that via configuration right now so just smoke it.
- if ( encodedPassword != null && encodedPassword.startsWith( "{" ) )
- {
- encodedPassword = encodedPassword.substring( encodedPassword.indexOf( '}' ) + 1 );
- }
-
- user.setEncodedPassword( encodedPassword );
-
- // REDBACK-215: skip NPE
- user.setLastPasswordChange( new Date() );
-
- return user;
- }
-
- public String getUserIdAttribute()
- {
- return userIdAttribute;
- }
-
- public String getEmailAttribute()
- {
- return emailAttribute;
- }
-
- public void setEmailAttribute( String emailAttribute )
- {
- this.emailAttribute = emailAttribute;
- }
-
- public String getFullNameAttribute()
- {
- return fullNameAttribute;
- }
-
- public void setFullNameAttribute( String fullNameAttribute )
- {
- this.fullNameAttribute = fullNameAttribute;
- }
-
- public void setMaxResultCount( int maxResultCount )
- {
- this.maxResultCount = maxResultCount;
- }
-
- public String getUserBaseDn()
- {
- return userBaseDn;
- }
-
- public void setUserBaseDn( String userBaseDn )
- {
- this.userBaseDn = userBaseDn;
- }
-
- public String getUserObjectClass()
- {
- return userObjectClass;
- }
-
- public String getUserFilter()
- {
- return userFilter;
- }
-
- public void setUserFilter( String userFilter )
- {
- this.userFilter = userFilter;
- }
-
- public void setUserObjectClass( String userObjectClass )
- {
- this.userObjectClass = userObjectClass;
- }
-
- public void setPasswordAttribute( String passwordAttribute )
- {
- this.passwordAttribute = passwordAttribute;
- }
-
- public void setUserIdAttribute( String userIdAttribute )
- {
- this.userIdAttribute = userIdAttribute;
- }
-
- public LdapUser newUserInstance( String username, String fullName, String email )
- {
- return new LdapUser( username, fullName, email );
- }
-
- public LdapUser newTemplateUserInstance()
- {
- return new LdapUser();
- }
-
- public String[] getReturningAttributes()
- {
- return new String[]{ getUserIdAttribute(), getEmailAttribute(), getFullNameAttribute(),
- getPasswordAttribute() };
- }
-
- public UserConfiguration getUserConf()
- {
- return userConf;
- }
-
- public void setUserConf( UserConfiguration userConf )
- {
- this.userConf = userConf;
- }
-}
+++ /dev/null
-package org.apache.archiva.redback.common.ldap;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.archiva.redback.users.User;
-
-import javax.naming.directory.Attributes;
-
-/**
- *
- */
-public interface UserMapper
-{
- LdapUser getUser( Attributes attributes )
- throws MappingException;
-
- Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
- throws MappingException;
-
- UserUpdate getUpdate( LdapUser user )
- throws MappingException;
-
- String[] getUserAttributeNames();
-
- String getEmailAddressAttribute();
-
- String getUserFullNameAttribute();
-
- String getPasswordAttribute();
-
- String getUserIdAttribute();
-
- String getEmailAttribute();
-
- String getUserBaseDn();
-
- String getUserObjectClass();
-
- String getUserFilter();
-
- LdapUser newUserInstance( String username, String fullName, String email );
-
- LdapUser newTemplateUserInstance();
-
- String[] getReturningAttributes();
-
- void initialize();
-
-}
+++ /dev/null
-package org.apache.archiva.redback.common.ldap;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import javax.naming.directory.Attributes;
-
-/**
- *
- */
-public class UserUpdate
-{
-
- private final Attributes created;
-
- private final Attributes modified;
-
- private final Attributes removed;
-
- public UserUpdate( Attributes created, Attributes modified, Attributes removed )
- {
- this.created = created;
- this.modified = modified;
- this.removed = removed;
- }
-
- public Attributes getAddedAttributes()
- {
- return created;
- }
-
- public Attributes getModifiedAttributes()
- {
- return modified;
- }
-
- public Attributes getRemovedAttributes()
- {
- return removed;
- }
-
- public boolean hasAdditions()
- {
- return ( created != null ) && ( created.size() > 0 );
- }
-
- public boolean hasModifications()
- {
- return ( modified != null ) && ( modified.size() > 0 );
- }
-
-
-
-}
--- /dev/null
+package org.apache.archiva.redback.common.ldap.user;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.redback.users.User;
+
+import javax.naming.directory.Attributes;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+// TODO this class should be able to be replaced with a model
+public class LdapUser
+ implements User, Serializable
+{
+
+ private String username;
+
+ private String fullName;
+
+ private String email;
+
+ private String encodedPassword;
+
+ private List<String> previousEncodedPasswords;
+
+ private boolean locked = false;
+
+ private boolean requiresPasswordChange = false;
+
+ private boolean permanent = true;
+
+ private boolean valid = true;
+
+ private Date creationDate = null;
+
+ private int failedLoginAttempts;
+
+ private Date lastLoginDate = null;
+
+ private Date lastPasswordChange = null;
+
+ // DO NOT STORE AS SUCH!!!
+ private String newPassword;
+
+ private Attributes originalAttributes;
+
+ /**
+ * @since 2.1
+ */
+ private String userManagerId = "ldap";
+
+ public LdapUser( String username )
+ {
+ this.username = username;
+ this.previousEncodedPasswords = new ArrayList<String>( 0 );
+ this.failedLoginAttempts = 0;
+ }
+
+ public LdapUser( String username, String fullName, String email )
+ {
+ this( username );
+ this.fullName = fullName;
+ this.email = email;
+ }
+
+ public LdapUser()
+ {
+ previousEncodedPasswords = new ArrayList<String>( 0 );
+ failedLoginAttempts = Integer.MIN_VALUE;
+ }
+
+ public void addPreviousEncodedPassword( String encodedPassword )
+ {
+ previousEncodedPasswords.add( encodedPassword );
+ }
+
+ public Date getAccountCreationDate()
+ {
+ return creationDate;
+ }
+
+ public int getCountFailedLoginAttempts()
+ {
+ return failedLoginAttempts;
+ }
+
+ public String getEmail()
+ {
+ return email;
+ }
+
+ public String getEncodedPassword()
+ {
+ return encodedPassword;
+ }
+
+ public String getFullName()
+ {
+ return fullName;
+ }
+
+ public Date getLastLoginDate()
+ {
+ return lastLoginDate;
+ }
+
+ public Date getLastPasswordChange()
+ {
+ return lastPasswordChange;
+ }
+
+ public String getPassword()
+ {
+ return newPassword;
+ }
+
+ public List<String> getPreviousEncodedPasswords()
+ {
+ return previousEncodedPasswords;
+ }
+
+
+ public String getUsername()
+ {
+ return username;
+ }
+
+ public boolean isLocked()
+ {
+ return locked;
+ }
+
+ public boolean isPasswordChangeRequired()
+ {
+ return requiresPasswordChange;
+ }
+
+ public boolean isPermanent()
+ {
+ return permanent;
+ }
+
+ public boolean isValidated()
+ {
+ return valid;
+ }
+
+ public void setCountFailedLoginAttempts( int count )
+ {
+ failedLoginAttempts = count;
+ }
+
+ public void setEmail( String address )
+ {
+ email = address;
+ }
+
+ public void setEncodedPassword( String encodedPassword )
+ {
+ this.encodedPassword = encodedPassword;
+ }
+
+ public void setFullName( String name )
+ {
+ fullName = name;
+ }
+
+ public void setAccountCreationDate( Date date )
+ {
+ creationDate = date;
+ }
+
+ public void setLastLoginDate( Date date )
+ {
+ lastLoginDate = date;
+ }
+
+ public void setLastPasswordChange( Date passwordChangeDate )
+ {
+ lastPasswordChange = passwordChangeDate;
+ }
+
+ public void setLocked( boolean locked )
+ {
+ this.locked = locked;
+ }
+
+ public void setPassword( String rawPassword )
+ {
+ newPassword = rawPassword;
+ }
+
+ public void setPasswordChangeRequired( boolean changeRequired )
+ {
+ requiresPasswordChange = changeRequired;
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ this.permanent = permanent;
+ }
+
+ public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
+ {
+ previousEncodedPasswords = new ArrayList<String>( encodedPasswordList );
+ }
+
+ public void setUsername( String name )
+ {
+ username = name;
+ }
+
+ public void setValidated( boolean valid )
+ {
+ this.valid = valid;
+ }
+
+ public Attributes getOriginalAttributes()
+ {
+ return originalAttributes;
+ }
+
+ public void setOriginalAttributes( Attributes originalAttributes )
+ {
+ this.originalAttributes = originalAttributes;
+ }
+
+ public String getUserManagerId()
+ {
+ return userManagerId;
+ }
+
+}
--- /dev/null
+package org.apache.archiva.redback.common.ldap.user;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.redback.common.ldap.LdapUtils;
+import org.apache.archiva.redback.common.ldap.MappingException;
+import org.apache.archiva.redback.configuration.UserConfiguration;
+import org.apache.archiva.redback.configuration.UserConfigurationKeys;
+import org.apache.archiva.redback.users.User;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import java.util.Date;
+
+/**
+ * @author <a href="jesse@codehaus.org"> jesse
+ */
+@Service("userMapper#ldap")
+public class LdapUserMapper
+ implements UserMapper
+{
+ /**
+ *
+ */
+ String emailAttribute = "mail";
+
+ /**
+ *
+ */
+ String fullNameAttribute = "givenName";
+
+ /**
+ *
+ */
+ String passwordAttribute = "userPassword";
+
+ /**
+ *
+ */
+ String userIdAttribute = "cn";
+
+ /**
+ *
+ */
+ String userBaseDn;
+
+ /**
+ *
+ */
+ String userObjectClass = "inetOrgPerson";
+
+ /**
+ *
+ */
+ String userFilter;
+
+ /**
+ *
+ */
+ int maxResultCount = 0;
+
+ @Inject
+ @Named(value = "userConfiguration#default")
+ private UserConfiguration userConf;
+
+ @PostConstruct
+ public void initialize()
+ {
+ emailAttribute = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_EMAIL, emailAttribute );
+ fullNameAttribute =
+ userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_FULLNAME, fullNameAttribute );
+ passwordAttribute =
+ userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_PASSWORD, passwordAttribute );
+ userIdAttribute = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_ID, userIdAttribute );
+ userBaseDn = userConf.getConcatenatedList( "ldap.config.mapper.attribute.user.base.dn",
+ userConf.getConcatenatedList( "ldap.config.base.dn", userBaseDn ) );
+ userObjectClass =
+ userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_OBJECT_CLASS, userObjectClass );
+ userFilter = userConf.getString( UserConfigurationKeys.LDAP_MAPPER_USER_ATTRIBUTE_FILTER, userFilter );
+ maxResultCount = userConf.getInt( UserConfigurationKeys.LDAP_MAX_RESULT_COUNT, maxResultCount );
+ }
+
+ public Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
+ throws MappingException
+ {
+ Attributes userAttrs = new BasicAttributes();
+
+ boolean passwordSet = false;
+
+ if ( !passwordSet && ( user.getEncodedPassword() != null ) )
+ {
+ userAttrs.put( getPasswordAttribute(), user.getEncodedPassword() );
+ }
+
+ if ( !StringUtils.isEmpty( user.getFullName() ) )
+ {
+ userAttrs.put( getUserFullNameAttribute(), user.getFullName() );
+ }
+
+ if ( !StringUtils.isEmpty( user.getEmail() ) )
+ {
+ userAttrs.put( getEmailAddressAttribute(), user.getEmail() );
+ }
+
+ return userAttrs;
+ }
+
+ public String getEmailAddressAttribute()
+ {
+ return emailAttribute;
+ }
+
+ public String getUserFullNameAttribute()
+ {
+ return fullNameAttribute;
+ }
+
+ public String getPasswordAttribute()
+ {
+ return passwordAttribute;
+ }
+
+ public String[] getUserAttributeNames()
+ {
+ return new String[]{ emailAttribute, fullNameAttribute, passwordAttribute, userIdAttribute };
+ }
+
+ public int getMaxResultCount()
+ {
+ return maxResultCount;
+ }
+
+ public UserUpdate getUpdate( LdapUser user )
+ throws MappingException
+ {
+
+ Attributes addAttrs = new BasicAttributes();
+
+ Attributes modAttrs = new BasicAttributes();
+
+ if ( !StringUtils.isEmpty( user.getFullName() ) )
+ {
+ if ( user.getFullName() == null )
+ {
+ addAttrs.put( getUserFullNameAttribute(), user.getFullName() );
+ }
+ else if ( !user.getFullName().equals( user.getFullName() ) )
+ {
+ modAttrs.put( getUserFullNameAttribute(), user.getFullName() );
+ }
+ }
+
+ if ( !StringUtils.isEmpty( user.getEmail() ) )
+ {
+ if ( user.getEmail() == null )
+ {
+ addAttrs.put( getEmailAddressAttribute(), user.getEmail() );
+ }
+ else if ( !user.getEmail().equals( user.getEmail() ) )
+ {
+ modAttrs.put( getEmailAddressAttribute(), user.getEmail() );
+ }
+ }
+
+ return null;
+ }
+
+ public LdapUser getUser( Attributes attributes )
+ throws MappingException
+ {
+ String userIdAttribute = getUserIdAttribute();
+ String emailAddressAttribute = getEmailAddressAttribute();
+ String nameAttribute = getUserFullNameAttribute();
+ String passwordAttribute = getPasswordAttribute();
+
+ String userId = LdapUtils.getAttributeValue( attributes, userIdAttribute, "username" );
+
+ LdapUser user = new LdapUser( userId );
+ user.setOriginalAttributes( attributes );
+
+ user.setEmail( LdapUtils.getAttributeValue( attributes, emailAddressAttribute, "email address" ) );
+ user.setFullName( LdapUtils.getAttributeValue( attributes, nameAttribute, "name" ) );
+
+ String encodedPassword = LdapUtils.getAttributeValueFromByteArray( attributes, passwordAttribute, "password" );
+
+ // it seems to be a common convention for the password to come back prepended with the encoding type..
+ // however we deal with that via configuration right now so just smoke it.
+ if ( encodedPassword != null && encodedPassword.startsWith( "{" ) )
+ {
+ encodedPassword = encodedPassword.substring( encodedPassword.indexOf( '}' ) + 1 );
+ }
+
+ user.setEncodedPassword( encodedPassword );
+
+ // REDBACK-215: skip NPE
+ user.setLastPasswordChange( new Date() );
+
+ return user;
+ }
+
+ public String getUserIdAttribute()
+ {
+ return userIdAttribute;
+ }
+
+ public String getEmailAttribute()
+ {
+ return emailAttribute;
+ }
+
+ public void setEmailAttribute( String emailAttribute )
+ {
+ this.emailAttribute = emailAttribute;
+ }
+
+ public String getFullNameAttribute()
+ {
+ return fullNameAttribute;
+ }
+
+ public void setFullNameAttribute( String fullNameAttribute )
+ {
+ this.fullNameAttribute = fullNameAttribute;
+ }
+
+ public void setMaxResultCount( int maxResultCount )
+ {
+ this.maxResultCount = maxResultCount;
+ }
+
+ public String getUserBaseDn()
+ {
+ return userBaseDn;
+ }
+
+ public void setUserBaseDn( String userBaseDn )
+ {
+ this.userBaseDn = userBaseDn;
+ }
+
+ public String getUserObjectClass()
+ {
+ return userObjectClass;
+ }
+
+ public String getUserFilter()
+ {
+ return userFilter;
+ }
+
+ public void setUserFilter( String userFilter )
+ {
+ this.userFilter = userFilter;
+ }
+
+ public void setUserObjectClass( String userObjectClass )
+ {
+ this.userObjectClass = userObjectClass;
+ }
+
+ public void setPasswordAttribute( String passwordAttribute )
+ {
+ this.passwordAttribute = passwordAttribute;
+ }
+
+ public void setUserIdAttribute( String userIdAttribute )
+ {
+ this.userIdAttribute = userIdAttribute;
+ }
+
+ public LdapUser newUserInstance( String username, String fullName, String email )
+ {
+ return new LdapUser( username, fullName, email );
+ }
+
+ public LdapUser newTemplateUserInstance()
+ {
+ return new LdapUser();
+ }
+
+ public String[] getReturningAttributes()
+ {
+ return new String[]{ getUserIdAttribute(), getEmailAttribute(), getFullNameAttribute(),
+ getPasswordAttribute() };
+ }
+
+ public UserConfiguration getUserConf()
+ {
+ return userConf;
+ }
+
+ public void setUserConf( UserConfiguration userConf )
+ {
+ this.userConf = userConf;
+ }
+}
--- /dev/null
+package org.apache.archiva.redback.common.ldap.user;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.redback.common.ldap.MappingException;
+import org.apache.archiva.redback.users.User;
+
+import javax.naming.directory.Attributes;
+
+/**
+ *
+ */
+public interface UserMapper
+{
+ LdapUser getUser( Attributes attributes )
+ throws MappingException;
+
+ Attributes getCreationAttributes( User user, boolean encodePasswordIfChanged )
+ throws MappingException;
+
+ UserUpdate getUpdate( LdapUser user )
+ throws MappingException;
+
+ String[] getUserAttributeNames();
+
+ String getEmailAddressAttribute();
+
+ String getUserFullNameAttribute();
+
+ String getPasswordAttribute();
+
+ String getUserIdAttribute();
+
+ String getEmailAttribute();
+
+ String getUserBaseDn();
+
+ String getUserObjectClass();
+
+ String getUserFilter();
+
+ LdapUser newUserInstance( String username, String fullName, String email );
+
+ LdapUser newTemplateUserInstance();
+
+ String[] getReturningAttributes();
+
+ void initialize();
+
+}
--- /dev/null
+package org.apache.archiva.redback.common.ldap.user;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.naming.directory.Attributes;
+
+/**
+ *
+ */
+public class UserUpdate
+{
+
+ private final Attributes created;
+
+ private final Attributes modified;
+
+ private final Attributes removed;
+
+ public UserUpdate( Attributes created, Attributes modified, Attributes removed )
+ {
+ this.created = created;
+ this.modified = modified;
+ this.removed = removed;
+ }
+
+ public Attributes getAddedAttributes()
+ {
+ return created;
+ }
+
+ public Attributes getModifiedAttributes()
+ {
+ return modified;
+ }
+
+ public Attributes getRemovedAttributes()
+ {
+ return removed;
+ }
+
+ public boolean hasAdditions()
+ {
+ return ( created != null ) && ( created.size() > 0 );
+ }
+
+ public boolean hasModifications()
+ {
+ return ( modified != null ) && ( modified.size() > 0 );
+ }
+
+
+
+}
*/
import junit.framework.TestCase;
-import org.apache.archiva.redback.common.ldap.LdapUserMapper;
+import org.apache.archiva.redback.common.ldap.user.LdapUserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
*/
-import org.apache.archiva.redback.common.ldap.LdapUser;
-import org.apache.archiva.redback.common.ldap.UserMapper;
+import org.apache.archiva.redback.common.ldap.user.LdapUser;
+import org.apache.archiva.redback.common.ldap.user.UserMapper;
import org.apache.archiva.redback.users.AbstractUserManager;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
* under the License.
*/
-import org.apache.archiva.redback.common.ldap.UserMapper;
+import org.apache.archiva.redback.common.ldap.user.UserMapper;
import org.apache.archiva.redback.users.AbstractUserQuery;
public class LdapUserQuery
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
-import org.apache.archiva.redback.common.ldap.LdapUser;
-import org.apache.archiva.redback.common.ldap.LdapUserMapper;
-import org.apache.archiva.redback.common.ldap.UserMapper;
+import org.apache.archiva.redback.common.ldap.user.LdapUser;
+import org.apache.archiva.redback.common.ldap.user.LdapUserMapper;
+import org.apache.archiva.redback.common.ldap.user.UserMapper;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.common.ldap.MappingException;
* under the License.
*/
-import org.apache.archiva.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.user.LdapUser;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.common.ldap.MappingException;
import org.apache.archiva.redback.users.ldap.LdapUserQuery;
* under the License.
*/
-import org.apache.archiva.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.user.LdapUser;
import org.apache.archiva.redback.components.cache.builder.CacheBuilder;
import org.springframework.stereotype.Service;
}
/**
- * @see LdapCacheService#addUser(org.apache.archiva.redback.common.ldap.LdapUser)
+ * @see LdapCacheService#addUser(org.apache.archiva.redback.common.ldap.user.LdapUser)
*/
public void addUser( LdapUser user )
{
* under the License.
*/
-import org.apache.archiva.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.user.LdapUser;
/**
* LdapCacheService
*/
import junit.framework.TestCase;
-import org.apache.archiva.redback.common.ldap.LdapUser;
+import org.apache.archiva.redback.common.ldap.user.LdapUser;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
<property name="userConf" ref="userConfiguration#default"/>
</bean>
- <bean name="userMapper#ldap" class="org.apache.archiva.redback.common.ldap.LdapUserMapper">
+ <bean name="userMapper#ldap" class="org.apache.archiva.redback.common.ldap.user.LdapUserMapper">
<property name="emailAttribute" value="mail"/>
<property name="fullNameAttribute" value="givenName"/>
<property name="passwordAttribute" value="userPassword"/>