Tweaks to file provider

This commit is contained in:
Stian Thorgersen 2015-03-09 15:23:54 +01:00
parent b79160722c
commit f6a2c23314
9 changed files with 48 additions and 37 deletions

View file

@ -727,7 +727,6 @@ public class RepresentationToModel {
hashedCred.setHashIterations(cred.getHashIterations());
try {
if (cred.getSalt() != null) hashedCred.setSalt(Base64.decode(cred.getSalt()));
// hashedCred.setSalt(Base64.decode(cred.getSalt()));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}

View file

@ -1028,13 +1028,17 @@ public class RealmAdapter implements RealmModel {
@Override
public void setMasterAdminApp(ApplicationModel app) {
if (app == null) throw new NullPointerException("app == null");
String appId = app.getId();
if (appId == null) {
throw new IllegalStateException("Master Admin app not initialized.");
if (app == null) {
realm.setAdminAppId(null);
this.masterAdminApp = null;
} else {
String appId = app.getId();
if (appId == null) {
throw new IllegalStateException("Master Admin app not initialized.");
}
realm.setAdminAppId(appId);
this.masterAdminApp = app;
}
realm.setAdminAppId(appId);
this.masterAdminApp = app;
}
@Override

View file

@ -24,8 +24,6 @@ import org.keycloak.testsuite.broker.util.UserSessionStatusServlet;
import org.keycloak.testsuite.rule.AbstractKeycloakRule;
import java.net.URL;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.testutils.KeycloakServer;
/**
* @author pedroigor
@ -34,9 +32,7 @@ public class BrokerKeyCloakRule extends AbstractKeycloakRule {
@Override
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
//server.importRealm(getClass().getResourceAsStream("/broker-test/test-realm-with-broker.json"));
RealmRepresentation realmWithBroker = KeycloakServer.loadJson(getClass().getResourceAsStream("/broker-test/test-realm-with-broker.json"), RealmRepresentation.class);
manager.importRealm(realmWithBroker);
server.importRealm(getClass().getResourceAsStream("/broker-test/test-realm-with-broker.json"));
URL url = getClass().getResource("/broker-test/test-app-keycloak.json");
deployApplication("test-app", "/test-app", UserSessionStatusServlet.class, url.getPath(), "manager");
deployApplication("test-app-allowed-providers", "/test-app-allowed-providers", UserSessionStatusServlet.class, url.getPath(), "manager");

View file

@ -17,7 +17,6 @@ import org.openqa.selenium.WebDriver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.keycloak.representations.idm.RealmRepresentation;
/**
* @author pedroigor
@ -37,9 +36,7 @@ public class IdentityProviderHintTest {
@Override
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
//server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-kc-oidc.json"));
RealmRepresentation realmWithOIDC = KeycloakServer.loadJson(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-kc-oidc.json"), RealmRepresentation.class);
manager.importRealm(realmWithOIDC);
server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-kc-oidc.json"));
}
};

View file

@ -15,7 +15,6 @@ import java.io.IOException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.keycloak.representations.idm.RealmRepresentation;
/**
* @author pedroigor
@ -32,9 +31,7 @@ public class OIDCKeyCloakServerBrokerBasicTest extends AbstractIdentityProviderT
@Override
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
//server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-kc-oidc.json"));
RealmRepresentation realmWithOIDC = KeycloakServer.loadJson(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-kc-oidc.json"), RealmRepresentation.class);
manager.importRealm(realmWithOIDC);
server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-kc-oidc.json"));
}
};

View file

@ -19,7 +19,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.keycloak.representations.idm.RealmRepresentation;
/**
* @author pedroigor
@ -36,9 +35,7 @@ public class SAMLKeyCloakServerBrokerBasicTest extends AbstractIdentityProviderT
@Override
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
//server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-saml.json"));
RealmRepresentation realmWithSAML = KeycloakServer.loadJson(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-saml.json"), RealmRepresentation.class);
manager.importRealm(realmWithSAML);
server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-saml.json"));
}
};

View file

@ -19,7 +19,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.keycloak.representations.idm.RealmRepresentation;
/**
* @author pedroigor
@ -36,9 +35,7 @@ public class SAMLKeyCloakServerBrokerWithSignatureTest extends AbstractIdentityP
@Override
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
//server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-saml-with-signature.json"));
RealmRepresentation realmWithOIDC = KeycloakServer.loadJson(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-saml-with-signature.json"), RealmRepresentation.class);
manager.importRealm(realmWithOIDC);
server.importRealm(getClass().getResourceAsStream("/broker-test/test-broker-realm-with-saml-with-signature.json"));
}
};

View file

@ -20,6 +20,9 @@ import org.keycloak.models.utils.RepresentationToModel;
import org.keycloak.representations.idm.CredentialRepresentation;
import org.keycloak.services.managers.RealmManager;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@ -44,11 +47,17 @@ public class AdapterTest extends AbstractModelTest {
realmModel.setAccessCodeLifespanUserAction(600);
realmModel.setEnabled(true);
realmModel.setName("JUGGLER");
// realmModel.setPrivateKeyPem("0234234");
// realmModel.setPublicKeyPem("0234234");
KeyPair keyPair = generateKeypair();
realmModel.setPrivateKey(keyPair.getPrivate());
realmModel.setPublicKey(keyPair.getPublic());
realmModel.setAccessTokenLifespan(1000);
realmModel.addDefaultRole("foo");
session.getTransaction().commit();
resetSession();
realmModel = realmManager.getRealm(realmModel.getId());
assertNotNull(realmModel);
Assert.assertEquals(realmModel.getAccessCodeLifespan(), 100);
@ -56,8 +65,8 @@ public class AdapterTest extends AbstractModelTest {
Assert.assertEquals(realmModel.getAccessTokenLifespan(), 1000);
Assert.assertEquals(realmModel.isEnabled(), true);
Assert.assertEquals(realmModel.getName(), "JUGGLER");
// Assert.assertEquals(realmModel.getPrivateKeyPem(), "0234234");
// Assert.assertEquals(realmModel.getPublicKeyPem(), "0234234");
Assert.assertArrayEquals(realmModel.getPrivateKey().getEncoded(), keyPair.getPrivate().getEncoded());
Assert.assertArrayEquals(realmModel.getPublicKey().getEncoded(), keyPair.getPublic().getEncoded());
Assert.assertEquals(1, realmModel.getDefaultRoles().size());
Assert.assertEquals("foo", realmModel.getDefaultRoles().get(0));
}
@ -69,8 +78,9 @@ public class AdapterTest extends AbstractModelTest {
realmModel.setAccessCodeLifespanUserAction(600);
realmModel.setEnabled(true);
realmModel.setName("JUGGLER");
// realmModel.setPrivateKeyPem("0234234");
// realmModel.setPublicKeyPem("0234234");
KeyPair keyPair = generateKeypair();
realmModel.setPrivateKey(keyPair.getPrivate());
realmModel.setPublicKey(keyPair.getPublic());
realmModel.setAccessTokenLifespan(1000);
realmModel.addDefaultRole("foo");
@ -81,8 +91,8 @@ public class AdapterTest extends AbstractModelTest {
Assert.assertEquals(realmModel.getAccessTokenLifespan(), 1000);
Assert.assertEquals(realmModel.isEnabled(), true);
Assert.assertEquals(realmModel.getName(), "JUGGLER");
// Assert.assertEquals(realmModel.getPrivateKeyPem(), "0234234");
// Assert.assertEquals(realmModel.getPublicKeyPem(), "0234234");
Assert.assertArrayEquals(realmModel.getPrivateKey().getEncoded(), keyPair.getPrivate().getEncoded());
Assert.assertArrayEquals(realmModel.getPublicKey().getEncoded(), keyPair.getPublic().getEncoded());
Assert.assertEquals(1, realmModel.getDefaultRoles().size());
Assert.assertEquals("foo", realmModel.getDefaultRoles().get(0));
@ -90,7 +100,7 @@ public class AdapterTest extends AbstractModelTest {
commit();
List<RealmModel> realms = model.getRealms();
// Assert.assertEquals(realms.size(), 2);
Assert.assertEquals(realms.size(), 2);
}
@ -738,4 +748,8 @@ public class AdapterTest extends AbstractModelTest {
resetSession();
}
private KeyPair generateKeypair() throws NoSuchAlgorithmException {
return KeyPairGenerator.getInstance("RSA").generateKeyPair();
}
}

View file

@ -8,6 +8,7 @@ import io.undertow.servlet.api.ServletInfo;
import io.undertow.servlet.api.WebResourceCollection;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.junit.rules.ExternalResource;
import org.junit.rules.TemporaryFolder;
import org.keycloak.Config;
import org.keycloak.adapters.KeycloakConfigResolver;
import org.keycloak.models.KeycloakSession;
@ -37,9 +38,15 @@ import java.util.Map;
*/
public abstract class AbstractKeycloakRule extends ExternalResource {
protected TemporaryFolder temporaryFolder;
protected KeycloakServer server;
protected void before() throws Throwable {
temporaryFolder = new TemporaryFolder();
temporaryFolder.create();
System.setProperty("keycloak.tmp.dir", temporaryFolder.newFolder().getAbsolutePath());
server = new KeycloakServer();
configureServer(server);
@ -210,6 +217,9 @@ public abstract class AbstractKeycloakRule extends ExternalResource {
removeTestRealms();
stopServer();
Time.setOffset(0);
temporaryFolder.delete();
System.getProperties().remove("keycloak.tmp.dir");
}
protected void removeTestRealms() {