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 e365a6147b..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; @@ -29,6 +30,7 @@ public class RealmRepresentation { protected List users; protected List roleMappings; protected List scopeMappings; + protected List socialMappings; protected List applications; @@ -144,6 +146,18 @@ public class RealmRepresentation { return mapping; } + public List getSocialMappings() { + return socialMappings; + } + + public SocialMappingRepresentation socialMapping(String username) { + SocialMappingRepresentation mapping = new SocialMappingRepresentation(); + mapping.setUsername(username); + if (socialMappings == null) socialMappings = new ArrayList(); + socialMappings.add(mapping); + return mapping; + } + public Set getRequiredCredentials() { return requiredCredentials; } @@ -223,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/core/src/main/java/org/keycloak/representations/idm/SocialLinkRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/SocialLinkRepresentation.java new file mode 100644 index 0000000000..a6e183890a --- /dev/null +++ b/core/src/main/java/org/keycloak/representations/idm/SocialLinkRepresentation.java @@ -0,0 +1,26 @@ +package org.keycloak.representations.idm; + +/** + * @author Marek Posolda + */ +public class SocialLinkRepresentation { + + protected String socialProvider; + protected String socialUsername; + + public String getSocialProvider() { + return socialProvider; + } + + public void setSocialProvider(String socialProvider) { + this.socialProvider = socialProvider; + } + + public String getSocialUsername() { + return socialUsername; + } + + public void setSocialUsername(String socialUsername) { + this.socialUsername = socialUsername; + } +} diff --git a/core/src/main/java/org/keycloak/representations/idm/SocialMappingRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/SocialMappingRepresentation.java new file mode 100644 index 0000000000..57dd874a8c --- /dev/null +++ b/core/src/main/java/org/keycloak/representations/idm/SocialMappingRepresentation.java @@ -0,0 +1,43 @@ +package org.keycloak.representations.idm; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Marek Posolda + */ +public class SocialMappingRepresentation { + + protected String self; // link + protected String username; + protected List socialLinks; + + public String getSelf() { + return self; + } + + public void setSelf(String self) { + this.self = self; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public List getSocialLinks() { + return socialLinks; + } + + public SocialLinkRepresentation socialLink(String socialProvider, String socialUsername) { + SocialLinkRepresentation link = new SocialLinkRepresentation(); + link.setSocialProvider(socialProvider); + link.setSocialUsername(socialUsername); + if (socialLinks == null) socialLinks = new ArrayList(); + socialLinks.add(link); + return link; + } +} diff --git a/examples/as7-eap-demo/server/src/main/resources/META-INF/testrealm.json b/examples/as7-eap-demo/server/src/main/resources/META-INF/testrealm.json index f92e34c199..bb918efc31 100755 --- a/examples/as7-eap-demo/server/src/main/resources/META-INF/testrealm.json +++ b/examples/as7-eap-demo/server/src/main/resources/META-INF/testrealm.json @@ -6,6 +6,8 @@ "sslNotRequired": true, "cookieLoginAllowed": true, "registrationAllowed": true, + "social": true, + "automaticRegistrationAfterSocialLogin": false, "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" ], diff --git a/forms/src/main/java/org/keycloak/forms/RegisterBean.java b/forms/src/main/java/org/keycloak/forms/RegisterBean.java index 60d247acd1..77d6a8cbe6 100755 --- a/forms/src/main/java/org/keycloak/forms/RegisterBean.java +++ b/forms/src/main/java/org/keycloak/forms/RegisterBean.java @@ -26,6 +26,7 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest; @@ -42,6 +43,8 @@ public class RegisterBean { private HashMap formData; + private boolean socialRegistration; + @PostConstruct public void init() { FacesContext ctx = FacesContext.getCurrentInstance(); @@ -49,6 +52,9 @@ public class RegisterBean { this.formData = new HashMap(); + Boolean socialRegistrationAttr = (Boolean)request.getAttribute(FormFlows.SOCIAL_REGISTRATION); + this.socialRegistration = socialRegistrationAttr != null && socialRegistrationAttr; + @SuppressWarnings("unchecked") MultivaluedMap formData = (MultivaluedMap) request.getAttribute(FormFlows.DATA); if (formData != null) { @@ -62,4 +68,8 @@ public class RegisterBean { return formData; } + public boolean isSocialRegistration() { + return socialRegistration; + } + } diff --git a/forms/src/main/java/org/keycloak/forms/SocialBean.java b/forms/src/main/java/org/keycloak/forms/SocialBean.java index b007083044..fab91b165e 100644 --- a/forms/src/main/java/org/keycloak/forms/SocialBean.java +++ b/forms/src/main/java/org/keycloak/forms/SocialBean.java @@ -46,6 +46,9 @@ public class SocialBean { @ManagedProperty(value = "#{realm}") private RealmBean realm; + @ManagedProperty(value = "#{register}") + private RegisterBean registerBean; + @ManagedProperty(value = "#{url}") private UrlBean url; @@ -73,4 +76,32 @@ public class SocialBean { return providers; } + // Display panel with social providers just in case that social is enabled for realm, but we are not in the middle of registration with social + public boolean isDisplaySocialProviders() { + return realm.isSocial() && !registerBean.isSocialRegistration(); + } + + public RealmBean getRealm() { + return realm; + } + + public void setRealm(RealmBean realm) { + this.realm = realm; + } + + public UrlBean getUrl() { + return url; + } + + public void setUrl(UrlBean url) { + this.url = url; + } + + public RegisterBean getRegisterBean() { + return registerBean; + } + + public void setRegisterBean(RegisterBean registerBean) { + this.registerBean = registerBean; + } } diff --git a/forms/src/main/java/org/keycloak/forms/UrlBean.java b/forms/src/main/java/org/keycloak/forms/UrlBean.java index ba006096d1..62017d00bb 100644 --- a/forms/src/main/java/org/keycloak/forms/UrlBean.java +++ b/forms/src/main/java/org/keycloak/forms/UrlBean.java @@ -45,6 +45,9 @@ public class UrlBean { @ManagedProperty(value = "#{realm}") private RealmBean realm; + @ManagedProperty(value = "#{register}") + private RegisterBean registerBean; + @PostConstruct public void init() { FacesContext ctx = FacesContext.getCurrentInstance(); @@ -64,6 +67,14 @@ public class UrlBean { this.realm = realm; } + public RegisterBean getRegisterBean() { + return registerBean; + } + + public void setRegisterBean(RegisterBean registerBean) { + this.registerBean = registerBean; + } + public String getAccessUrl() { return Urls.accountAccessPage(baseURI, realm.getId()).toString(); } @@ -98,7 +109,10 @@ public class UrlBean { public String getRegistrationAction() { if (realm.isSaas()) { + // TODO: saas social registration return Urls.saasRegisterAction(baseURI).toString(); + } else if (registerBean.isSocialRegistration()) { + return Urls.socialRegisterAction(baseURI, realm.getId()).toString(); } else { return Urls.realmRegisterAction(baseURI, realm.getId()).toString(); } diff --git a/forms/src/main/resources/META-INF/resources/forms/theme/default/register.xhtml b/forms/src/main/resources/META-INF/resources/forms/theme/default/register.xhtml index 0078271801..ca9d8b6745 100755 --- a/forms/src/main/resources/META-INF/resources/forms/theme/default/register.xhtml +++ b/forms/src/main/resources/META-INF/resources/forms/theme/default/register.xhtml @@ -39,6 +39,8 @@ -

#{messages.alreadyHaveAccount} #{messages.logIn}.

+ +

#{messages.alreadyHaveAccount} #{messages.logIn}.

+
\ No newline at end of file diff --git a/forms/src/main/resources/META-INF/resources/forms/theme/default/template-login.xhtml b/forms/src/main/resources/META-INF/resources/forms/theme/default/template-login.xhtml index 05ee4fb803..e99a442c26 100644 --- a/forms/src/main/resources/META-INF/resources/forms/theme/default/template-login.xhtml +++ b/forms/src/main/resources/META-INF/resources/forms/theme/default/template-login.xhtml @@ -39,12 +39,12 @@ body { - +