Repository: cxf-fediz Updated Branches: refs/heads/master 8ac43f306 -> 664d577dc
Change path pattern of Client Registration Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/664d577d Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/664d577d Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/664d577d Branch: refs/heads/master Commit: 664d577dc8cd7ad1700e78b42343bf6fc4b64810 Parents: 8ac43f3 Author: Jan Bernhardt <[email protected]> Authored: Thu Dec 10 13:57:12 2015 +0100 Committer: Jan Bernhardt <[email protected]> Committed: Thu Dec 10 14:50:33 2015 +0100 ---------------------------------------------------------------------- .../service/oidc/ClientRegistrationService.java | 61 ++++++++++---------- .../main/webapp/WEB-INF/applicationContext.xml | 4 +- .../webapp/WEB-INF/views/registerClient.jsp | 4 +- .../webapp/WEB-INF/views/registeredClients.jsp | 2 +- services/oidc/src/main/webapp/WEB-INF/web.xml | 4 +- 5 files changed, 38 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/664d577d/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 ec9cc73..7fb0f35 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 @@ -44,44 +44,42 @@ import org.apache.cxf.rt.security.crypto.CryptoUtils; @Path("/") public class ClientRegistrationService { - - private Map<String, Collection<Client>> registrations = - new ConcurrentHashMap<String, Collection<Client>>(); + + private Map<String, Collection<Client>> registrations = new ConcurrentHashMap<String, Collection<Client>>(); private OAuthDataManager manager; private Map<String, String> homeRealms = new LinkedHashMap<String, String>(); private boolean protectIdTokenWithClientSecret; - + @Context private SecurityContext sc; - - + @GET @Produces(MediaType.TEXT_HTML) - @Path("/") + @Path("/register") public RegisterClient registerStart() { return new RegisterClient(homeRealms); } - + @GET @Produces(MediaType.TEXT_HTML) - @Path("/register") - public Collection<Client> registerForm() { + @Path("/") + public Collection<Client> getClients() { return getClientRegistrations(); } - + @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML) - @Path("/register") + @Path("/") public Collection<Client> registerForm(@FormParam("appName") String appName, - @FormParam("appDescription") String appDesc, - @FormParam("appType") String appType, - @FormParam("redirectURI") String redirectURI, - @FormParam("homeRealm") String homeRealm) { + @FormParam("appDescription") String appDesc, @FormParam("appType") String appType, + @FormParam("redirectURI") String redirectURI, @FormParam("homeRealm") String homeRealm) { String clientId = generateClientId(); boolean isConfidential = "confidential".equals(appType); - String clientSecret = isConfidential ? generateClientSecret() : null; - + String clientSecret = isConfidential + ? generateClientSecret() + : null; + FedizClient newClient = new FedizClient(clientId, clientSecret, isConfidential, appName); newClient.setHomeRealm(homeRealm); newClient.setApplicationDescription(appDesc); @@ -91,33 +89,34 @@ public class ClientRegistrationService { String userName = sc.getUserPrincipal().getName(); UserSubject userSubject = new UserSubject(userName); newClient.setResourceOwnerSubject(userSubject); - + return registerNewClient(newClient); } - + protected String generateClientId() { return Base64UrlUtility.encode(CryptoUtils.generateSecureRandomBytes(10)); } - + protected String generateClientSecret() { // TODO: may need to be 384/8 or 512/8 if not a default HS256 but HS384 or HS512 - int keySizeOctets = protectIdTokenWithClientSecret ? 32 : 16; + int keySizeOctets = protectIdTokenWithClientSecret + ? 32 + : 16; return Base64UrlUtility.encode(CryptoUtils.generateSecureRandomBytes(keySizeOctets)); } - + protected Collection<Client> registerNewClient(Client newClient) { manager.setClient(newClient); Collection<Client> clientRegistrations = getClientRegistrations(); clientRegistrations.add(newClient); return clientRegistrations; - } protected Collection<Client> getClientRegistrations() { String userName = getUserName(); return getClientRegistrations(userName); } - + protected Collection<Client> getClientRegistrations(String userName) { Collection<Client> userClientRegs = registrations.get(userName); if (userClientRegs == null) { @@ -126,11 +125,14 @@ public class ClientRegistrationService { } return userClientRegs; } - + private String getUserName() { + if (sc == null || sc.getUserPrincipal() == null) { + return null; + } return sc.getUserPrincipal().getName(); } - + public void setDataProvider(OAuthDataManager m) { this.manager = m; } @@ -138,16 +140,15 @@ public class ClientRegistrationService { public void setHomeRealms(Map<String, String> homeRealms) { this.homeRealms = homeRealms; } - + public void init() { for (Client c : manager.getClients()) { String userName = c.getResourceOwnerSubject().getLogin(); getClientRegistrations(userName).add(c); } } - + public void setProtectIdTokenWithClientSecret(boolean protectIdTokenWithClientSecret) { this.protectIdTokenWithClientSecret = protectIdTokenWithClientSecret; } } - http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/664d577d/services/oidc/src/main/webapp/WEB-INF/applicationContext.xml ---------------------------------------------------------------------- diff --git a/services/oidc/src/main/webapp/WEB-INF/applicationContext.xml b/services/oidc/src/main/webapp/WEB-INF/applicationContext.xml index 9c9e5c9..85f5e41 100644 --- a/services/oidc/src/main/webapp/WEB-INF/applicationContext.xml +++ b/services/oidc/src/main/webapp/WEB-INF/applicationContext.xml @@ -98,7 +98,7 @@ </map> </property> </bean> - <jaxrs:server address="/client"> + <jaxrs:server address="/clients"> <jaxrs:serviceBeans> <ref bean="clientRegService"/> </jaxrs:serviceBeans> @@ -114,7 +114,7 @@ <property name="dispatcherName" value="jsp"/> <property name="resourcePaths"> <map> - <entry key="/client/register" value="/WEB-INF/views/registeredClients.jsp"/> + <entry key="/clients" value="/WEB-INF/views/registeredClients.jsp"/> </map> </property> </bean> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/664d577d/services/oidc/src/main/webapp/WEB-INF/views/registerClient.jsp ---------------------------------------------------------------------- diff --git a/services/oidc/src/main/webapp/WEB-INF/views/registerClient.jsp b/services/oidc/src/main/webapp/WEB-INF/views/registerClient.jsp index a414dd9..99e8ff8 100644 --- a/services/oidc/src/main/webapp/WEB-INF/views/registerClient.jsp +++ b/services/oidc/src/main/webapp/WEB-INF/views/registerClient.jsp @@ -24,7 +24,7 @@ <br/> <div class="padded"> - <form action="/fediz-oidc/client/register" + <form action="/fediz-oidc/clients" method="POST"> <table> <tr> @@ -112,7 +112,7 @@ <br/> <big><big> <p> -Back to your account <a href="<%= basePath %>"> page</a> +Return to <a href="<%= basePath %>clients">registered Clients</a> </p> </big></big> </div> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/664d577d/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp ---------------------------------------------------------------------- diff --git a/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp b/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp index 5657e56..ce8ed9f 100644 --- a/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp +++ b/services/oidc/src/main/webapp/WEB-INF/views/registeredClients.jsp @@ -75,7 +75,7 @@ <br/> <br/> <p> -Back to <a href="<%= basePath %>client">Client Registration page</a> +<a href="<%= basePath + "clients/register" %>">Register a new client</a> </p> </div> </body> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/664d577d/services/oidc/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/services/oidc/src/main/webapp/WEB-INF/web.xml b/services/oidc/src/main/webapp/WEB-INF/web.xml index 1cca8e0..2c313a7 100644 --- a/services/oidc/src/main/webapp/WEB-INF/web.xml +++ b/services/oidc/src/main/webapp/WEB-INF/web.xml @@ -36,7 +36,7 @@ </filter-mapping> <filter-mapping> <filter-name>FederationFilter</filter-name> - <url-pattern>/client/*</url-pattern> + <url-pattern>/clients/*</url-pattern> </filter-mapping> <context-param> @@ -72,7 +72,7 @@ <security-constraint> <web-resource-collection> <web-resource-name>Client Registration Protected Area</web-resource-name> - <url-pattern>/client/*</url-pattern> + <url-pattern>/clients/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>*</role-name>
