Skip to content

Commit

Permalink
Merge pull request keycloak#1514 from stianst/master
Browse files Browse the repository at this point in the history
KEYCLOAK-1714 Add @JsonIgnoreProperties(ignoreUnknown = true) to JWSH…
  • Loading branch information
stianst committed Jul 28, 2015
2 parents 2e3c7a3 + f980362 commit 6305977
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,7 @@ void readModelFile(KeycloakSession session) {
ImportUtils.importFromStream(session, JsonSerialization.mapper, fis, Strategy.IGNORE_EXISTING);
session.realms().getMigrationModel().setStoredVersion(model.getModelVersion());

List<RealmRepresentation> realmReps = new ArrayList<RealmRepresentation>();
for (RealmRepresentation realmRep : model.getRealms()) {
if (Config.getAdminRealm().equals(realmRep.getRealm())) {
realmReps.add(0, realmRep);
} else {
realmReps.add(realmRep);
}
}
for (RealmRepresentation realmRep : realmReps) {
ImportUtils.importRealm(session, realmRep, Strategy.IGNORE_EXISTING);
}

ImportUtils.importRealms(session, model.getRealms(), Strategy.IGNORE_EXISTING);
} catch (IOException ioe) {
logger.error("Unable to read model file " + kcdata.getAbsolutePath(), ioe);
} finally {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/keycloak/jose/jws/JWSHeader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.keycloak.jose.jws;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize;
Expand All @@ -11,6 +12,7 @@
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class JWSHeader implements Serializable {
@JsonProperty("alg")
private Algorithm algorithm;
Expand Down
1 change: 1 addition & 0 deletions examples/cordova/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Install to Android phone or emulator

mkdir platforms plugins
cordova plugin add org.apache.cordova.inappbrowser
cordova plugin add cordova-plugin-whitelist
cordova platform add android
cordova run android

Expand Down
1 change: 1 addition & 0 deletions examples/cordova/www/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<preference name="permissions" value="none"/>

<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="cordova-plugin-whitelist" version="1.0.0" source="npm" />

<access origin="*"/>
</widget>
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.keycloak.exportimport.ExportImportConfig;

/**
Expand All @@ -33,6 +31,21 @@ public class ImportUtils {

private static final Logger logger = Logger.getLogger(ImportUtils.class);

public static void importRealms(KeycloakSession session, Collection<RealmRepresentation> realms, Strategy strategy) {
// Import admin realm first
for (RealmRepresentation realm : realms) {
if (Config.getAdminRealm().equals(realm.getRealm())) {
importRealm(session, realm, strategy);
}
}

for (RealmRepresentation realm : realms) {
if (!Config.getAdminRealm().equals(realm.getRealm())) {
importRealm(session, realm, strategy);
}
}
}

/**
* Fully import realm from representation, save it to model and return model of newly created realm
*
Expand All @@ -41,15 +54,15 @@ public class ImportUtils {
* @param strategy specifies whether to overwrite or ignore existing realm or user entries
* @return newly imported realm (or existing realm if ignoreExisting is true and realm of this name already exists)
*/
public static RealmModel importRealm(KeycloakSession session, RealmRepresentation rep, Strategy strategy) {
public static void importRealm(KeycloakSession session, RealmRepresentation rep, Strategy strategy) {
String realmName = rep.getRealm();
RealmProvider model = session.realms();
RealmModel realm = model.getRealmByName(realmName);

if (realm != null) {
if (strategy == Strategy.IGNORE_EXISTING) {
logger.infof("Realm '%s' already exists. Import skipped", realmName);
return realm;
return;
} else {
logger.infof("Realm '%s' already exists. Removing it before import", realmName);
if (Config.getAdminRealm().equals(realm.getId())) {
Expand All @@ -73,7 +86,7 @@ public static RealmModel importRealm(KeycloakSession session, RealmRepresentatio
logger.infof("Realm '%s' imported", realmName);
}

return realm;
return;
}

private static void refreshMasterAdminApps(RealmProvider model, RealmModel realm) {
Expand Down Expand Up @@ -145,9 +158,7 @@ public static void setupMasterAdminManagement(RealmProvider model, RealmModel re
*/
public static void importFromStream(KeycloakSession session, ObjectMapper mapper, InputStream is, Strategy strategy) throws IOException {
Map<String, RealmRepresentation> realmReps = getRealmsFromStream(mapper, is);
for (RealmRepresentation realmRep : realmReps.values()) {
importRealm(session, realmRep, strategy);
}
importRealms(session, realmReps.values(), strategy);
}

public static Map<String, RealmRepresentation> getRealmsFromStream(ObjectMapper mapper, InputStream is) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public void importModel(KeycloakSessionFactory factory, final Strategy strategy)

@Override
protected void runExportImportTask(KeycloakSession session) throws IOException {
for (RealmRepresentation realmRep : realmReps.values()) {
ImportUtils.importRealm(session, realmRep, strategy);
}
ImportUtils.importRealms(session, realmReps.values(), strategy);
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,6 @@ module.controller('UserFederationMapperCtrl', function($scope, realm, provider,
$scope.changed = false;
};

$scope.cancel = function() {
window.history.back();
};

$scope.remove = function() {
Dialog.confirmDelete($scope.mapper.name, 'mapper', function() {
UserFederationMapper.remove({ realm: realm.realm, provider: provider.id, mapperId : $scope.mapper.id }, function() {
Expand All @@ -1016,6 +1012,7 @@ module.controller('UserFederationMapperCreateCtrl', function($scope, realm, prov
$scope.mapper = { federationProviderDisplayName: provider.displayName, config: {}};
$scope.mapperTypes = mapperTypes;
$scope.mapperType = null;
$scope.changed = true;

$scope.$watch('mapperType', function() {
if ($scope.mapperType != null) {
Expand Down Expand Up @@ -1052,8 +1049,8 @@ module.controller('UserFederationMapperCreateCtrl', function($scope, realm, prov
});
};

$scope.cancel = function() {
window.history.back();
$scope.reset = function() {
$location.url("/realms/" + realm.realm + '/user-federation/providers/' + provider.providerName + '/' + provider.id + '/mappers');
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ <h1 data-ng-show="create">Add User Federation Mapper</h1>
</fieldset>

<div class="form-group">
<div class="col-md-10 col-md-offset-2" data-ng-show="!create && access.manageRealm">
<button kc-save data-ng-show="changed">Save</button>
<button kc-reset data-ng-disabled="!changed">Clear changes</button>
<div class="col-md-10 col-md-offset-2" data-ng-show="access.manageRealm">
<button kc-save data-ng-disabled="!changed">Save</button>
<button kc-reset data-ng-disabled="!changed">Cancel</button>
</div>
</div>
</form>
Expand Down

0 comments on commit 6305977

Please sign in to comment.