[portal-commits] JBoss Portal SVN: r11814 - in branches/JBoss_Portal_Branch_2_7/core-identity/src: resources/portal-identity-sar/conf/bundles and 2 other directories.
portal-commits at lists.jboss.org
portal-commits at lists.jboss.org
Thu Sep 4 15:35:42 EDT 2008
Author: thomas.heute at jboss.com
Date: 2008-09-04 15:35:41 -0400 (Thu, 04 Sep 2008)
New Revision: 11814
Added:
branches/JBoss_Portal_Branch_2_7/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/RoleValidator.java
Modified:
branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-sar/conf/bundles/Identity.properties
branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml
branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/jsf/admin/roles/createRole.xhtml
Log:
JBPORTAL-2130: Creation of alrady existing role ends up (fails) with an exception
Added: branches/JBoss_Portal_Branch_2_7/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/RoleValidator.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/RoleValidator.java (rev 0)
+++ branches/JBoss_Portal_Branch_2_7/core-identity/src/main/org/jboss/portal/core/identity/ui/validators/RoleValidator.java 2008-09-04 19:35:41 UTC (rev 11814)
@@ -0,0 +1,88 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt 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.jboss.portal.core.identity.ui.validators;
+
+import java.util.ResourceBundle;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import javax.portlet.PortletContext;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+
+public class RoleValidator implements Validator
+{
+ /** The role module */
+ private RoleModule roleModule;
+
+ /** The logger */
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(RoleValidator.class);
+
+ public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
+ {
+ String rolename = (String) value;
+ ResourceBundle bundle = ResourceBundle.getBundle("conf.bundles.Identity", context.getViewRoot().getLocale());
+ PortletContext portletContext = (PortletContext) context.getExternalContext().getContext();
+ roleModule = (RoleModule) portletContext.getAttribute("RoleModule");
+
+ try
+ {
+ @SuppressWarnings("unused")
+ Role u = roleModule.findRoleByName(rolename);
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ bundle.getString("IDENTITY_VALIDATION_ERROR_ROLENAME_TAKEN"),
+ bundle.getString("IDENTITY_VALIDATION_ERROR_ROLENAME_TAKEN")));
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ bundle.getString("IDENTITY_VALIDATION_ERROR_ROLENAME_ERROR"),
+ bundle.getString("IDENTITY_VALIDATION_ERROR_ROLENAME_ERROR")));
+ }
+ catch (IdentityException e)
+ {
+ // TODO: Throw a catchable error
+ if (e.getMessage().contains("No such role"))
+ {
+ // ignore
+ }
+ else
+ {
+ log.error("Error validation rolename", e);
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ bundle.getString("IDENTITY_VALIDATION_ERROR_ROLENAME_ERROR"),
+ bundle.getString("IDENTITY_VALIDATION_ERROR_ROLENAME_ERROR")));
+ }
+ }
+ }
+}
Modified: branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-sar/conf/bundles/Identity.properties
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-sar/conf/bundles/Identity.properties 2008-09-04 17:23:53 UTC (rev 11813)
+++ branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-sar/conf/bundles/Identity.properties 2008-09-04 19:35:41 UTC (rev 11814)
@@ -166,7 +166,9 @@
IDENTITY_VALIDATION_ERROR_REGISTRATION=Failed to register user.
IDENTITY_VALIDATION_ERROR_USERNAME_TAKEN=This username is already taken.
-IDENTITY_VALIDATION_ERROR_USERNAME_ERROR=Error while validating username.
+IDENTITY_VALIDATION_ERROR_USERNAME_ERROR=Error while validating the username.
+IDENTITY_VALIDATION_ERROR_ROLENAME_TAKEN=This role name is already taken.
+IDENTITY_VALIDATION_ERROR_ROLENAME_ERROR=Error while validating the role name.
IDENTITY_VALIDATION_ERROR_PASSWORD_DOESNT_MATCH=The passwords doesn't match.
IDENTITY_VALIDATION_ERROR_PASSWORD_ERROR=Error while validating password.
IDENTITY_VALIDATION_ERROR_INVALID_EMAIL=Invalid E-Mail address.
Modified: branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml 2008-09-04 17:23:53 UTC (rev 11813)
+++ branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml 2008-09-04 19:35:41 UTC (rev 11814)
@@ -209,6 +209,10 @@
<validator-id>UsernameValidator</validator-id>
<validator-class>org.jboss.portal.core.identity.ui.validators.UsernameValidator</validator-class>
</validator>
+ <validator>
+ <validator-id>RoleValidator</validator-id>
+ <validator-class>org.jboss.portal.core.identity.ui.validators.RoleValidator</validator-class>
+ </validator>
<validator>
<validator-id>PasswordValidator</validator-id>
<validator-class>org.jboss.portal.core.identity.ui.validators.PasswordValidator</validator-class>
Modified: branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/jsf/admin/roles/createRole.xhtml
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/jsf/admin/roles/createRole.xhtml 2008-09-04 17:23:53 UTC (rev 11813)
+++ branches/JBoss_Portal_Branch_2_7/core-identity/src/resources/portal-identity-war/jsf/admin/roles/createRole.xhtml 2008-09-04 19:35:41 UTC (rev 11814)
@@ -21,9 +21,12 @@
<ui:define name="content">
<h3><h:outputText value="#{bundle.IDENTITY_MANAGEMENT_CREATE_ROLE}"/></h3>
<h:form>
- <h:panelGrid columns="2">
+ <h:panelGrid columns="3">
<h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ROLE}"/>
- <h:inputText id="rolename" value="#{createrolemgr.uiRole.name}" required="true"/>
+ <h:inputText id="rolename" value="#{createrolemgr.uiRole.name}" required="true">
+ <f:validator validatorId="RoleValidator"/>
+ </h:inputText>
+ <h:message for="rolename" infoClass="portlet-msg-success" errorClass="portlet-msg-error" fatalClass="portlet-msg-error" warnClass="portlet-msg-alert"/>
<h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ROLE_DISPLAY}"/>
<h:inputText id="roledisplayname" value="#{createrolemgr.uiRole.displayName}"/>
More information about the portal-commits
mailing list