Return-Path: Delivered-To: apmail-portals-jetspeed-dev-archive@www.apache.org Received: (qmail 56306 invoked from network); 12 Dec 2008 13:06:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Dec 2008 13:06:51 -0000 Received: (qmail 44831 invoked by uid 500); 12 Dec 2008 13:06:57 -0000 Delivered-To: apmail-portals-jetspeed-dev-archive@portals.apache.org Received: (qmail 44781 invoked by uid 500); 12 Dec 2008 13:06:57 -0000 Mailing-List: contact jetspeed-dev-help@portals.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@portals.apache.org Received: (qmail 44736 invoked by uid 99); 12 Dec 2008 13:06:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Dec 2008 05:06:57 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Dec 2008 13:06:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7CEC02388A5D; Fri, 12 Dec 2008 05:05:52 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r725991 [11/32] - in /portals/jetspeed-2/applications/j2-admin/trunk: src/main/java/ src/main/java/org/apache/jetspeed/portlets/ src/main/java/org/apache/jetspeed/portlets/admin/ src/main/java/org/apache/jetspeed/portlets/custom/ src/main/j... Date: Fri, 12 Dec 2008 13:05:40 -0000 To: jetspeed-dev@portals.apache.org From: ate@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081212130552.7CEC02388A5D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ChangePasswordPortlet.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ChangePasswordPortlet.java?rev=725991&r1=725990&r2=725991&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ChangePasswordPortlet.java (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ChangePasswordPortlet.java Fri Dec 12 05:05:25 2008 @@ -1,236 +1,236 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jetspeed.portlets.security; - -import java.io.IOException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.ResourceBundle; - -import javax.portlet.ActionRequest; -import javax.portlet.ActionResponse; -import javax.portlet.PortletConfig; -import javax.portlet.PortletException; -import javax.portlet.PortletRequest; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; -import javax.security.auth.Subject; - -import org.apache.jetspeed.CommonPortletServices; -import org.apache.jetspeed.PortalReservedParameters; -import org.apache.jetspeed.audit.AuditActivity; -import org.apache.jetspeed.request.RequestContext; -import org.apache.jetspeed.security.InvalidNewPasswordException; -import org.apache.jetspeed.security.InvalidPasswordException; -import org.apache.jetspeed.security.PasswordAlreadyUsedException; -import org.apache.jetspeed.security.PasswordCredential; -import org.apache.jetspeed.security.SecurityException; -import org.apache.jetspeed.security.User; -import org.apache.jetspeed.security.UserCredential; -import org.apache.jetspeed.security.UserManager; -import org.apache.portals.bridges.common.GenericServletPortlet; - -/** - * This portlet allows a logged on user to change its password. - * - * @author Ate Douma - * @version $Id: ChangePasswordPortlet.java 348264 2005-11-22 22:06:45Z taylor $ - */ -public class ChangePasswordPortlet extends GenericServletPortlet -{ - private UserManager manager; - private AuditActivity audit; - - public static final String USER_ADMINISTRATION = "J2 User Administration"; - - public static final String CURRENT_PASSWORD = "currentPassword"; - public static final String NEW_PASSWORD = "newPassword"; - public static final String NEW_PASSWORD_AGAIN = "newPasswordAgain"; - public static final String ERROR_MESSAGES = "errorMessages"; - public static final String PASSWORD_CHANGED = "passwordChanged"; - public static final String WHY = "why"; - public static final String REQUIRED = "required"; - public static final String CANCELLED = "cancelled"; - - public void init(PortletConfig config) - throws PortletException - { - super.init(config); - manager = (UserManager) getPortletContext().getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT); - if (null == manager) - { - throw new PortletException("Failed to find the User Manager on portlet initialization"); - } - audit = (AuditActivity)getPortletContext().getAttribute(CommonPortletServices.CPS_AUDIT_ACTIVITY); - if (null == audit) - { - throw new PortletException("Failed to find the Audit Activity on portlet initialization"); - } - } - - public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException - { - response.setContentType("text/html"); - - if ( request.getUserPrincipal() != null ) - { - RequestContext requestContext = (RequestContext)request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); - Integer passwordDaysValid = (Integer)requestContext.getAttribute(PasswordCredential.PASSWORD_CREDENTIAL_DAYS_VALID_REQUEST_ATTR_KEY); - - if ( passwordDaysValid != null ) - { - ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.ChgPwdResources",request.getLocale()); - if ( passwordDaysValid.intValue() < 1 ) - { - request.setAttribute(WHY,bundle.getString("chgpwd.message.change.required")); - request.setAttribute(REQUIRED,Boolean.TRUE); - } - else if ( passwordDaysValid.intValue() == 1 ) - { - request.setAttribute(WHY,bundle.getString("chgpwd.message.expires.today")); - request.setAttribute(REQUIRED,Boolean.TRUE); - } - else - { - MessageFormat mf = new MessageFormat(bundle.getString("chgpwd.message.expires.in.days")); - request.setAttribute(WHY,mf.format(new Integer[]{passwordDaysValid})); - } - } - - ArrayList errorMessages = (ArrayList)request.getPortletSession().getAttribute(ERROR_MESSAGES); - if (errorMessages != null ) - { - request.getPortletSession().removeAttribute(ERROR_MESSAGES); - request.setAttribute(ERROR_MESSAGES,errorMessages); - } - else - { - Boolean password_changed = (Boolean)request.getPortletSession().getAttribute(PASSWORD_CHANGED); - if ( password_changed != null ) - { - request.getPortletSession().removeAttribute(PASSWORD_CHANGED); - request.setAttribute(PASSWORD_CHANGED,password_changed); - } - } - } - super.doView(request, response); - } - - public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, - IOException - { - if ( actionRequest.getUserPrincipal() != null ) - { - ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.ChgPwdResources",actionRequest.getLocale()); - - ArrayList errorMessages = new ArrayList(); - - String cancelled = actionRequest.getParameter(CANCELLED); - if ( cancelled == null ) - { - String currPassword = actionRequest.getParameter(CURRENT_PASSWORD); - String newPassword = actionRequest.getParameter(NEW_PASSWORD); - String newPasswordAgain = actionRequest.getParameter(NEW_PASSWORD_AGAIN); - String userName = actionRequest.getUserPrincipal().getName(); - - if (currPassword == null || currPassword.length() == 0) - { - errorMessages.add(bundle.getString("chgpwd.error.currentPasswordNull")); - currPassword = null; - } - if (newPassword == null || newPassword.length() == 0) - { - errorMessages.add(bundle.getString("chgpwd.error.newPasswordNull")); - newPassword = null; - } - if (newPassword != null && newPassword.length() == 0) - { - newPassword = null; - } - - if (newPassword != null && - (newPasswordAgain == null || (newPasswordAgain != null && !newPassword.equals(newPasswordAgain)))) - { - errorMessages.add(bundle.getString("chgpwd.error.newPasswordsDoNotMatch")); - } - if ( errorMessages.size() == 0 ) - { - try - { - //manager.setPassword(userName, currPassword, newPassword); - // Changes for new Security API's - User user = manager.getUser(userName); - PasswordCredential credential = manager.getPasswordCredential(user); - credential.setPassword(currPassword, newPassword); - manager.storePasswordCredential(credential); - audit.logUserActivity(userName, getIPAddress(actionRequest), AuditActivity.PASSWORD_CHANGE_SUCCESS, USER_ADMINISTRATION); - - // update Subject in session to reflect the changed PasswordCredential - RequestContext requestContext = (RequestContext)actionRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); - Subject subject = (Subject)requestContext.getSessionAttribute(PortalReservedParameters.SESSION_KEY_SUBJECT); - Iterator iter = subject.getPrivateCredentials().iterator(); - while (iter.hasNext()) - { - Object o = iter.next(); - if (o instanceof UserCredential) - { - ((UserCredential)o).synchronize(credential); - break; - } - } - } - catch ( InvalidPasswordException ipe ) - { - errorMessages.add(bundle.getString("chgpwd.error.invalidPassword")); - } - catch ( InvalidNewPasswordException inpe ) - { - errorMessages.add(bundle.getString("chgpwd.error.invalidNewPassword")); - } - catch ( PasswordAlreadyUsedException paue ) - { - errorMessages.add(bundle.getString("chgpwd.error.passwordAlreadyUsed")); - } - catch ( SecurityException e) - { - // todo: localization of all exception messages - errorMessages.add(e.getMessage()); - } - } - if ( errorMessages.size() > 0 ) - { - actionRequest.getPortletSession().setAttribute(ERROR_MESSAGES,errorMessages); - audit.logUserActivity(userName, getIPAddress(actionRequest), AuditActivity.PASSWORD_CHANGE_FAILURE, errorMessages.toString()); - } - else - { - actionRequest.getPortletSession().setAttribute(PASSWORD_CHANGED,Boolean.TRUE); - } - } - } - } - - protected String getIPAddress(PortletRequest request) - { - RequestContext context = (RequestContext)request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); - if (context == null) - return ""; - return context.getRequest().getRemoteAddr(); - } - -} + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.portlets.security; + +import java.io.IOException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.ResourceBundle; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.PortletConfig; +import javax.portlet.PortletException; +import javax.portlet.PortletRequest; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import javax.security.auth.Subject; + +import org.apache.jetspeed.CommonPortletServices; +import org.apache.jetspeed.PortalReservedParameters; +import org.apache.jetspeed.audit.AuditActivity; +import org.apache.jetspeed.request.RequestContext; +import org.apache.jetspeed.security.InvalidNewPasswordException; +import org.apache.jetspeed.security.InvalidPasswordException; +import org.apache.jetspeed.security.PasswordAlreadyUsedException; +import org.apache.jetspeed.security.PasswordCredential; +import org.apache.jetspeed.security.SecurityException; +import org.apache.jetspeed.security.User; +import org.apache.jetspeed.security.UserCredential; +import org.apache.jetspeed.security.UserManager; +import org.apache.portals.bridges.common.GenericServletPortlet; + +/** + * This portlet allows a logged on user to change its password. + * + * @author Ate Douma + * @version $Id: ChangePasswordPortlet.java 348264 2005-11-22 22:06:45Z taylor $ + */ +public class ChangePasswordPortlet extends GenericServletPortlet +{ + private UserManager manager; + private AuditActivity audit; + + public static final String USER_ADMINISTRATION = "J2 User Administration"; + + public static final String CURRENT_PASSWORD = "currentPassword"; + public static final String NEW_PASSWORD = "newPassword"; + public static final String NEW_PASSWORD_AGAIN = "newPasswordAgain"; + public static final String ERROR_MESSAGES = "errorMessages"; + public static final String PASSWORD_CHANGED = "passwordChanged"; + public static final String WHY = "why"; + public static final String REQUIRED = "required"; + public static final String CANCELLED = "cancelled"; + + public void init(PortletConfig config) + throws PortletException + { + super.init(config); + manager = (UserManager) getPortletContext().getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT); + if (null == manager) + { + throw new PortletException("Failed to find the User Manager on portlet initialization"); + } + audit = (AuditActivity)getPortletContext().getAttribute(CommonPortletServices.CPS_AUDIT_ACTIVITY); + if (null == audit) + { + throw new PortletException("Failed to find the Audit Activity on portlet initialization"); + } + } + + public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException + { + response.setContentType("text/html"); + + if ( request.getUserPrincipal() != null ) + { + RequestContext requestContext = (RequestContext)request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); + Integer passwordDaysValid = (Integer)requestContext.getAttribute(PasswordCredential.PASSWORD_CREDENTIAL_DAYS_VALID_REQUEST_ATTR_KEY); + + if ( passwordDaysValid != null ) + { + ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.ChgPwdResources",request.getLocale()); + if ( passwordDaysValid.intValue() < 1 ) + { + request.setAttribute(WHY,bundle.getString("chgpwd.message.change.required")); + request.setAttribute(REQUIRED,Boolean.TRUE); + } + else if ( passwordDaysValid.intValue() == 1 ) + { + request.setAttribute(WHY,bundle.getString("chgpwd.message.expires.today")); + request.setAttribute(REQUIRED,Boolean.TRUE); + } + else + { + MessageFormat mf = new MessageFormat(bundle.getString("chgpwd.message.expires.in.days")); + request.setAttribute(WHY,mf.format(new Integer[]{passwordDaysValid})); + } + } + + ArrayList errorMessages = (ArrayList)request.getPortletSession().getAttribute(ERROR_MESSAGES); + if (errorMessages != null ) + { + request.getPortletSession().removeAttribute(ERROR_MESSAGES); + request.setAttribute(ERROR_MESSAGES,errorMessages); + } + else + { + Boolean password_changed = (Boolean)request.getPortletSession().getAttribute(PASSWORD_CHANGED); + if ( password_changed != null ) + { + request.getPortletSession().removeAttribute(PASSWORD_CHANGED); + request.setAttribute(PASSWORD_CHANGED,password_changed); + } + } + } + super.doView(request, response); + } + + public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, + IOException + { + if ( actionRequest.getUserPrincipal() != null ) + { + ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jetspeed.portlets.security.resources.ChgPwdResources",actionRequest.getLocale()); + + ArrayList errorMessages = new ArrayList(); + + String cancelled = actionRequest.getParameter(CANCELLED); + if ( cancelled == null ) + { + String currPassword = actionRequest.getParameter(CURRENT_PASSWORD); + String newPassword = actionRequest.getParameter(NEW_PASSWORD); + String newPasswordAgain = actionRequest.getParameter(NEW_PASSWORD_AGAIN); + String userName = actionRequest.getUserPrincipal().getName(); + + if (currPassword == null || currPassword.length() == 0) + { + errorMessages.add(bundle.getString("chgpwd.error.currentPasswordNull")); + currPassword = null; + } + if (newPassword == null || newPassword.length() == 0) + { + errorMessages.add(bundle.getString("chgpwd.error.newPasswordNull")); + newPassword = null; + } + if (newPassword != null && newPassword.length() == 0) + { + newPassword = null; + } + + if (newPassword != null && + (newPasswordAgain == null || (newPasswordAgain != null && !newPassword.equals(newPasswordAgain)))) + { + errorMessages.add(bundle.getString("chgpwd.error.newPasswordsDoNotMatch")); + } + if ( errorMessages.size() == 0 ) + { + try + { + //manager.setPassword(userName, currPassword, newPassword); + // Changes for new Security API's + User user = manager.getUser(userName); + PasswordCredential credential = manager.getPasswordCredential(user); + credential.setPassword(currPassword, newPassword); + manager.storePasswordCredential(credential); + audit.logUserActivity(userName, getIPAddress(actionRequest), AuditActivity.PASSWORD_CHANGE_SUCCESS, USER_ADMINISTRATION); + + // update Subject in session to reflect the changed PasswordCredential + RequestContext requestContext = (RequestContext)actionRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); + Subject subject = (Subject)requestContext.getSessionAttribute(PortalReservedParameters.SESSION_KEY_SUBJECT); + Iterator iter = subject.getPrivateCredentials().iterator(); + while (iter.hasNext()) + { + Object o = iter.next(); + if (o instanceof UserCredential) + { + ((UserCredential)o).synchronize(credential); + break; + } + } + } + catch ( InvalidPasswordException ipe ) + { + errorMessages.add(bundle.getString("chgpwd.error.invalidPassword")); + } + catch ( InvalidNewPasswordException inpe ) + { + errorMessages.add(bundle.getString("chgpwd.error.invalidNewPassword")); + } + catch ( PasswordAlreadyUsedException paue ) + { + errorMessages.add(bundle.getString("chgpwd.error.passwordAlreadyUsed")); + } + catch ( SecurityException e) + { + // todo: localization of all exception messages + errorMessages.add(e.getMessage()); + } + } + if ( errorMessages.size() > 0 ) + { + actionRequest.getPortletSession().setAttribute(ERROR_MESSAGES,errorMessages); + audit.logUserActivity(userName, getIPAddress(actionRequest), AuditActivity.PASSWORD_CHANGE_FAILURE, errorMessages.toString()); + } + else + { + actionRequest.getPortletSession().setAttribute(PASSWORD_CHANGED,Boolean.TRUE); + } + } + } + } + + protected String getIPAddress(PortletRequest request) + { + RequestContext context = (RequestContext)request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); + if (context == null) + return ""; + return context.getRequest().getRemoteAddr(); + } + +} Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/ChangePasswordPortlet.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityApplicationResources.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityApplicationResources.java?rev=725991&r1=725990&r2=725991&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityApplicationResources.java (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityApplicationResources.java Fri Dec 12 05:05:25 2008 @@ -1,31 +1,31 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jetspeed.portlets.security; - -/** - *

- * Common resources used by the security applications. - *

- * - * @author David Le Strat - */ -public class SecurityApplicationResources -{ - /** Role tree table binding variable. */ - public static final String ROLE_TREE_TABLE = "roleTreeTable"; - -} + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.portlets.security; + +/** + *

+ * Common resources used by the security applications. + *

+ * + * @author David Le Strat + */ +public class SecurityApplicationResources +{ + /** Role tree table binding variable. */ + public static final String ROLE_TREE_TABLE = "roleTreeTable"; + +} Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityApplicationResources.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityResources.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityResources.java?rev=725991&r1=725990&r2=725991&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityResources.java (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityResources.java Fri Dec 12 05:05:25 2008 @@ -1,64 +1,64 @@ -/* +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jetspeed.portlets.security; - -/** - * Common resources used by Security Portlets - * - * @author David Sean Taylor - * @version $Id: SecurityResources.java 348264 2005-11-22 22:06:45Z taylor $ - */ -public interface SecurityResources -{ - public final static String CURRENT_USER = "current_user"; - public final static String PAM_CURRENT_USER = "org.apache.jetspeed.pam.user"; - public final static String REQUEST_SELECT_USER = "select_user"; - - public final static String PORTLET_URL = "portlet_url"; - public final static String REQUEST_SELECT_PORTLET = "select_portlet"; - public final static String REQUEST_SELECT_TAB = "selected_tab"; - public final static String PORTLET_ACTION = "portlet_action"; - - // Message Topics - public final static String TOPIC_USERS = "users"; - public final static String TOPIC_USER = "user"; - public final static String TOPIC_GROUPS = "groups"; - public final static String TOPIC_GROUP = "group"; - public final static String TOPIC_ROLES = "roles"; - public final static String TOPIC_ROLE = "role"; - public final static String TOPIC_PROFILES = "profiles"; - - /** Messages **/ - public static final String MESSAGE_SELECTED = "selected"; - public static final String MESSAGE_CHANGED = "changed"; - public static final String MESSAGE_STATUS = "status"; - public static final String MESSAGE_REFRESH = "refresh"; - public static final String MESSAGE_FILTERED = "filtered"; - public static final String MESSAGE_REFRESH_PROFILES = "refresh.profiles"; - public static final String MESSAGE_REFRESH_ROLES = "refresh.roles"; - public static final String MESSAGE_REFRESH_GROUPS = "refresh.groups"; - public static final String MESSAGE_REFRESH_SUBSITES = "refresh.subsites"; - - /** the selected non-leaf node in the tree view */ - public final static String REQUEST_NODE = "node"; - /** the selected leaf node in the tree view */ - public final static String REQUEST_SELECT_NODE = "select_node"; - - /** The Error Messages KEY */ - public static final String ERROR_MESSAGES = "errorMessages"; - -} + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.portlets.security; + +/** + * Common resources used by Security Portlets + * + * @author David Sean Taylor + * @version $Id: SecurityResources.java 348264 2005-11-22 22:06:45Z taylor $ + */ +public interface SecurityResources +{ + public final static String CURRENT_USER = "current_user"; + public final static String PAM_CURRENT_USER = "org.apache.jetspeed.pam.user"; + public final static String REQUEST_SELECT_USER = "select_user"; + + public final static String PORTLET_URL = "portlet_url"; + public final static String REQUEST_SELECT_PORTLET = "select_portlet"; + public final static String REQUEST_SELECT_TAB = "selected_tab"; + public final static String PORTLET_ACTION = "portlet_action"; + + // Message Topics + public final static String TOPIC_USERS = "users"; + public final static String TOPIC_USER = "user"; + public final static String TOPIC_GROUPS = "groups"; + public final static String TOPIC_GROUP = "group"; + public final static String TOPIC_ROLES = "roles"; + public final static String TOPIC_ROLE = "role"; + public final static String TOPIC_PROFILES = "profiles"; + + /** Messages **/ + public static final String MESSAGE_SELECTED = "selected"; + public static final String MESSAGE_CHANGED = "changed"; + public static final String MESSAGE_STATUS = "status"; + public static final String MESSAGE_REFRESH = "refresh"; + public static final String MESSAGE_FILTERED = "filtered"; + public static final String MESSAGE_REFRESH_PROFILES = "refresh.profiles"; + public static final String MESSAGE_REFRESH_ROLES = "refresh.roles"; + public static final String MESSAGE_REFRESH_GROUPS = "refresh.groups"; + public static final String MESSAGE_REFRESH_SUBSITES = "refresh.subsites"; + + /** the selected non-leaf node in the tree view */ + public final static String REQUEST_NODE = "node"; + /** the selected leaf node in the tree view */ + public final static String REQUEST_SELECT_NODE = "select_node"; + + /** The Error Messages KEY */ + public static final String ERROR_MESSAGES = "errorMessages"; + +} Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityResources.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityUtil.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityUtil.java?rev=725991&r1=725990&r2=725991&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityUtil.java (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityUtil.java Fri Dec 12 05:05:25 2008 @@ -4,116 +4,116 @@ * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.jetspeed.portlets.security; - -import java.io.NotSerializableException; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Iterator; - -import javax.portlet.PortletRequest; -import javax.portlet.RenderRequest; -import javax.security.auth.Subject; -import javax.servlet.http.HttpServletRequest; - -import org.apache.jetspeed.PortalReservedParameters; -import org.apache.jetspeed.request.RequestContext; -import org.apache.portals.gems.browser.BrowserPortlet; -import org.apache.portals.messaging.PortletMessaging; - - -/** - * Abstract Security Browser - factored out common functionality for security browsers - * - * @author David Sean Taylor - * @version $Id: SecurityUtil.java 348264 2005-11-22 22:06:45Z taylor $ - */ -public abstract class SecurityUtil extends BrowserPortlet -{ - - public static Principal getPrincipal(Subject subject, Class classe) - { - Principal principal = null; - Iterator principals = subject.getPrincipals().iterator(); - while (principals.hasNext()) - { - Principal p = (Principal) principals.next(); - if (classe.isInstance(p)) - { - principal = p; - break; - } - } - return principal; - } - - public static boolean isEmpty(String s) - { - if (s == null) return true; - - if (s.trim().equals("")) return true; - - return false; - } - - public static String getAbsoluteUrl(RenderRequest renderRequest, String relativePath) - { - RequestContext requestContext = (RequestContext) renderRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); - HttpServletRequest request = requestContext.getRequest(); - StringBuffer path = new StringBuffer(); - if ( !requestContext.getPortalURL().isRelativeOnly() ) - { - path.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort()); - } - return requestContext.getResponse().encodeURL(path.append(request.getContextPath()).append(request.getServletPath()).append( - relativePath).toString()); - } - - public static void publishErrorMessage(PortletRequest request, String message) - { - try - { - ArrayList errors = (ArrayList)PortletMessaging.receive(request,SecurityResources.ERROR_MESSAGES); - if ( errors == null ) - { - errors = new ArrayList(); - } - errors.add(message); - PortletMessaging.publish(request, SecurityResources.ERROR_MESSAGES, errors); - } - catch (NotSerializableException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public static void publishErrorMessage(PortletRequest request, String topic, String message) - { - try - { - ArrayList errors = (ArrayList)PortletMessaging.receive(request,topic,SecurityResources.ERROR_MESSAGES); - if ( errors == null ) - { - errors = new ArrayList(); - } - errors.add(message); - PortletMessaging.publish(request, topic, SecurityResources.ERROR_MESSAGES, errors); - } - catch (NotSerializableException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } -} + * the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.jetspeed.portlets.security; + +import java.io.NotSerializableException; +import java.security.Principal; +import java.util.ArrayList; +import java.util.Iterator; + +import javax.portlet.PortletRequest; +import javax.portlet.RenderRequest; +import javax.security.auth.Subject; +import javax.servlet.http.HttpServletRequest; + +import org.apache.jetspeed.PortalReservedParameters; +import org.apache.jetspeed.request.RequestContext; +import org.apache.portals.gems.browser.BrowserPortlet; +import org.apache.portals.messaging.PortletMessaging; + + +/** + * Abstract Security Browser - factored out common functionality for security browsers + * + * @author David Sean Taylor + * @version $Id: SecurityUtil.java 348264 2005-11-22 22:06:45Z taylor $ + */ +public abstract class SecurityUtil extends BrowserPortlet +{ + + public static Principal getPrincipal(Subject subject, Class classe) + { + Principal principal = null; + Iterator principals = subject.getPrincipals().iterator(); + while (principals.hasNext()) + { + Principal p = (Principal) principals.next(); + if (classe.isInstance(p)) + { + principal = p; + break; + } + } + return principal; + } + + public static boolean isEmpty(String s) + { + if (s == null) return true; + + if (s.trim().equals("")) return true; + + return false; + } + + public static String getAbsoluteUrl(RenderRequest renderRequest, String relativePath) + { + RequestContext requestContext = (RequestContext) renderRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); + HttpServletRequest request = requestContext.getRequest(); + StringBuffer path = new StringBuffer(); + if ( !requestContext.getPortalURL().isRelativeOnly() ) + { + path.append(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getServerPort()); + } + return requestContext.getResponse().encodeURL(path.append(request.getContextPath()).append(request.getServletPath()).append( + relativePath).toString()); + } + + public static void publishErrorMessage(PortletRequest request, String message) + { + try + { + ArrayList errors = (ArrayList)PortletMessaging.receive(request,SecurityResources.ERROR_MESSAGES); + if ( errors == null ) + { + errors = new ArrayList(); + } + errors.add(message); + PortletMessaging.publish(request, SecurityResources.ERROR_MESSAGES, errors); + } + catch (NotSerializableException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void publishErrorMessage(PortletRequest request, String topic, String message) + { + try + { + ArrayList errors = (ArrayList)PortletMessaging.receive(request,topic,SecurityResources.ERROR_MESSAGES); + if ( errors == null ) + { + errors = new ArrayList(); + } + errors.add(message); + PortletMessaging.publish(request, topic, SecurityResources.ERROR_MESSAGES, errors); + } + catch (NotSerializableException e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/SecurityUtil.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ConstraintsViewController.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ConstraintsViewController.java?rev=725991&r1=725990&r2=725991&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ConstraintsViewController.java (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ConstraintsViewController.java Fri Dec 12 05:05:25 2008 @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.jetspeed.portlets.security.constraints; - +package org.apache.jetspeed.portlets.security.constraints; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,94 +37,94 @@ import org.springframework.web.portlet.ModelAndView; import org.springframework.web.portlet.context.PortletConfigAware; import org.springframework.web.portlet.mvc.AbstractController; - -public class ConstraintsViewController extends AbstractController implements InitializingBean, PortletConfigAware -{ - private static final String ROLES_CACHE_SESSION_ATTRIBUTE_NAME = "j2Roles"; - private static final String GROUPS_CACHE_SESSION_ATTRIBUTE_NAME = "j2Groups"; - - private PortletConfig portletConfig ; - protected PageManager pageManager; - - protected RoleManager rm = null; - protected GroupManager gm = null; - - public void afterPropertiesSet() throws Exception - { -// System.out.println("+++ after property set"); - //throw new IllegalArgumentException("A DOMTreeService is required"); - } - - public ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception - { - Map model = new HashMap(); - model.put( "messages", portletConfig.getResourceBundle( request.getLocale() ) ); - model.put( "greeting", "Hello"); - boolean constraintsEnabled = pageManager.getConstraintsEnabled(); - model.put("constraintsEnabled", new Boolean(constraintsEnabled)); - PageSecurity constraints = pageManager.getPageSecurity(); - model.put("defs", constraints.getSecurityConstraintsDefs()); - model.put("globals", constraints.getGlobalSecurityConstraintsRefs()); - - PortletSession session = request.getPortletSession(); - List roles = (List) session.getAttribute(ROLES_CACHE_SESSION_ATTRIBUTE_NAME, PortletSession.PORTLET_SCOPE); - if ( roles == null ) - { - try + +public class ConstraintsViewController extends AbstractController implements InitializingBean, PortletConfigAware +{ + private static final String ROLES_CACHE_SESSION_ATTRIBUTE_NAME = "j2Roles"; + private static final String GROUPS_CACHE_SESSION_ATTRIBUTE_NAME = "j2Groups"; + + private PortletConfig portletConfig ; + protected PageManager pageManager; + + protected RoleManager rm = null; + protected GroupManager gm = null; + + public void afterPropertiesSet() throws Exception + { +// System.out.println("+++ after property set"); + //throw new IllegalArgumentException("A DOMTreeService is required"); + } + + public ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception + { + Map model = new HashMap(); + model.put( "messages", portletConfig.getResourceBundle( request.getLocale() ) ); + model.put( "greeting", "Hello"); + boolean constraintsEnabled = pageManager.getConstraintsEnabled(); + model.put("constraintsEnabled", new Boolean(constraintsEnabled)); + PageSecurity constraints = pageManager.getPageSecurity(); + model.put("defs", constraints.getSecurityConstraintsDefs()); + model.put("globals", constraints.getGlobalSecurityConstraintsRefs()); + + PortletSession session = request.getPortletSession(); + List roles = (List) session.getAttribute(ROLES_CACHE_SESSION_ATTRIBUTE_NAME, PortletSession.PORTLET_SCOPE); + if ( roles == null ) + { + try { roles = rm.getRoles(""); - session.setAttribute(ROLES_CACHE_SESSION_ATTRIBUTE_NAME, roles, PortletSession.PORTLET_SCOPE); -// System.out.println( "roles: " + roles.toString() ); - } - catch(Exception e) - { - logger.error( "Could not get list of roles from RoleManager.", e); - } - } - model.put("roles", roles); - - List groups = (List) session.getAttribute(GROUPS_CACHE_SESSION_ATTRIBUTE_NAME, PortletSession.PORTLET_SCOPE); - if ( groups == null ) - { - try - { + session.setAttribute(ROLES_CACHE_SESSION_ATTRIBUTE_NAME, roles, PortletSession.PORTLET_SCOPE); +// System.out.println( "roles: " + roles.toString() ); + } + catch(Exception e) + { + logger.error( "Could not get list of roles from RoleManager.", e); + } + } + model.put("roles", roles); + + List groups = (List) session.getAttribute(GROUPS_CACHE_SESSION_ATTRIBUTE_NAME, PortletSession.PORTLET_SCOPE); + if ( groups == null ) + { + try + { groups = gm.getGroups(""); - session.setAttribute(GROUPS_CACHE_SESSION_ATTRIBUTE_NAME, groups, PortletSession.PORTLET_SCOPE); -// System.out.println( "groups: " + groups.toString() ); - } - catch(Exception e) - { - logger.error( "Could not get list of groups from GroupManager.", e); - } - } - model.put("groups", groups); - - model.put("renderRequest", request); - - return new ModelAndView("constraintsView", "model", model); - } - - public void setPortletConfig(PortletConfig portletConfig) - { -// System.out.println("+++ in set portlet config"); - this.portletConfig = portletConfig; - pageManager = (PageManager) getPortletContext().getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT); - if (null == pageManager) - { - PortletException pe = new PortletException("Failed to find the Page Manager on portlet initialization"); - throw new RuntimeException(pe); - } - - rm = (RoleManager) getPortletContext().getAttribute(CommonPortletServices.CPS_ROLE_MANAGER_COMPONENT); - if (rm == null) - throw new RuntimeException("Could not get instance of portal role manager component"); - - gm = (GroupManager) getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT); - if (gm == null) - throw new RuntimeException("Could not get instance of portal group manager component"); - -// System.out.println("--- out set portlet config:" + pageManager); - } - - -} + session.setAttribute(GROUPS_CACHE_SESSION_ATTRIBUTE_NAME, groups, PortletSession.PORTLET_SCOPE); +// System.out.println( "groups: " + groups.toString() ); + } + catch(Exception e) + { + logger.error( "Could not get list of groups from GroupManager.", e); + } + } + model.put("groups", groups); + + model.put("renderRequest", request); + + return new ModelAndView("constraintsView", "model", model); + } + + public void setPortletConfig(PortletConfig portletConfig) + { +// System.out.println("+++ in set portlet config"); + this.portletConfig = portletConfig; + pageManager = (PageManager) getPortletContext().getAttribute(CommonPortletServices.CPS_PAGE_MANAGER_COMPONENT); + if (null == pageManager) + { + PortletException pe = new PortletException("Failed to find the Page Manager on portlet initialization"); + throw new RuntimeException(pe); + } + + rm = (RoleManager) getPortletContext().getAttribute(CommonPortletServices.CPS_ROLE_MANAGER_COMPONENT); + if (rm == null) + throw new RuntimeException("Could not get instance of portal role manager component"); + + gm = (GroupManager) getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT); + if (gm == null) + throw new RuntimeException("Could not get instance of portal group manager component"); + +// System.out.println("--- out set portlet config:" + pageManager); + } + + +} Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ConstraintsViewController.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java?rev=725991&r1=725990&r2=725991&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java Fri Dec 12 05:05:25 2008 @@ -4,169 +4,169 @@ * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.jetspeed.portlets.security.groups; - -import java.io.IOException; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; - -import javax.portlet.ActionRequest; -import javax.portlet.ActionResponse; -import javax.portlet.PortletConfig; -import javax.portlet.PortletException; -import javax.portlet.PortletMode; -import javax.portlet.RenderRequest; -import javax.portlet.RenderResponse; - -import org.apache.jetspeed.CommonPortletServices; -import org.apache.jetspeed.portlets.security.SecurityResources; -import org.apache.jetspeed.portlets.security.SecurityUtil; -import org.apache.jetspeed.security.Group; -import org.apache.jetspeed.security.GroupManager; -import org.apache.jetspeed.security.SecurityException; -import org.apache.portals.gems.browser.BrowserIterator; -import org.apache.portals.gems.browser.DatabaseBrowserIterator; -import org.apache.portals.gems.browser.BrowserPortlet; -import org.apache.portals.gems.util.StatusMessage; -import org.apache.portals.messaging.PortletMessaging; -import org.apache.velocity.context.Context; - -/** - * Group Browser - flat non-hierarchical view - * - * @author David Sean Taylor - * @version $Id: GroupBrowser.java 348264 2005-11-22 22:06:45Z taylor $ - */ -public class GroupBrowser extends BrowserPortlet -{ - private GroupManager groupManager; - - public void init(PortletConfig config) - throws PortletException - { - super.init(config); - groupManager = (GroupManager) - getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT); - if (null == groupManager) - { - throw new PortletException("Failed to find the Group Manager on portlet initialization"); - } - } - - public void getRows(RenderRequest request, String sql, int windowSize) - { - getRows(request, sql, windowSize, ""); - } - - public void getRows(RenderRequest request, String sql, int windowSize, String filter) - { - List resultSetTitleList = new ArrayList(); - List resultSetTypeList = new ArrayList(); - - resultSetTypeList.add(String.valueOf(Types.VARCHAR)); - resultSetTitleList.add("group"); // resource bundle key - - try + * the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.jetspeed.portlets.security.groups; + +import java.io.IOException; +import java.sql.Types; +import java.util.ArrayList; +import java.util.List; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.PortletConfig; +import javax.portlet.PortletException; +import javax.portlet.PortletMode; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import org.apache.jetspeed.CommonPortletServices; +import org.apache.jetspeed.portlets.security.SecurityResources; +import org.apache.jetspeed.portlets.security.SecurityUtil; +import org.apache.jetspeed.security.Group; +import org.apache.jetspeed.security.GroupManager; +import org.apache.jetspeed.security.SecurityException; +import org.apache.portals.gems.browser.BrowserIterator; +import org.apache.portals.gems.browser.DatabaseBrowserIterator; +import org.apache.portals.gems.browser.BrowserPortlet; +import org.apache.portals.gems.util.StatusMessage; +import org.apache.portals.messaging.PortletMessaging; +import org.apache.velocity.context.Context; + +/** + * Group Browser - flat non-hierarchical view + * + * @author David Sean Taylor + * @version $Id: GroupBrowser.java 348264 2005-11-22 22:06:45Z taylor $ + */ +public class GroupBrowser extends BrowserPortlet +{ + private GroupManager groupManager; + + public void init(PortletConfig config) + throws PortletException + { + super.init(config); + groupManager = (GroupManager) + getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT); + if (null == groupManager) + { + throw new PortletException("Failed to find the Group Manager on portlet initialization"); + } + } + + public void getRows(RenderRequest request, String sql, int windowSize) + { + getRows(request, sql, windowSize, ""); + } + + public void getRows(RenderRequest request, String sql, int windowSize, String filter) + { + List resultSetTitleList = new ArrayList(); + List resultSetTypeList = new ArrayList(); + + resultSetTypeList.add(String.valueOf(Types.VARCHAR)); + resultSetTitleList.add("group"); // resource bundle key + + try { List list = groupManager.getGroupNames(filter); BrowserIterator iterator = new DatabaseBrowserIterator(list, resultSetTitleList, resultSetTypeList, windowSize); setBrowserIterator(request, iterator); iterator.sort("group"); // resource bundle key - } - catch (SecurityException sex) - { - SecurityUtil.publishErrorMessage(request, SecurityResources.TOPIC_GROUPS, sex.getMessage()); - } - } - - public void doView(RenderRequest request, RenderResponse response) - throws PortletException, IOException - { - String selected = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_SELECTED); - if (selected != null) - { - Context context = this.getContext(request); - context.put("selected", selected); - } - StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_STATUS); - if (msg != null) - { - this.getContext(request).put("statusMsg", msg); - } - - String filtered = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_FILTERED); - if (filtered != null) - { - this.getContext(request).put(FILTERED, "on"); - } - String refresh = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_REFRESH); - if (refresh != null) - { - this.clearBrowserIterator(request); - } - - ArrayList errorMessages = (ArrayList)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS, SecurityResources.ERROR_MESSAGES); - if (errorMessages != null ) - { - this.getContext(request).put(SecurityResources.ERROR_MESSAGES, errorMessages); - } - - super.doView(request, response); - } - - public void processAction(ActionRequest request, ActionResponse response) - throws PortletException, IOException - { - if (request.getPortletMode() == PortletMode.VIEW) - { - String selected = request.getParameter("group"); - if (selected != null) - { - Group group = lookupGroup(request, selected); - if (group != null) - { - PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_SELECTED, selected); - PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_CHANGED, selected); - } - } - } - - String filtered = request.getParameter(FILTERED); - if (filtered != null) - { - PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_FILTERED, "on"); - } - else - { - PortletMessaging.cancel(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_FILTERED); - } - - super.processAction(request, response); - - } - - private Group lookupGroup(ActionRequest actionRequest, String groupName) - { - try - { - return groupManager.getGroup(groupName); - } - catch (SecurityException sex) - { - SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_GROUPS, sex.getMessage()); - return null; - } - } - -} + } + catch (SecurityException sex) + { + SecurityUtil.publishErrorMessage(request, SecurityResources.TOPIC_GROUPS, sex.getMessage()); + } + } + + public void doView(RenderRequest request, RenderResponse response) + throws PortletException, IOException + { + String selected = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_SELECTED); + if (selected != null) + { + Context context = this.getContext(request); + context.put("selected", selected); + } + StatusMessage msg = (StatusMessage)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_STATUS); + if (msg != null) + { + this.getContext(request).put("statusMsg", msg); + } + + String filtered = (String)PortletMessaging.receive(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_FILTERED); + if (filtered != null) + { + this.getContext(request).put(FILTERED, "on"); + } + String refresh = (String)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_REFRESH); + if (refresh != null) + { + this.clearBrowserIterator(request); + } + + ArrayList errorMessages = (ArrayList)PortletMessaging.consume(request, SecurityResources.TOPIC_GROUPS, SecurityResources.ERROR_MESSAGES); + if (errorMessages != null ) + { + this.getContext(request).put(SecurityResources.ERROR_MESSAGES, errorMessages); + } + + super.doView(request, response); + } + + public void processAction(ActionRequest request, ActionResponse response) + throws PortletException, IOException + { + if (request.getPortletMode() == PortletMode.VIEW) + { + String selected = request.getParameter("group"); + if (selected != null) + { + Group group = lookupGroup(request, selected); + if (group != null) + { + PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_SELECTED, selected); + PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_CHANGED, selected); + } + } + } + + String filtered = request.getParameter(FILTERED); + if (filtered != null) + { + PortletMessaging.publish(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_FILTERED, "on"); + } + else + { + PortletMessaging.cancel(request, SecurityResources.TOPIC_GROUPS, SecurityResources.MESSAGE_FILTERED); + } + + super.processAction(request, response); + + } + + private Group lookupGroup(ActionRequest actionRequest, String groupName) + { + try + { + return groupManager.getGroup(groupName); + } + catch (SecurityException sex) + { + SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_GROUPS, sex.getMessage()); + return null; + } + } + +} Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/groups/GroupBrowser.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org For additional commands, e-mail: jetspeed-dev-help@portals.apache.org