diff --git a/openid-connect-common/src/main/java/org/mitre/openid/connect/service/StatsService.java b/openid-connect-common/src/main/java/org/mitre/openid/connect/service/StatsService.java new file mode 100644 index 000000000..bd6063258 --- /dev/null +++ b/openid-connect-common/src/main/java/org/mitre/openid/connect/service/StatsService.java @@ -0,0 +1,24 @@ +/** + * + */ +package org.mitre.openid.connect.service; + +import java.util.Map; + +/** + * @author jricher + * + */ +public interface StatsService { + + /** + * Calculate summary statistics + * approvalCount: total approved sites + * userCount: unique users + * clientCount: unique clients + * + * @return + */ + public Map<String, Integer> calculateSummaryStats(); + +} diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultStatsService.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultStatsService.java new file mode 100644 index 000000000..71189d0b1 --- /dev/null +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultStatsService.java @@ -0,0 +1,49 @@ +/** + * + */ +package org.mitre.openid.connect.service.impl; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.mitre.openid.connect.model.ApprovedSite; +import org.mitre.openid.connect.service.ApprovedSiteService; +import org.mitre.openid.connect.service.StatsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author jricher + * + */ +@Service +public class DefaultStatsService implements StatsService { + + @Autowired + private ApprovedSiteService approvedSiteService; + + @Override + public Map<String, Integer> calculateSummaryStats() { + // get all approved sites + Collection<ApprovedSite> allSites = approvedSiteService.getAll(); + + // process to find number of unique users and sites + Set<String> userIds = new HashSet<String>(); + Set<String> clientIds = new HashSet<String>(); + for (ApprovedSite approvedSite : allSites) { + userIds.add(approvedSite.getUserId()); + clientIds.add(approvedSite.getClientId()); + } + + Map<String, Integer> e = new HashMap<String, Integer>(); + + e.put("approvalCount", allSites.size()); + e.put("userCount", userIds.size()); + e.put("clientCount", clientIds.size()); + return e; + } + +} diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ManagerController.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ManagerController.java index d8a915469..df1efcc3b 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ManagerController.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/ManagerController.java @@ -15,8 +15,13 @@ ******************************************************************************/ package org.mitre.openid.connect.web; +import java.util.Map; + +import org.mitre.openid.connect.service.StatsService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; /** @@ -28,9 +33,16 @@ import org.springframework.web.bind.annotation.RequestMapping; @PreAuthorize("hasRole('ROLE_USER')") // TODO: this probably shouldn't be here public class ManagerController { + @Autowired + private StatsService statsService; @RequestMapping({"", "home", "index"}) - public String showHomePage() { + public String showHomePage(ModelMap m) { + + Map<String, Integer> summary = statsService.calculateSummaryStats(); + + m.put("statsSummary", summary); + return "home"; } diff --git a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/StatsAPI.java b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/StatsAPI.java index baab1cbe4..70bae8980 100644 --- a/openid-connect-server/src/main/java/org/mitre/openid/connect/web/StatsAPI.java +++ b/openid-connect-server/src/main/java/org/mitre/openid/connect/web/StatsAPI.java @@ -1,13 +1,9 @@ package org.mitre.openid.connect.web; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; -import org.mitre.openid.connect.model.ApprovedSite; import org.mitre.openid.connect.service.ApprovedSiteService; +import org.mitre.openid.connect.service.StatsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; @@ -21,31 +17,12 @@ import org.springframework.web.bind.annotation.RequestMapping; public class StatsAPI { @Autowired - private ApprovedSiteService approvedSiteService; + private StatsService statsService; - public StatsAPI() { - - } - @RequestMapping("summary") public String statsSummary(ModelMap m) { - // get all approved sites - Collection<ApprovedSite> allSites = approvedSiteService.getAll(); - - // process to find number of unique users and sites - Set<String> userIds = new HashSet<String>(); - Set<String> clientIds = new HashSet<String>(); - for (ApprovedSite approvedSite : allSites) { - userIds.add(approvedSite.getUserId()); - clientIds.add(approvedSite.getClientId()); - } - - Map<String, Integer> e = new HashMap<String, Integer>(); - - e.put("approvalCount", allSites.size()); - e.put("userCount", userIds.size()); - e.put("clientCount", clientIds.size()); + Map<String, Integer> e = statsService.calculateSummaryStats(); m.put("entity", e); diff --git a/openid-connect-server/src/main/webapp/WEB-INF/views/home.jsp b/openid-connect-server/src/main/webapp/WEB-INF/views/home.jsp index 08362794b..eff0142a5 100644 --- a/openid-connect-server/src/main/webapp/WEB-INF/views/home.jsp +++ b/openid-connect-server/src/main/webapp/WEB-INF/views/home.jsp @@ -14,10 +14,10 @@ <div class="hero-unit"> <h1>Welcome!</h1> - <p>Can't remember your passwords? Tired of filling out registration forms? - OpenID is a <strong>safe</strong>, <strong>faster</strong>, and <strong>easier</strong> way to log - in to - web sites.</p> + <p>OpenID Connect is a next-generation protocol built on top of the OAuth2 authorization framework. + OpenID Connect lets you log into a remote site using your identity without exposing your + credentials, like a username and password. + </p> <p><a class="btn btn-primary btn-large" href="http://openid.net/connect/">Learn more »</a></p> </div> @@ -26,24 +26,16 @@ <div class="span6"> <h2>About</h2> - <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, - tortor - mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada - magna - mollis euismod. Donec sed odio dui. </p> + <p>This OpenID Connect service is built from the MITREid Connect Open Source project started by The MITRE Corporation.</p> - <p><a class="btn" href="#">More »</a></p> + <p><a class="btn" href="http://github.com/mitreid-connect/">More »</a></p> </div> <div class="span6"> <h2>Contact</h2> - <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, - tortor - mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada - magna - mollis euismod. Donec sed odio dui. </p> + <p>For more information or support, contact the administrators of this system.</p> - <p><a class="btn" href="#">Email »</a></p> + <p><a class="btn" href="mailto:idp@example.com?Subject=OpenID Connect">Email »</a></p> </div> </div> @@ -53,10 +45,9 @@ <div class="span12"> <h2>Current Statistics</h2> - <p>You'll be keen to know that there have been <span class="label label-info">4720</span> users of this - system who have logged in to - <span class="label label-info">203</span> - total sites, for a total of <span class="label label-info">6224</span> site approvals.</p> + <p>There have been <span class="label label-info">${statsSummary["userCount"]}</span> users of this + system who have logged in to <span class="label label-info">${statsSummary["clientCount"]}</span> + total sites, for a total of <span class="label label-info">${statsSummary["approvalCount"]}</span> site approvals.</p> </div> </div>