Merge branch 'KEYCLOAK-1421' of https://github.com/velias/keycloak into velias-KEYCLOAK-1421
Conflicts: testsuite/integration/src/test/java/org/keycloak/testsuite/model/UserModelTest.java
This commit is contained in:
commit
db20077c37
22 files changed
+161
-5
No files matched your search
@@ -20,6 +20,13 @@ public interface UserModel {
|
||||
String getUsername();
|
||||
|
||||
void setUsername(String username);
|
||||
|
||||
/**
|
||||
* Get timestamp of user creation. May be null for old users created before this feature introduction.
|
||||
*/
|
||||
Long getCreatedTimestamp();
|
||||
|
||||
void setCreatedTimestamp(Long timestamp);
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
@@ -106,4 +113,4 @@ public interface UserModel {
|
||||
public static enum RequiredAction {
|
||||
VERIFY_EMAIL, UPDATE_PROFILE, CONFIGURE_TOTP, UPDATE_PASSWORD
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import java.util.Map;
|
||||
public class UserEntity extends AbstractIdentifiableEntity {
|
||||
|
||||
private String username;
|
||||
private Long createdTimestamp;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String email;
|
||||
@@ -34,6 +35,15 @@ public class UserEntity extends AbstractIdentifiableEntity {
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Long getCreatedTimestamp() {
|
||||
return createdTimestamp;
|
||||
}
|
||||
|
||||
public void setCreatedTimestamp(Long timestamp) {
|
||||
this.createdTimestamp = timestamp;
|
||||
}
|
||||
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
|
||||
@@ -51,6 +51,7 @@ public class ModelToRepresentation {
|
||||
UserRepresentation rep = new UserRepresentation();
|
||||
rep.setId(user.getId());
|
||||
rep.setUsername(user.getUsername());
|
||||
rep.setCreatedTimestamp(user.getCreatedTimestamp());
|
||||
rep.setLastName(user.getLastName());
|
||||
rep.setFirstName(user.getFirstName());
|
||||
rep.setEmail(user.getEmail());
|
||||
|
||||
@@ -799,6 +799,7 @@ public class RepresentationToModel {
|
||||
// Import users just to user storage. Don't federate
|
||||
UserModel user = session.userStorage().addUser(newRealm, userRep.getId(), userRep.getUsername(), false, false);
|
||||
user.setEnabled(userRep.isEnabled());
|
||||
user.setCreatedTimestamp(userRep.getCreatedTimestamp());
|
||||
user.setEmail(userRep.getEmail());
|
||||
user.setEmailVerified(userRep.isEmailVerified());
|
||||
user.setFirstName(userRep.getFirstName());
|
||||
|
||||
@@ -235,4 +235,14 @@ public class UserModelDelegate implements UserModel {
|
||||
public UserModel getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCreatedTimestamp(){
|
||||
return delegate.getCreatedTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreatedTimestamp(Long timestamp){
|
||||
delegate.setCreatedTimestamp(timestamp);
|
||||
}
|
||||
}
|
||||
@@ -305,6 +305,7 @@ public class FileUserProvider implements UserProvider {
|
||||
|
||||
UserEntity userEntity = new UserEntity();
|
||||
userEntity.setId(userId);
|
||||
userEntity.setCreatedTimestamp(System.currentTimeMillis());
|
||||
userEntity.setUsername(username);
|
||||
// Compatibility with JPA model, which has user disabled by default
|
||||
// userEntity.setEnabled(true);
|
||||
|
||||
@@ -98,6 +98,16 @@ public class UserAdapter implements UserModel, Comparable {
|
||||
user.setUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCreatedTimestamp() {
|
||||
return user.getCreatedTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreatedTimestamp(Long timestamp) {
|
||||
user.setCreatedTimestamp(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return user.isEnabled();
|
||||
|
||||
Vendored
+11
@@ -60,6 +60,17 @@ public class UserAdapter implements UserModel {
|
||||
updated.setUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCreatedTimestamp() {
|
||||
// get from cached always as it is immutable
|
||||
return cached.getCreatedTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreatedTimestamp(Long timestamp) {
|
||||
// nothing to do as this value is immutable
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if (updated != null) return updated.isEnabled();
|
||||
|
||||
+6
-1
@@ -22,6 +22,7 @@ public class CachedUser implements Serializable {
|
||||
private String id;
|
||||
private String realm;
|
||||
private String username;
|
||||
private Long createdTimestamp;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String email;
|
||||
@@ -34,11 +35,11 @@ public class CachedUser implements Serializable {
|
||||
private Set<String> requiredActions = new HashSet<>();
|
||||
private Set<String> roleMappings = new HashSet<String>();
|
||||
|
||||
|
||||
public CachedUser(RealmModel realm, UserModel user) {
|
||||
this.id = user.getId();
|
||||
this.realm = realm.getId();
|
||||
this.username = user.getUsername();
|
||||
this.createdTimestamp = user.getCreatedTimestamp();
|
||||
this.firstName = user.getFirstName();
|
||||
this.lastName = user.getLastName();
|
||||
this.attributes.putAll(user.getAttributes());
|
||||
@@ -66,6 +67,10 @@ public class CachedUser implements Serializable {
|
||||
return username;
|
||||
}
|
||||
|
||||
public Long getCreatedTimestamp() {
|
||||
return createdTimestamp;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class JpaUserProvider implements UserProvider {
|
||||
|
||||
UserEntity entity = new UserEntity();
|
||||
entity.setId(id);
|
||||
entity.setCreatedTimestamp(System.currentTimeMillis());
|
||||
entity.setUsername(username.toLowerCase());
|
||||
entity.setRealmId(realm.getId());
|
||||
em.persist(entity);
|
||||
|
||||
@@ -77,6 +77,16 @@ public class UserAdapter implements UserModel {
|
||||
user.setUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCreatedTimestamp() {
|
||||
return user.getCreatedTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreatedTimestamp(Long timestamp) {
|
||||
user.setCreatedTimestamp(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return user.isEnabled();
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.persistence.NamedQuery;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -44,6 +45,8 @@ public class UserEntity {
|
||||
protected String username;
|
||||
@Column(name = "FIRST_NAME")
|
||||
protected String firstName;
|
||||
@Column(name = "CREATED_TIMESTAMP")
|
||||
protected Long createdTimestamp;
|
||||
@Column(name = "LAST_NAME")
|
||||
protected String lastName;
|
||||
@Column(name = "EMAIL")
|
||||
@@ -90,6 +93,14 @@ public class UserEntity {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Long getCreatedTimestamp() {
|
||||
return createdTimestamp;
|
||||
}
|
||||
|
||||
public void setCreatedTimestamp(Long timestamp) {
|
||||
createdTimestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
+2
@@ -3,6 +3,7 @@ package org.keycloak.models.mongo.keycloak.adapters;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.QueryBuilder;
|
||||
|
||||
import org.keycloak.connections.mongo.api.MongoStore;
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.ClientModel;
|
||||
@@ -274,6 +275,7 @@ public class MongoUserProvider implements UserProvider {
|
||||
MongoUserEntity userEntity = new MongoUserEntity();
|
||||
userEntity.setId(id);
|
||||
userEntity.setUsername(username);
|
||||
userEntity.setCreatedTimestamp(System.currentTimeMillis());
|
||||
// Compatibility with JPA model, which has user disabled by default
|
||||
// userEntity.setEnabled(true);
|
||||
userEntity.setRealmId(realm.getId());
|
||||
|
||||
+11
@@ -4,6 +4,7 @@ import static org.keycloak.models.utils.Pbkdf2PasswordEncoder.getSalt;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.QueryBuilder;
|
||||
|
||||
import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.ProtocolMapperModel;
|
||||
@@ -70,6 +71,16 @@ public class UserAdapter extends AbstractMongoAdapter<MongoUserEntity> implement
|
||||
updateUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getCreatedTimestamp() {
|
||||
return user.getCreatedTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreatedTimestamp(Long timestamp) {
|
||||
user.setCreatedTimestamp(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return user.isEnabled();
|
||||
|
||||
Reference in new issue
Block a user