From d0fdf8140e159c3f7312797530d7b5cfbd00fddd Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Tue, 5 Feb 2013 15:47:32 -0500 Subject: [PATCH] sorting on approval page --- .../org/mitre/oauth2/model/SystemScope.java | 68 +++++++++++++++++++ .../web/OAuthConfirmationController.java | 17 ++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/SystemScope.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/SystemScope.java index 6e795a1a0..fff8505e2 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/SystemScope.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/model/SystemScope.java @@ -133,6 +133,74 @@ public class SystemScope { this.defaultScope = defaultScope; } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (allowDynReg ? 1231 : 1237); + result = prime * result + (defaultScope ? 1231 : 1237); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((icon == null) ? 0 : icon.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SystemScope other = (SystemScope) obj; + if (allowDynReg != other.allowDynReg) { + return false; + } + if (defaultScope != other.defaultScope) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (icon == null) { + if (other.icon != null) { + return false; + } + } else if (!icon.equals(other.icon)) { + return false; + } + if (id == null) { + if (other.id != null) { + return false; + } + } else if (!id.equals(other.id)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + } diff --git a/openid-connect-server/src/main/java/org/mitre/oauth2/web/OAuthConfirmationController.java b/openid-connect-server/src/main/java/org/mitre/oauth2/web/OAuthConfirmationController.java index b702025bc..9275b2beb 100644 --- a/openid-connect-server/src/main/java/org/mitre/oauth2/web/OAuthConfirmationController.java +++ b/openid-connect-server/src/main/java/org/mitre/oauth2/web/OAuthConfirmationController.java @@ -19,6 +19,7 @@ package org.mitre.oauth2.web; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -36,6 +37,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.servlet.ModelAndView; +import com.google.common.collect.Sets; + /** * @author jricher * @@ -88,7 +91,19 @@ public class OAuthConfirmationController { Set scopes = scopeService.fromStrings(clientAuth.getScope()); - model.put("scopes", scopes); + Set sortedScopes = new LinkedHashSet(scopes.size()); + Set systemScopes = scopeService.getAll(); + + // sort scopes for display + for (SystemScope s : systemScopes) { + if (scopes.contains(s)) { + sortedScopes.add(s); + } + } + + sortedScopes.addAll(Sets.difference(scopes, systemScopes)); + + model.put("scopes", sortedScopes); return new ModelAndView("oauth/approve", model); }