KEYCLOAK-1707 Can't export SAML keys

This commit is contained in:
Stian Thorgersen 2015-07-27 13:00:22 +02:00
parent fda6a6657f
commit 6a2b369014
3 changed files with 20 additions and 12 deletions

View file

@ -310,17 +310,23 @@ module.controller('ClientCertificateExportCtrl', function($scope, $location, $ht
data: $scope.jks, data: $scope.jks,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'client/octet-stream' 'Accept': 'application/octet-stream'
} }
}).success(function(data){ }).success(function(data){
var blob = new Blob([data], { var blob = new Blob([data], {
type: 'client/octet-stream' type: 'application/octet-stream'
}); });
var ext = ".jks"; var ext = ".jks";
if ($scope.jks.format == 'PKCS12') ext = ".p12"; if ($scope.jks.format == 'PKCS12') ext = ".p12";
saveAs(blob, 'keystore' + ext); saveAs(blob, 'keystore' + ext);
}).error(function(){ }).error(function(data) {
Notifications.error("Error downloading."); var errorMsg = 'Error downloading';
try {
var error = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(data)));
errorMsg = error['error_description'] ? error['error_description'] : errorMsg;
} catch (err) {
}
Notifications.error(errorMsg);
}); });
} }

View file

@ -30,9 +30,9 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-10 col-md-offset-2" data-ng-show="access.manageRealm"> <div class="col-md-10 col-md-offset-2" data-ng-show="access.manageRealm">
<button class="btn btn-primary" type="submit" data-ng-click="generateSigningKey()">Generate new keys</button> <button class="btn btn-default" type="submit" data-ng-click="generateSigningKey()">Generate new keys</button>
<button class="btn btn-primary" type="submit" data-ng-click="importSigningKey()">Import</button> <button class="btn btn-default" type="submit" data-ng-click="importSigningKey()">Import</button>
<button class="btn btn-primary" type="submit" data-ng-hide="!signingKeyInfo.certificate" data-ng-click="exportSigningKey()">Export</button> <button class="btn btn-default" type="submit" data-ng-hide="!signingKeyInfo.certificate" data-ng-click="exportSigningKey()">Export</button>
</div> </div>
</div> </div>
</fieldset> </fieldset>
@ -56,9 +56,9 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-10 col-md-offset-2" data-ng-show="access.manageRealm"> <div class="col-md-10 col-md-offset-2" data-ng-show="access.manageRealm">
<button class="btn btn-primary" type="submit" data-ng-click="generateEncryptionKey()">Generate new keys</button> <button class="btn btn-default" type="submit" data-ng-click="generateEncryptionKey()">Generate new keys</button>
<button class="btn btn-primary" type="submit" data-ng-click="importEncryptionKey()">Import</button> <button class="btn btn-default" type="submit" data-ng-click="importEncryptionKey()">Import</button>
<button class="btn btn-primary" type="submit" data-ng-hide="!encryptionKeyInfo.certificate" data-ng-click="exportEncryptionKey()">Export</button> <button class="btn btn-default" type="submit" data-ng-hide="!encryptionKeyInfo.certificate" data-ng-click="exportEncryptionKey()">Export</button>
</div> </div>
</div> </div>
</fieldset> </fieldset>

View file

@ -11,6 +11,7 @@ import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.services.ErrorResponseException;
import org.keycloak.util.CertificateUtils; import org.keycloak.util.CertificateUtils;
import org.keycloak.util.PemUtils; import org.keycloak.util.PemUtils;
@ -21,6 +22,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -281,10 +283,10 @@ public class ClientAttributeCertificateResource {
throw new NotFoundException("keypair not generated for client"); throw new NotFoundException("keypair not generated for client");
} }
if (privatePem != null && config.getKeyPassword() == null) { if (privatePem != null && config.getKeyPassword() == null) {
throw new BadRequestException("Need to specify a key password for jks download"); throw new ErrorResponseException("password-missing", "Need to specify a key password for jks download", Response.Status.BAD_REQUEST);
} }
if (config.getStorePassword() == null) { if (config.getStorePassword() == null) {
throw new BadRequestException("Need to specify a store password for jks download"); throw new ErrorResponseException("password-missing", "Need to specify a store password for jks download", Response.Status.BAD_REQUEST);
} }
final KeyStore keyStore; final KeyStore keyStore;
try { try {