KEYCLOAK-2367
This commit is contained in:
parent
192987bad5
commit
726f746b85
4 changed files with 20 additions and 6 deletions
0
core/src/main/java/org/keycloak/representations/idm/CertificateRepresentation.java
Normal file → Executable file
0
core/src/main/java/org/keycloak/representations/idm/CertificateRepresentation.java
Normal file → Executable 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.plugins.providers.multipart.MultipartFormDataInput;
|
||||||
import org.jboss.resteasy.spi.NotAcceptableException;
|
import org.jboss.resteasy.spi.NotAcceptableException;
|
||||||
import org.jboss.resteasy.spi.NotFoundException;
|
import org.jboss.resteasy.spi.NotFoundException;
|
||||||
|
import org.keycloak.common.util.StreamUtil;
|
||||||
import org.keycloak.events.admin.OperationType;
|
import org.keycloak.events.admin.OperationType;
|
||||||
import org.keycloak.models.ClientModel;
|
import org.keycloak.models.ClientModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
@ -175,10 +176,19 @@ public class ClientAttributeCertificateResource {
|
||||||
|
|
||||||
private CertificateRepresentation getCertFromRequest(UriInfo uriInfo, MultipartFormDataInput input) throws IOException {
|
private CertificateRepresentation getCertFromRequest(UriInfo uriInfo, MultipartFormDataInput input) throws IOException {
|
||||||
auth.requireManage();
|
auth.requireManage();
|
||||||
|
CertificateRepresentation info = new CertificateRepresentation();
|
||||||
Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
|
Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
|
||||||
List<InputPart> inputParts = uploadForm.get("file");
|
|
||||||
|
|
||||||
String keystoreFormat = uploadForm.get("keystoreFormat").get(0).getBodyAsString();
|
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();
|
String keyAlias = uploadForm.get("keyAlias").get(0).getBodyAsString();
|
||||||
List<InputPart> keyPasswordPart = uploadForm.get("keyPassword");
|
List<InputPart> keyPasswordPart = uploadForm.get("keyPassword");
|
||||||
char[] keyPassword = keyPasswordPart != null ? keyPasswordPart.get(0).getBodyAsString().toCharArray() : null;
|
char[] keyPassword = keyPasswordPart != null ? keyPasswordPart.get(0).getBodyAsString().toCharArray() : null;
|
||||||
|
@ -202,7 +212,6 @@ public class ClientAttributeCertificateResource {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
CertificateRepresentation info = new CertificateRepresentation();
|
|
||||||
if (privateKey != null) {
|
if (privateKey != null) {
|
||||||
String privateKeyPem = KeycloakModelUtils.getPemFromKey(privateKey);
|
String privateKeyPem = KeycloakModelUtils.getPemFromKey(privateKey);
|
||||||
info.setPrivateKey(privateKeyPem);
|
info.setPrivateKey(privateKeyPem);
|
||||||
|
|
|
@ -360,9 +360,14 @@ module.controller('ClientCertificateImportCtrl', function($scope, $location, $ht
|
||||||
|
|
||||||
$scope.keyFormats = [
|
$scope.keyFormats = [
|
||||||
"JKS",
|
"JKS",
|
||||||
"PKCS12"
|
"PKCS12",
|
||||||
|
"Certificate PEM"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$scope.hideKeystoreSettings = function() {
|
||||||
|
return $scope.uploadKeyFormat == 'Certificate PEM';
|
||||||
|
}
|
||||||
|
|
||||||
$scope.uploadKeyFormat = $scope.keyFormats[0];
|
$scope.uploadKeyFormat = $scope.keyFormats[0];
|
||||||
|
|
||||||
$scope.uploadFile = function() {
|
$scope.uploadFile = function() {
|
||||||
|
|
|
@ -23,14 +23,14 @@
|
||||||
</div>
|
</div>
|
||||||
<kc-tooltip>{{:: 'archive-format.tooltip' | translate}}</kc-tooltip>
|
<kc-tooltip>{{:: 'archive-format.tooltip' | translate}}</kc-tooltip>
|
||||||
</div>
|
</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>
|
<label class="col-md-2 control-label" for="uploadKeyAlias">{{:: 'key-alias' | translate}}</label>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<input class="form-control" type="text" id="uploadKeyAlias" name="uploadKeyAlias" data-ng-model="uploadKeyAlias" autofocus required>
|
<input class="form-control" type="text" id="uploadKeyAlias" name="uploadKeyAlias" data-ng-model="uploadKeyAlias" autofocus required>
|
||||||
</div>
|
</div>
|
||||||
<kc-tooltip>{{:: 'key-alias.tooltip' | translate}}</kc-tooltip>
|
<kc-tooltip>{{:: 'key-alias.tooltip' | translate}}</kc-tooltip>
|
||||||
</div>
|
</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>
|
<label class="col-md-2 control-label" for="uploadStorePassword">{{:: 'store-password' | translate}}</label>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<input class="form-control" type="password" id="uploadStorePassword" name="uploadStorePassword" data-ng-model="uploadStorePassword" autofocus required>
|
<input class="form-control" type="password" id="uploadStorePassword" name="uploadStorePassword" data-ng-model="uploadStorePassword" autofocus required>
|
||||||
|
|
Loading…
Reference in a new issue