added Id field to DefaultUserInfo object, switched "userId" terminology to "subject"
parent
30c6271e72
commit
8fccbf3483
|
@ -33,10 +33,12 @@ import com.google.gson.JsonObject;
|
|||
@Table(name="user_info")
|
||||
@NamedQueries({
|
||||
@NamedQuery(name="DefaultUserInfo.getAll", query = "select u from DefaultUserInfo u"),
|
||||
@NamedQuery(name="DefaultUserInfo.getByUsername", query = "select u from DefaultUserInfo u WHERE u.preferredUsername = :username")
|
||||
@NamedQuery(name="DefaultUserInfo.getByUsername", query = "select u from DefaultUserInfo u WHERE u.preferredUsername = :username"),
|
||||
@NamedQuery(name="DefaultUserInfo.getBySubject", query = "select u from DefaultUserInfo u WHERE u.sub = :sub")
|
||||
})
|
||||
public class DefaultUserInfo implements UserInfo {
|
||||
|
||||
private Long id;
|
||||
private String sub;
|
||||
private String preferredUsername;
|
||||
private String name;
|
||||
|
@ -58,12 +60,25 @@ public class DefaultUserInfo implements UserInfo {
|
|||
private String birthdate;
|
||||
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.openid.connect.model.UserInfo#getUserId()
|
||||
*/
|
||||
@Override
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Basic
|
||||
@Column(name="sub")
|
||||
public String getSub() {
|
||||
return sub;
|
||||
|
|
|
@ -28,13 +28,13 @@ import org.mitre.openid.connect.model.UserInfo;
|
|||
public interface UserInfoRepository {
|
||||
|
||||
/**
|
||||
* Returns the UserInfo for the given user id
|
||||
* Returns the UserInfo for the given subject
|
||||
*
|
||||
* @param userId
|
||||
* userId the user id of the UserInfo
|
||||
* @param sub
|
||||
* the subject of the UserInfo
|
||||
* @return a valid UserInfo if it exists, null otherwise
|
||||
*/
|
||||
public UserInfo getByUserId(String userId);
|
||||
public UserInfo getBySubject(String sub);
|
||||
|
||||
/**
|
||||
* Persists a UserInfo
|
||||
|
@ -52,14 +52,6 @@ public interface UserInfoRepository {
|
|||
*/
|
||||
public void remove(UserInfo userInfo);
|
||||
|
||||
/**
|
||||
* Removes the UserInfo from the repository for the given user id
|
||||
*
|
||||
* @param userId
|
||||
* the user id for the UserInfo object to remove
|
||||
*/
|
||||
public void removeByUserId(String userId);
|
||||
|
||||
/**
|
||||
* Return a collection of all UserInfos managed by this repository
|
||||
*
|
||||
|
|
|
@ -34,13 +34,14 @@ public interface UserInfoService {
|
|||
public void save(UserInfo userInfo);
|
||||
|
||||
/**
|
||||
* Get UserInfo for user id
|
||||
* Get UserInfo for the Subject
|
||||
*
|
||||
* @param userId
|
||||
* user id for UserInfo
|
||||
* @return UserInfo for user id, or null
|
||||
* @param sub
|
||||
* subject for UserInfo
|
||||
* @return UserInfo for sub, or null
|
||||
*/
|
||||
public UserInfo getByUserId(String userId);
|
||||
public UserInfo getBySubject(String userId);
|
||||
|
||||
/**
|
||||
* Remove the UserInfo
|
||||
*
|
||||
|
@ -49,11 +50,11 @@ public interface UserInfoService {
|
|||
*/
|
||||
public void remove(UserInfo userInfo);
|
||||
|
||||
|
||||
/**
|
||||
* Remove the UserInfo
|
||||
*
|
||||
* @param userId
|
||||
* user id for UserInfo to remove
|
||||
* Get the UserInfo for the given preferredUsername field
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
public void removeByUserId(String userId);
|
||||
public UserInfo getByUsername(String username);
|
||||
}
|
||||
|
|
|
@ -44,8 +44,11 @@ public class JpaUserInfoRepository implements UserInfoRepository {
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
public UserInfo getByUserId(String userId) {
|
||||
return manager.find(DefaultUserInfo.class, userId);
|
||||
public UserInfo getBySubject(String sub) {
|
||||
TypedQuery<DefaultUserInfo> query = manager.createNamedQuery("DefaultUserInfo.getBySubject", DefaultUserInfo.class);
|
||||
query.setParameter("sub", sub);
|
||||
|
||||
return getSingleResult(query.getResultList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,18 +70,6 @@ public class JpaUserInfoRepository implements UserInfoRepository {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeByUserId(String userId) {
|
||||
UserInfo found = manager.find(DefaultUserInfo.class, userId);
|
||||
|
||||
if (found != null) {
|
||||
manager.remove(found);
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<DefaultUserInfo> getAll() {
|
||||
|
|
|
@ -57,8 +57,8 @@ public class DefaultUserInfoService implements UserInfoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public UserInfo getByUserId(String userId) {
|
||||
return userInfoRepository.getByUserId(userId);
|
||||
public UserInfo getBySubject(String userId) {
|
||||
return userInfoRepository.getBySubject(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,10 +67,10 @@ public class DefaultUserInfoService implements UserInfoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeByUserId(String userId) {
|
||||
userInfoRepository.removeByUserId(userId);
|
||||
public UserInfo getByUsername(String username) {
|
||||
return userInfoRepository.getByUsername(username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the userInfoRepository
|
||||
*/
|
||||
|
|
|
@ -87,7 +87,7 @@ public class UserInfoEndpoint {
|
|||
}
|
||||
|
||||
String userId = p.getName();
|
||||
UserInfo userInfo = userInfoService.getByUserId(userId);
|
||||
UserInfo userInfo = userInfoService.getBySubject(userId);
|
||||
|
||||
if (userInfo == null) {
|
||||
logger.error("getInfo failed; user not found: " + userId);
|
||||
|
|
|
@ -36,7 +36,7 @@ public class UserInfoInterceptor extends HandlerInterceptorAdapter {
|
|||
if (p != null && p.getName() != null) { // don't bother checking if we don't have a principal
|
||||
|
||||
// try to look up a user based on it
|
||||
UserInfo user = userInfoService.getByUserId(p.getName());
|
||||
UserInfo user = userInfoService.getBySubject(p.getName());
|
||||
|
||||
// if we have one, inject it so views can use it
|
||||
if (user != null) {
|
||||
|
|
Loading…
Reference in New Issue