You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jb...@apache.org on 2015/12/01 13:59:45 UTC
cxf-fediz git commit: Improved Registration Page
Repository: cxf-fediz
Updated Branches:
refs/heads/master d05027bce -> e5c3ea7c4
Improved Registration Page
Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/e5c3ea7c
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/e5c3ea7c
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/e5c3ea7c
Branch: refs/heads/master
Commit: e5c3ea7c418b10bee4bcfe74db0c9c2aaf5d8c06
Parents: d05027b
Author: Jan Bernhardt <jb...@talend.com>
Authored: Tue Dec 1 13:53:02 2015 +0100
Committer: Jan Bernhardt <jb...@talend.com>
Committed: Tue Dec 1 13:59:01 2015 +0100
----------------------------------------------------------------------
.../service/oidc/ClientRegistrationService.java | 36 +++++----
.../src/main/webapp/WEB-INF/views/consumers.jsp | 65 ---------------
.../src/main/webapp/WEB-INF/views/hashSet.jsp | 83 ++++++++++++++++++++
3 files changed, 105 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/e5c3ea7c/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/ClientRegistrationService.java
----------------------------------------------------------------------
diff --git a/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/ClientRegistrationService.java b/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/ClientRegistrationService.java
index 87c0381..c663b09 100644
--- a/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/ClientRegistrationService.java
+++ b/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/ClientRegistrationService.java
@@ -19,8 +19,8 @@
package org.apache.cxf.fediz.service.oidc;
+import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -38,16 +38,14 @@ import javax.ws.rs.core.SecurityContext;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.common.util.Base64UrlUtility;
-import org.apache.cxf.rs.security.oauth2.client.Consumer;
-import org.apache.cxf.rs.security.oauth2.client.Consumers;
import org.apache.cxf.rs.security.oauth2.common.Client;
import org.apache.cxf.rt.security.crypto.CryptoUtils;
@Path("/")
public class ClientRegistrationService {
- private Map<String, Map<String, Consumer>> registrations =
- new ConcurrentHashMap<String, Map<String, Consumer>>();
+ private Map<String, Collection<Client>> registrations =
+ new ConcurrentHashMap<String, Collection<Client>>();
private OAuthDataManager manager;
private Map<String, String> homeRealms = new LinkedHashMap<String, String>();
@Context
@@ -61,11 +59,18 @@ public class ClientRegistrationService {
return new RegisterClient(homeRealms);
}
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ @Path("/register")
+ public Collection<Client> registerForm() {
+ return getClientRegistrations();
+ }
+
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
@Path("/register")
- public Consumers registerForm(@FormParam("appName") String appName,
+ public Collection<Client> registerForm(@FormParam("appName") String appName,
@FormParam("appDescription") String appDesc,
@FormParam("appType") String appType,
@FormParam("redirectURI") String redirectURI,
@@ -94,19 +99,22 @@ public class ClientRegistrationService {
return Base64UrlUtility.encode(CryptoUtils.generateSecureRandomBytes(keySizeOctets));
}
- private Consumers registerNewClient(Client newClient) {
+ protected Collection<Client> registerNewClient(Client newClient) {
manager.setClient(newClient);
+ Collection<Client> clientRegistrations = getClientRegistrations();
+ clientRegistrations.add(newClient);
+ return clientRegistrations;
+
+ }
+
+ protected Collection<Client> getClientRegistrations() {
String userName = sc.getUserPrincipal().getName();
- Map<String, Consumer> userClientRegs = registrations.get(userName);
+ Collection<Client> userClientRegs = registrations.get(userName);
if (userClientRegs == null) {
- userClientRegs = new HashMap<String, Consumer>();
+ userClientRegs = new HashSet<Client>();
registrations.put(userName, userClientRegs);
}
- Consumer c = new Consumer(newClient.getClientId(), newClient.getClientSecret());
- c.setDescription(newClient.getApplicationDescription());
- userClientRegs.put(newClient.getClientId(), c);
- return new Consumers(new HashSet<Consumer>(userClientRegs.values()));
-
+ return userClientRegs;
}
public void setDataProvider(OAuthDataManager m) {
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/e5c3ea7c/services/oidc/src/main/webapp/WEB-INF/views/consumers.jsp
----------------------------------------------------------------------
diff --git a/services/oidc/src/main/webapp/WEB-INF/views/consumers.jsp b/services/oidc/src/main/webapp/WEB-INF/views/consumers.jsp
deleted file mode 100644
index 9f53713..0000000
--- a/services/oidc/src/main/webapp/WEB-INF/views/consumers.jsp
+++ /dev/null
@@ -1,65 +0,0 @@
-<%@ page import="javax.servlet.http.HttpServletRequest, org.apache.cxf.rs.security.oauth2.client.Consumer, org.apache.cxf.rs.security.oauth2.client.Consumers" %>
-
-<%
- Consumers regs = (Consumers)request.getAttribute("data");
- String basePath = request.getContextPath() + request.getServletPath();
- if (!basePath.endsWith("/")) {
- basePath += "/";
- }
-%>
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>API Client Registration Confirmation</title>
- <STYLE TYPE="text/css">
- <!--
- div.padded {
- padding-left: 2em;
- }
- -->
-</STYLE>
-</head>
-<body>
-<div class="padded">
-
-<h1>Registered API Clients</h1>
-<em></em>
-<br/>
-<table border="1">
- <tr><th><big><big>Client Name</big></big></th><th><big><big>Client Identifier</big></big></th><th><big><big>Client Secret</big></big></th></tr>
- <%
- for (Consumer entry : regs.getConsumers()) {
- %>
- <tr>
- <td><big><big><%= entry.getDescription() %></big></big></td>
- <td><big><big><input type="text" name="clientId" readonly="readonly" value="<%= entry.getKey() %>"/></big></big></td>
- <%
- if (entry.getSecret() != null) {
- %>
- <td><big><big><%= entry.getSecret() %></big></big></td>
- <%
- } else {
- %>
- <td><big><big>Unavailable for public client</big></big></td>
- <%
- }
- %>
- </tr>
- <%
- }
- %>
-
-</table>
-
-<br/>
-<p>
-<big><big>
-</p>
-<br/>
-<p>
-Back to <a href="<%= basePath %>client">Client Registration page</a>
-</p>
-</big></big>
-</div>
-</body>
-</html>
-
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/e5c3ea7c/services/oidc/src/main/webapp/WEB-INF/views/hashSet.jsp
----------------------------------------------------------------------
diff --git a/services/oidc/src/main/webapp/WEB-INF/views/hashSet.jsp b/services/oidc/src/main/webapp/WEB-INF/views/hashSet.jsp
new file mode 100644
index 0000000..99adac2
--- /dev/null
+++ b/services/oidc/src/main/webapp/WEB-INF/views/hashSet.jsp
@@ -0,0 +1,83 @@
+<%@ page import="org.apache.cxf.rs.security.oauth2.common.Client"%>
+<%@ page import="java.util.Collection"%>
+<%@ page import="javax.servlet.http.HttpServletRequest, org.apache.cxf.rs.security.oauth2.client.Consumer, org.apache.cxf.rs.security.oauth2.client.Consumers" %>
+
+<%
+ Collection<Client> regs = (Collection<Client>)request.getAttribute("data");
+ String basePath = request.getContextPath() + request.getServletPath();
+ if (!basePath.endsWith("/")) {
+ basePath += "/";
+ }
+%>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>API Client Registration Confirmation</title>
+ <STYLE TYPE="text/css">
+ table {
+ border-collapse: collapse;
+ }
+ table th {
+ background-color: #f0f0f0;
+ border-color: #ccc;
+ border-style: solid;
+ border-width: 1px;
+ padding: 3px 4px;
+ text-align: center;
+ }
+ table td {
+ border-color: #ccc;
+ border-style: solid;
+ border-width: 1px;
+ padding: 3px 4px;
+ }
+ </STYLE>
+</head>
+<body>
+<div class="padded">
+<h1>Registered API Clients</h1>
+<br/>
+<table border="1">
+ <tr><th>Client Name</th><th>Client Identifier</th><th>Client Secret</th><th>Redirect URIs</th></tr>
+ <%
+ for (Client client : regs) {
+ %>
+ <tr>
+ <td><%= client.getApplicationName() %></td>
+ <td><input type="text" name="clientId" size="15" readonly="readonly" value="<%= client.getClientId() %>" /></td>
+ <td>
+ <%
+ if (client.getClientSecret() != null) {
+ %>
+ <input type="text" name="clientSecret" size="25" readonly="readonly" value="<%= client.getClientSecret() %>" />
+ <%
+ } else {
+ %>
+ <i>Unavailable for public client</i>
+ <%
+ }
+ %>
+ </td>
+ <td>
+ <% if(client.getRedirectUris() != null) {
+ for (String redirectURI : client.getRedirectUris()) {
+ %>
+ <%= redirectURI %><br/>
+ <% }
+ } %>
+ </td>
+ </tr>
+ <%
+ }
+ %>
+
+</table>
+
+<br/>
+<br/>
+<p>
+Back to <a href="<%= basePath %>client">Client Registration page</a>
+</p>
+</div>
+</body>
+</html>
+