[Yanel-commits] rev 22930 - in public/yanel/trunk: conf src/build src/contributions/resources src/contributions/resources/yanel-user src/contributions/resources/yanel-user/src src/contributions/resources/yanel-user/src/build src/contributions/resources/yanel-user/src/java src/contributions/resources/yanel-user/src/java/org src/contributions/resources/yanel-user/src/java/org/wyona src/contributions/resources/yanel-user/src/java/org/wyona/yanel src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources src/contributions/resources/yanel-user/xml src/contributions/resources/yanel-user/xslt src/realms/use-cases/yanel/ac-identities src/realms/use-cases/yanel/ac-identities/groups src/realms/use-cases/yanel/ac-identities/users src/realms/use-cases/yanel/data src/realms/use-cases/yanel/rti

josias at wyona.com josias at wyona.com
Fri Feb 23 22:37:41 CET 2007


Author: josias
Date: 2007-02-23 22:37:40 +0100 (Fri, 23 Feb 2007)
New Revision: 22930

Added:
   public/yanel/trunk/src/contributions/resources/yanel-user/
   public/yanel/trunk/src/contributions/resources/yanel-user/build.xml
   public/yanel/trunk/src/contributions/resources/yanel-user/resource.xml
   public/yanel/trunk/src/contributions/resources/yanel-user/src/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/build/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/build/build.properties
   public/yanel/trunk/src/contributions/resources/yanel-user/src/build/dependencies.xml
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/
   public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java
   public/yanel/trunk/src/contributions/resources/yanel-user/src/test/
   public/yanel/trunk/src/contributions/resources/yanel-user/xml/
   public/yanel/trunk/src/contributions/resources/yanel-user/xml/yanel-user-profile.xml
   public/yanel/trunk/src/contributions/resources/yanel-user/xslt/
   public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl
   public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/
   public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/admin.xml
   public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/editor.xml
   public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/
   public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/alice.xml
   public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/lenya.xml
   public/yanel/trunk/src/realms/use-cases/yanel/rti/alice.yanel-rc
Modified:
   public/yanel/trunk/conf/yanel.xml
   public/yanel/trunk/src/build/dependencies.xml
   public/yanel/trunk/src/realms/use-cases/yanel/data/index.html
Log:
added user resource to edit user profile/password. see bug #5116, thanks to paloma

Modified: public/yanel/trunk/conf/yanel.xml
===================================================================
--- public/yanel/trunk/conf/yanel.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/conf/yanel.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -32,7 +32,10 @@
 -->
   <resource src="../src/contributions/resources/nutch/"         compile="true"/>
   <resource src="../src/contributions/resources/davcollection/" compile="true"/>
-  <resource src="../src/contributions/resources/pdf/"           compile="true"/> 
+  <resource src="../src/contributions/resources/pdf/"           compile="true"/>
+
+  <resource src="../src/contributions/resources/yanel-user/"    compile="true"/> 
+
 </resources>
 
 # Realms configuration

Modified: public/yanel/trunk/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/build/dependencies.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/build/dependencies.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -34,7 +34,7 @@
       <dependency groupId="wyona-org-commons" artifactId="wyona-org-commons"
                   version="0.0.1-dev-r22621"/>
       <dependency groupId="wyona-org-security" artifactId="wyona-org-security-core"
-                  version="0.0.1-dev-r22197"/>
+                  version="0.0.1-dev-r22929"/>
 
       <!-- TODO: Add to yanel.xml, because these libs are only needed during runtime -->
       <dependency groupId="avalon-framework" artifactId="avalon-framework-api"
@@ -60,7 +60,7 @@
       <dependency groupId="xalan" artifactId="xalan"
                   version="2.7.0"/>
       <dependency groupId="wyona-org-security" artifactId="wyona-org-security-impl"
-                  version="0.0.1-dev-r22197"/>
+                  version="0.0.1-dev-r22929"/>
       <!-- IMPORTANT: Please make sure to update pom-core.xml as well! -->
       <dependency groupId="yarep" artifactId="yarep-impl"
                   version="0.0.1-dev-r22672"/>

