diff --git a/openid-connect-common/src/main/java/org/mitre/openid/connect/model/DefaultUserInfo.java b/openid-connect-common/src/main/java/org/mitre/openid/connect/model/DefaultUserInfo.java index d33dca040..b4212c58a 100644 --- a/openid-connect-common/src/main/java/org/mitre/openid/connect/model/DefaultUserInfo.java +++ b/openid-connect-common/src/main/java/org/mitre/openid/connect/model/DefaultUserInfo.java @@ -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; diff --git a/openid-connect-common/src/main/java/org/mitre/openid/connect/repository/UserInfoRepository.java b/openid-connect-common/src/main/java/org/mitre/openid/connect/repository/UserInfoRepository.java index 2e7e63f1e..1027377e0 100644 --- a/openid-connect-common/src/main/java/org/mitre/openid/connect/repository/UserInfoRepository.java +++ b/openid-connect-common/src/main/java/org/mitre/openid/connect/repository/UserInfoRepository.java @@ -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 * diff --git a/openid-connect-common/src/main/java/org/mitre/openid/connect/service/UserInfoService.java b/openid-connect-common/src/main/java/org/mitre/openid/connect/service/UserInfoService.java index 851b0502a..0f1403127 100644 --- a/openid-connect-common/src/main/java/org/mitre/openid/connect/service/UserInfoService.java +++ b/openid-connect-common/src/main/java/org/mitre/openid/connect/service/UserInfoService.java @@ -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); } diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/repository/impl/JpaUserInfoRepository.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/repository/impl/JpaUserInfoRepository.java index dd2eea515..18cc7d61d 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/repository/impl/JpaUserInfoRepository.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/repository/impl/JpaUserInfoRepository.java @@ -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 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 getAll() { diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultUserInfoService.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultUserInfoService.java index 64a344931..6aac2fbe0 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultUserInfoService.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultUserInfoService.java @@ -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 */ diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoEndpoint.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoEndpoint.java index 0cc620a37..4a369bd3b 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoEndpoint.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoEndpoint.java @@ -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); diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java index 28a610ade..f9ee36a1b 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java @@ -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) {