diff --git a/model/src/main/java/org/cloudfoundry/identity/uaa/client/ClientMetadata.java b/model/src/main/java/org/cloudfoundry/identity/uaa/client/ClientMetadata.java
index 360c99458ba..6dc949c7419 100644
--- a/model/src/main/java/org/cloudfoundry/identity/uaa/client/ClientMetadata.java
+++ b/model/src/main/java/org/cloudfoundry/identity/uaa/client/ClientMetadata.java
@@ -1,3 +1,15 @@
+/*******************************************************************************
+ * Cloud Foundry
+ * Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved.
+ *
+ * This product is licensed to you under the Apache License, Version 2.0 (the "License").
+ * You may not use this product except in compliance with the License.
+ *
+ * This product includes a number of subcomponents with
+ * separate copyright notices and license terms. Your use of these
+ * subcomponents is subject to the terms and conditions of the
+ * subcomponent's license, as noted in the LICENSE file.
+ *******************************************************************************/
package org.cloudfoundry.identity.uaa.client;
import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -5,22 +17,11 @@
import java.net.URL;
-/*******************************************************************************
- * Cloud Foundry
- * Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved.
- *
- * This product is licensed to you under the Apache License, Version 2.0 (the "License").
- * You may not use this product except in compliance with the License.
- *
- * This product includes a number of subcomponents with
- * separate copyright notices and license terms. Your use of these
- * subcomponents is subject to the terms and conditions of the
- * subcomponent's license, as noted in the LICENSE file.
- *******************************************************************************/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ClientMetadata {
private String clientId;
+ private String clientName;
private String identityZoneId;
private boolean showOnHomePage;
private URL appLaunchUrl;
@@ -67,4 +68,12 @@ public String getAppIcon() {
public void setAppIcon(String appIcon) {
this.appIcon = appIcon;
}
+
+ public String getClientName() {
+ return clientName;
+ }
+
+ public void setClientName(String clientName) {
+ this.clientName = clientName;
+ }
}
diff --git a/server/src/main/java/org/cloudfoundry/identity/uaa/client/JdbcClientMetadataProvisioning.java b/server/src/main/java/org/cloudfoundry/identity/uaa/client/JdbcClientMetadataProvisioning.java
index 87a1b2ab605..71770e4e2e9 100644
--- a/server/src/main/java/org/cloudfoundry/identity/uaa/client/JdbcClientMetadataProvisioning.java
+++ b/server/src/main/java/org/cloudfoundry/identity/uaa/client/JdbcClientMetadataProvisioning.java
@@ -12,12 +12,17 @@
*******************************************************************************/
package org.cloudfoundry.identity.uaa.client;
+import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.cloudfoundry.identity.uaa.util.JsonUtils;
import org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
+import org.springframework.security.oauth2.provider.ClientDetailsService;
+import org.springframework.security.oauth2.provider.ClientRegistrationService;
+import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
@@ -27,23 +32,35 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
+import java.util.Map;
+
+import static org.cloudfoundry.identity.uaa.oauth.client.ClientConstants.CLIENT_NAME;
+import static org.springframework.util.StringUtils.hasText;
public class JdbcClientMetadataProvisioning implements ClientMetadataProvisioning {
private static final Log logger = LogFactory.getLog(JdbcClientMetadataProvisioning.class);
- private static final String CLIENT_METADATA_FIELDS = "client_id, identity_zone_id, show_on_home_page, app_launch_url, app_icon";
+
+ private static final String CLIENT_METADATA_FIELDS = "client_id, identity_zone_id, show_on_home_page, app_launch_url, app_icon, additional_information";
private static final String CLIENT_METADATA_QUERY = "select " + CLIENT_METADATA_FIELDS + " from oauth_client_details where client_id=? and identity_zone_id=?";
private static final String CLIENT_METADATAS_QUERY = "select " + CLIENT_METADATA_FIELDS + " from oauth_client_details where identity_zone_id=? and ((app_launch_url is not null and char_length(app_launch_url)>0) or (app_icon is not null and octet_length(app_icon)>0))";
private static final String CLIENT_METADATA_UPDATE_FIELDS = "show_on_home_page, app_launch_url, app_icon";
private static final String CLIENT_METADATA_UPDATE = "update oauth_client_details set " + CLIENT_METADATA_UPDATE_FIELDS.replace(",", "=?,") + "=?" + " where client_id=? and identity_zone_id=?";
private JdbcTemplate template;
+ private ClientDetailsService clientDetailsService;
+ private ClientRegistrationService clientRegistrationService;
private final RowMapper mapper = new ClientMetadataRowMapper();
- JdbcClientMetadataProvisioning(JdbcTemplate template) {
+ JdbcClientMetadataProvisioning(ClientDetailsService clientDetailsService,
+ ClientRegistrationService clientRegistrationService,
+ JdbcTemplate template) {
Assert.notNull(template);
+ Assert.notNull(clientDetailsService);
this.template = template;
+ this.clientDetailsService = clientDetailsService;
+ this.clientRegistrationService = clientRegistrationService;
}
public void setTemplate(JdbcTemplate template) {
@@ -65,6 +82,8 @@ public ClientMetadata retrieve(String clientId) {
@Override
public ClientMetadata update(ClientMetadata resource) {
logger.debug("Updating metadata for client: " + resource.getClientId());
+
+ updateClientNameIfNotEmpty(resource);
int updated = template.update(CLIENT_METADATA_UPDATE, ps -> {
int pos = 1;
ps.setBoolean(pos++, resource.isShowOnHomePage());
@@ -89,6 +108,15 @@ public ClientMetadata update(ClientMetadata resource) {
return resultingClientMetadata;
}
+ protected void updateClientNameIfNotEmpty(ClientMetadata resource) {
+ //we don't remove it, only set values
+ if (hasText(resource.getClientName())) {
+ BaseClientDetails client = (BaseClientDetails) clientDetailsService.loadClientByClientId(resource.getClientId());
+ client.addAdditionalInformation(CLIENT_NAME, resource.getClientName());
+ clientRegistrationService.updateClientDetails(client);
+ }
+ }
+
private class ClientMetadataRowMapper implements RowMapper {
@@ -105,7 +133,14 @@ public ClientMetadata mapRow(ResultSet rs, int rowNum) throws SQLException {
// it is safe to ignore this as client_metadata rows are always created from a ClientMetadata instance whose launch url property is strongly typed to URL
}
byte[] iconBytes = rs.getBytes(pos++);
- if(iconBytes != null) { clientMetadata.setAppIcon(new String(Base64Utils.encode(iconBytes))); }
+ if(iconBytes != null) {
+ clientMetadata.setAppIcon(new String(Base64Utils.encode(iconBytes)));
+ }
+ String json = rs.getString(pos++);
+ if (hasText(json)) {
+ Map additionalInformation = JsonUtils.readValue(json, new TypeReference