Refactored stats processor into a service, made home page into a smart page.

pull/210/head
Justin Richer 2012-08-28 17:42:20 -04:00
parent e8eaf48efd
commit 11b35267b4
5 changed files with 100 additions and 47 deletions

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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";
}

View File

@ -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);

View File

@ -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 &raquo;</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 &raquo;</a></p>
<p><a class="btn" href="http://github.com/mitreid-connect/">More &raquo;</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 &raquo;</a></p>
<p><a class="btn" href="mailto:idp@example.com?Subject=OpenID Connect">Email &raquo;</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>