From b2544dbe8f067891b609f304841ddb65d7ac0e19 Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 19 Aug 2013 15:03:42 +0200 Subject: [PATCH] Added realm option automaticRegistrationAfterSocialLogin to specify whether user is automatically registered after social login or whether he needs to confirm registration data --- .../representations/idm/RealmRepresentation.java | 9 +++++++++ .../org/keycloak/services/managers/RealmManager.java | 3 +++ .../java/org/keycloak/services/models/RealmModel.java | 4 ++++ .../services/models/picketlink/RealmAdapter.java | 11 +++++++++++ .../models/picketlink/mappings/RealmData.java | 10 ++++++++++ .../src/test/java/org/keycloak/test/ImportTest.java | 5 +++++ services/src/test/resources/testrealm-demo.json | 1 + 7 files changed, 43 insertions(+) diff --git a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java index 525ed7488f..92c3f106de 100755 --- a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java @@ -19,6 +19,7 @@ public class RealmRepresentation { protected boolean cookieLoginAllowed; protected boolean registrationAllowed; protected boolean social; + protected boolean automaticRegistrationAfterSocialLogin; protected String privateKey; protected String publicKey; protected List roles; @@ -236,4 +237,12 @@ public class RealmRepresentation { public void setSocial(boolean social) { this.social = social; } + + public boolean isAutomaticRegistrationAfterSocialLogin() { + return automaticRegistrationAfterSocialLogin; + } + + public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin) { + this.automaticRegistrationAfterSocialLogin = automaticRegistrationAfterSocialLogin; + } } diff --git a/services/src/main/java/org/keycloak/services/managers/RealmManager.java b/services/src/main/java/org/keycloak/services/managers/RealmManager.java index 506503e03a..603fc56786 100755 --- a/services/src/main/java/org/keycloak/services/managers/RealmManager.java +++ b/services/src/main/java/org/keycloak/services/managers/RealmManager.java @@ -71,6 +71,7 @@ public class RealmManager { realm.setSocial(rep.isSocial()); realm.setCookieLoginAllowed(rep.isCookieLoginAllowed()); realm.setRegistrationAllowed(rep.isRegistrationAllowed()); + realm.setAutomaticRegistrationAfterSocialLogin(rep.isAutomaticRegistrationAfterSocialLogin()); realm.setSslNotRequired((rep.isSslNotRequired())); realm.setAccessCodeLifespan(rep.getAccessCodeLifespan()); realm.setTokenLifespan(rep.getTokenLifespan()); @@ -106,6 +107,7 @@ public class RealmManager { newRealm.setSslNotRequired(rep.isSslNotRequired()); newRealm.setCookieLoginAllowed(rep.isCookieLoginAllowed()); newRealm.setRegistrationAllowed(rep.isRegistrationAllowed()); + newRealm.setAutomaticRegistrationAfterSocialLogin(rep.isAutomaticRegistrationAfterSocialLogin()); if (rep.getPrivateKey() == null || rep.getPublicKey() == null) { generateRealmKeys(newRealm); } else { @@ -252,6 +254,7 @@ public class RealmManager { rep.setRealm(realm.getName()); rep.setEnabled(realm.isEnabled()); rep.setSocial(realm.isSocial()); + rep.setAutomaticRegistrationAfterSocialLogin(realm.isAutomaticRegistrationAfterSocialLogin()); rep.setSslNotRequired(realm.isSslNotRequired()); rep.setCookieLoginAllowed(realm.isCookieLoginAllowed()); rep.setPublicKey(realm.getPublicKeyPem()); diff --git a/services/src/main/java/org/keycloak/services/models/RealmModel.java b/services/src/main/java/org/keycloak/services/models/RealmModel.java index 8ccc942f7a..9a1f3e5c8e 100755 --- a/services/src/main/java/org/keycloak/services/models/RealmModel.java +++ b/services/src/main/java/org/keycloak/services/models/RealmModel.java @@ -138,4 +138,8 @@ public interface RealmModel { boolean isSocial(); void setSocial(boolean social); + + public boolean isAutomaticRegistrationAfterSocialLogin(); + + public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin); } diff --git a/services/src/main/java/org/keycloak/services/models/picketlink/RealmAdapter.java b/services/src/main/java/org/keycloak/services/models/picketlink/RealmAdapter.java index 816aab4a63..4641f0923b 100755 --- a/services/src/main/java/org/keycloak/services/models/picketlink/RealmAdapter.java +++ b/services/src/main/java/org/keycloak/services/models/picketlink/RealmAdapter.java @@ -122,6 +122,17 @@ public class RealmAdapter implements RealmModel { realm.setSocial(social); } + @Override + public boolean isAutomaticRegistrationAfterSocialLogin() { + return realm.isAutomaticRegistrationAfterSocialLogin(); + } + + @Override + public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin) { + realm.setAutomaticRegistrationAfterSocialLogin(automaticRegistrationAfterSocialLogin); + updateRealm(); + } + @Override public boolean isSslNotRequired() { return realm.isSslNotRequired(); diff --git a/services/src/main/java/org/keycloak/services/models/picketlink/mappings/RealmData.java b/services/src/main/java/org/keycloak/services/models/picketlink/mappings/RealmData.java index 1fc6b7f54a..aeb0ad75a2 100755 --- a/services/src/main/java/org/keycloak/services/models/picketlink/mappings/RealmData.java +++ b/services/src/main/java/org/keycloak/services/models/picketlink/mappings/RealmData.java @@ -15,6 +15,7 @@ public class RealmData extends AbstractPartition { private boolean cookieLoginAllowed; private boolean registrationAllowed; private boolean social; + private boolean automaticRegistrationAfterSocialLogin; private int tokenLifespan; private int accessCodeLifespan; private String publicKeyPem; @@ -55,6 +56,15 @@ public class RealmData extends AbstractPartition { this.social = social; } + @AttributeProperty + public boolean isAutomaticRegistrationAfterSocialLogin() { + return automaticRegistrationAfterSocialLogin; + } + + public void setAutomaticRegistrationAfterSocialLogin(boolean automaticRegistrationAfterSocialLogin) { + this.automaticRegistrationAfterSocialLogin = automaticRegistrationAfterSocialLogin; + } + @AttributeProperty public boolean isSslNotRequired() { return sslNotRequired; diff --git a/services/src/test/java/org/keycloak/test/ImportTest.java b/services/src/test/java/org/keycloak/test/ImportTest.java index 95590f7e6c..e237c67b8d 100755 --- a/services/src/test/java/org/keycloak/test/ImportTest.java +++ b/services/src/test/java/org/keycloak/test/ImportTest.java @@ -59,6 +59,7 @@ public class ImportTest { defaultRealm.setSslNotRequired(false); defaultRealm.setCookieLoginAllowed(true); defaultRealm.setRegistrationAllowed(true); + defaultRealm.setAutomaticRegistrationAfterSocialLogin(false); manager.generateRealmKeys(defaultRealm); defaultRealm.addRequiredCredential(CredentialRepresentation.PASSWORD); RoleModel role = defaultRealm.addRole(SaasService.REALM_CREATOR_ROLE); @@ -69,6 +70,8 @@ public class ImportTest { RealmModel realm = manager.createRealm("demo", rep.getRealm()); manager.importRealm(rep, realm); realm.addRealmAdmin(admin); + + Assert.assertFalse(realm.isAutomaticRegistrationAfterSocialLogin()); List creds = realm.getRequiredCredentials(); Assert.assertEquals(1, creds.size()); RequiredCredentialModel cred = creds.get(0); @@ -131,6 +134,7 @@ public class ImportTest { defaultRealm.setSslNotRequired(false); defaultRealm.setCookieLoginAllowed(true); defaultRealm.setRegistrationAllowed(true); + defaultRealm.setAutomaticRegistrationAfterSocialLogin(false); manager.generateRealmKeys(defaultRealm); defaultRealm.addRequiredCredential(CredentialRepresentation.PASSWORD); RoleModel role = defaultRealm.addRole(SaasService.REALM_CREATOR_ROLE); @@ -142,6 +146,7 @@ public class ImportTest { manager.importRealm(rep, realm); realm.addRealmAdmin(admin); + Assert.assertTrue(realm.isAutomaticRegistrationAfterSocialLogin()); verifyRequiredCredentials(realm.getRequiredCredentials(), "password"); verifyRequiredCredentials(realm.getRequiredApplicationCredentials(), "totp"); verifyRequiredCredentials(realm.getRequiredOAuthClientCredentials(), "cert"); diff --git a/services/src/test/resources/testrealm-demo.json b/services/src/test/resources/testrealm-demo.json index 75007a3ca1..ffb5f98394 100755 --- a/services/src/test/resources/testrealm-demo.json +++ b/services/src/test/resources/testrealm-demo.json @@ -5,6 +5,7 @@ "accessCodeLifespan": 10, "sslNotRequired": true, "cookieLoginAllowed": true, + "automaticRegistrationAfterSocialLogin": true, "privateKey": "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=", "publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", "requiredCredentials": [ "password" ],