KEYCLOAK-2367

This commit is contained in:
Bill Burke 2016-02-04 16:50:02 -05:00 committed by Josh Cain
parent 192987bad5
commit 726f746b85
4 changed files with 20 additions and 6 deletions

View file

@ -22,6 +22,7 @@ import org.jboss.resteasy.plugins.providers.multipart.InputPart;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
import org.jboss.resteasy.spi.NotAcceptableException;
import org.jboss.resteasy.spi.NotFoundException;
import org.keycloak.common.util.StreamUtil;
import org.keycloak.events.admin.OperationType;
import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession;
@ -175,10 +176,19 @@ public class ClientAttributeCertificateResource {
private CertificateRepresentation getCertFromRequest(UriInfo uriInfo, MultipartFormDataInput input) throws IOException {
auth.requireManage();
CertificateRepresentation info = new CertificateRepresentation();
Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
List<InputPart> inputParts = uploadForm.get("file");
String keystoreFormat = uploadForm.get("keystoreFormat").get(0).getBodyAsString();
List<InputPart> inputParts = uploadForm.get("file");
if (keystoreFormat.equals("Certificate PEM")) {
String pem = StreamUtil.readString(inputParts.get(0).getBody(InputStream.class, null));
info.setCertificate(pem);
return info;
}
String keyAlias = uploadForm.get("keyAlias").get(0).getBodyAsString();
List<InputPart> keyPasswordPart = uploadForm.get("keyPassword");
char[] keyPassword = keyPasswordPart != null ? keyPasswordPart.get(0).getBodyAsString().toCharArray() : null;
@ -202,7 +212,6 @@ public class ClientAttributeCertificateResource {
throw new RuntimeException(e);
}
CertificateRepresentation info = new CertificateRepresentation();
if (privateKey != null) {
String privateKeyPem = KeycloakModelUtils.getPemFromKey(privateKey);
info.setPrivateKey(privateKeyPem);

View file

@ -360,9 +360,14 @@ module.controller('ClientCertificateImportCtrl', function($scope, $location, $ht
$scope.keyFormats = [
"JKS",
"PKCS12"
"PKCS12",
"Certificate PEM"
];
$scope.hideKeystoreSettings = function() {
return $scope.uploadKeyFormat == 'Certificate PEM';
}
$scope.uploadKeyFormat = $scope.keyFormats[0];
$scope.uploadFile = function() {

View file

@ -23,14 +23,14 @@
</div>
<kc-tooltip>{{:: 'archive-format.tooltip' | translate}}</kc-tooltip>
</div>
<div class="form-group">
<div class="form-group" data-ng-hide="hideKeystoreSettings()">
<label class="col-md-2 control-label" for="uploadKeyAlias">{{:: 'key-alias' | translate}}</label>
<div class="col-md-6">
<input class="form-control" type="text" id="uploadKeyAlias" name="uploadKeyAlias" data-ng-model="uploadKeyAlias" autofocus required>
</div>
<kc-tooltip>{{:: 'key-alias.tooltip' | translate}}</kc-tooltip>
</div>
<div class="form-group">
<div class="form-group" data-ng-hide="hideKeystoreSettings()">
<label class="col-md-2 control-label" for="uploadStorePassword">{{:: 'store-password' | translate}}</label>
<div class="col-md-6">
<input class="form-control" type="password" id="uploadStorePassword" name="uploadStorePassword" data-ng-model="uploadStorePassword" autofocus required>