r965 - in xwiki/trunk/src: main/java/com/xpn/xwiki main/java/com/xpn/xwiki/objects/classes main/java/com/xpn/xwiki/user/api main/java/com/xpn/xwiki/user/impl/LDAP main/java/com/xpn/xwiki/user/impl/exo main/java/com/xpn/xwiki/user/impl/xwiki test/java/com/xpn/xwiki/test
Nguyen Viet Chung
chungnv at users.forge.objectweb.org
Wed Mar 8 05:01:10 CET 2006
Author: chungnv
Date: 2006-03-08 05:01:09 +0100 (Wed, 08 Mar 2006)
New Revision: 965
Modified:
xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/GroupsClass.java
xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/LevelsClass.java
xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/UsersClass.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiRightService.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/LDAP/LDAPAuthServiceImpl.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoAuthServiceImpl.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoFilter.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoGroupServiceImpl.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiAuthServiceImpl.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java
xwiki/trunk/src/test/java/com/xpn/xwiki/test/GroovyTestRightService.java
Log:
Fixes for eXo 1.1 integration
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/XWikiException.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -25,22 +25,20 @@
package com.xpn.xwiki;
+import com.xpn.xwiki.store.XWikiBatcher;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.hibernate.JDBCException;
+
+import javax.servlet.ServletException;
+import javax.xml.transform.TransformerException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.MessageFormat;
-import java.util.ArrayList;
import java.util.List;
-import javax.servlet.ServletException;
-import javax.xml.transform.TransformerException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.hibernate.JDBCException;
-import com.xpn.xwiki.store.XWikiBatcher;
-
public class XWikiException extends Exception {
private static final Log log = LogFactory.getLog(XWikiException.class);
@@ -145,6 +143,10 @@
public static final int ERROR_XWIKI_ACCESS_DENIED = 9001;
public static final int ERROR_XWIKI_ACCESS_TOKEN_INVALID = 9002;
+ public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_USERS = 9003;
+ public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_GROUPS = 9004;
+ public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_ADDING_USERS = 9005;
+ public static final int ERROR_XWIKI_ACCESS_EXO_EXCEPTION_LISTING_USERS = 9006;
public static final int ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG = 10001;
public static final int ERROR_XWIKI_EMAIL_CANNOT_PREPARE_VALIDATION_EMAIL = 10002;
@@ -248,8 +250,7 @@
this.message = message;
}
- public String getMessage()
- {
+ public String getMessage() {
StringBuffer buffer = new StringBuffer();
buffer.append("Error number ");
buffer.append(getCode());
@@ -257,23 +258,18 @@
buffer.append(getModuleName());
buffer.append(": ");
- if (message!=null)
- {
- if (args==null)
+ if (message != null) {
+ if (args == null)
buffer.append(message);
- else
- {
- MessageFormat msgFormat = new MessageFormat (message);
- try
- {
+ else {
+ MessageFormat msgFormat = new MessageFormat(message);
+ try {
buffer.append(msgFormat.format(args));
}
- catch (Exception e)
- {
+ catch (Exception e) {
buffer.append("Cannot format message " + message + " with args ");
- for (int i = 0; i< args.length ; i++)
- {
- if (i!=0)
+ for (int i = 0; i < args.length; i++) {
+ if (i != 0)
buffer.append(",");
buffer.append(args[i]);
}
@@ -281,23 +277,22 @@
}
}
- if (exception!=null) {
- buffer.append("\nWrapped Exception: ");
- buffer.append(exception.getMessage());
+ if (exception != null) {
+ buffer.append("\nWrapped Exception: ");
+ buffer.append(exception.getMessage());
}
return buffer.toString();
}
- public String getFullMessage()
- {
+ public String getFullMessage() {
StringBuffer buffer = new StringBuffer(getMessage());
buffer.append("\n");
buffer.append(getStackTraceAsString());
buffer.append("\n");
List list = XWikiBatcher.getSQLStats().getRecentSqlList();
- if (list.size()>0) {
+ if (list.size() > 0) {
buffer.append("Recent SQL:\n");
- for (int i=0;i<list.size();i++) {
+ for (int i = 0; i < list.size(); i++) {
buffer.append(list.get(i));
buffer.append("\n");
}
@@ -307,16 +302,16 @@
public void printStackTrace(PrintWriter s) {
super.printStackTrace(s);
- if (exception!=null) {
+ if (exception != null) {
s.write("\n\nWrapped Exception:\n\n");
if (exception instanceof org.hibernate.JDBCException) {
- (((JDBCException)exception).getSQLException()).printStackTrace(s);
+ (((JDBCException) exception).getSQLException()).printStackTrace(s);
} else if (exception instanceof MethodInvocationException) {
- (((MethodInvocationException)exception).getWrappedThrowable()).printStackTrace(s);
+ (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s);
} else if (exception instanceof ServletException) {
- (((ServletException)exception).getRootCause()).printStackTrace(s);
+ (((ServletException) exception).getRootCause()).printStackTrace(s);
} else if (exception instanceof TransformerException) {
- (((TransformerException)exception).getCause()).printStackTrace(s);
+ (((TransformerException) exception).getCause()).printStackTrace(s);
} else {
exception.printStackTrace(s);
}
@@ -325,16 +320,16 @@
public void printStackTrace(PrintStream s) {
super.printStackTrace(s);
- if (exception!=null) {
+ if (exception != null) {
s.print("\n\nWrapped Exception:\n\n");
if (exception instanceof org.hibernate.JDBCException) {
- (((JDBCException)exception).getSQLException()).printStackTrace(s);
+ (((JDBCException) exception).getSQLException()).printStackTrace(s);
} else if (exception instanceof MethodInvocationException) {
- (((MethodInvocationException)exception).getWrappedThrowable()).printStackTrace(s);
+ (((MethodInvocationException) exception).getWrappedThrowable()).printStackTrace(s);
} else if (exception instanceof ServletException) {
- (((ServletException)exception).getRootCause()).printStackTrace(s);
+ (((ServletException) exception).getRootCause()).printStackTrace(s);
} else if (exception instanceof TransformerException) {
- (((TransformerException)exception).getCause()).printStackTrace(s);
+ (((TransformerException) exception).getCause()).printStackTrace(s);
} else {
exception.printStackTrace(s);
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/GroupsClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/GroupsClass.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/GroupsClass.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -1,16 +1,18 @@
package com.xpn.xwiki.objects.classes;
-import com.xpn.xwiki.objects.meta.PropertyMetaClass;
-import com.xpn.xwiki.objects.*;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.objects.BaseCollection;
+import com.xpn.xwiki.objects.BaseProperty;
+import com.xpn.xwiki.objects.StringProperty;
+import com.xpn.xwiki.objects.meta.PropertyMetaClass;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ecs.xhtml.option;
import org.apache.ecs.xhtml.select;
-import org.apache.ecs.xhtml.option;
-import org.apache.commons.lang.StringUtils;
-import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
public class GroupsClass extends ListClass {
@@ -33,11 +35,13 @@
}
- list.remove("XWiki.XWikiAllGroup");
- list.add(0,"XWiki.XWikiAllGroup");
- if ((context.getWiki().isVirtual()&&(!context.getDatabase().equals("xwiki")))) {
- list.remove("xwiki:XWiki.XWikiAllGroup");
- list.add(0,"xwiki:XWiki.XWikiAllGroup");
+ if (list.contains("XWiki.XWikiAllGroup")) {
+ list.remove("XWiki.XWikiAllGroup");
+ list.add(0, "XWiki.XWikiAllGroup");
+ if ((context.getWiki().isVirtual() && (!context.getDatabase().equals("xwiki")))) {
+ list.remove("xwiki:XWiki.XWikiAllGroup");
+ list.add(0, "xwiki:XWiki.XWikiAllGroup");
+ }
}
return list;
}
@@ -54,7 +58,7 @@
public BaseProperty fromStringArray(String[] strings) {
List list = new ArrayList();
- for (int i=0;i<strings.length;i++)
+ for (int i = 0; i < strings.length; i++)
list.add(strings[i]);
BaseProperty prop = newProperty();
prop.setValue(StringUtils.join(list.toArray(), ","));
@@ -65,43 +69,43 @@
return context.getWiki().getUserName(value, null, false, context);
}
- public static List getListFromString(String value) {
+ public static List getListFromString(String value) {
List list = new ArrayList();
- if (value==null)
+ if (value == null)
return list;
String val = StringUtils.replace(value, "\\,", "%SEP%");
- String[] result = StringUtils.split(value,", ");
- for (int i=0;i<result.length;i++)
- list.add(StringUtils.replace(result[i],"%SEP%", ","));
+ String[] result = StringUtils.split(value, ", ");
+ for (int i = 0; i < result.length; i++)
+ list.add(StringUtils.replace(result[i], "%SEP%", ","));
return list;
}
- public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
- select select = new select(prefix + name, 1);
- select.setMultiple(isMultiSelect());
- select.setSize(getSize());
+ public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+ select select = new select(prefix + name, 1);
+ select.setMultiple(isMultiSelect());
+ select.setSize(getSize());
- List list = getList(context);
- List selectlist;
+ List list = getList(context);
+ List selectlist;
- BaseProperty prop = (BaseProperty)object.safeget(name);
- if (prop==null) {
- selectlist = new ArrayList();
- } else {
- selectlist = getListFromString((String)prop.getValue());
- }
+ BaseProperty prop = (BaseProperty) object.safeget(name);
+ if (prop == null) {
+ selectlist = new ArrayList();
+ } else {
+ selectlist = getListFromString((String) prop.getValue());
+ }
- // Add options from Set
- for (Iterator it=list.iterator();it.hasNext();) {
- String value = it.next().toString();
- option option = new option(value, value);
- option.addElement(getText(value, context));
- if (selectlist.contains(value))
- option.setSelected(true);
- select.addElement(option);
- }
+ // Add options from Set
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ String value = it.next().toString();
+ option option = new option(value, value);
+ option.addElement(getText(value, context));
+ if (selectlist.contains(value))
+ option.setSelected(true);
+ select.addElement(option);
+ }
- buffer.append(select.toString());
+ buffer.append(select.toString());
}
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/LevelsClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/LevelsClass.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/LevelsClass.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -1,16 +1,18 @@
package com.xpn.xwiki.objects.classes;
-import com.xpn.xwiki.objects.meta.PropertyMetaClass;
-import com.xpn.xwiki.objects.*;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.objects.BaseCollection;
+import com.xpn.xwiki.objects.BaseProperty;
+import com.xpn.xwiki.objects.StringProperty;
+import com.xpn.xwiki.objects.meta.PropertyMetaClass;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ecs.xhtml.option;
import org.apache.ecs.xhtml.select;
-import org.apache.ecs.xhtml.option;
-import org.apache.commons.lang.StringUtils;
-import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
public class LevelsClass extends ListClass {
@@ -26,7 +28,7 @@
public List getList(XWikiContext context) {
List list;
try {
- list = context.getWiki().getGroupService().listAllLevels(context);
+ list = context.getWiki().getRightService().listAllLevels(context);
} catch (XWikiException e) {
// TODO add log exception
list = new ArrayList();
@@ -54,7 +56,7 @@
public BaseProperty fromStringArray(String[] strings) {
List list = new ArrayList();
- for (int i=0;i<strings.length;i++)
+ for (int i = 0; i < strings.length; i++)
list.add(strings[i]);
BaseProperty prop = newProperty();
prop.setValue(StringUtils.join(list.toArray(), ","));
@@ -65,43 +67,43 @@
return context.getWiki().getUserName(value, null, false, context);
}
- public static List getListFromString(String value) {
+ public static List getListFromString(String value) {
List list = new ArrayList();
- if (value==null)
+ if (value == null)
return list;
String val = StringUtils.replace(value, "\\,", "%SEP%");
- String[] result = StringUtils.split(value,", ");
- for (int i=0;i<result.length;i++)
- list.add(StringUtils.replace(result[i],"%SEP%", ","));
+ String[] result = StringUtils.split(value, ", ");
+ for (int i = 0; i < result.length; i++)
+ list.add(StringUtils.replace(result[i], "%SEP%", ","));
return list;
}
- public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
- select select = new select(prefix + name, 1);
- select.setMultiple(isMultiSelect());
- select.setSize(getSize());
+ public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+ select select = new select(prefix + name, 1);
+ select.setMultiple(isMultiSelect());
+ select.setSize(getSize());
- List list = getList(context);
- List selectlist;
+ List list = getList(context);
+ List selectlist;
- BaseProperty prop = (BaseProperty)object.safeget(name);
- if (prop==null) {
- selectlist = new ArrayList();
- } else {
- selectlist = getListFromString((String)prop.getValue());
- }
+ BaseProperty prop = (BaseProperty) object.safeget(name);
+ if (prop == null) {
+ selectlist = new ArrayList();
+ } else {
+ selectlist = getListFromString((String) prop.getValue());
+ }
- // Add options from Set
- for (Iterator it=list.iterator();it.hasNext();) {
- String value = it.next().toString();
- option option = new option(value, value);
- option.addElement(getText(value, context));
- if (selectlist.contains(value))
- option.setSelected(true);
- select.addElement(option);
- }
+ // Add options from Set
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ String value = it.next().toString();
+ option option = new option(value, value);
+ option.addElement(getText(value, context));
+ if (selectlist.contains(value))
+ option.setSelected(true);
+ select.addElement(option);
+ }
- buffer.append(select.toString());
+ buffer.append(select.toString());
}
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/UsersClass.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/UsersClass.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/objects/classes/UsersClass.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -1,16 +1,18 @@
package com.xpn.xwiki.objects.classes;
-import com.xpn.xwiki.objects.meta.PropertyMetaClass;
-import com.xpn.xwiki.objects.*;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.objects.BaseCollection;
+import com.xpn.xwiki.objects.BaseProperty;
+import com.xpn.xwiki.objects.StringProperty;
+import com.xpn.xwiki.objects.meta.PropertyMetaClass;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ecs.xhtml.option;
import org.apache.ecs.xhtml.select;
-import org.apache.ecs.xhtml.option;
-import org.apache.commons.lang.StringUtils;
-import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
public class UsersClass extends ListClass {
@@ -26,7 +28,7 @@
public List getList(XWikiContext context) {
List list;
try {
- list = context.getWiki().getGroupService().listMemberForGroup("XWiki.XWikiAllGroup", context);
+ list = context.getWiki().getGroupService().listMemberForGroup(null, context);
} catch (XWikiException e) {
// TODO add log exception
list = new ArrayList();
@@ -34,7 +36,7 @@
}
list.remove("XWiki.XWikiGuest");
- list.add(0,"XWiki.XWikiGuest");
+ list.add(0, "XWiki.XWikiGuest");
return list;
}
@@ -50,7 +52,7 @@
public BaseProperty fromStringArray(String[] strings) {
List list = new ArrayList();
- for (int i=0;i<strings.length;i++)
+ for (int i = 0; i < strings.length; i++)
list.add(strings[i]);
BaseProperty prop = newProperty();
prop.setValue(StringUtils.join(list.toArray(), ","));
@@ -61,43 +63,43 @@
return context.getWiki().getUserName(value, null, false, context);
}
- public static List getListFromString(String value) {
+ public static List getListFromString(String value) {
List list = new ArrayList();
- if (value==null)
+ if (value == null)
return list;
String val = StringUtils.replace(value, "\\,", "%SEP%");
- String[] result = StringUtils.split(value,", ");
- for (int i=0;i<result.length;i++)
- list.add(StringUtils.replace(result[i],"%SEP%", ","));
+ String[] result = StringUtils.split(value, ", ");
+ for (int i = 0; i < result.length; i++)
+ list.add(StringUtils.replace(result[i], "%SEP%", ","));
return list;
}
- public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
- select select = new select(prefix + name, 1);
- select.setMultiple(isMultiSelect());
- select.setSize(getSize());
+ public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
+ select select = new select(prefix + name, 1);
+ select.setMultiple(isMultiSelect());
+ select.setSize(getSize());
- List list = getList(context);
- List selectlist;
+ List list = getList(context);
+ List selectlist;
- BaseProperty prop = (BaseProperty)object.safeget(name);
- if (prop==null) {
- selectlist = new ArrayList();
- } else {
- selectlist = getListFromString((String)prop.getValue());
- }
+ BaseProperty prop = (BaseProperty) object.safeget(name);
+ if (prop == null) {
+ selectlist = new ArrayList();
+ } else {
+ selectlist = getListFromString((String) prop.getValue());
+ }
- // Add options from Set
- for (Iterator it=list.iterator();it.hasNext();) {
- String value = it.next().toString();
- option option = new option(value, value);
- option.addElement(getText(value, context));
- if (selectlist.contains(value))
- option.setSelected(true);
- select.addElement(option);
- }
+ // Add options from Set
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ String value = it.next().toString();
+ option option = new option(value, value);
+ option.addElement(getText(value, context));
+ if (selectlist.contains(value))
+ option.setSelected(true);
+ select.addElement(option);
+ }
- buffer.append(select.toString());
+ buffer.append(select.toString());
}
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiGroupService.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -22,19 +22,24 @@
package com.xpn.xwiki.user.api;
-import java.util.Collection;
-import java.util.List;
-
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import java.util.Collection;
+import java.util.List;
+
public interface XWikiGroupService {
public void init(XWiki xwiki);
+
public void flushCache();
+
public Collection listGroupsForUser(String username, XWikiContext context) throws XWikiException;
- public void addUserToGroup(String user, String database, String group);
+
+ public void addUserToGroup(String user, String database, String group) throws XWikiException;
+
public List listMemberForGroup(String s, XWikiContext context) throws XWikiException;
+
public List listAllGroups(XWikiContext context) throws XWikiException;
- public List listAllLevels(XWikiContext context) throws XWikiException;
+
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiRightService.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiRightService.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/api/XWikiRightService.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -1,23 +1,23 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ */
package com.xpn.xwiki.user.api;
@@ -25,10 +25,18 @@
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiDocument;
+import java.util.List;
+
public interface XWikiRightService {
public boolean checkAccess(String action, XWikiDocument doc, XWikiContext context) throws XWikiException;
+
public boolean hasAccessLevel(String right, String username, String docname, XWikiContext context) throws XWikiException;
+
public boolean hasProgrammingRights(XWikiContext context);
+
public boolean hasProgrammingRights(XWikiDocument doc, XWikiContext context);
+
public boolean hasAdminRights(XWikiContext context);
+
+ public List listAllLevels(XWikiContext context) throws XWikiException;
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/LDAP/LDAPAuthServiceImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/LDAP/LDAPAuthServiceImpl.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/LDAP/LDAPAuthServiceImpl.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -22,49 +22,43 @@
package com.xpn.xwiki.user.impl.LDAP;
-import java.io.UnsupportedEncodingException;
-import java.security.Principal;
-import java.text.MessageFormat;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.securityfilter.realm.SimplePrincipal;
-
-import com.novell.ldap.LDAPAttribute;
-import com.novell.ldap.LDAPAttributeSet;
-import com.novell.ldap.LDAPConnection;
-import com.novell.ldap.LDAPEntry;
-import com.novell.ldap.LDAPException;
-import com.novell.ldap.LDAPSearchResults;
+import com.novell.ldap.*;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.securityfilter.realm.SimplePrincipal;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.text.MessageFormat;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+
public class LDAPAuthServiceImpl extends XWikiAuthServiceImpl {
private static final Log log = LogFactory.getLog(LDAPAuthServiceImpl.class);
public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException {
Principal principal = null;
- if ((username==null)||(username.trim().equals("")))
+ if ((username == null) || (username.trim().equals("")))
return null;
- if ((password==null)||(password.trim().equals("")))
+ if ((password == null) || (password.trim().equals("")))
return null;
String superadmin = "superadmin";
if (username.equals(superadmin)) {
String superadminpassword = context.getWiki().Param("xwiki.superadminpassword");
- if ((superadminpassword!=null)&&(superadminpassword.equals(password))) {
- principal = new SimplePrincipal("XWiki.superadmin");
+ if ((superadminpassword != null) && (superadminpassword.equals(password))) {
+ principal = new SimplePrincipal("superadmin");
return principal;
} else {
return null;
@@ -74,95 +68,82 @@
// If we have the context then we are using direct mode
// then we should specify the database
// This is needed for virtual mode to work
- if (context!=null) {
+ if (context != null) {
String susername = username;
int i = username.indexOf(".");
- if (i!=-1)
- susername = username.substring(i+1);
+ if (i != -1)
+ susername = username.substring(i + 1);
- String DN = getLDAP_DN(susername, context);
+ String DN = getLDAP_DN(susername, context);
- if (DN != null && DN.length()!=0)
- {
- if (checkDNPassword(DN, susername, password, context))
- {
- principal = GetUserPrincipal(susername, context);
- }
- }
- else
- {
- HashMap attributes = new HashMap();
- if (checkUserPassword(susername, password, attributes, context))
- {
- principal = GetUserPrincipal(susername, context);
- if (principal == null && attributes.size() > 0)
- {
- // In case of Virtual Wikis, users should be added in the main wiki
- // if ldap is not configured for the virtual wiki
- if (context.isVirtual()) {
- String db = context.getDatabase();
- try {
- // Switch to the main database in case of
- // virtual and if not local LDAP configuration
- if (context.getWiki().getXWikiPreference("ldap_server", context) == null || context.getWiki().getXWikiPreference("ldap_server", context).length() == 0) {
- context.setDatabase(context.getWiki().getDatabase());
- }
- try {
- CreateUserFromLDAP(susername, attributes, context);
- principal = GetUserPrincipal(susername, context);
- } catch (Exception e) {
- }
- } finally {
- context.setDatabase(db);
- }
- } else {
- CreateUserFromLDAP(susername, attributes, context);
- principal = GetUserPrincipal(susername, context);
- }
- context.getWiki().flushCache();
- }
- }
+ if (DN != null && DN.length() != 0) {
+ if (checkDNPassword(DN, susername, password, context)) {
+ principal = GetUserPrincipal(susername, context);
+ }
+ } else {
+ HashMap attributes = new HashMap();
+ if (checkUserPassword(susername, password, attributes, context)) {
+ principal = GetUserPrincipal(susername, context);
+ if (principal == null && attributes.size() > 0) {
+ // In case of Virtual Wikis, users should be added in the main wiki
+ // if ldap is not configured for the virtual wiki
+ if (context.isVirtual()) {
+ String db = context.getDatabase();
+ try {
+ // Switch to the main database in case of
+ // virtual and if not local LDAP configuration
+ if (context.getWiki().getXWikiPreference("ldap_server", context) == null || context.getWiki().getXWikiPreference("ldap_server", context).length() == 0)
+ {
+ context.setDatabase(context.getWiki().getDatabase());
+ }
+ try {
+ CreateUserFromLDAP(susername, attributes, context);
+ principal = GetUserPrincipal(susername, context);
+ } catch (Exception e) {
+ }
+ } finally {
+ context.setDatabase(db);
+ }
+ } else {
+ CreateUserFromLDAP(susername, attributes, context);
+ principal = GetUserPrincipal(susername, context);
+ }
+ context.getWiki().flushCache();
+ }
+ }
}
}
return principal;
}
private void CreateUserFromLDAP(String susername, HashMap attributes, XWikiContext context) throws XWikiException {
- String ldapFieldMapping = getParam("ldap_fields_mapping",context);
- if (ldapFieldMapping != null && ldapFieldMapping.length() > 0)
- {
+ String ldapFieldMapping = getParam("ldap_fields_mapping", context);
+ if (ldapFieldMapping != null && ldapFieldMapping.length() > 0) {
String[] fields = ldapFieldMapping.split(",");
BaseClass bclass = context.getWiki().getUserClass(context);
BaseObject bobj = new BaseObject();
bobj.setClassName(bclass.getName());
String name = null;
String fullwikiname = null;
- for(int i = 0; i < fields.length; i++ )
- {
+ for (int i = 0; i < fields.length; i++) {
String[] field = fields[i].split("=");
- if (2 == field.length)
- {
- String fieldName = field[0];
- if (attributes.containsKey(field[1]))
- {
- String fieldValue;
- fieldValue = (String)attributes.get(field[1]);
- if (fieldName.equals("name"))
- {
- name = fieldValue;
- fullwikiname = "XWiki." + name;
- bobj.setName(fullwikiname);
- }
- else
- {
- bobj.setStringValue(fieldName, fieldValue);
- }
- }
+ if (2 == field.length) {
+ String fieldName = field[0];
+ if (attributes.containsKey(field[1])) {
+ String fieldValue;
+ fieldValue = (String) attributes.get(field[1]);
+ if (fieldName.equals("name")) {
+ name = fieldValue;
+ fullwikiname = "XWiki." + name;
+ bobj.setName(fullwikiname);
+ } else {
+ bobj.setStringValue(fieldName, fieldValue);
+ }
+ }
}
}
- if (name != null && name.length() > 0)
- {
+ if (name != null && name.length() > 0) {
XWikiDocument doc = context.getWiki().getDocument(fullwikiname, context);
doc.setParent("");
doc.addObject(bclass.getName(), bobj);
@@ -183,22 +164,24 @@
// First we check in the local database
try {
String user = findUser(susername, context);
- if (user!=null) {
+ if (user != null) {
principal = new SimplePrincipal(user);
}
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
if (context.isVirtual()) {
- if (principal==null) {
+ if (principal == null) {
// Then we check in the main database
String db = context.getDatabase();
try {
context.setDatabase(context.getWiki().getDatabase());
try {
String user = findUser(susername, context);
- if (user!=null)
+ if (user != null)
principal = new SimplePrincipal(context.getDatabase() + ":" + user);
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
} finally {
context.setDatabase(db);
}
@@ -207,29 +190,30 @@
return principal;
}
- public String getLDAP_DN(String susername, XWikiContext context)
- {
- String DN=null;
- if (context!=null) {
+ public String getLDAP_DN(String susername, XWikiContext context) {
+ String DN = null;
+ if (context != null) {
// First we check in the local database
try {
String user = findUser(susername, context);
- if (user!=null && user.length()!=0) {
+ if (user != null && user.length() != 0) {
DN = readLDAP_DN(user, context);
}
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
if (context.isVirtual()) {
- if (DN==null || DN.length()==0) {
+ if (DN == null || DN.length() == 0) {
// Then we check in the main database
String db = context.getDatabase();
try {
context.setDatabase(context.getWiki().getDatabase());
try {
String user = findUser(susername, context);
- if (user!=null && user.length()!=0)
+ if (user != null && user.length() != 0)
DN = readLDAP_DN(user, context);
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
} finally {
context.setDatabase(db);
}
@@ -244,11 +228,12 @@
try {
XWikiDocument doc = context.getWiki().getDocument(username, context);
// We only allow empty password from users having a XWikiUsers object.
- if (doc.getObject("XWiki.XWikiUsers")!=null) {
- DN = doc.getStringValue("XWiki.XWikiUsers", "ldap_dn");
+ if (doc.getObject("XWiki.XWikiUsers") != null) {
+ DN = doc.getStringValue("XWiki.XWikiUsers", "ldap_dn");
}
- } catch (Throwable e) {}
+ } catch (Throwable e) {
+ }
return DN;
}
@@ -260,89 +245,85 @@
try {
if (log.isDebugEnabled())
- log.debug("LDAP Password check for user " + username);
+ log.debug("LDAP Password check for user " + username);
int ldapPort = getLDAPPort(context);
int ldapVersion = LDAPConnection.LDAP_V3;
String ldapHost = getParam("ldap_server", context);
- String bindDNFormat = getParam("ldap_bind_DN",context);
- String bindPasswordFormat = getParam("ldap_bind_pass",context);
+ String bindDNFormat = getParam("ldap_bind_DN", context);
+ String bindPasswordFormat = getParam("ldap_bind_pass", context);
int checkLevel = GetCheckLevel(context);
Object[] arguments = {
- username,
- password
- };
+ username,
+ password
+ };
String bindDN = MessageFormat.format(bindDNFormat, arguments);
- String bindPassword = MessageFormat.format(bindPasswordFormat, arguments);
+ String bindPassword = MessageFormat.format(bindPasswordFormat, arguments);
- String baseDN = getParam("ldap_base_DN",context);
+ String baseDN = getParam("ldap_base_DN", context);
- lc.connect( ldapHost, ldapPort );
+ lc.connect(ldapHost, ldapPort);
if (log.isDebugEnabled())
- log.debug("LDAP Connect successfull to host " + ldapHost + " and port " + ldapPort );
+ log.debug("LDAP Connect successfull to host " + ldapHost + " and port " + ldapPort);
// authenticate to the server
result = Bind(bindDN, bindPassword, lc, ldapVersion);
if (log.isDebugEnabled())
- log.debug("LDAP Bind returned");
+ log.debug("LDAP Bind returned");
- if (result && checkLevel > 0)
- {
+ if (result && checkLevel > 0) {
if (log.isDebugEnabled())
- log.debug("LDAP searching user");
+ log.debug("LDAP searching user");
LDAPSearchResults searchResults =
- lc.search( baseDN,
- LDAPConnection.SCOPE_SUB ,
- "("+ getParam("ldap_UID_attr",context) +
- "=" + username + ")",
+ lc.search(baseDN,
+ LDAPConnection.SCOPE_SUB,
+ "(" + getParam("ldap_UID_attr", context) +
+ "=" + username + ")",
null, // return all attributes
false); // return attrs and values
- if (searchResults.hasMore())
- {
+ if (searchResults.hasMore()) {
if (log.isDebugEnabled())
- log.debug("LDAP searching found user");
+ log.debug("LDAP searching found user");
LDAPEntry nextEntry = searchResults.next();
foundDN = nextEntry.getDN();
if (log.isDebugEnabled())
- log.debug("LDAP searching found DN: " + foundDN);
+ log.debug("LDAP searching found DN: " + foundDN);
- if (checkLevel > 1)
- {
+ if (checkLevel > 1) {
if (log.isDebugEnabled())
- log.debug("LDAP comparing password");
+ log.debug("LDAP comparing password");
LDAPAttribute attr = new LDAPAttribute(
- "userPassword", password );
- result = lc.compare( foundDN, attr );
+ "userPassword", password);
+ result = lc.compare(foundDN, attr);
}
- if (result)
- {
+ if (result) {
if (log.isDebugEnabled())
- log.debug("LDAP adding user attributes");
+ log.debug("LDAP adding user attributes");
LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
Iterator allAttributes = attributeSet.iterator();
- while(allAttributes.hasNext()) {
+ while (allAttributes.hasNext()) {
LDAPAttribute attribute =
- (LDAPAttribute)allAttributes.next();
+ (LDAPAttribute) allAttributes.next();
String attributeName = attribute.getName();
Enumeration allValues = attribute.getStringValues();
- if( allValues != null) {
- while(allValues.hasMoreElements()) {
+ if (allValues != null) {
+ while (allValues.hasMoreElements()) {
if (log.isDebugEnabled())
- log.debug("LDAP adding user attribute " + attributeName);
+ log.debug("LDAP adding user attribute " + attributeName);
String Value = (String) allValues.nextElement();
attributes.put(attributeName, Value);
@@ -351,41 +332,39 @@
}
attributes.put("dn", foundDN);
}
- }
- else {
+ } else {
if (log.isDebugEnabled())
- log.debug("LDAP search user failed");
+ log.debug("LDAP search user failed");
notinLDAP = true;
}
if (log.isInfoEnabled()) {
if (result)
- log.info("LDAP Password check for user " + username + " successfull");
+ log.info("LDAP Password check for user " + username + " successfull");
else
- log.info("LDAP Password check for user " + username + " failed");
+ log.info("LDAP Password check for user " + username + " failed");
}
}
}
- catch( LDAPException e ) {
+ catch (LDAPException e) {
if (log.isInfoEnabled())
log.info("LDAP Password check for user " + username + " failed with exception " + e.getMessage());
- if ( e.getResultCode() == LDAPException.NO_SUCH_OBJECT ) {
+ if (e.getResultCode() == LDAPException.NO_SUCH_OBJECT) {
notinLDAP = true;
- } else if ( e.getResultCode() ==
- LDAPException.NO_SUCH_ATTRIBUTE ) {
+ } else if (e.getResultCode() ==
+ LDAPException.NO_SUCH_ATTRIBUTE) {
notinLDAP = true;
}
}
catch (Throwable e) {
notinLDAP = true;
if (log.isErrorEnabled())
- log.error("LDAP Password check for user " + username + " failed with exception " + e.getMessage());
+ log.error("LDAP Password check for user " + username + " failed with exception " + e.getMessage());
}
- finally
- {
+ finally {
if (log.isDebugEnabled())
- log.debug("LDAP check in finally block");
+ log.debug("LDAP check in finally block");
try {
lc.disconnect();
@@ -394,10 +373,9 @@
}
}
- if (notinLDAP)
- {
+ if (notinLDAP) {
if (log.isDebugEnabled())
- log.debug("LDAP Password check reverting to XWiki");
+ log.debug("LDAP Password check reverting to XWiki");
// Use XWiki password if user not in LDAP
result = checkPassword(username, password, context);
@@ -410,22 +388,22 @@
private String getParam(String name, XWikiContext context) {
String param = "";
try {
- param = context.getWiki().getXWikiPreference(name,context);
- } catch (Exception e) {}
- if (param == null || "".equals(param))
- {
- try{
- param = context.getWiki().Param("xwiki.authentication." + StringUtils.replace(name, "ldap_","ldap."));
- } catch (Exception e) {}
+ param = context.getWiki().getXWikiPreference(name, context);
+ } catch (Exception e) {
}
+ if (param == null || "".equals(param)) {
+ try {
+ param = context.getWiki().Param("xwiki.authentication." + StringUtils.replace(name, "ldap_", "ldap."));
+ } catch (Exception e) {
+ }
+ }
if (param == null)
param = "";
return param;
}
- protected int GetCheckLevel(XWikiContext context)
- {
- String checkLevel = getParam("ldap_check_level", context);
+ protected int GetCheckLevel(XWikiContext context) {
+ String checkLevel = getParam("ldap_check_level", context);
int val = 2;
if ("1".equals(checkLevel))
val = 1;
@@ -436,9 +414,9 @@
private int getLDAPPort(XWikiContext context) {
try {
- return context.getWiki().getXWikiPreferenceAsInt("ldap_port", context);
+ return context.getWiki().getXWikiPreferenceAsInt("ldap_port", context);
} catch (Exception e) {
- return (int)context.getWiki().ParamAsLong("xwiki.authentication.ldap.port", LDAPConnection.DEFAULT_PORT);
+ return (int) context.getWiki().ParamAsLong("xwiki.authentication.ldap.port", LDAPConnection.DEFAULT_PORT);
}
}
@@ -451,43 +429,41 @@
int ldapPort = getLDAPPort(context);
int ldapVersion = LDAPConnection.LDAP_V3;
String ldapHost = getParam("ldap_server", context);
- String bindDN = getParam("ldap_bind_DN",context);
- String bindPassword = getParam("ldap_bind_pass",context);
- String baseDN = getParam("ldap_base_DN",context);
+ String bindDN = getParam("ldap_bind_DN", context);
+ String bindPassword = getParam("ldap_bind_pass", context);
+ String baseDN = getParam("ldap_base_DN", context);
- lc.connect( ldapHost, ldapPort );
+ lc.connect(ldapHost, ldapPort);
// authenticate to the server
result = Bind(DN, password, lc, ldapVersion);
if (log.isDebugEnabled()) {
if (result)
- log.debug("(debug) Password check for user " + DN + " successfull");
+ log.debug("(debug) Password check for user " + DN + " successfull");
else
- log.debug("(debug) Password check for user " + DN + " failed");
+ log.debug("(debug) Password check for user " + DN + " failed");
}
}
- catch( LDAPException e ) {
- if ( e.getResultCode() == LDAPException.NO_SUCH_OBJECT ) {
+ catch (LDAPException e) {
+ if (e.getResultCode() == LDAPException.NO_SUCH_OBJECT) {
notinLDAP = true;
- } else if ( e.getResultCode() ==
- LDAPException.NO_SUCH_ATTRIBUTE ) {
+ } else if (e.getResultCode() ==
+ LDAPException.NO_SUCH_ATTRIBUTE) {
notinLDAP = true;
}
}
catch (Throwable e) {
e.printStackTrace();
}
- finally
- {
+ finally {
try {
lc.disconnect();
} catch (LDAPException e) {
e.printStackTrace();
}
}
- if (notinLDAP)
- {
+ if (notinLDAP) {
// Use XWiki password if user not in LDAP
result = checkPassword(username, password, context);
}
@@ -498,25 +474,24 @@
private boolean Bind(String bindDN, String bindPassword, LDAPConnection lc, int ldapVersion) throws UnsupportedEncodingException {
boolean bound = false;
if (log.isDebugEnabled())
- log.debug("LDAP Bind starting");
+ log.debug("LDAP Bind starting");
- if (bindDN != null && bindDN.length() > 0 && bindPassword != null)
- {
- try
- {
- lc.bind( ldapVersion, bindDN, bindPassword.getBytes("UTF8") );
+ if (bindDN != null && bindDN.length() > 0 && bindPassword != null) {
+ try {
+ lc.bind(ldapVersion, bindDN, bindPassword.getBytes("UTF8"));
bound = true;
if (log.isDebugEnabled())
- log.debug("LDAP Bind successfull");
+ log.debug("LDAP Bind successfull");
}
- catch(LDAPException e) {
+ catch (LDAPException e) {
if (log.isErrorEnabled())
- log.error("LDAP Bind failed with Exception " + e.getMessage());
- };
+ log.error("LDAP Bind failed with Exception " + e.getMessage());
+ }
+ ;
} else {
if (log.isDebugEnabled())
- log.debug("LDAP Bind does not have binding info");
+ log.debug("LDAP Bind does not have binding info");
}
return bound;
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoAuthServiceImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoAuthServiceImpl.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoAuthServiceImpl.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -1,63 +1,69 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author ludovic
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author ludovic
+ * @author sdumitriu
+ */
package com.xpn.xwiki.user.impl.exo;
-import java.security.Principal;
-
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.services.exception.ExoServiceException;
-import org.exoplatform.services.security.SecurityService;
-import org.securityfilter.realm.SimplePrincipal;
-
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.user.api.XWikiUser;
import com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.UserHandler;
+import org.exoplatform.services.security.SecurityService;
+import org.securityfilter.realm.SimplePrincipal;
+import java.security.Principal;
+import java.util.HashMap;
+
public class ExoAuthServiceImpl extends XWikiAuthServiceImpl {
- private SecurityService securityService;
+ private SecurityService securityService_;
+ private static final Log log = LogFactory.getLog(ExoAuthServiceImpl.class);
protected SecurityService getSecurityService() {
- if (securityService==null) {
- PortalContainer manager = PortalContainer.getInstance();
- securityService = (SecurityService) manager.getComponentInstanceOfType(SecurityService.class);
- }
- return securityService;
- }
+ if (securityService_ == null) {
+ PortalContainer manager = PortalContainer.getInstance();
+ securityService_ = (SecurityService) manager.getComponentInstanceOfType(SecurityService.class);
+ }
+ return securityService_;
+ }
public XWikiUser checkAuth(XWikiContext context) throws XWikiException {
- if (context.getMode()==XWikiContext.MODE_PORTLET) {
+ if (context.getMode() == XWikiContext.MODE_PORTLET) {
String user = context.getRequest().getRemoteUser();
- if ((user==null)||user.equals(""))
- user = "XWiki.XWikiGuest";
+ if ((user == null) || user.equals(""))
+ user = "XWiki.XWikiGuest";
else
- user = "XWiki." + user;
+ user = "XWiki." + user;
context.setUser(user);
return new XWikiUser(user);
} else {
XWikiUser user = super.checkAuth(context);
- if (user==null)
+ if (user == null)
return new XWikiUser("XWiki.XWikiGuest");
else
return new XWikiUser("XWiki." + user.getUser());
@@ -66,21 +72,106 @@
public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException {
String superadmin = "superadmin";
+ SecurityService securityService = getSecurityService();
+
if (username.equals(superadmin)) {
String superadminpassword = context.getWiki().Param("xwiki.superadminpassword");
- if ((superadminpassword!=null)&&(superadminpassword.equals(password))) {
- return new SimplePrincipal("XWiki.superadmin");
+ if ((superadminpassword != null) && (superadminpassword.equals(password))) {
+ return new SimplePrincipal("superadmin");
} else {
return null;
}
}
try {
- if (getSecurityService().authenticate(username, password))
+ if (securityService.authenticate(username, password))
return new SimplePrincipal(username);
- } catch (ExoServiceException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
+
+ /*
+ if(context != null){
+ String susername = username;
+ int i = username.indexOf(".");
+ if (i!=-1) susername = username.substring(i+1);
+ String exo = getExo_DN(susername,context) ;
+
+ }
+ */
return null;
}
+
+ public String getExo_DN(String susername, XWikiContext context) {
+ String EX = null;
+ if (context != null) {
+ // First we check in the local database
+ try {
+ String user = findUser(susername, context);
+ if (user != null && user.length() != 0) {
+ EX = readExo_DN(user, context);
+ }
+ } catch (Exception e) {
+ }
+
+ if (context.isVirtual()) {
+ if (EX == null || EX.length() == 0) {
+ // Then we check in the main database
+ String db = context.getDatabase();
+ try {
+ context.setDatabase(context.getWiki().getDatabase());
+ try {
+ String user = findUser(susername, context);
+ if (user != null && user.length() != 0)
+ EX = readExo_DN(user, context);
+ } catch (Exception e) {
+ }
+ } finally {
+ context.setDatabase(db);
+ }
+ }
+ }
+ }
+ return EX;
+ }
+
+ private String readExo_DN(String username, XWikiContext context) {
+ String EX = null;
+ try {
+ XWikiDocument doc = context.getWiki().getDocument(username, context);
+ // We only allow empty password from users having a XWikiUsers object.
+ if (doc.getObject("XWiki.XWikiUsers") != null) {
+ EX = doc.getStringValue("XWiki.XWikiUsers", "exo_ex");
+ }
+
+ } catch (Throwable e) {
+ }
+ return EX;
+ }
+
+ private void CreateUserFromExo(String susername, HashMap attributes, XWikiContext context) throws XWikiException {
+ UserHandler userHandler = ExoGroupServiceImpl.getOrganizationService().getUserHandler();
+ User user = userHandler.createUserInstance();
+
+
+ }
+
+ private String getParam(String name, XWikiContext context) {
+ String param = "";
+ try {
+ param = context.getWiki().getXWikiPreference(name, context);
+ } catch (Exception e) {
+ }
+ if (param == null || "".equals(param)) {
+ try {
+ param = context.getWiki().Param("xwiki.authentication." + StringUtils.replace(name, "exo_", "exo."));
+ } catch (Exception e) {
+ }
+ }
+ if (param == null)
+ param = "";
+ return param;
+ }
+
+
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoFilter.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoFilter.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoFilter.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -1,45 +1,46 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author sdumitriu
+ */
package com.xpn.xwiki.user.impl.exo;
-import java.io.IOException;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.RootContainer;
+import javax.servlet.*;
+import java.io.IOException;
+
public class ExoFilter implements Filter {
public static final String EXO_CONTAINER = "portal";
+ public static FilterConfig filterCongif_ = null;
public void init(FilterConfig filterConfig) throws ServletException {
+ if (filterConfig != null) {
+ filterCongif_ = filterConfig;
+ } else {
+ PortalContainer manager = RootContainer.getInstance().getPortalContainer(EXO_CONTAINER);
+ filterCongif_ = (FilterConfig) manager.getComponentInstanceOfType(FilterConfig.class);
+ }
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoGroupServiceImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoGroupServiceImpl.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/exo/ExoGroupServiceImpl.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -22,72 +22,173 @@
package com.xpn.xwiki.user.impl.exo;
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.cache.api.XWikiCache;
+import com.xpn.xwiki.cache.api.XWikiCacheService;
+import com.xpn.xwiki.user.api.XWikiGroupService;
+import org.exoplatform.commons.utils.PageList;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.organization.*;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.services.organization.Group;
-import org.exoplatform.services.organization.OrganizationService;
+public class ExoGroupServiceImpl implements XWikiGroupService {
+ private static OrganizationService organizationService;
+ private XWikiCache groupCache;
-import com.xpn.xwiki.XWiki;
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.user.api.XWikiGroupService;
+ protected GroupHandler getGroupHandler() {
+ if (organizationService == null) {
+ organizationService = getOrganizationService();
+ }
+ return organizationService.getGroupHandler();
+ }
-public class ExoGroupServiceImpl implements XWikiGroupService {
- private OrganizationService organizationService;
+ public static OrganizationService getOrganizationService() {
+ if (organizationService == null) {
+ PortalContainer manager = PortalContainer.getInstance();
+ organizationService = (OrganizationService) manager.getComponentInstanceOfType(OrganizationService.class);
+ }
+ return organizationService;
+ }
- protected OrganizationService getOrganizationService() {
- if (organizationService==null) {
- PortalContainer manager = PortalContainer.getInstance();
- organizationService = (OrganizationService) manager.getComponentInstanceOfType(OrganizationService.class);
- }
- return organizationService;
- }
+ protected UserHandler getUserHandler() {
+ if (organizationService == null) {
+ organizationService = getOrganizationService();
+ }
+ return organizationService.getUserHandler();
+ }
+ protected MembershipHandler getMembershipHandler() {
+ if (organizationService == null) {
+ organizationService = getOrganizationService();
+ }
+ return organizationService.getMembershipHandler();
+ }
+
+ protected MembershipTypeHandler getMembershipTypeHandler() {
+ if (organizationService == null) {
+ organizationService = getOrganizationService();
+ }
+ return organizationService.getMembershipTypeHandler();
+ }
+
public void init(XWiki xwiki) {
+ XWikiCacheService cacheService = xwiki.getCacheService();
+ groupCache = cacheService.newCache();
}
public void flushCache() {
+ groupCache.flushAll();
}
public Collection listGroupsForUser(String username, XWikiContext context) throws XWikiException {
+ GroupHandler groupHandler = getGroupHandler();
+ Collection groups = null;
try {
- if (username.startsWith("XWiki."))
+ if (username.startsWith("XWiki.")) {
username = username.substring(6);
- Collection groups = getOrganizationService().findGroupsOfUser(username);
- ArrayList list = new ArrayList();
- if (groups==null)
- return list;
- Iterator it = groups.iterator();
- while (it.hasNext()) {
- Group group = (Group)it.next();
- list.add(group.getGroupName());
- }
- return list;
+ groups = groupHandler.findGroupsOfUser(username);
+ }
+
+ ArrayList list = new ArrayList();
+ if (groups == null)
+ return list;
+ Iterator it = groups.iterator();
+ while (it.hasNext()) {
+ Group group = (Group) it.next();
+ list.add(group.getGroupName());
+ }
+ return list;
} catch (Exception e) {
- e.printStackTrace();
+ Object[] args = {username};
+ throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_EXO_EXCEPTION_LISTING_USERS,
+ "Exception while listing groups for user {0}", e, args);
+
}
- return null;
}
- public void addUserToGroup(String user, String database, String group) {
+ public void addUserToGroup(String user, String database, String group) throws XWikiException {
+ // TODO: test this code
+
+ MembershipHandler membershipHandler = getMembershipHandler();
+ MembershipTypeHandler memberShipTypeHandler = getMembershipTypeHandler();
+ boolean broadcast = false;
+ Collection list = null;
+ // check user and group exist membership
+ try {
+ list = membershipHandler.findMembershipsByUserAndGroup(user, group);
+ // size = 0 -----> user and group does not exist membership
+ if (list.size() == 0) {
+ broadcast = true;
+ }
+
+ // link membership
+ MembershipType mst = memberShipTypeHandler.findMembershipType(group);
+ if (mst == null) {
+ mst = memberShipTypeHandler.createMembershipTypeInstance();
+ }
+ User username = getUserHandler().findUserByName(user);
+ Group groupname = getGroupHandler().findGroupById(group);
+ membershipHandler.linkMembership(username, groupname, mst, broadcast);
+ } catch (Exception e) {
+ Object[] args = {user, group};
+ throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_EXO_EXCEPTION_ADDING_USERS,
+ "Exception while adding user {0} to group {1}", e, args);
+ }
}
- public List listMemberForGroup(String s, XWikiContext context) throws XWikiException {
- // Implement for eXo
- return new ArrayList();
+ public List listMemberForGroup(String group, XWikiContext context) throws XWikiException {
+ UserHandler userHandler = getUserHandler();
+
+ List usersList = new ArrayList();
+ List exoList = null;
+
+ try {
+ if (group == null) {
+ PageList plist = null;
+ plist = userHandler.getUserPageList(100);
+ exoList = plist.getAll();
+ } else
+ exoList = userHandler.findUsersByGroup(group).getAll();
+
+ if (exoList != null) {
+ for (int i = 0; i < exoList.size(); i++) {
+ User user = (User) exoList.get(i);
+ usersList.add(user.getUserName());
+ }
+ }
+ return usersList;
+ } catch (Exception e) {
+ Object[] args = {group};
+ throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_EXO_EXCEPTION_USERS,
+ "Exception while listing users for group {0}", e, args);
+ }
}
public List listAllGroups(XWikiContext context) throws XWikiException {
- // Implement for eXo
- return new ArrayList();
+ GroupHandler handlerGroup = getGroupHandler();
+ List allGroups = new ArrayList();
+ List exoGroups = null;
+ try {
+ exoGroups = (List) handlerGroup.getAllGroups();
+
+ if (exoGroups != null) {
+ for (int i = 0; i < exoGroups.size(); i++) {
+ Group group = (Group) exoGroups.get(i);
+ allGroups.add(group.getId());
+ }
+ }
+ return allGroups;
+ } catch (Exception e) {
+ Object[] args = {};
+ throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_EXO_EXCEPTION_USERS,
+ "Exception while listing groups", e, args);
+ }
}
- public List listAllLevels(XWikiContext context) throws XWikiException {
- // Implement for eXo
- return new ArrayList();
- }
}
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiAuthServiceImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiAuthServiceImpl.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiAuthServiceImpl.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -1,41 +1,27 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author sdumitriu
+ */
package com.xpn.xwiki.user.impl.xwiki;
-import java.io.IOException;
-import java.security.Principal;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.securityfilter.config.SecurityConfig;
-import org.securityfilter.filter.SecurityRequestWrapper;
-import org.securityfilter.realm.SimplePrincipal;
-
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
@@ -43,14 +29,26 @@
import com.xpn.xwiki.user.api.XWikiAuthService;
import com.xpn.xwiki.user.api.XWikiUser;
import com.xpn.xwiki.web.Utils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.securityfilter.config.SecurityConfig;
+import org.securityfilter.filter.SecurityRequestWrapper;
+import org.securityfilter.realm.SimplePrincipal;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.security.Principal;
+import java.util.List;
+
public class XWikiAuthServiceImpl implements XWikiAuthService {
private static final Log log = LogFactory.getLog(XWikiAuthServiceImpl.class);
protected XWikiAuthenticator authenticator;
protected XWikiAuthenticator getAuthenticator(XWikiContext context) throws XWikiException {
- if (authenticator!=null)
+ if (authenticator != null)
return authenticator;
try {
@@ -60,64 +58,64 @@
authenticator = new MyBasicAuthenticator();
SecurityConfig sconfig = new SecurityConfig(false);
sconfig.setAuthMethod("BASIC");
- if (xwiki.Param("xwiki.authentication.realname")!=null)
+ if (xwiki.Param("xwiki.authentication.realname") != null)
sconfig.setRealmName(xwiki.Param("xwiki.authentication.realname"));
else
sconfig.setRealmName("XWiki");
authenticator.init(null, sconfig);
} else {
- authenticator = new MyFormAuthenticator();
+ authenticator = new MyFormAuthenticator();
SecurityConfig sconfig = new SecurityConfig(false);
sconfig.setAuthMethod("FORM");
- if (xwiki.Param("xwiki.authentication.realname")!=null)
+ if (xwiki.Param("xwiki.authentication.realname") != null)
sconfig.setRealmName(xwiki.Param("xwiki.authentication.realname"));
else
sconfig.setRealmName("XWiki");
- if (xwiki.Param("xwiki.authentication.defaultpage")!=null)
+ if (xwiki.Param("xwiki.authentication.defaultpage") != null)
sconfig.setDefaultPage(xwiki.Param("xwiki.authentication.defaultpage"));
else
sconfig.setDefaultPage("/bin/view/Main/WebHome");
- if (xwiki.Param("xwiki.authentication.loginpage")!=null)
+ if (xwiki.Param("xwiki.authentication.loginpage") != null)
sconfig.setLoginPage(xwiki.Param("xwiki.authentication.loginpage"));
else
sconfig.setLoginPage("/bin/login/XWiki/XWikiLogin");
- if (xwiki.Param("xwiki.authentication.logoutpage")!=null)
+ if (xwiki.Param("xwiki.authentication.logoutpage") != null)
sconfig.setLogoutPage(xwiki.Param("xwiki.authentication.logoutpage"));
else
sconfig.setLogoutPage("/bin/logout/XWiki/XWikiLogout");
- if (xwiki.Param("xwiki.authentication.errorpage")!=null)
+ if (xwiki.Param("xwiki.authentication.errorpage") != null)
sconfig.setErrorPage(xwiki.Param("xwiki.authentication.errorpage"));
else
sconfig.setErrorPage("/bin/loginerror/XWiki/XWikiLogin");
MyPersistentLoginManager persistent = new MyPersistentLoginManager();
- if (xwiki.Param("xwiki.authentication.cookiepath")!=null)
+ if (xwiki.Param("xwiki.authentication.cookiepath") != null)
persistent.setCookiePath(xwiki.Param("xwiki.authentication.cookiepath"));
- if (xwiki.Param("xwiki.authentication.cookiedomains")!=null) {
- String[] cdomains = StringUtils.split(xwiki.Param("xwiki.authentication.cookiedomains"),",");
+ if (xwiki.Param("xwiki.authentication.cookiedomains") != null) {
+ String[] cdomains = StringUtils.split(xwiki.Param("xwiki.authentication.cookiedomains"), ",");
persistent.setCookieDomains(cdomains);
}
- if (xwiki.Param("xwiki.authentication.cookielife")!=null)
+ if (xwiki.Param("xwiki.authentication.cookielife") != null)
persistent.setCookieLife(xwiki.Param("xwiki.authentication.cookielife"));
- if (xwiki.Param("xwiki.authentication.protection")!=null)
+ if (xwiki.Param("xwiki.authentication.protection") != null)
persistent.setProtection(xwiki.Param("xwiki.authentication.protection"));
- if (xwiki.Param("xwiki.authentication.useip")!=null)
+ if (xwiki.Param("xwiki.authentication.useip") != null)
persistent.setUseIP(xwiki.Param("xwiki.authentication.useip"));
- if (xwiki.Param("xwiki.authentication.encryptionalgorithm")!=null)
+ if (xwiki.Param("xwiki.authentication.encryptionalgorithm") != null)
persistent.setEncryptionAlgorithm(xwiki.Param("xwiki.authentication.encryptionalgorithm"));
- if (xwiki.Param("xwiki.authentication.encryptionmode")!=null)
+ if (xwiki.Param("xwiki.authentication.encryptionmode") != null)
persistent.setEncryptionMode(xwiki.Param("xwiki.authentication.encryptionmode"));
- if (xwiki.Param("xwiki.authentication.encryptionpadding")!=null)
+ if (xwiki.Param("xwiki.authentication.encryptionpadding") != null)
persistent.setEncryptionPadding(xwiki.Param("xwiki.authentication.encryptionpadding"));
- if (xwiki.Param("xwiki.authentication.validationKey")!=null)
+ if (xwiki.Param("xwiki.authentication.validationKey") != null)
persistent.setValidationKey(xwiki.Param("xwiki.authentication.validationKey"));
- if (xwiki.Param("xwiki.authentication.encryptionKey")!=null)
+ if (xwiki.Param("xwiki.authentication.encryptionKey") != null)
persistent.setEncryptionKey(xwiki.Param("xwiki.authentication.encryptionKey"));
sconfig.setPersistentLoginManager(persistent);
MyFilterConfig fconfig = new MyFilterConfig();
- if (xwiki.Param("xwiki.authentication.loginsubmitpage")!=null)
+ if (xwiki.Param("xwiki.authentication.loginsubmitpage") != null)
fconfig.setInitParameter("loginSubmitPattern", xwiki.Param("xwiki.authentication.loginsubmitpage"));
else
fconfig.setInitParameter("loginSubmitPattern", "/login/XWiki/XWikiLogin");
@@ -128,7 +126,7 @@
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_USER,
XWikiException.ERROR_XWIKI_USER_INIT,
- "Cannot initialize authentication system",e);
+ "Cannot initialize authentication system", e);
}
}
@@ -137,13 +135,13 @@
HttpServletRequest request = null;
HttpServletResponse response = null;
- if (context.getRequest()!=null)
- request = context.getRequest().getHttpServletRequest();
+ if (context.getRequest() != null)
+ request = context.getRequest().getHttpServletRequest();
- if (context.getResponse()!=null)
- response = context.getResponse().getHttpServletResponse();
+ if (context.getResponse() != null)
+ response = context.getResponse().getHttpServletResponse();
- if (request==null)
+ if (request == null)
return null;
XWikiAuthenticator auth = getAuthenticator(context);
@@ -162,16 +160,16 @@
return null;
}
- Principal user = wrappedRequest.getUserPrincipal();
- if (log.isInfoEnabled()) {
- if (user!=null)
- log.info("User " + user.getName() + " is authentified");
- }
+ Principal user = wrappedRequest.getUserPrincipal();
+ if (log.isInfoEnabled()) {
+ if (user != null)
+ log.info("User " + user.getName() + " is authentified");
+ }
- if (user==null)
- return null;
- else
- return new XWikiUser(user.getName());
+ if (user == null)
+ return null;
+ else
+ return new XWikiUser(user.getName());
} catch (Exception e) {
e.printStackTrace();
return null;
@@ -180,9 +178,9 @@
public void showLogin(XWikiContext context) throws XWikiException {
try {
- if (context.getMode()==XWikiContext.MODE_SERVLET) {
- getAuthenticator(context).showLogin(context.getRequest().getHttpServletRequest(),
- context.getResponse().getHttpServletResponse(), context);
+ if (context.getMode() == XWikiContext.MODE_SERVLET) {
+ getAuthenticator(context).showLogin(context.getRequest().getHttpServletRequest(),
+ context.getResponse().getHttpServletResponse(), context);
}
} catch (IOException e) {
// If this fails we continue
@@ -193,17 +191,17 @@
public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException {
Principal principal = null;
- if ((username==null)||(username.trim().equals("")))
+ if ((username == null) || (username.trim().equals("")))
return null;
- if ((password==null)||(password.trim().equals("")))
+ if ((password == null) || (password.trim().equals("")))
return null;
String superadmin = "superadmin";
if (username.equals(superadmin)) {
String superadminpassword = context.getWiki().Param("xwiki.superadminpassword");
- if ((superadminpassword!=null)&&(superadminpassword.equals(password))) {
- principal = new SimplePrincipal("XWiki.superadmin");
+ if ((superadminpassword != null) && (superadminpassword.equals(password))) {
+ principal = new SimplePrincipal("superadmin");
return principal;
} else {
return null;
@@ -213,34 +211,36 @@
// If we have the context then we are using direct mode
// then we should specify the database
// This is needed for virtual mode to work
- if (context!=null) {
+ if (context != null) {
String susername = username;
int i = username.indexOf(".");
- if (i!=-1)
- susername = username.substring(i+1);
+ if (i != -1)
+ susername = username.substring(i + 1);
// First we check in the local database
try {
String user = findUser(susername, context);
- if (user!=null) {
+ if (user != null) {
if (checkPassword(user, password, context))
principal = new SimplePrincipal(user);
}
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
if (context.isVirtual()) {
- if (principal==null) {
+ if (principal == null) {
// Then we check in the main database
String db = context.getDatabase();
try {
context.setDatabase(context.getWiki().getDatabase());
try {
String user = findUser(susername, context);
- if (user==null)
+ if (user == null)
return null;
if (checkPassword(user, password, context))
principal = new SimplePrincipal(context.getDatabase() + ":" + user);
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
} finally {
context.setDatabase(db);
}
@@ -252,15 +252,15 @@
protected String findUser(String susername, XWikiContext context) throws XWikiException {
// First lets look in the cache
- if (context.getWiki().exists("XWiki." + susername, context))
+ if (context.getWiki().exists("XWiki." + susername, context))
return "XWiki." + susername;
String sql = "select distinct doc.web, doc.name from XWikiDocument as doc where doc.web='XWiki' and doc.name like '" + Utils.SQLFilter(susername) + "'";
List list = context.getWiki().search(sql, context);
- if (list.size()==0)
+ if (list.size() == 0)
return null;
- if (list.size()>1) {
- for (int i=0;i<list.size();i++) {
+ if (list.size() > 1) {
+ for (int i = 0; i < list.size(); i++) {
Object[] result = (Object[]) list.get(0);
if (result[1].equals(susername))
return result[0] + "." + result[1];
@@ -275,16 +275,16 @@
boolean result = false;
XWikiDocument doc = context.getWiki().getDocument(username, context);
// We only allow empty password from users having a XWikiUsers object.
- if (doc.getObject("XWiki.XWikiUsers")!=null) {
- String passwd = doc.getStringValue("XWiki.XWikiUsers", "password");
- result = (password.equals(passwd));
+ if (doc.getObject("XWiki.XWikiUsers") != null) {
+ String passwd = doc.getStringValue("XWiki.XWikiUsers", "password");
+ result = (password.equals(passwd));
}
if (log.isDebugEnabled()) {
if (result)
- log.debug("(debug) Password check for user " + username + " successfull");
+ log.debug("(debug) Password check for user " + username + " successfull");
else
- log.debug("(debug) Password check for user " + username + " failed");
+ log.debug("(debug) Password check for user " + username + " failed");
}
return result;
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiGroupServiceImpl.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -23,15 +23,9 @@
package com.xpn.xwiki.user.impl.xwiki;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Vector;
-
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.cache.api.XWikiCache;
import com.xpn.xwiki.cache.api.XWikiCacheNeedsRefreshException;
import com.xpn.xwiki.cache.api.XWikiCacheService;
@@ -40,10 +34,16 @@
import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
import com.xpn.xwiki.notify.XWikiNotificationInterface;
import com.xpn.xwiki.notify.XWikiNotificationRule;
+import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.user.api.XWikiGroupService;
import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.web.Utils;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+
public class XWikiGroupServiceImpl implements XWikiGroupService, XWikiDocChangeNotificationInterface {
private XWikiCache groupCache;
@@ -62,7 +62,7 @@
String database = context.getDatabase();
try {
String shortname = Util.getName(username);
- String veryshortname = shortname.substring(shortname.indexOf(".")+1);
+ String veryshortname = shortname.substring(shortname.indexOf(".") + 1);
String key = database + ":" + shortname;
try {
list = (List) groupCache.getFromCache(key);
@@ -104,21 +104,20 @@
String sql = "";
try {
- String gshortname = Util.getName(group, context);
- if (gshortname.equals("XWiki.XWikiAllGroup")) {
+ if (group == null) {
sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='XWiki.XWikiUsers'";
return context.getWiki().getStore().searchDocumentsNames(sql, context);
- }
- else {
+ } else {
+ String gshortname = Util.getName(group, context);
XWikiDocument docgroup = context.getWiki().getDocument(gshortname, context);
Vector v = docgroup.getObjects("XWiki.XWikiGroups");
- for (int i=0;i<v.size();i++) {
+ for (int i = 0; i < v.size(); i++) {
BaseObject bobj = (BaseObject) v.get(i);
- if (bobj!=null) {
+ if (bobj != null) {
String members = bobj.getStringValue("member");
- if (members!=null) {
+ if (members != null) {
String[] members2 = members.split(" ,");
- for (int j=0;j<members2.length;j++) {
+ for (int j = 0; j < members2.length; j++) {
list.add(members2[i]);
}
}
@@ -131,17 +130,16 @@
}
}
- public List listAllGroups(XWikiContext context) throws XWikiException
- {
+ public List listAllGroups(XWikiContext context) throws XWikiException {
String sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='XWiki.XWikiGroups'";
return context.getWiki().getStore().searchDocumentsNames(sql, context);
}
public List listAllLevels(XWikiContext context) throws XWikiException {
List list = new ArrayList();
- String levels ="admin,view,edit,comment,delete,register,programming";
- String[] level = levels.split(",");
- for (int i=0; i<level.length; i++) {
+ String levels = "admin,view,edit,comment,delete,register,programming";
+ String[] level = levels.split(",");
+ for (int i = 0; i < level.length; i++) {
list.add(level[i]);
}
return list;
@@ -149,17 +147,17 @@
public void notify(XWikiNotificationRule rule, XWikiDocument newdoc, XWikiDocument olddoc, int event, XWikiContext context) {
try {
- if (event==XWikiNotificationInterface.EVENT_CHANGE) {
+ if (event == XWikiNotificationInterface.EVENT_CHANGE) {
boolean flushCache = false;
- if ((olddoc!=null)&&(olddoc.getObjects("XWiki.XWikiGroups")!=null))
- flushCache = true;
+ if ((olddoc != null) && (olddoc.getObjects("XWiki.XWikiGroups") != null))
+ flushCache = true;
- if ((newdoc!=null)&&(newdoc.getObjects("XWiki.XWikiGroups")!=null))
- flushCache = true;
+ if ((newdoc != null) && (newdoc.getObjects("XWiki.XWikiGroups") != null))
+ flushCache = true;
if (flushCache)
- groupCache.flushAll();
+ groupCache.flushAll();
}
} catch (Exception e) {
e.printStackTrace();
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java 2006-03-07 01:51:59 UTC (rev 964)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java 2006-03-08 04:01:09 UTC (rev 965)
@@ -26,18 +26,6 @@
package com.xpn.xwiki.user.impl.xwiki;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Vector;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiDocument;
@@ -47,7 +35,13 @@
import com.xpn.xwiki.user.api.XWikiRightService;
import com.xpn.xwiki.user.api.XWikiUser;
import com.xpn.xwiki.util.Util;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import java.util.*;
+
public class XWikiRightServiceImpl implements XWikiRightService {
private static final Log log = LogFactory.getLog(XWikiRightServiceImpl.class);
private static Map actionMap;
@@ -67,6 +61,16 @@
log.debug("Access has been denied for (" + name + "," + resourceKey + "," + accessLevel + ") at " + info, e);
}
+ public List listAllLevels(XWikiContext context) throws XWikiException {
+ List list = new ArrayList();
+ String levels = "admin,view,edit,comment,delete,register,programming";
+ String[] level = levels.split(",");
+ for (int i = 0; i < level.length; i++) {
+ list.add(level[i]);
+ }
+ return list;
+ }
+
public String getRight(String action) {
if (actionMap == null) {
actionMap = new HashMap();
@@ -89,11 +93,10 @@
actionMap.put("register", "register");
}
- String right = (String)actionMap.get(action);
- if (right==null) {
+ String right = (String) actionMap.get(action);
+ if (right == null) {
return "edit";
- }
- else
+ } else
return right;
}
@@ -105,7 +108,7 @@
if (right.equals("login")) {
user = context.getWiki().checkAuth(context);
- if (user==null)
+ if (user == null)
username = "XWiki.XWikiGuest";
else
username = user.getUser();
@@ -120,7 +123,7 @@
if (right.equals("delete")) {
user = context.getWiki().checkAuth(context);
String creator = doc.getCreator();
- if ((user!=null)&&(user.getUser()!=null)&&(creator!=null)) {
+ if ((user != null) && (user.getUser() != null) && (creator != null)) {
if (user.getUser().equals(creator)) {
context.getWiki().prepareResources(context);
return true;
@@ -132,33 +135,33 @@
// We do not need to authenticate twice
// This seems to cause a problem in virtual wikis
user = context.getXWikiUser();
- if (user==null) {
- needsAuth = needsAuth(right, context);
- try {
- if (context.getMode()!=XWikiContext.MODE_XMLRPC)
- user = context.getWiki().checkAuth(context);
- else
- user = new XWikiUser(context.getUser());
+ if (user == null) {
+ needsAuth = needsAuth(right, context);
+ try {
+ if (context.getMode() != XWikiContext.MODE_XMLRPC)
+ user = context.getWiki().checkAuth(context);
+ else
+ user = new XWikiUser(context.getUser());
- if ((user==null)&&(needsAuth)) {
- context.getWiki().prepareResources(context);
- if (context.getRequest()!=null)
- context.getWiki().getAuthService().showLogin(context);
- logDeny("unauthentified", doc.getFullName(), action, "Authentication needed");
- return false;
+ if ((user == null) && (needsAuth)) {
+ context.getWiki().prepareResources(context);
+ if (context.getRequest() != null)
+ context.getWiki().getAuthService().showLogin(context);
+ logDeny("unauthentified", doc.getFullName(), action, "Authentication needed");
+ return false;
+ }
+ } catch (XWikiException e) {
+ if (needsAuth)
+ throw e;
}
- } catch (XWikiException e) {
- if (needsAuth)
- throw e;
- }
- if (user==null)
- username = "XWiki.XWikiGuest";
- else
- username = user.getUser();
+ if (user == null)
+ username = "XWiki.XWikiGuest";
+ else
+ username = user.getUser();
- // Save the user
- context.setUser(username);
+ // Save the user
+ context.setUser(username);
} else {
username = user.getUser();
}
@@ -168,12 +171,11 @@
try {
// Verify access rights and return if ok
String docname;
- if (context.getDatabase()!=null) {
+ if (context.getDatabase() != null) {
docname = context.getDatabase() + ":" + doc.getFullName();
- if (username.indexOf(":")==-1)
+ if (username.indexOf(":") == -1)
username = context.getDatabase() + ":" + username;
- }
- else
+ } else
docname = doc.getFullName();
if (context.getWiki().getRightService().hasAccessLevel(right, username, docname, context)) {
@@ -187,14 +189,13 @@
return false;
}
- if (user==null) {
+ if (user == null) {
// Denied Guest need to be authenticated
logDeny("unauthentified", doc.getFullName(), action, "Guest has been denied - Redirecting to authentication");
- if (context.getRequest()!=null)
+ if (context.getRequest() != null)
context.getWiki().getAuthService().showLogin(context);
return false;
- }
- else {
+ } else {
logDeny(username, doc.getFullName(), action, "access manager denied right");
return false;
}
@@ -204,16 +205,20 @@
boolean needsAuth = false;
try {
needsAuth = context.getWiki().getXWikiPreference("authenticate_" + right, "", context).toLowerCase().equals("yes");
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
try {
- needsAuth |= (context.getWiki().getXWikiPreferenceAsInt("authenticate_" + right, 0, context)==1);
- } catch (Exception e) {}
+ needsAuth |= (context.getWiki().getXWikiPreferenceAsInt("authenticate_" + right, 0, context) == 1);
+ } catch (Exception e) {
+ }
try {
needsAuth |= context.getWiki().getWebPreference("authenticate_" + right, "", context).toLowerCase().equals("yes");
- } catch (Exception e) {}
+ } catch (Exception e) {
+ }
try {
- needsAuth |= (context.getWiki().getWebPreferenceAsInt("authenticate_" + right, 0, context)==1);
- } catch (Exception e) {}
+ needsAuth |= (context.getWiki().getWebPreferenceAsInt("authenticate_" + right, 0, context) == 1);
+ } catch (Exception e) {
+ }
return needsAuth;
}
@@ -231,14 +236,13 @@
String fieldName = user ? "users" : "groups";
boolean found = false;
-
// Get the userdb and the shortname
String userdatabase = null;
String shortname = name;
int i0 = name.indexOf(":");
- if (i0!=-1) {
- userdatabase = name.substring(0,i0);
- shortname = name.substring(i0+1);
+ if (i0 != -1) {
+ userdatabase = name.substring(0, i0);
+ shortname = name.substring(i0 + 1);
}
if (log.isDebugEnabled())
@@ -246,42 +250,47 @@
+ "," + user + "," + allow + "," + global);
Vector vobj = doc.getObjects(className);
- if (vobj!=null)
- {
- for (int i=0;i<vobj.size();i++) {
+ if (vobj != null) {
+ for (int i = 0; i < vobj.size(); i++) {
BaseObject bobj = (BaseObject) vobj.get(i);
- if (bobj==null)
+ if (bobj == null)
continue;
String users = bobj.getStringValue(fieldName);
String levels = bobj.getStringValue("levels");
- boolean allowdeny = (bobj.getIntValue("allow")==1);
+ boolean allowdeny = (bobj.getIntValue("allow") == 1);
if (allowdeny == allow) {
- String[] levelsarray = StringUtils.split(levels," ,|");
+ String[] levelsarray = StringUtils.split(levels, " ,|");
if (ArrayUtils.contains(levelsarray, accessLevel)) {
if (log.isDebugEnabled())
log.debug("Found a right for " + allow);
found = true;
- String[] userarray = StringUtils.split(users," ,|");
+ String[] userarray = StringUtils.split(users, " ,|");
+ for (int ii = 0; i < userarray.length; i++) {
+ String value = userarray[ii];
+ if (value.indexOf("XWiki.") == -1)
+ userarray[ii] = "XWiki." + value;
+ }
+
// In the case where the document database and the user database is the same
// then we allow the usage of the short name, otherwise the fully qualified name is requested
if (context.getDatabase().equals(userdatabase)) {
if (ArrayUtils.contains(userarray, shortname)) {
if (log.isDebugEnabled())
log.debug("Found matching right in " + users + " for " + shortname);
- return true;
+ return true;
}
// We should also allow to skip "XWiki." from the usernames and group lists
- String veryshortname = shortname.substring(shortname.indexOf(".")+1);
+ String veryshortname = shortname.substring(shortname.indexOf(".") + 1);
if (ArrayUtils.contains(userarray, veryshortname)) {
if (log.isDebugEnabled())
log.debug("Found matching right in " + users + " for " + shortname);
- return true;
+ return true;
}
}
- if ((context.getDatabase()!=null)&&
+ if ((context.getDatabase() != null) &&
(ArrayUtils.contains(userarray, name))) {
if (log.isDebugEnabled())
log.debug("Found matching right in " + users + " for " + name);
@@ -296,8 +305,8 @@
log.debug("Searching for matching rights at group level");
// Didn't found right at this level.. Let's go to group level
- Map grouplistcache = (Map)context.get("grouplist");
- if (grouplistcache==null) {
+ Map grouplistcache = (Map) context.get("grouplist");
+ if (grouplistcache == null) {
grouplistcache = new HashMap();
context.put("grouplist", grouplistcache);
}
@@ -307,23 +316,26 @@
String key = context.getDatabase() + ":" + name;
Collection grouplist1 = (Collection) grouplistcache.get(key);
- if (grouplist1==null) {
+ if (grouplist1 == null) {
grouplist1 = new ArrayList();
try {
- Collection glist = groupService.listGroupsForUser(name, context);
- Iterator it = glist.iterator();
- while (it.hasNext()) {
- grouplist1.add(context.getDatabase() + ":" + it.next());
- }
- } catch (Exception e) {}
+ Collection glist = groupService.listGroupsForUser(name, context);
+ Iterator it = glist.iterator();
- if (grouplist1!=null)
+ while (it.hasNext()) {
+ grouplist1.add(context.getDatabase() + ":" + it.next());
+ }
+ } catch (Exception e) {
+
+ }
+
+ if (grouplist1 != null)
grouplistcache.put(key, grouplist1);
else
grouplistcache.put(key, new ArrayList());
}
- if (grouplist1!=null)
+ if (grouplist1 != null)
grouplist.addAll(grouplist1);
if (context.isVirtual()) {
@@ -335,19 +347,19 @@
String key2 = context.getDatabase() + ":" + name;
Collection grouplist2 = (Collection) grouplistcache.get(key2);
- if (grouplist2==null) {
- Collection glist = groupService.listGroupsForUser(shortname, context);
- Iterator it = glist.iterator();
- while (it.hasNext()) {
- grouplist2.add(context.getDatabase() + ":" + it.next());
+ if (grouplist2 == null) {
+ Collection glist = groupService.listGroupsForUser(shortname, context);
+ Iterator it = glist.iterator();
+ while (it.hasNext()) {
+ grouplist2.add(context.getDatabase() + ":" + it.next());
+ }
+ if (grouplist2 != null)
+ grouplistcache.put(key2, grouplist2);
+ else
+ grouplistcache.put(key2, new ArrayList());
}
- if (grouplist2!=null)
- grouplistcache.put(key2, grouplist2);
- else
- grouplistcache.put(key2, new ArrayList());
- }
- if (grouplist2!=null)
+ if (grouplist2 != null)
grouplist.addAll(grouplist2);
}
} catch (Exception e) {
@@ -357,17 +369,17 @@
}
if (log.isDebugEnabled())
- log.debug("Searching for matching rights for " + ((grouplist==null) ? "0" : "" + grouplist.size())
+ log.debug("Searching for matching rights for " + ((grouplist == null) ? "0" : "" + grouplist.size())
+ " groups: " + grouplist);
- if (grouplist!=null) {
+ if (grouplist != null) {
Iterator groupit = grouplist.iterator();
while (groupit.hasNext()) {
String group = (String) groupit.next();
try {
// We need to construct the full group name to make sure the groups are
// handled separately
- boolean result = checkRight(group,doc, accessLevel, false, allow, global, context);
+ boolean result = checkRight(group, doc, accessLevel, false, allow, global, context);
if (result)
return true;
} catch (XWikiRightNotFoundException e) {
@@ -402,22 +414,22 @@
if (isReadOnly) {
if ("edit".equals(accessLevel) ||
- "delete".equals (accessLevel) ||
- "comment".equals(accessLevel ) ||
+ "delete".equals(accessLevel) ||
+ "comment".equals(accessLevel) ||
"register".equals(accessLevel)) {
- logDeny (name,resourceKey,accessLevel,"server in read-only mode");
+ logDeny(name, resourceKey, accessLevel, "server in read-only mode");
return false;
- }
+ }
}
- if (name.equals("XWiki.XWikiGuest")||name.endsWith(":XWiki.XWikiGuest")) {
+ if (name.equals("XWiki.XWikiGuest") || name.endsWith(":XWiki.XWikiGuest")) {
if (needsAuth(accessLevel, context))
return false;
}
- if (name.equals("XWiki.superadmin")||name.endsWith(":XWiki.superadmin")) {
- logAllow(name, resourceKey, accessLevel, "super admin level");
- return true;
+ if (name.equals("XWiki.superadmin") || name.endsWith(":XWiki.superadmin")) {
+ logAllow(name, resourceKey, accessLevel, "super admin level");
+ return true;
}
try {
@@ -426,12 +438,13 @@
xwikimasterdoc = context.getWiki().getDocument("XWiki.XWikiPreferences", context);
// Verify XWiki Master super user
try {
- allow = checkRight(name, xwikimasterdoc , "admin", true, true, true, context);
+ allow = checkRight(name, xwikimasterdoc, "admin", true, true, true, context);
if (allow) {
logAllow(name, resourceKey, accessLevel, "master admin level");
return true;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
// Verify XWiki programming right
if (accessLevel.equals("programming")) {
@@ -440,16 +453,16 @@
return false;
try {
- allow = checkRight(name, xwikimasterdoc , "programming", user, true, true, context);
+ allow = checkRight(name, xwikimasterdoc, "programming", user, true, true, context);
if (allow) {
logAllow(name, resourceKey, accessLevel, "programming level");
return true;
- }
- else {
+ } else {
logDeny(name, resourceKey, accessLevel, "programming level");
return false;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
logDeny(name, resourceKey, accessLevel, "programming level (no right found)");
return false;
}
@@ -461,16 +474,16 @@
// Verify XWiki register right
if (accessLevel.equals("register")) {
try {
- allow = checkRight(name, xwikimasterdoc , "register", user, true, true, context);
+ allow = checkRight(name, xwikimasterdoc, "register", user, true, true, context);
if (allow) {
logAllow(name, resourceKey, accessLevel, "register level");
return true;
- }
- else {
+ } else {
logDeny(name, resourceKey, accessLevel, "register level");
return false;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
logDeny(name, resourceKey, accessLevel, "register level (no right found)");
return false;
}
@@ -478,7 +491,7 @@
try {
// Verify Wiki Owner
String wikiOwner = context.getWikiOwner();
- if (wikiOwner!=null) {
+ if (wikiOwner != null) {
if (wikiOwner.equals(name)) {
logAllow(name, resourceKey, accessLevel, "admin level from wiki ownership");
return true;
@@ -493,23 +506,25 @@
// Verify XWiki super user
try {
- allow = checkRight(name, xwikidoc , "admin", user, true, true, context);
+ allow = checkRight(name, xwikidoc, "admin", user, true, true, context);
if (allow) {
logAllow(name, resourceKey, accessLevel, "admin level");
return true;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
// Verify Web super user
String web = Util.getWeb(resourceKey);
XWikiDocument webdoc = context.getWiki().getDocument(web, "WebPreferences", context);
try {
- allow = checkRight(name, webdoc , "admin", user, true, true, context);
+ allow = checkRight(name, webdoc, "admin", user, true, true, context);
if (allow) {
logAllow(name, resourceKey, accessLevel, "web admin level");
return true;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
// First check if this document is denied to the specific user
resourceKey = Util.getName(resourceKey, context);
@@ -521,73 +536,77 @@
logDeny(name, resourceKey, accessLevel, "document level");
return false;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
try {
- allow = checkRight(name, doc , accessLevel, user, true, false, context);
+ allow = checkRight(name, doc, accessLevel, user, true, false, context);
allow_found = true;
if (allow) {
logAllow(name, resourceKey, accessLevel, "document level");
return true;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
-
// Check if this document is denied/allowed
// through the web WebPreferences Global Rights
try {
- deny = checkRight(name, webdoc, accessLevel, user, false, true, context);
+ deny = checkRight(name, webdoc, accessLevel, user, false, true, context);
deny_found = true;
if (deny) {
logDeny(name, resourceKey, accessLevel, "web level");
return false;
}
- } catch (XWikiRightNotFoundException e) {}
+ } catch (XWikiRightNotFoundException e) {
+ }
// If a right was found at the document level
// then we cannot check the web rights anymore
if (!allow_found) {
- try {
- allow = checkRight(name, webdoc , accessLevel, user, true, true, context);
- allow_found = true;
- if (allow) {
- logAllow(name, resourceKey, accessLevel, "web level");
- return true;
+ try {
+ allow = checkRight(name, webdoc, accessLevel, user, true, true, context);
+ allow_found = true;
+ if (allow) {
+ logAllow(name, resourceKey, accessLevel, "web level");
+ return true;
+ }
+