You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2006/04/13 13:36:26 UTC

svn commit: r393787 [12/22] - in /geronimo/trunk/applications: ./ console/ console/console-core/ console/console-core/src/ console/console-core/src/java/ console/console-core/src/java/org/ console/console-core/src/java/org/apache/ console/console-core/...

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,206 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.logmanager;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Map;
+import java.util.LinkedHashMap;
+
+import javax.portlet.*;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+
+import org.apache.geronimo.console.BasePortlet;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.management.geronimo.WebAccessLog;
+import org.apache.geronimo.management.geronimo.WebManager;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class WebAccessLogViewerPortlet extends BasePortlet {
+    private final static Log log = LogFactory.getLog(WebAccessLogViewerPortlet.class);
+
+    protected PortletRequestDispatcher searchView;
+
+    protected PortletRequestDispatcher helpView;
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderRespose) throws PortletException, IOException {
+        helpView.include(renderRequest, renderRespose);
+    }
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderRespose) throws PortletException, IOException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String[] names = PortletManager.getWebManagerNames(renderRequest);
+
+        //todo: new
+        Map products = new LinkedHashMap();
+        String chosen = renderRequest.getParameter("selectedContainer");
+        if(chosen != null) { // Carry on to render the results with the right selection
+            renderRequest.setAttribute("selectedContainer", chosen);
+        }
+        WebAccessLog chosenLog = null;
+        if(names != null) {
+            for (int i = 0; i < names.length; i++) {
+                String webManagerName = names[i];
+                WebManager manager = (WebManager) PortletManager.getManagedBean(renderRequest, webManagerName);
+                String[] containers = PortletManager.getWebContainerNames(renderRequest, webManagerName);
+                if (containers != null) {
+                    for (int j = 0; j < containers.length; j++) {
+                        String containerName = containers[j];
+                        String combined = webManagerName+"%"+containerName;
+                        if(containers.length == 1) {
+                            products.put(manager.getProductName(), combined);
+                        } else {
+                            try {
+                                ObjectName containerON = ObjectName.getInstance(containerName);
+                                products.put(manager.getProductName()+" ("+containerON.getKeyProperty(NameFactory.J2EE_NAME)+")", combined);
+                            } catch (MalformedObjectNameException e) {
+                                log.error("Unable to parse ObjectName", e);
+                            }
+                        }
+                        if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
+                            if(chosen == null || chosen.equals(combined)) {
+                                chosenLog = PortletManager.getWebAccessLog(renderRequest, webManagerName, containerName);
+                            }
+                        }
+                    }
+                } else {
+                    log.error("No web containers found for manager "+manager.getProductName());
+                }
+            }
+        } else {
+            log.error("No web managers found!");
+        }
+        renderRequest.setAttribute("webContainers", products);
+        final String[] logNames = chosenLog.getLogNames();
+        renderRequest.setAttribute("webLogs", logNames);
+        String logToSearch = renderRequest.getParameter("selectedLog");
+        if(logToSearch == null) {
+            logToSearch = logNames[0];
+        } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search?  todo: fix this with some AJAX to repopulate the form when container is changed
+            boolean found = false;
+            for (int i = 0; i < logNames.length; i++) {
+                String test = logNames[i];
+                if(test.equals(logToSearch)) {
+                    found = true;
+                    break;
+                }
+            }
+            if(!found) { // Must has been for the other container -- make it work.
+                logToSearch = logNames[0];
+            }
+        }
+
+        String action = renderRequest.getParameter("action");
+        if ("refresh".equals(action)) {
+            //todo: currently refreshes on every request; that's pretty slow.
+        }
+
+
+        //todo: completely revamp this argument processing
+        String startDate = (String) renderRequest.getParameter("startDate");
+        String startMonth = (String) renderRequest.getParameter("startMonth");
+        String startYear = (String) renderRequest.getParameter("startYear");
+        String endDate = (String) renderRequest.getParameter("endDate");
+        String endMonth = (String) renderRequest.getParameter("endMonth");
+        String endYear = (String) renderRequest.getParameter("endYear");
+
+        Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
+        // If not all dates were passed we assume than no fields were passed and just
+        // filter on the current date.
+        if (startDate == null || startMonth == null || startYear == null
+                || endDate == null || endMonth == null || endYear == null) {
+            // just keep the month date and year
+            cal1.set(Calendar.MILLISECOND, 0);
+            cal1.set(Calendar.MINUTE, 0);
+            cal1.set(Calendar.SECOND, 0);
+            cal1.set(Calendar.HOUR_OF_DAY, 0);
+
+            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
+            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
+            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
+            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
+
+            WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
+                                        null, null, null, null, cal1.getTime(), cal2.getTime(), null, null);
+            renderRequest.setAttribute("logs", matchingItems.getResults());
+            renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
+        } else {
+            cal1.clear();
+            cal2.clear();
+            // get the requested start date (defaults to 00:00:00:000 for time
+            cal1.set(Calendar.DATE, Integer.parseInt(startDate));
+            cal1.set(Calendar.MONTH, Integer.parseInt(startMonth));
+            cal1.set(Calendar.YEAR, Integer.parseInt(startYear));
+            // get the requested end date - Note: must set time to end of day
+            cal2.set(Calendar.DATE, Integer.parseInt(endDate));
+            cal2.set(Calendar.MONTH, Integer.parseInt(endMonth));
+            cal2.set(Calendar.YEAR, Integer.parseInt(endYear));
+            cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
+            cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
+            cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
+            cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
+            // Get other search criteria
+            String requestHost = (String) renderRequest.getParameter("requestHost");
+            String authUser = (String) renderRequest.getParameter("authUser");
+            String requestMethod = (String) renderRequest.getParameter("requestMethod");
+            String requestedURI = (String) renderRequest.getParameter("requestedURI");
+            boolean ignoreDates = renderRequest.getParameter("ignoreDates") != null;
+            if (ignoreDates) {
+                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
+                                                requestHost, authUser, requestMethod, requestedURI, null, null, null, null);
+                renderRequest.setAttribute("logs", matchingItems.getResults());
+                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
+            } else {
+                WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
+                                                requestHost, authUser, requestMethod, requestedURI, cal1.getTime(), cal2.getTime(), null, null);
+                renderRequest.setAttribute("logs", matchingItems.getResults());
+                renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
+            }
+            if (ignoreDates) renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
+            renderRequest.setAttribute("requestHost", requestHost);
+            renderRequest.setAttribute("authUser", authUser);
+            renderRequest.setAttribute("requestMethod", requestMethod);
+            renderRequest.setAttribute("requestedURI", requestedURI);
+
+        }
+        renderRequest.setAttribute("toDate", cal2.getTime());
+        renderRequest.setAttribute("fromDate", cal1.getTime());
+        searchView.include(renderRequest, renderRespose);
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        PortletContext pc = portletConfig.getPortletContext();
+        searchView = pc.getRequestDispatcher("/WEB-INF/view/webaccesslogmanager/view.jsp");
+        helpView = pc.getRequestDispatcher("/WEB-INF/view/webaccesslogmanager/help.jsp");
+        super.init(portletConfig);
+    }
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        //todo: according to portlet spec, all forms should submit to Action not Render
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,248 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.repository;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.portlet.PortletFileUpload;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.console.BasePortlet;
+import org.apache.geronimo.console.util.PortletManager;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.repository.FileWriteMonitor;
+import org.apache.geronimo.kernel.repository.ListableRepository;
+import org.apache.geronimo.kernel.repository.WriteableRepository;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+public class RepositoryViewPortlet extends BasePortlet {
+
+    private final static Log log = LogFactory.getLog(RepositoryViewPortlet.class);
+
+    private Kernel kernel;
+
+    private PortletContext ctx;
+
+    private PortletRequestDispatcher normalView;
+
+    private PortletRequestDispatcher helpView;
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        kernel = KernelRegistry.getSingleKernel();
+        ctx = portletConfig.getPortletContext();
+        normalView = ctx
+                .getRequestDispatcher("/WEB-INF/view/repository/normal.jsp");
+        helpView = ctx
+                .getRequestDispatcher("/WEB-INF/view/repository/help.jsp");
+    }
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        try {
+
+
+
+            List list = new ArrayList();
+            WriteableRepository repo = PortletManager.getWritableRepositories(actionRequest)[0];
+
+            File uploadFile = null;
+            File file = null;
+            String name = null;
+            String basename = null;
+            String fileType = null;
+            String artifact = null;
+            String version = null;
+            String group = null;
+
+            PortletFileUpload uploader = new PortletFileUpload(new DiskFileItemFactory());
+            try {
+                List items = uploader.parseRequest(actionRequest);
+                for (Iterator i = items.iterator(); i.hasNext();) {
+                    FileItem item = (FileItem) i.next();
+                    if (!item.isFormField()) {
+                        String fieldName = item.getFieldName().trim();
+                        name = item.getName().trim();
+
+                        if (name.length() == 0) {
+                            file = null;
+                        } else {
+                            // IE sends full path while Firefox sends just basename
+                            // in the case of "FullName" we may be able to infer the group
+                            // Note, we can't use File.separatorChar because the file separator
+                            // is dependent upon the client and not the server.
+                            String fileChar = "\\";
+                            int fileNameIndex = name.lastIndexOf(fileChar);
+                            if (fileNameIndex == -1) {
+                               fileChar = "/";
+                               fileNameIndex = name.lastIndexOf(fileChar);
+                            }
+                            if (fileNameIndex != -1) {
+                               basename = name.substring(fileNameIndex + 1);
+                            }
+                            else {
+                               basename = name;
+                            }
+
+                            // Create the temporary file to be used for import to the server
+                            file = File.createTempFile("geronimo-import", "");
+                            file.deleteOnExit();
+                            log.debug("Writing repository import file to "+file.getAbsolutePath());
+                        }
+
+                        if ("local".equals(fieldName)) {
+                            uploadFile = file;
+                        }
+
+                        if (file != null) {
+                            try {
+                                item.write(file);
+                            } catch (Exception e) {
+                                throw new PortletException(e);
+                            }
+                        }
+                    // This is not the file itself, but one of the form fields for the URI
+                    } else {
+                        String fieldName = item.getFieldName().trim();
+                        if ("group".equals(fieldName)) {
+                            group = item.getString().trim();
+                        } else if ("artifact".equals(fieldName)) {
+                            artifact = item.getString().trim();
+                        } else if ("version".equals(fieldName)) {
+                            version = item.getString().trim();
+                        } else if ("fileType".equals(fieldName)) {
+                            fileType = item.getString().trim();
+                        }
+                    }
+                }
+
+                String uri = group + "/" + artifact + "/" + version + "/" + fileType;
+
+                repo.copyToRepository(file, new URI(uri), new FileWriteMonitor() {
+                    public void writeStarted(String fileDescription) {
+                        System.out.print("Copying into repository "+fileDescription+"...");
+                        System.out.flush();
+                    }
+
+                    public void writeProgress(int bytes) {
+                    }
+
+                    public void writeComplete(int bytes) {
+                        System.out.println(" Finished.");
+                    }
+                });
+            } catch (FileUploadException e) {
+                throw new PortletException(e);
+            } catch (URISyntaxException e) {
+                throw new IOException("Unable to save to repository URI: "+e.getMessage());
+            }
+        } catch (PortletException e) {
+            throw e;
+        }
+    }
+
+    protected void doView(RenderRequest request, RenderResponse response)
+            throws PortletException, IOException {
+        // i think generic portlet already does this
+        if (WindowState.MINIMIZED.equals(request.getWindowState())) {
+            return;
+        }
+
+        try {
+            List list = new ArrayList();
+            ListableRepository[] repos = PortletManager.getListableRepositories(request);
+            for (int i = 0; i < repos.length; i++) {
+                ListableRepository repo = repos[i];
+                try {
+                    final URI[] uris = repo.listURIs();
+                    for (int j = 0; j < uris.length; j++) {
+                        if(uris[j] == null) {
+                            continue; // probably a JAR lacks a version number in the name, etc.
+                        }
+                        String fileName = uris[j].toString();
+                        list.add(fileName);
+                    }
+                } catch (URISyntaxException e) {
+                    e.printStackTrace();
+                }
+            }
+            Collections.sort(list);
+
+            request.setAttribute("org.apache.geronimo.console.repo.list", list);
+
+        } catch (Exception e) {
+            throw new PortletException(e);
+        }
+
+        normalView.include(request, response);
+    }
+
+    public void doHelp(RenderRequest request, RenderResponse response)
+            throws PortletException, IOException {
+        helpView.include(request, response);
+    }
+
+    public List listing(File dir, String basepath) throws java.io.IOException {
+        if (dir == null) {
+            throw new IllegalArgumentException("directory argument is null");
+        }
+
+        if (!dir.isDirectory()) {
+            throw new IllegalArgumentException("directory argument expected");
+        }
+
+        List listing = new ArrayList();
+
+        List ls = Arrays.asList(dir.listFiles());
+        Iterator iter = ls.iterator();
+
+        while (iter.hasNext()) {
+            File f = (File) iter.next();
+
+            if (f.isDirectory()) {
+                List listing1 = listing(f, basepath);
+                listing.addAll(listing1);
+            } else {
+                listing.add(f.getCanonicalPath().substring(
+                        basepath.length() + 1));
+            }
+        }
+        return listing;
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/repository/RepositoryViewPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/AbstractSecurityManagerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/AbstractSecurityManagerPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/AbstractSecurityManagerPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/AbstractSecurityManagerPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,58 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.securitymanager;
+
+import java.io.IOException;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.BasePortlet;
+
+public abstract class AbstractSecurityManagerPortlet extends BasePortlet {
+
+    protected PortletRequestDispatcher normalView;
+
+    protected PortletRequestDispatcher addNormalView;
+
+    protected PortletRequestDispatcher maximizedView;
+
+    protected PortletRequestDispatcher addMaximizedView;
+
+    protected PortletRequestDispatcher helpView;
+
+    protected PortletRequestDispatcher errorView;
+
+    protected void doEdit(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        if (WindowState.NORMAL.equals(renderRequest.getWindowState())) {
+            addNormalView.include(renderRequest, renderResponse);
+        } else {
+            addMaximizedView.include(renderRequest, renderResponse);
+        }
+    }
+
+    protected void doHelp(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        helpView.include(renderRequest, renderResponse);
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/AbstractSecurityManagerPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/AbstractSecurityManagerPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/AbstractSecurityManagerPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEGroupsPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEGroupsPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEGroupsPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEGroupsPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,144 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.securitymanager;
+
+import java.io.IOException;
+import java.util.Hashtable;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.util.SERealmGroupHelper;
+import org.apache.geronimo.console.util.SERealmUserHelper;
+
+public class SEGroupsPortlet extends AbstractSecurityManagerPortlet {
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String errorMessage = renderRequest.getParameter("errorMessage");
+
+        if (errorMessage != null) {
+            renderRequest.setAttribute("errorMessage", errorMessage);
+            errorView.include(renderRequest, renderResponse);
+        } else {
+            String currAction = renderRequest.getParameter("currAction");
+            String message = renderRequest.getParameter("message");
+            renderRequest.setAttribute("message", message);
+
+            try {
+                if ("new".equals(currAction)) {
+                    renderRequest.setAttribute("users", SERealmUserHelper
+                            .getUsers());
+                    addMaximizedView.include(renderRequest, renderResponse);
+                } else if ("edit".equals(currAction)) {
+                    String group = renderRequest.getParameter("group");
+                    renderRequest.setAttribute("group", group);
+                    renderRequest.setAttribute("users", SERealmUserHelper
+                            .getUsers());
+                    addMaximizedView.include(renderRequest, renderResponse);
+                } else {
+                    String[] groups = SERealmGroupHelper.getGroups();
+                    Hashtable groupsInfo = new Hashtable();
+                    for (int i = 0; i < groups.length; i++) {
+                        String currentGroup = groups[i];
+                        groupsInfo.put(currentGroup, SERealmGroupHelper
+                                .getUsers(currentGroup));
+                    }
+                    renderRequest.setAttribute("groupsInfo", groupsInfo);
+
+                    if (WindowState.NORMAL.equals(renderRequest
+                            .getWindowState())) {
+                        normalView.include(renderRequest, renderResponse);
+                    } else {
+                        maximizedView.include(renderRequest, renderResponse);
+                    }
+                }
+            } catch (Exception e) {
+                errorMessage = e.getMessage();
+                renderRequest.setAttribute("errorMessage", errorMessage);
+                errorView.include(renderRequest, renderResponse);
+            }
+        }
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        PortletContext pc = portletConfig.getPortletContext();
+        normalView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/normal.jsp");
+        addNormalView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addnormal.jsp");
+        maximizedView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/maximized.jsp");
+        addMaximizedView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/addmaximized.jsp");
+        helpView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/help.jsp");
+        errorView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/groups/error.jsp");
+    }
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        String action = actionRequest.getParameter("action").trim();
+        String cancel = actionRequest.getParameter("cancel");
+        String currAction = "";
+        if (cancel != null) {
+            action = "";
+        }
+        String group = actionRequest.getParameter("group");
+        String[] users = actionRequest.getParameterValues("users");
+
+        try {
+            if ("delete".equals(action)) {
+                SERealmGroupHelper.deleteGroup(group);
+            } else if ("update".equals(action)) {
+                SERealmGroupHelper.updateGroup(group, users);
+            } else if ("add".equals(action)) {
+                try {
+                    SERealmGroupHelper.addGroup(group, users);
+                } catch (Exception e) {
+                    actionResponse.setRenderParameter("message",
+                            "ERROR: Error in SEGroupsPortlet while adding group "+group+". Cause:"+e.getMessage());
+                }
+            } else if ("new".equals(action)) {
+                currAction = "new";
+            } else if ("edit".equals(action)) {
+                currAction = "edit";
+            }
+            actionResponse.setRenderParameter("currAction", currAction);
+            if (group != null) {
+                actionResponse.setRenderParameter("group", group);
+            }
+        } catch (Exception e) {
+            actionResponse.setRenderParameter("message",
+                    "Error encountered in SEGroupsPortlet. Cause: "
+                            + e.getMessage());
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEGroupsPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEGroupsPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEGroupsPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEUsersPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEUsersPortlet.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEUsersPortlet.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEUsersPortlet.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,144 @@
+/**
+ *
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.geronimo.console.securitymanager;
+
+import java.io.IOException;
+import java.util.Hashtable;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.geronimo.console.util.SERealmUserHelper;
+
+public class SEUsersPortlet extends AbstractSecurityManagerPortlet {
+
+    protected void doView(RenderRequest renderRequest,
+            RenderResponse renderResponse) throws PortletException, IOException {
+        if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
+            return;
+        }
+
+        String errorMessage = renderRequest.getParameter("errorMessage");
+
+        if (errorMessage != null) {
+            renderRequest.setAttribute("errorMessage", errorMessage);
+            errorView.include(renderRequest, renderResponse);
+        } else {
+            try {
+                String[] users = SERealmUserHelper.getUsers();
+
+                Hashtable userInfo = new Hashtable();
+                for (int i = 0; i < users.length; i++) {
+                    String currentUser = users[i];
+                    userInfo.put(currentUser, SERealmUserHelper
+                            .getPassword(currentUser.toString()));
+                }
+
+                String currAction = renderRequest.getParameter("currAction");
+                renderRequest.setAttribute("message", renderRequest
+                        .getParameter("message"));
+
+                if ("new".equals(currAction) || "edit".equals(currAction)) {
+                    if (currAction.equals("edit")) {
+                        String user = renderRequest.getParameter("user");
+                        renderRequest.setAttribute("userID", user);
+                        renderRequest.setAttribute("password",
+                                SERealmUserHelper.getPassword(user));
+                    }
+                    addMaximizedView.include(renderRequest, renderResponse);
+                } else {
+                    if (WindowState.NORMAL.equals(renderRequest
+                            .getWindowState())) {
+                        renderRequest.setAttribute("userInfo", userInfo);
+                        normalView.include(renderRequest, renderResponse);
+                    } else {
+                        renderRequest.setAttribute("userInfo", userInfo);
+                        maximizedView.include(renderRequest, renderResponse);
+                    }
+                }
+            } catch (Exception e) {
+                errorMessage = e.getMessage();
+                renderRequest.setAttribute("errorMessage", errorMessage);
+                errorView.include(renderRequest, renderResponse);
+            }
+        }
+    }
+
+    public void init(PortletConfig portletConfig) throws PortletException {
+        super.init(portletConfig);
+        PortletContext pc = portletConfig.getPortletContext();
+        normalView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/normal.jsp");
+        addNormalView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/addnormal.jsp");
+        maximizedView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/maximized.jsp");
+        addMaximizedView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/addmaximized.jsp");
+        helpView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/se/users/help.jsp");
+        errorView = pc
+                .getRequestDispatcher("/WEB-INF/view/securityrealmmanager/derby/groups/error.jsp");
+    }
+
+    public void processAction(ActionRequest actionRequest,
+            ActionResponse actionResponse) throws PortletException, IOException {
+        String action = actionRequest.getParameter("action").trim();
+        String cancel = actionRequest.getParameter("cancel");
+        String currAction = "";
+        if (cancel != null) {
+            action = "";
+        }
+        String user = actionRequest.getParameter("userId");
+        String password = actionRequest.getParameter("password");
+
+        try {
+            if ("delete".equals(action)) {
+                SERealmUserHelper.deleteUser(user);
+            } else if ("update".equals(action)) {
+                SERealmUserHelper.updateUser(user, password);
+            } else if ("add".equals(action)) {
+                try {
+                    SERealmUserHelper.addUser(user, password);
+                } catch (Exception e) {
+                    actionResponse.setRenderParameter("message",
+                            "ERROR: Error in SEUsersPortlet while adding user "+user+". Cause: "+e.getMessage());
+                }
+            } else if ("new".equals(action)) {
+                currAction = "new";
+            } else if ("edit".equals(action)) {
+                currAction = "edit";
+            }
+            actionResponse.setRenderParameter("currAction", currAction);
+            if (user != null) {
+                actionResponse.setRenderParameter("user", user);
+            }
+        } catch (Exception e) {
+            actionResponse.setRenderParameter("message",
+                    "Error encountered in SEUsersPortlet. Cause: "
+                            + e.getMessage());
+        }
+    }
+
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEUsersPortlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEUsersPortlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/SEUsersPortlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java?rev=393787&view=auto
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java (added)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java Thu Apr 13 04:34:08 2006
@@ -0,0 +1,236 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.console.securitymanager.realm;
+
+import java.io.Serializable;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Properties;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+import java.util.Comparator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Describes an available login module, including how to create and configure it.
+ * Reads the list of available login modules from a properties file on the class path.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MasterLoginModuleInfo implements Serializable {
+    private final static Log log = LogFactory.getLog(MasterLoginModuleInfo.class);
+    private static MasterLoginModuleInfo[] allModules;
+    private String name;
+    private String className;
+    private boolean testable = true;
+    private OptionInfo[] options = new OptionInfo[0];
+
+    private MasterLoginModuleInfo(String name, String className) {
+        this.name = name;
+        this.className = className;
+    }
+
+    public OptionInfo[] getOptions() {
+        return options;
+    }
+
+    public Map getOptionMap() {
+        Map map = new HashMap();
+        for (int i = 0; i < options.length; i++) {
+            OptionInfo info = options[i];
+            map.put(info.getName(), info);
+        }
+        return map;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getClassName() {
+        return className;
+    }
+
+    public boolean isTestable() {
+        return testable;
+    }
+
+    private void setTestable(boolean testable) {
+        this.testable = testable;
+    }
+
+    private void setOptions(OptionInfo[] options) {
+        this.options = options;
+    }
+
+    public static MasterLoginModuleInfo[] getAllModules() {
+        if(allModules == null) {
+            allModules = loadModules();
+        }
+        return allModules;
+    }
+
+    private static MasterLoginModuleInfo[] loadModules() {
+        List list = new ArrayList();
+        Map map = new HashMap(), fieldMap = new HashMap();
+        InputStream in = MasterLoginModuleInfo.class.getResourceAsStream("/login-modules.properties");
+        if(in == null) {
+            log.error("Unable to locate login module properties file");
+            return null;
+        }
+        Properties props = new Properties();
+        try {
+            props.load(in);
+            in.close();
+        } catch (IOException e) {
+            log.error("Unable to read login module properties file", e);
+        }
+        for (Iterator it = props.keySet().iterator(); it.hasNext();) {
+            String key = (String) it.next();
+            if(key.startsWith("module.")) {
+                String name = key.substring(7, key.indexOf('.', 7));
+                MasterLoginModuleInfo info = (MasterLoginModuleInfo) map.get(name);
+                if(info == null) {
+                    info = new MasterLoginModuleInfo(props.getProperty("module."+name+".name"),
+                            props.getProperty("module."+name+".class"));
+                    String test = props.getProperty("module."+name+".testable");
+                    if(test != null) {
+                        info.setTestable(new Boolean(test.trim()).booleanValue());
+                    }
+                    map.put(name, info);
+                    list.add(info);
+                }
+                String prefix = "module."+name+".field.";
+                if(key.startsWith(prefix)) {
+                    String fieldName = key.substring(prefix.length(), key.indexOf('.', prefix.length()));
+                    List fields = (List) fieldMap.get(name);
+                    if(fields == null) {
+                        fields = new ArrayList();
+                        fieldMap.put(name, fields);
+                    }
+                    OptionInfo option = null;
+                    for (int i = 0; i < fields.size(); i++) {
+                        OptionInfo opt = (OptionInfo) fields.get(i);
+                        if(opt.getName().equals(fieldName)) {
+                            option = opt;
+                            break;
+                        }
+                    }
+                    if(option == null) {
+                        option = new OptionInfo(fieldName, props.getProperty(prefix+fieldName+".displayName"),
+                                props.getProperty(prefix+fieldName+".description"));
+                        String test = props.getProperty(prefix+fieldName+".password");
+                        if(test != null) {
+                            option.setPassword(true);
+                        }
+                        test = props.getProperty(prefix+fieldName+".length");
+                        if(test != null) {
+                            option.setLength(Integer.parseInt(test.trim()));
+                        }
+                        test = props.getProperty(prefix+fieldName+".displayOrder");
+                        if(test != null) {
+                            option.setDisplayOrder(Integer.parseInt(test.trim()));
+                        }
+                        fields.add(option);
+                    }
+                }
+            }
+        }
+        for (Iterator it = map.keySet().iterator(); it.hasNext();) {
+            String name = (String) it.next();
+            MasterLoginModuleInfo info = (MasterLoginModuleInfo) map.get(name);
+            List fields = (List) fieldMap.get(name);
+            if(fields != null) {
+                Collections.sort(fields);
+                info.setOptions((OptionInfo[]) fields.toArray(new OptionInfo[fields.size()]));
+            }
+        }
+        Collections.sort(list, new Comparator() {
+            public int compare(Object o1, Object o2) {
+                MasterLoginModuleInfo m1 = (MasterLoginModuleInfo) o1, m2 = (MasterLoginModuleInfo) o2;
+                if(m1.getName().equals("Other")) {
+                    return 1;
+                } else if(m2.getName().equals("Other")) {
+                    return -1;
+                } else {
+                    return m1.getName().compareTo(m2.getName());
+                }
+            }
+        });
+        return (MasterLoginModuleInfo[]) list.toArray(new MasterLoginModuleInfo[list.size()]);
+    }
+
+    public final static class OptionInfo implements Serializable, Comparable {
+        private final String name;
+        private final String displayName;
+        private final String description;
+        private boolean password = false;
+        private int length = 30;
+        private int displayOrder = 1;
+
+        public OptionInfo(String name, String displayName, String description) {
+            this.name = name;
+            this.displayName = displayName;
+            this.description = description;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getDisplayName() {
+            return displayName;
+        }
+
+        public String getDescription() {
+            return description;
+        }
+
+        public boolean isPassword() {
+            return password;
+        }
+
+        public void setPassword(boolean password) {
+            this.password = password;
+        }
+
+        public int getLength() {
+            return length;
+        }
+
+        public void setLength(int length) {
+            this.length = length;
+        }
+
+        public int getDisplayOrder() {
+            return displayOrder;
+        }
+
+        public void setDisplayOrder(int displayOrder) {
+            this.displayOrder = displayOrder;
+        }
+
+        public int compareTo(Object o) {
+            return displayOrder - ((OptionInfo)o).displayOrder;
+        }
+    }
+}

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/securitymanager/realm/MasterLoginModuleInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain