On 4/19/07, ChenRanHow <[EMAIL PROTECTED]> wrote:
Dear Matt
I tried the ldap.zip file.
It seems the role and user model had some modifications
Would you mind to paste them ?
ex: role.getMembers missed .
These are modified based on the project I was working on - but there's
really nothing special about them. I've attached User and Role.
Matt
Regards
Chenztw
On 4/18/07, Matt Raible <[EMAIL PROTECTED]> wrote:
> What tutorial are you talking about? The one on the wiki doesn't
> require any code AFAIK. Attached is an LDAP version of AppFuse I
> created a while back. It doesn't fully work, but it might have what
> you're looking for. It uses Spring LDAP to do most of the heavy
> lifting.
>
> Matt
>
> On 4/17/07, reddeagle9 <[EMAIL PROTECTED]> wrote:
> >
> > Hi Guys,
> > Appufse 1.9.4 spring mvc, with acegi
> >
> > Today i have swapped out dao authentication for ldap (active directory) and
> > i am almost there. I followed the tutorial posted and can connect to ldap
> > and find the user.
> >
> > In the LdapTemplate class
> >
> > public Object searchForSingleEntry(final String base, final String filter,
> > final Object[] params,
> > final LdapEntryMapper mapper) {
> > return execute(new LdapCallback() {
> > public Object doInDirContext(DirContext ctx)
> > throws NamingException {
> > NamingEnumeration results = ctx.search(base, filter,
> > params, searchControls);
> >
> > if (!results.hasMore()) {
> > throw new IncorrectResultSizeDataAccessException(1,
> > 0);
> > }
> >
> > SearchResult searchResult = (SearchResult)
> > results.next();
> >
> > if (results.hasMore()) {
> > // We don't know how many results but set to 2 which
> > is good enough
> > throw new IncorrectResultSizeDataAccessException(1,
> > 2);
> > }
> >
> > I get an exception at if (results.hasMore()) {
> >
> > The searchResult object contains my details as retrieved from ldap.
> >
> > and i have the following exception
> >
> > org.acegisecurity.ldap.LdapDataAccessException: LdapCallback;Unprocessed
> > Continuation Reference(s); nested exception is
> > javax.naming.PartialResultException: Unprocessed Continuation Reference(s);
> > remaining name 'DC=example,DC=com'
> >
> > Anyone shed any light on this, has be baffeled.
> >
> > When i use an ldap broswer and search for a user, i do not see the attribute
> > userPassword as an attribute.?
> >
> > Cheers guys
> > --
> > View this message in context:
http://www.nabble.com/Authenticating-with-ldap-almost-there-tf3591637s2369.html#a10037977
> > Sent from the AppFuse - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> http://raibledesigns.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
ChenRanHow
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
http://raibledesigns.com
package org.appfuse.model;
import java.io.Serializable;
import java.util.List;
import org.acegisecurity.GrantedAuthority;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
/**
* This class is used to represent available roles in the database.</p>
*
* <p><a href="Role.java.html"><i>View Source</i></a></p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Matt Raible</a>
* Version by Dan Kibler [EMAIL PROTECTED]
* Extended to implement Acegi GrantedAuthority interface by David Carter [EMAIL PROTECTED]
* Decorated for use with xfire webservice by <a href="mailto:[EMAIL PROTECTED]">Mika Goeckel</a>
* @hibernate.class table="role"
* @aegis.mapping
*/
public class Role extends BaseObject implements Serializable, GrantedAuthority {
private static final long serialVersionUID = 3690197650654049848L;
private Long id;
private String name;
private String description;
private String[] members;
public Role() {}
public Role(String name) {
this.name = name;
}
/**
* @hibernate.id column="id" generator-class="native" unsaved-value="null"
* @return the primary key of the role (will be null when using UserDaoLdap)
*/
public Long getId() {
return id;
}
/**
* @see org.acegisecurity.GrantedAuthority#getAuthority()
*/
public String getAuthority() {
return getName();
}
/**
* @hibernate.property column="name" length="20"
* @return the name of the role
*/
public String getName() {
return this.name;
}
/**
* @hibernate.property column="description" length="64"
* @return the friendly description for the role
*/
public String getDescription() {
return this.description;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public String[] getMembers() {
return members;
}
public void setMembers(String[] members) {
this.members = members;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Role)) return false;
final Role role = (Role) o;
return !(name != null ? !name.equals(role.name) : role.name != null);
}
public int hashCode() {
return (name != null ? name.hashCode() : 0);
}
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE)
.append(this.name)
.toString();
}
}
package org.appfuse.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.userdetails.UserDetails;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
/**
* User class - also used to generate the Hibernate mapping file.
*
* <p><a href="User.java.html"><i>View Source</i></a>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Matt Raible</a>
* Updated by Dan Kibler ([EMAIL PROTECTED])
* Extended to implement Acegi UserDetails interface
* by David Carter [EMAIL PROTECTED]
* Decorated for use with xfire webservice by <a href="mailto:[EMAIL PROTECTED]">Mika Goeckel</a>
*
* @hibernate.class table="app_user"
* @aegis.mapping
*/
public class User extends BaseObject implements Serializable, UserDetails {
private static final long serialVersionUID = 3832626162173359411L;
protected Long id;
protected String username; // required
protected String password; // required
protected String confirmPassword;
protected String firstName; // required
protected String lastName; // required
protected String phoneNumber;
protected String email; // required; unique
protected String passwordHint;
protected String title;
protected String department;
protected Integer version;
protected Set<Role> roles = new HashSet<Role>();
protected boolean enabled;
protected boolean accountExpired;
protected boolean accountLocked;
protected boolean credentialsExpired;
public User() {}
public User(String username) {
this.username = username;
}
/**
* @hibernate.id column="id" generator-class="native" unsaved-value="null"
*/
public Long getId() {
return id;
}
/**
* @hibernate.property length="50" not-null="true" unique="true"
*/
public String getUsername() {
return username;
}
/**
* @hibernate.property column="password" not-null="true"
*/
public String getPassword() {
return password;
}
public String getConfirmPassword() {
return confirmPassword;
}
/**
* @hibernate.property column="first_name" not-null="true" length="50"
*/
public String getFirstName() {
return firstName;
}
/**
* @hibernate.property column="last_name" not-null="true" length="50"
*/
public String getLastName() {
return lastName;
}
/**
* Returns the full name.
*/
public String getFullName() {
return firstName + ' ' + lastName;
}
/**
* @hibernate.property name="email" not-null="true" unique="true" length="50"
*/
public String getEmail() {
return email;
}
/**
* @hibernate.property column="phone_number" not-null="false" length="25"
*/
public String getPhoneNumber() {
return phoneNumber;
}
/**
* @hibernate.property column="password_hint" not-null="false" length="100"
*/
public String getPasswordHint() {
return passwordHint;
}
/**
* @hibernate.property length="100"
*/
public String getDepartment() {
return department;
}
/**
* @hibernate.property length="50"
*/
public String getTitle() {
return title;
}
/**
* @hibernate.set table="user_role" cascade="save-update" lazy="false"
* @hibernate.collection-key column="user_id"
* @hibernate.collection-many-to-many class="org.appfuse.model.Role" column="role_id"
* @aegis.property componentType="org.appfuse.model.Role"
*/
public Set<Role> getRoles() {
return roles;
}
/**
* Adds a role for the user
* @param role
*/
public void addRole(Role role) {
getRoles().add(role);
}
/**
* @see org.acegisecurity.userdetails.UserDetails#getAuthorities()
* @aegis.property ignore="true"
*/
public GrantedAuthority[] getAuthorities() {
return roles.toArray(new GrantedAuthority[0]);
}
/**
* @hibernate.version
*/
public Integer getVersion() {
return version;
}
/**
* @hibernate.property column="account_enabled" type="yes_no"
*/
public boolean isEnabled() {
return enabled;
}
/**
* @hibernate.property column="account_expired" not-null="true" type="yes_no"
*/
public boolean isAccountExpired() {
return accountExpired;
}
/**
* @see org.acegisecurity.userdetails.UserDetails#isAccountNonExpired()
* @aegis.property ignore="true"
*/
public boolean isAccountNonExpired() {
return !isAccountExpired();
}
/**
* @hibernate.property column="account_locked" not-null="true" type="yes_no"
*/
public boolean isAccountLocked() {
return accountLocked;
}
/**
* @see org.acegisecurity.userdetails.UserDetails#isAccountNonLocked()
* @aegis.property ignore="true"
*/
public boolean isAccountNonLocked() {
return !isAccountLocked();
}
/**
* @hibernate.property column="credentials_expired" not-null="true" type="yes_no"
*/
public boolean isCredentialsExpired() {
return credentialsExpired;
}
/**
* @see org.acegisecurity.userdetails.UserDetails#isCredentialsNonExpired()
* @aegis.property ignore="true"
*/
public boolean isCredentialsNonExpired() {
return !credentialsExpired;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setFullName(String fullName) {
if (fullName != null && fullName.indexOf(" ") > -1) {
String[] tokens = fullName.split(" ");
this.firstName = tokens[0];
if (tokens.length > 1) {
this.lastName = tokens[1];
}
}
}
public void setEmail(String email) {
this.email = email;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public void setPasswordHint(String passwordHint) {
this.passwordHint = passwordHint;
}
public void setDepartment(String department) {
this.department = department;
}
public void setTitle(String title) {
this.title = title;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
public void setVersion(Integer version) {
this.version = version;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* Convert user roles to LabelValue objects for convenience.
* @aegis.property ignore="true"
*/
public List getRoleList() {
List<LabelValue> userRoles = new ArrayList<LabelValue>();
if (this.roles != null) {
for (Role role : roles) {
// convert the user's roles to LabelValue Objects
userRoles.add(new LabelValue(role.getName(),
role.getName()));
}
}
return userRoles;
}
public void setAccountExpired(boolean accountExpired) {
this.accountExpired = accountExpired;
}
public void setAccountLocked(boolean accountLocked) {
this.accountLocked = accountLocked;
}
public void setCredentialsExpired(boolean credentialsExpired) {
this.credentialsExpired = credentialsExpired;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof User)) return false;
final User user = (User) o;
return !(username != null ? !username.equals(user.getUsername()) : user.getUsername() != null);
}
public int hashCode() {
return (username != null ? username.hashCode() : 0);
}
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this,
ToStringStyle.DEFAULT_STYLE).append("username", this.username)
.append("enabled", this.enabled)
.append("accountExpired",this.accountExpired)
.append("credentialsExpired",this.credentialsExpired)
.append("accountLocked",this.accountLocked);
GrantedAuthority[] auths = this.getAuthorities();
if (auths != null) {
sb.append("Granted Authorities: ");
for (int i = 0; i < auths.length; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(auths[i].toString());
}
} else {
sb.append("No Granted Authorities");
}
return sb.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]