Added more messages to resource bundle for forms

This commit is contained in:
Stian Thorgersen 2013-08-15 12:16:08 +01:00
parent f88097582d
commit 5f90150058
12 changed files with 274 additions and 19 deletions

View file

@ -1,3 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.forms; package org.keycloak.forms;
import java.net.URI; import java.net.URI;
@ -21,6 +42,9 @@ import org.keycloak.services.models.RequiredCredentialModel;
import org.keycloak.services.resources.flows.FormFlows; import org.keycloak.services.resources.flows.FormFlows;
import org.keycloak.services.resources.flows.Urls; import org.keycloak.services.resources.flows.Urls;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
@ManagedBean(name = "forms") @ManagedBean(name = "forms")
@RequestScoped @RequestScoped
public class FormsBean { public class FormsBean {

View file

@ -17,3 +17,16 @@ passwordConfirm=Password confirmation
authenticatorCode=Authenticator Code authenticatorCode=Authenticator Code
clientCertificate=Client Certificate clientCertificate=Client Certificate
invalidUser=Invalid username or password
invalidPassword=Invalid username or password
accountDisabled=Account is disabled, contact admin
missingName=Please specify full name
missingEmail=Please specify email
missingUsername=Please specify username
missingPassword=Please specify password
invalidPasswordConfirm=Password confirmation doesn't match
usernameExists=Username already exists

View file

@ -0,0 +1,47 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.messages;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class Messages {
public static final String ACCOUNT_DISABLED = "accountDisabled";
public static final String INVALID_PASSWORD = "invalidPassword";
public static final String INVALID_PASSWORD_CONFIRM = "invalidPasswordConfirm";
public static final String INVALID_USER = "invalidUser";
public static final String MISSING_EMAIL = "missingEmail";
public static final String MISSING_NAME = "missingName";
public static final String MISSING_PASSWORD = "missingPassword";
public static final String MISSING_USERNAME = "missingUsername";
public static final String USERNAME_EXISTS = "usernameExists";
}

View file

@ -9,6 +9,7 @@ import org.keycloak.representations.idm.CredentialRepresentation;
import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.services.managers.AuthenticationManager; import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.messages.Messages;
import org.keycloak.services.models.RealmModel; import org.keycloak.services.models.RealmModel;
import org.keycloak.services.models.RoleModel; import org.keycloak.services.models.RoleModel;
import org.keycloak.services.models.UserCredentialModel; import org.keycloak.services.models.UserCredentialModel;
@ -254,13 +255,13 @@ public class SaasService {
if (user == null) { if (user == null) {
logger.info("Not Authenticated! Incorrect user name"); logger.info("Not Authenticated! Incorrect user name");
return Flows.forms(realm, request).setError("Invalid username or password").setFormData(formData) return Flows.forms(realm, request).setError(Messages.INVALID_USER).setFormData(formData)
.forwardToLogin(); .forwardToLogin();
} }
if (!user.isEnabled()) { if (!user.isEnabled()) {
logger.info("NAccount is disabled, contact admin."); logger.info("Account is disabled, contact admin.");
return Flows.forms(realm, request).setError("Invalid username or password") return Flows.forms(realm, request).setError(Messages.ACCOUNT_DISABLED)
.setFormData(formData).forwardToLogin(); .setFormData(formData).forwardToLogin();
} }
@ -268,7 +269,7 @@ public class SaasService {
if (!authenticated) { if (!authenticated) {
logger.info("Not Authenticated! Invalid credentials"); logger.info("Not Authenticated! Invalid credentials");
return Flows.forms(realm, request).setError("Invalid username or password").setFormData(formData) return Flows.forms(realm, request).setError(Messages.INVALID_PASSWORD).setFormData(formData)
.forwardToLogin(); .forwardToLogin();
} }
@ -343,7 +344,7 @@ public class SaasService {
newUser.credential(CredentialRepresentation.PASSWORD, formData.getFirst("password")); newUser.credential(CredentialRepresentation.PASSWORD, formData.getFirst("password"));
UserModel user = registerMe(defaultRealm, newUser); UserModel user = registerMe(defaultRealm, newUser);
if (user == null) { if (user == null) {
return Flows.forms(defaultRealm, request).setError("Username already exists.") return Flows.forms(defaultRealm, request).setError(Messages.USERNAME_EXISTS)
.setFormData(formData).forwardToRegistration(); .setFormData(formData).forwardToRegistration();
} }
@ -382,23 +383,23 @@ public class SaasService {
private String validateRegistrationForm(MultivaluedMap<String, String> formData) { private String validateRegistrationForm(MultivaluedMap<String, String> formData) {
if (isEmpty(formData.getFirst("name"))) { if (isEmpty(formData.getFirst("name"))) {
return "Please specify full name"; return Messages.MISSING_NAME;
} }
if (isEmpty(formData.getFirst("email"))) { if (isEmpty(formData.getFirst("email"))) {
return "Please specify email"; return Messages.MISSING_EMAIL;
} }
if (isEmpty(formData.getFirst("username"))) { if (isEmpty(formData.getFirst("username"))) {
return "Please specify username"; return Messages.MISSING_USERNAME;
} }
if (isEmpty(formData.getFirst("password"))) { if (isEmpty(formData.getFirst("password"))) {
return "Please specify password"; return Messages.MISSING_PASSWORD;
} }
if (!formData.getFirst("password").equals(formData.getFirst("password-confirm"))) { if (!formData.getFirst("password").equals(formData.getFirst("password-confirm"))) {
return "Password confirmation doesn't match."; return Messages.INVALID_PASSWORD_CONFIRM;
} }
return null; return null;

View file

@ -1,3 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.resources; package org.keycloak.services.resources;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -39,6 +60,9 @@ import org.keycloak.social.SocialProviderException;
import org.keycloak.social.SocialRequestManager; import org.keycloak.social.SocialRequestManager;
import org.keycloak.social.SocialUser; import org.keycloak.social.SocialUser;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
@Path("/social") @Path("/social")
public class SocialResource { public class SocialResource {

View file

@ -17,6 +17,7 @@ import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.RealmManager;
import org.keycloak.services.managers.ResourceAdminManager; import org.keycloak.services.managers.ResourceAdminManager;
import org.keycloak.services.managers.TokenManager; import org.keycloak.services.managers.TokenManager;
import org.keycloak.services.messages.Messages;
import org.keycloak.services.models.RealmModel; import org.keycloak.services.models.RealmModel;
import org.keycloak.services.models.RoleModel; import org.keycloak.services.models.RoleModel;
import org.keycloak.services.models.UserCredentialModel; import org.keycloak.services.models.UserCredentialModel;
@ -203,7 +204,7 @@ public class TokenService {
if (user == null) { if (user == null) {
logger.error("Incorrect user name."); logger.error("Incorrect user name.");
return Flows.forms(realm, request).setError("Invalid username or password").setFormData(formData) return Flows.forms(realm, request).setError(Messages.INVALID_USER).setFormData(formData)
.forwardToLogin(); .forwardToLogin();
} }
if (!user.isEnabled()) { if (!user.isEnabled()) {
@ -213,7 +214,7 @@ public class TokenService {
if (!authenticated) { if (!authenticated) {
logger.error("Authentication failed"); logger.error("Authentication failed");
return Flows.forms(realm, request).setError("Invalid username or password").setFormData(formData) return Flows.forms(realm, request).setError(Messages.INVALID_PASSWORD).setFormData(formData)
.forwardToLogin(); .forwardToLogin();
} }
@ -258,7 +259,7 @@ public class TokenService {
UserModel user = realm.getUser(username); UserModel user = realm.getUser(username);
if (user != null) { if (user != null) {
return Flows.forms(realm, request).setError("Username already exists.").setFormData(formData) return Flows.forms(realm, request).setError(Messages.USERNAME_EXISTS).setFormData(formData)
.forwardToRegistration(); .forwardToRegistration();
} }
@ -579,23 +580,23 @@ public class TokenService {
private String validateRegistrationForm(MultivaluedMap<String, String> formData) { private String validateRegistrationForm(MultivaluedMap<String, String> formData) {
if (isEmpty(formData.getFirst("name"))) { if (isEmpty(formData.getFirst("name"))) {
return "Please specify full name"; return Messages.MISSING_NAME;
} }
if (isEmpty(formData.getFirst("email"))) { if (isEmpty(formData.getFirst("email"))) {
return "Please specify email"; return Messages.MISSING_EMAIL;
} }
if (isEmpty(formData.getFirst("username"))) { if (isEmpty(formData.getFirst("username"))) {
return "Please specify username"; return Messages.MISSING_USERNAME;
} }
if (isEmpty(formData.getFirst("password"))) { if (isEmpty(formData.getFirst("password"))) {
return "Please specify password"; return Messages.MISSING_PASSWORD;
} }
if (!formData.getFirst("password").equals(formData.getFirst("password-confirm"))) { if (!formData.getFirst("password").equals(formData.getFirst("password-confirm"))) {
return "Password confirmation doesn't match."; return Messages.INVALID_PASSWORD_CONFIRM;
} }
return null; return null;

View file

@ -1,3 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.resources.flows; package org.keycloak.services.resources.flows;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
@ -7,6 +28,9 @@ import org.keycloak.services.managers.AuthenticationManager;
import org.keycloak.services.managers.TokenManager; import org.keycloak.services.managers.TokenManager;
import org.keycloak.services.models.RealmModel; import org.keycloak.services.models.RealmModel;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class Flows { public class Flows {
private Flows() { private Flows() {

View file

@ -1,3 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.resources.flows; package org.keycloak.services.resources.flows;
import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.MultivaluedMap;
@ -7,6 +28,9 @@ import org.jboss.resteasy.spi.HttpRequest;
import org.keycloak.services.models.RealmModel; import org.keycloak.services.models.RealmModel;
import org.picketlink.idm.model.sample.Realm; import org.picketlink.idm.model.sample.Realm;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class FormFlows { public class FormFlows {
public static final String REALM = Realm.class.getName(); public static final String REALM = Realm.class.getName();

View file

@ -1,3 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.resources.flows; package org.keycloak.services.resources.flows;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -15,6 +36,10 @@ import org.keycloak.services.models.RoleModel;
import org.keycloak.services.models.UserModel; import org.keycloak.services.models.UserModel;
import org.keycloak.services.resources.TokenService; import org.keycloak.services.resources.TokenService;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class OAuthFlows { public class OAuthFlows {
private static final Logger log = Logger.getLogger(OAuthFlows.class); private static final Logger log = Logger.getLogger(OAuthFlows.class);

View file

@ -1,3 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.resources.flows; package org.keycloak.services.resources.flows;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -6,6 +27,9 @@ import org.jboss.resteasy.logging.Logger;
import org.jboss.resteasy.spi.HttpRequest; import org.jboss.resteasy.spi.HttpRequest;
import org.keycloak.services.JspRequestParameters; import org.keycloak.services.JspRequestParameters;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class PageFlows { public class PageFlows {
private static final Logger log = Logger.getLogger(PageFlows.class); private static final Logger log = Logger.getLogger(PageFlows.class);

View file

@ -1,5 +1,29 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.resources.flows; package org.keycloak.services.resources.flows;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class Pages { public class Pages {
public final static String LOGIN = "/sdk/login.xhtml"; public final static String LOGIN = "/sdk/login.xhtml";

View file

@ -1,3 +1,24 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.services.resources.flows; package org.keycloak.services.resources.flows;
import java.net.URI; import java.net.URI;
@ -9,6 +30,9 @@ import org.keycloak.services.resources.SaasService;
import org.keycloak.services.resources.SocialResource; import org.keycloak.services.resources.SocialResource;
import org.keycloak.services.resources.TokenService; import org.keycloak.services.resources.TokenService;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
public class Urls { public class Urls {
private static UriBuilder realmBase(URI baseUri) { private static UriBuilder realmBase(URI baseUri) {