Skip to content

Commit

Permalink
create account: add optional firstName and lastName #36
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadR committed Jul 6, 2014
1 parent 16e672e commit dbfaacc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class GAEAuthenticationAccountRepositoryImpl extends
private static final String LOGIN_ATTEMPTS_LEFT_PROP_NAME = "loginAttemptsLeft";
private static final String ENABLED_PROP_NAME = "enabled";
private static final String LAST_PSWD_CHANGE_DATE_PROP_NAME = "lastPasswordChangeDate";
private static final String FIRST_NAME_PROP_NAME = "firstName";
private static final String LAST_NAME_PROP_NAME = "lastName";
private static final String AUTHORITIES_PROP_NAME = "authorities";

private static final String AUTH_FLOWS_USER_DB_KIND = "authentication-flows-user";
Expand Down Expand Up @@ -68,6 +70,10 @@ public void createUser(UserDetails user)
dbUser.setProperty(ENABLED_PROP_NAME, user.isEnabled());
dbUser.setProperty(LOGIN_ATTEMPTS_LEFT_PROP_NAME, authUser.getLoginAttemptsLeft());
dbUser.setProperty(LAST_PSWD_CHANGE_DATE_PROP_NAME, new Date( System.currentTimeMillis()) );

dbUser.setProperty( FIRST_NAME_PROP_NAME, authUser.getFirstName() );
dbUser.setProperty( LAST_NAME_PROP_NAME, authUser.getLastName() );

dbUser.setProperty(AUTHORITIES_PROP_NAME, "ROLE_USER" );

datastore.put(dbUser);
Expand Down Expand Up @@ -136,6 +142,8 @@ public UserDetails loadUserByUsername(String username)

String roleName = (String)entity.getProperty(AUTHORITIES_PROP_NAME);
GrantedAuthority userAuth = new SimpleGrantedAuthority(roleName);
String firstName = (String)entity.getProperty(FIRST_NAME_PROP_NAME);
String lastName = (String)entity.getProperty(LAST_NAME_PROP_NAME);
Collection<GrantedAuthority> authSet = new HashSet<GrantedAuthority>();
authSet.add(userAuth);

Expand All @@ -145,6 +153,8 @@ public UserDetails loadUserByUsername(String username)
isEnabled,
loginAttemptsLeft,
(Date)entity.getProperty(LAST_PSWD_CHANGE_DATE_PROP_NAME),
firstName,
lastName,
authSet);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface AuthenticationUser extends UserDetails
public int getLoginAttemptsLeft();

public Date getPasswordLastChangeDate();

public String getFirstName();
public String getLastName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.SpringSecurityCoreVersion;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.util.Assert;

import com.ohadr.auth_flows.interfaces.AuthenticationUser;
Expand All @@ -25,6 +23,8 @@ public class InMemoryAuthenticationUserImpl implements AuthenticationUser
private boolean activated;
private Date passwordLastChangeDate;
private int loginAttemptsLeft;
private String firstName;
private String lastName;
private final Set<GrantedAuthority> authorities;


Expand All @@ -34,13 +34,17 @@ public InMemoryAuthenticationUserImpl(
boolean activated,
int loginAttemptsLeft,
Date passwordLastChangeDate,
String firstName,
String lastName,
Collection<? extends GrantedAuthority> authorities)
{
this.email = username;
this.password = password;
this.activated = activated;
this.loginAttemptsLeft = loginAttemptsLeft;
this.passwordLastChangeDate = passwordLastChangeDate;
this.firstName = firstName;
this.lastName = lastName;
this.authorities = Collections.unmodifiableSet(sortAuthorities(authorities));
}

Expand Down Expand Up @@ -166,4 +170,16 @@ public int compare(GrantedAuthority g1, GrantedAuthority g2) {
}
}

@Override
public String getFirstName()
{
return firstName;
}

@Override
public String getLastName()
{
return lastName;
}

}

0 comments on commit dbfaacc

Please sign in to comment.