Added: public/yanel/trunk/src/contributions/resources/yanel-user/build.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/build.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/build.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+
+<project name="yanel-resource" default="compile">
+
+  <import file="src/build/dependencies.xml"/>
+
+  <target name="init" description="Initialize build" depends="dependencies">
+    <echo>Initialize build</echo>
+
+    <dirname property="resource.home.dir" file="${ant.file}"/>
+    <echo>Resource Home Directory: ${resource.home.dir}</echo>
+
+    <property file="${resource.home.dir}/src/build/local.build.properties"/>
+    <property file="${resource.home.dir}/src/build/build.properties"/>
+
+    <path id="classpath">
+      <pathelement path="${maven2.cp}"/>
+      <pathelement path="${maven2.resource.cp}"/>
+    </path>
+    <property name="resource.build.dir" value="${resource.home.dir}/build"/>
+    <property name="resource.classes.dir" value="${resource.build.dir}/classes"/>
+    <property name="resource.lib.dir" value="${resource.build.dir}/lib"/>
+    <property name="resource.java.dir" value="${resource.home.dir}/src/java"/>
+  </target>
+
+  <target name="compile" description="Compile Java classes" depends="init">
+
+    <mkdir dir="${resource.classes.dir}"/>
+    <javac srcdir="${resource.java.dir}" destdir="${resource.classes.dir}"
+      classpathref="classpath"
+      debug="true"
+    />
+    <mkdir dir="${resource.lib.dir}"/>
+    <jar destfile="${resource.lib.dir}/yanel-resource-${resource.name}-${resource.version}.jar"
+      basedir="${resource.classes.dir}"
+    />
+  </target>
+
+  <target name="clean" depends="init">
+    <delete dir="${resource.build.dir}"/>
+  </target>
+
+  <target name="copy-dependencies" depends="init">
+    <copy todir="${build.dir}/webapps/${servlet.context.prefix}/WEB-INF/lib">
+      <fileset refid="maven2.resource.fileset"/>
+      <mapper type="flatten"/>
+    </copy>
+  </target>
+</project>


Property changes on: public/yanel/trunk/src/contributions/resources/yanel-user/build.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/yanel-user/resource.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/resource.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/resource.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+
+<resource xmlns="http://www.wyona.org/yanel/1.0"
+  name="yanel-user"
+  namespace="http://www.wyona.org/yanel/resource/1.0"
+  class="org.wyona.yanel.impl.resources.YanelUserResource"
+  >
+<description>
+User management interface
+</description>
+
+<rtd>
+<!--
+  <property name="foo" default-value="bar"/>
+-->
+</rtd>
+</resource>


Property changes on: public/yanel/trunk/src/contributions/resources/yanel-user/resource.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/yanel-user/src/build/build.properties
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/src/build/build.properties	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/src/build/build.properties	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,2 @@
+resource.name=yanel-user
+resource.version=0.0.1-dev-rXXX


Property changes on: public/yanel/trunk/src/contributions/resources/yanel-user/src/build/build.properties
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/yanel-user/src/build/dependencies.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/src/build/dependencies.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/src/build/dependencies.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+
+<project name="yanel-user-dependencies" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <target name="dependencies" description="Dependencies">
+    <!-- INFO: http://maven.apache.org/ant-tasks.html -->
+    <artifact:remoteRepository id="wyona.remote.repository" url="http://www.wyona.org/maven2/"/>
+
+    <artifact:dependencies pathId="maven2.classpath" filesetId="maven2.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+      <dependency groupId="wyona-org-yanel" artifactId="yanel-core"
+                  version="${yanel.source.version}"/>
+     </artifact:dependencies>
+
+
+
+    <artifact:dependencies pathId="maven2.resource.classpath" filesetId="maven2.resource.fileset">
+      <remoteRepository refid="wyona.remote.repository"/>
+      <dependency groupId="avalon-framework" artifactId="avalon-framework-api"
+                  version="4.3"/>
+      <dependency groupId="avalon-framework" artifactId="avalon-framework-impl"
+                  version="4.3"/>
+      <dependency groupId="wyona-org-security" artifactId="wyona-org-security-core"
+                  version="0.0.1-dev-r22929"/>
+       <dependency groupId="wyona-org-security" artifactId="wyona-org-security-impl"
+                  version="0.0.1-dev-r22929"/>
+    </artifact:dependencies>
+
+    <property name="maven2.cp" refid="maven2.classpath"/>
+    <property name="maven2.resource.cp" refid="maven2.resource.classpath"/>
+    <!--<echo>Maven2 classpath: ${maven2.cp}</echo>-->
+  </target>
+
+</project>
+


Property changes on: public/yanel/trunk/src/contributions/resources/yanel-user/src/build/dependencies.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,535 @@
+/*
+ * Copyright 2006 Wyona
+ *
+ *  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.wyona.org/licenses/APACHE-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.wyona.yanel.impl.resources;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.wyona.yanel.core.Resource;
+import org.wyona.yanel.core.util.PathUtil;
+import org.wyona.yanel.core.attributes.viewable.View;
+import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
+import org.wyona.yanel.core.api.attributes.ViewableV2;
+import org.wyona.yanel.core.api.attributes.CreatableV2;
+
+import org.wyona.security.core.api.UserManager;
+import org.wyona.security.core.api.GroupManager;
+import org.wyona.security.core.api.User;
+import org.wyona.security.core.api.Group;
+import org.wyona.security.core.api.Item;
+import org.wyona.security.core.api.AccessManagementException;
+import org.wyona.yarep.core.Repository;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
+
+import org.apache.log4j.Category;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * This resource allows creating, editing and deleting users. A user is defined
+ * by the following parameters: userId userName (optional) group email password
+ */
+public class YanelUserResource extends Resource implements ViewableV2, CreatableV2 {
+
+    protected static final String POLICY = "policy";
+
+    protected static final String ROLE = "role";
+
+    protected static final String WORLD = "world";
+
+    protected static final String USER = "user";
+
+    protected static final String PERMISSION_ATTR = "permission";
+
+    protected static final String ID_ATTR = "id";
+
+    protected static final String XMLNS_ATTR = "xmlns";
+
+    protected static final String POLICIES_SUFFIX = ".policy";
+
+    protected static final String XMLNS = "http://www.wyona.org/security/1.0";
+
+    protected static final String MIME_TYPE = "application/xhtml+xml; charset=UTF-8";
+
+    private static Category log = Category.getInstance(YanelUserResource.class);
+
+    private HashMap properties = new HashMap();
+
+    /**
+     * Constructor
+     */
+    public YanelUserResource() {
+
+        properties.put("userId", "");
+        properties.put("userName", "");
+        properties.put("email", "");
+        properties.put("description", "");
+        properties.put("password", "");
+        properties.put("group", "");
+
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.ViewableV2#getViewDescriptors()
+     */
+    public ViewDescriptor[] getViewDescriptors() {
+        return null;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.ViewableV2#getMimeType(java.lang.String)
+     */
+    public String getMimeType(String viewId) {
+        return MIME_TYPE;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.ViewableV2#getView(String)
+     * @return The requested view. Possible views are: 
+     * defaultView - Displays change password, edit profile and delete forms 
+     * submitProfile - Result of updating the user's profile 
+     * submitPassword - Result of changing the user's password 
+     * submitDelete - Result of deleting the user
+     */
+    public View getView(String viewId) throws Exception {
+
+        View defaultView = new View();
+        File xslFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile()
+                .getAbsolutePath(), "xslt" + File.separator + "yanel-user-profile.xsl");
+        File xmlFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile()
+                .getAbsolutePath(), "xml" + File.separator + "yanel-user-profile.xml");
+
+        try {
+
+            Transformer transformer = TransformerFactory.newInstance().newTransformer(
+                    new StreamSource(xslFile));
+
+            String action = determineAction(request);
+            String userId = getConfiguration().getProperty("user");
+
+            if (action.equals("submitProfile")) {
+                updateUserProfile(request, transformer);
+            } else if (action.equals("submitPassword")) {
+                updatePassword(request, transformer);
+            } else if (action.equals("submitDelete")) {
+                if (deleteUser(getConfiguration().getProperty("user"))) {
+                    transformer.setParameter("success", "User deleted successfully");
+                } else {
+                    transformer.setParameter("error", "Unable to delete user successfully");
+                }
+                transformer.setParameter("userId", userId);
+            } else if (action.equals("submitDeleteFromGroup")) {
+                deleteFromGroup(action, transformer);
+            } else {
+                User user = realm.getIdentityManager().getUserManager().getUser(userId);
+                transformer.setParameter("userId", userId);
+                transformer.setParameter("userName", user.getName());
+                transformer.setParameter("email", user.getEmail());
+                Group[] groups = user.getGroups();
+                StringBuffer groupsString = new StringBuffer();
+                for (int i = 0; i < groups.length; i++) {
+                    groupsString.append(groups[i].getID()).append(";");
+                }
+                transformer.setParameter("groupsString", groupsString);
+            }
+
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            transformer.transform(new javax.xml.transform.stream.StreamSource(xmlFile),
+                    new StreamResult(baos));
+
+            defaultView.setMimeType(MIME_TYPE);
+            defaultView.setInputStream(new java.io.ByteArrayInputStream(baos.toByteArray()));
+        } catch (Exception e) {
+            // TODO: Improve exception handling
+            log.error(e.getMessage(), e);
+        }
+
+        return defaultView;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.ViewableV2#exists()
+     */
+    public boolean exists() throws Exception {
+        log.warn("Not implemented yet!");
+        return true;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.ViewableV2#getSize()
+     */
+    public long getSize() throws Exception {
+        log.warn("Not implemented yet!");
+        return -1;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.CreatableV2#getPropertyType(String)
+     */
+    public String getPropertyType(String propertyName) {
+        log.warn("Not implemented yet!");
+        return null;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.CreatableV2#create(HttpServletRequest)
+     *      Creates the user
+     */
+    public void create(HttpServletRequest request) {
+
+        try {
+            if (!realm.getIdentityManager().getUserManager().existsUser("rp.userId")) {
+                boolean doCreate = validateNewUserData(request);
+                if (doCreate) {
+                    UserManager um = realm.getIdentityManager().getUserManager();
+                    String userId = request.getParameter("rp.userId");
+                    String password = request.getParameter("rp.password");
+                    String email = request.getParameter("rp.email");
+                    String userName = request.getParameter("rp.userName");
+
+                    um.createUser(userId, userName, email, password);
+
+                    String group = request.getParameter("rp.group");
+                    GroupManager gm = realm.getIdentityManager().getGroupManager();
+                    gm.getGroup(group).addMember(um.getUser(userId));
+
+                    // TODO: Handle more than one group
+                    saveUserPolicy();
+                } else {
+                    log.error("Unable to create user: the data introduced was not valid");
+                }
+            } else {
+                log.error("Unable to create user: the supplied id already exists");
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.CreatableV2#createRTIProperties(HttpServletRequest)
+     */
+    public HashMap createRTIProperties(HttpServletRequest request) {
+        HashMap map = new HashMap();
+        map.put("user", request.getParameter("rp.userId"));
+        return map;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.CreatableV1#getPropertyNames()
+     */
+    public String[] getPropertyNames() {
+        String[] propertyNames = (String[]) properties.keySet().toArray(
+                new String[properties.keySet().size()]);
+        return propertyNames;
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.CreatableV1#setProperty(String,
+     *      Object)
+     */
+    public void setProperty(String name, Object value) {
+        properties.put(name, value);
+    }
+
+    /**
+     * @see org.wyona.yanel.core.api.attributes.CreatableV1#getProperty(String)
+     */
+    public Object getProperty(String name) {
+        Object property = properties.get(name);
+        return property;
+    }
+
+    /**
+     * Create a configuration object with the policies to access the user data.
+     * Only the user and lenya will be able to access the user data.
+     * 
+     * @param userId
+     *            The user who must be granted permission to modify data
+     * @return Configuration object containing the corresponding policies
+     */
+    private Configuration createPolicyConfiguration(String userId) {
+        DefaultConfiguration config = new DefaultConfiguration(POLICY);
+        config.setAttribute(XMLNS_ATTR, XMLNS);
+
+        DefaultConfiguration child = null;
+
+        child = new DefaultConfiguration(ROLE);
+        child.setAttribute(ID_ATTR, "view");
+        config.addChild(child);
+
+        DefaultConfiguration worldNode = new DefaultConfiguration(WORLD);
+        worldNode.setAttribute(PERMISSION_ATTR, "false");
+        child.addChild(worldNode);
+
+        DefaultConfiguration userNode = new DefaultConfiguration(USER);
+        userNode.setAttribute(ID_ATTR, "lenya");
+        userNode.setAttribute(PERMISSION_ATTR, "true");
+        child.addChild(userNode);
+
+        userNode = new DefaultConfiguration(USER);
+        userNode.setAttribute(ID_ATTR, userId);
+        userNode.setAttribute(PERMISSION_ATTR, "true");
+        child.addChild(userNode);
+
+        child = new DefaultConfiguration(ROLE);
+        child.setAttribute(ID_ATTR, "open");
+        config.addChild(child);
+
+        userNode = new DefaultConfiguration(USER);
+        userNode.setAttribute(ID_ATTR, "lenya");
+        userNode.setAttribute(PERMISSION_ATTR, "true");
+        child.addChild(userNode);
+
+        userNode = new DefaultConfiguration(USER);
+        userNode.setAttribute(ID_ATTR, userId);
+        userNode.setAttribute(PERMISSION_ATTR, "true");
+        child.addChild(userNode);
+
+        child = new DefaultConfiguration(ROLE);
+        child.setAttribute(ID_ATTR, "write");
+        config.addChild(child);
+
+        userNode = new DefaultConfiguration(USER);
+        userNode.setAttribute(ID_ATTR, "lenya");
+        userNode.setAttribute(PERMISSION_ATTR, "true");
+        child.addChild(userNode);
+
+        userNode = new DefaultConfiguration(USER);
+        userNode.setAttribute(ID_ATTR, userId);
+        userNode.setAttribute(PERMISSION_ATTR, "true");
+        child.addChild(userNode);
+
+        return config;
+    }
+
+    /**
+     * Updates the user profile
+     * 
+     * @param request
+     *            The request containing the data to update
+     * @param transformer
+     */
+    protected void updateUserProfile(HttpServletRequest request, Transformer transformer) {
+        String email = request.getParameter("email");
+        if (email == null || ("").equals(email)) {
+            transformer.setParameter("error", "emailNotSet");
+        } else if (!validateEmail(email)) {
+            transformer.setParameter("error", "emailNotValid");
+        } else {
+            try {
+                String userId = getConfiguration().getProperty("user");
+                User user = realm.getIdentityManager().getUserManager().getUser(userId);
+                user.setEmail(request.getParameter("email"));
+                user.setName(request.getParameter("userName"));
+                user.save();
+
+                transformer.setParameter("userId", userId);
+                transformer.setParameter("userName", user.getName());
+                transformer.setParameter("email", user.getEmail());
+                transformer.setParameter("success", "Profile updated successfully");
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+            }
+
+        }
+    }
+
+    /**
+     * Updates the groups the user belongs to. Currently it only allows for
+     * deletion of membership The action parameter is always
+     * submitDeleteFromGroup_X where X is the target group
+     * 
+     * @param request
+     *            The request containing the group involved
+     * @param transformer
+     */
+    protected void deleteFromGroup(String action, Transformer transformer) {
+
+        try {
+            String userId = getConfiguration().getProperty("user");
+            User user = getRealm().getIdentityManager().getUserManager().getUser(userId);
+            Group[] userGroups = user.getGroups();
+            GroupManager gm = getRealm().getIdentityManager().getGroupManager();
+
+            String targetGroup = action.substring(action.indexOf("_"));
+            log.error("USER GROUPS: " + userGroups.length);
+            if (userGroups.length > 0) {
+                Group group = gm.getGroup(targetGroup);
+                if (group.isMember(user)) {
+                    group.removeMember(user);
+                }
+                transformer.setParameter("success", "User successfully deleted from group"
+                        + targetGroup);
+            } else {
+                log.error("The user " + userId + "does not belong to any group!");
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Change user password
+     * 
+     * @param request
+     * @param transformer
+     */
+    protected void updatePassword(HttpServletRequest request, Transformer transformer) {
+        String oldPassword = request.getParameter("oldPassword");
+        try {
+            String userId = getConfiguration().getProperty("user");
+            if (getRealm().getIdentityManager().getUserManager().getUser(userId).authenticate(
+                    oldPassword)) {
+                String plainPassword = request.getParameter("newPassword");
+                boolean confirmation = plainPassword.equals(request
+                        .getParameter("newPasswordConfirmation"));
+                if (confirmation && !plainPassword.equals("")) {
+                    User user = getRealm().getIdentityManager().getUserManager().getUser(userId);
+                    user.setPassword(plainPassword);
+                    user.save();
+
+                    transformer.setParameter("success", "Password updated successfully");
+                } else {
+                    transformer.setParameter("error", "Either no new password was supplied "
+                            + "or the password supplied and its confirmation do not coincide");
+                }
+            } else {
+                transformer.setParameter("error", "Authentication failed!");
+            }
+            transformer.setParameter("userId", userId);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * This method checks if the specified email is valid against a regex
+     * 
+     * @param email
+     * @return true if email is valid
+     */
+    private boolean validateEmail(String email) {
+        String emailRegEx = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
+        Pattern pattern = Pattern.compile(emailRegEx);
+        Matcher matcher = pattern.matcher(email);
+
+        return matcher.find();
+    }
+
+    /**
+     * Determine the requested view: defaultView, submitProfile,
+     * submitPassword,submitGroup, submitDelete
+     * 
+     * @param request
+     * @return name of the desired view
+     */
+    private String determineAction(HttpServletRequest request) {
+        boolean submit = false;
+        String action = "defaultView";
+
+        Enumeration enumeration = request.getParameterNames();
+        while (enumeration.hasMoreElements() && !submit) {
+            action = enumeration.nextElement().toString();
+            if (action.startsWith("submit")) {
+                submit = true;
+            }
+        }
+        return action;
+    }
+
+    /**
+     * Saves the user data access policies to the policies repository
+     */
+    private void saveUserPolicy() {
+        Configuration policyConfig = createPolicyConfiguration(properties.get("userId").toString());
+        DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
+
+        String policyPath = getPath() + POLICIES_SUFFIX;
+
+        try {
+            Repository policiesRepository = getRealm().getPolicyManager().getPoliciesRepository();
+            serializer.serialize(policiesRepository.getNode(policyPath).getOutputStream(),
+                    policyConfig);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Validate the supplied user data. userName is optional
+     */
+    private boolean validateNewUserData(HttpServletRequest request)
+            throws AccessManagementException {
+        boolean isValid = true;
+        if (request.getParameter("rp.password").equals("")) {
+            isValid = false;
+            log.error("No password supplied");
+        }
+        if (request.getParameter("rp.userId").equals("")) {
+            isValid = false;
+            log.error("No userId supplied");
+        }
+        String group = request.getParameter("rp.group");
+        if (group.equals("") || !realm.getIdentityManager().getGroupManager().existsGroup(group)) {
+            isValid = false;
+            log.error("Either no group was supplied or the group does not exist");
+        }
+        if (!validateEmail(request.getParameter("rp.email"))) {
+            isValid = false;
+            log.error("No email supplied or email not valid");
+        }
+        return isValid;
+    }
+
+    /**
+     * Delete the user from the identities repository and remove the related
+     * user interface files
+     */
+    protected boolean deleteUser(String userId) {
+        boolean success = false;
+        try {
+            User user = realm.getIdentityManager().getUserManager().getUser(userId);
+            user.delete();
+
+            String userScreenPolicyPath = getPath() + POLICIES_SUFFIX;
+            Repository policiesRepo = getRealm().getPolicyManager().getPoliciesRepository();
+            policiesRepo.getNode(userScreenPolicyPath).remove();
+
+            String userScreenRCPath = PathUtil.getRCPath(getPath());
+            Repository rtiRepo = getRealm().getRTIRepository();
+            rtiRepo.getNode(userScreenRCPath).remove();
+
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+
+        return success;
+    }
+}


Property changes on: public/yanel/trunk/src/contributions/resources/yanel-user/src/java/org/wyona/yanel/impl/resources/YanelUserResource.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/yanel-user/xml/yanel-user-profile.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/xml/yanel-user-profile.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/xml/yanel-user-profile.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form name="user-profile-form"/>
+  


Property changes on: public/yanel/trunk/src/contributions/resources/yanel-user/xml/yanel-user-profile.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl
===================================================================
--- public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,224 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsl:stylesheet version="1.0"
+    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xhtml="http://www.w3.org/1999/xhtml"
+    xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:xalan="http://xml.apache.org/xalan">
+
+  <xsl:output method="xhtml" encoding="UTF-8"/>
+
+  <xsl:param name="userId" select="''"/>
+  <xsl:param name="userName" select="''"/>
+  <xsl:param name="email" select="''"/>
+  <xsl:param name="groupsString" select="''"/>
+  <xsl:param name="success" select="''"/>
+  <xsl:param name="error" select="''"/>
+
+  <xsl:template match="/">
+    <html xmlns="http://www.w3.org/1999/xhtml">
+      <xsl:choose>
+        <xsl:when test="$success != ''">
+          <head>
+            <title></title>
+          </head>
+          <body>
+            <xsl:apply-templates select="form" mode="success"/>
+          </body>
+        </xsl:when>
+        <xsl:when test="$error != ''">
+          <head>
+            <title></title>
+          </head>
+          <body>
+            <xsl:apply-templates select="form" mode="error"/>
+          </body>
+        </xsl:when>
+        <xsl:otherwise>
+          <head>
+            <title>Change user profile</title>
+          </head>
+          <body>
+            <h1> User Profile of <xsl:value-of select="$userId"/>
+            </h1>
+            <xsl:apply-templates select="form" mode="init"/>
+          </body>
+        </xsl:otherwise>
+      </xsl:choose>
+    </html>
+  </xsl:template>
+
+  <xsl:template match="form" mode="success">
+    <h4>
+      <xsl:value-of select="$success"/>
+    </h4>
+
+    <xsl:if test="starts-with($success, 'Profile')">
+      <p>
+        <table>
+          <tr>
+            <td>Name:</td>
+            <td>
+              <xsl:value-of select="$userName"/>
+            </td>
+          </tr>
+          <tr>
+            <td>E-Mail:</td>
+            <td>
+              <xsl:value-of select="$email"/>
+            </td>
+          </tr>
+        </table>
+      </p>
+    </xsl:if>
+
+  </xsl:template>
+
+  <xsl:template match="form" mode="error">
+    <h4>An error occurred: <xsl:value-of select="$error"/>
+    </h4>
+  </xsl:template>
+
+  <xsl:template match="form" mode="init">
+    <h2>Change Password</h2>
+    <form name="user-password-form" method="post" action="#">
+      <p>
+        <table cellpadding="0" cellspacing="0" border="0">
+          <tr>
+            <td>Enter current password:</td>
+            <td>
+              <input type="password" name="oldPassword"/>
+            </td>
+          </tr>
+          <tr>
+            <td>Enter new password:</td>
+            <td>
+              <input type="password" name="newPassword"/>
+            </td>
+          </tr>
+          <tr>
+            <td>Confirm new password:</td>
+            <td>
+              <input type="password" name="newPasswordConfirmation"/>
+            </td>
+          </tr>
+          <tr>
+            <td colspan="2">
+              <input type="submit" name="submitPassword" value="Change Password"/>
+            </td>
+          </tr>
+        </table>
+      </p>
+    </form>
+
+    <h2>Change Profile</h2>
+    <form name="user-profile-form" method="post" action="#">
+      <p>
+        <table>
+          <tr>
+            <td>Name:</td>
+            <td>
+              <input type="text" name="userName" value="{$userName}"/>
+            </td>
+          </tr>
+          <tr>
+            <td>E-Mail:</td>
+            <td>
+              <input type="text" name="email" value="{$email}"/>
+            </td>
+          </tr>
+          <tr>
+            <td colspan="2">
+              <input type="submit" name="submitProfile" value="Change Profile"/>
+            </td>
+          </tr>
+        </table>
+      </p>
+    </form>
+
+    <h2>Change Groups</h2>
+
+    <p>
+      <table>
+        <xsl:call-template name="process-groups"/>
+      </table>
+    </p>
+
+
+    <h2>Delete User</h2>
+    <form name="user-deletion-form" method="post" action="#">
+      <p>
+        <table>
+          <tr>
+            <td colspan="2">
+              <input type="submit" name="submitDelete" value="Delete"/>
+            </td>
+          </tr>
+        </table>
+      </p>
+    </form>
+  </xsl:template>
+
+  <xsl:template name="tokenize">
+    <xsl:param name="inputString"/>
+    <xsl:param name="separator" select="' '"/>
+    <xsl:param name="resultElement" select="'item'"/>
+    <xsl:variable
+        name="token"
+        select="substring-before($inputString, $separator)" />
+    <xsl:variable
+        name="nextToken"
+        select="substring-after($inputString, $separator)" />
+    <xsl:if test="$token">
+      <xsl:element name="{$resultElement}">
+        <xsl:value-of select="$token"/>
+      </xsl:element>
+    </xsl:if>
+    <xsl:if test="$nextToken">
+      <xsl:call-template name="tokenize">
+        <xsl:with-param name="inputString" select="$nextToken"/>
+        <xsl:with-param name="separator" select="$separator"/>
+        <xsl:with-param name="resultElement" select="$resultElement"/>
+      </xsl:call-template>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template name="process-groups">
+    <xsl:variable name="groups">
+      <xsl:call-template name="tokenize">
+        <xsl:with-param name="inputString" select="$groupsString"/>
+        <xsl:with-param name="separator" select="';'"/>
+        <xsl:with-param name="resultElement" select="'group'"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:for-each select="xalan:nodeset($groups)/node()">
+      <xsl:variable name="uniqueID">
+        <xsl:text>Group_</xsl:text>
+        <xsl:value-of select="."/>
+      </xsl:variable>
+      <tr>
+        <td/>
+        <td>
+          <form method="post" action="#">
+            <xsl:attribute name="name">
+              <xsl:value-of select="$uniqueID"/>
+            </xsl:attribute>
+            <h4>
+              <xsl:value-of select="."/>
+            </h4>
+            <input type="submit" value="Unsubscribe">
+              <xsl:attribute name="name">
+                <xsl:text>submitDeleteFrom</xsl:text>
+                <xsl:value-of select="$uniqueID"/>
+              </xsl:attribute>
+
+            </input>
+          </form>
+        </td>
+      </tr>
+    </xsl:for-each>
+  </xsl:template>
+
+</xsl:stylesheet>
+


Property changes on: public/yanel/trunk/src/contributions/resources/yanel-user/xslt/yanel-user-profile.xsl
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/admin.xml
===================================================================
--- public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/admin.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/admin.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<group id="admin" xmlns="http://www.wyona.org/security/1.0">
+  <name>Admins</name>
+  <members>
+    <member id="alice"/>
+    <member id="lenya"/>
+  </members>
+</group>


Property changes on: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/admin.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/editor.xml
===================================================================
--- public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/editor.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/editor.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<group id="editor" xmlns="http://www.wyona.org/security/1.0">
+  <name>My Editors</name>
+  <members>
+    <member id="alice"/>
+    <member id="lenya"/>
+  </members>
+</group>


Property changes on: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/groups/editor.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/alice.xml
===================================================================
--- public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/alice.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/alice.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<user id="alice">
+<name>Michael H. Wechner</name>
+<email>michi at wyona.org</email>
+<password>8e07dafd13495561db9063ebe4db4b27</password>
+</user>


Property changes on: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/alice.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/lenya.xml
===================================================================
--- public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/lenya.xml	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/lenya.xml	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+
+<user id="lenya" xmlns="http://www.wyona.org/security/1.0">
+  <name>Michael Wechner</name>  
+  <email>michi at wyona.org</email>
+  <password type="md5">8e07dafd13495561db9063ebe4db4b27</password>
+
+  
+</user>


Property changes on: public/yanel/trunk/src/realms/use-cases/yanel/ac-identities/users/lenya.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: public/yanel/trunk/src/realms/use-cases/yanel/data/index.html
===================================================================
--- public/yanel/trunk/src/realms/use-cases/yanel/data/index.html	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/realms/use-cases/yanel/data/index.html	2007-02-23 21:37:40 UTC (rev 22930)
@@ -24,6 +24,8 @@
   <li><a href="index.xhtml">index.xhtml</a></li>
 
   <li><a href="introspection-index.xml">introspection-index.xml</a></li>
+  
+  <li><a href="alice">Alice</a></li>
 
   <li><a href="hello/">hello/</a></li>
   <li><a href="hello">hello</a></li>

Added: public/yanel/trunk/src/realms/use-cases/yanel/rti/alice.yanel-rc
===================================================================
--- public/yanel/trunk/src/realms/use-cases/yanel/rti/alice.yanel-rc	2007-02-23 21:23:45 UTC (rev 22929)
+++ public/yanel/trunk/src/realms/use-cases/yanel/rti/alice.yanel-rc	2007-02-23 21:37:40 UTC (rev 22930)
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+
+<yanel:resource-config xmlns:yanel="http://www.wyona.org/yanel/rti/1.0">
+  <yanel:rti name="yanel-user" namespace="http://www.wyona.org/yanel/resource/1.0"/>
+  <yanel:property name="user" value="alice"/>  
+</yanel:resource-config>




More information about the Yanel-commits mailing list