You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/06/12 17:51:34 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting AbstractAuthenticatorAction.java AbstractUsernamePasswordAuthenticatorAction.java IMLAuthenticatorAction.java
egli 2003/06/12 08:51:33
Modified: src/java/org/apache/lenya/cms/cocoon/acting
AbstractAuthenticatorAction.java
AbstractUsernamePasswordAuthenticatorAction.java
IMLAuthenticatorAction.java
Log:
The authentication in the IMLAuthenticator is now done with
the help of the User class. That way we can transparently
authenticate LDAP users.
For that to work I had to change the interfaces and pass
the publication trough from the top Authenticator action.
Revision Changes Path
1.12 +14 -12 cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/AbstractAuthenticatorAction.java
Index: AbstractAuthenticatorAction.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/AbstractAuthenticatorAction.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractAuthenticatorAction.java 24 Apr 2003 13:52:38 -0000 1.11
+++ AbstractAuthenticatorAction.java 12 Jun 2003 15:51:33 -0000 1.12
@@ -57,6 +57,8 @@
import java.util.HashMap;
import java.util.Map;
import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationFactory;
/**
@@ -108,6 +110,9 @@
return null;
}
+ // Get the current publication
+ Publication publication = PublicationFactory.getPublication(objectModel);
+
// Get session
Session session = req.getSession(true);
@@ -117,7 +122,7 @@
return null;
}
- if (authenticate(req, new HashMap())) {
+ if (authenticate(req, publication)) {
getLogger().info(".act(): Authentication succeeded");
session.setAttribute("org.apache.lenya.cms.cocoon.acting.Authenticator.id", authenticatorId);
@@ -135,15 +140,12 @@
}
/**
- * DOCUMENT ME!
- *
- * @param request DOCUMENT ME!
- * @param map DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public abstract boolean authenticate(Request request, Map map)
+ * @param request
+ * @param publication
+ *
+ * @return
+ * @throws Exception
+ */
+ public abstract boolean authenticate(Request request, Publication publication)
throws Exception;
}
1.10 +34 -30 cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/AbstractUsernamePasswordAuthenticatorAction.java
Index: AbstractUsernamePasswordAuthenticatorAction.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/AbstractUsernamePasswordAuthenticatorAction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractUsernamePasswordAuthenticatorAction.java 24 Apr 2003 13:52:38 -0000 1.9
+++ AbstractUsernamePasswordAuthenticatorAction.java 12 Jun 2003 15:51:33 -0000 1.10
@@ -44,8 +44,7 @@
package org.apache.lenya.cms.cocoon.acting;
import org.apache.cocoon.environment.Request;
-
-import java.util.Map;
+import org.apache.lenya.cms.publication.Publication;
/**
* DOCUMENT ME!
@@ -54,32 +53,37 @@
* @version 1.12.29
*/
public abstract class AbstractUsernamePasswordAuthenticatorAction
- extends AbstractAuthenticatorAction {
-
- public boolean authenticate(Request request, Map map)
- throws Exception {
- String username = request.getParameter("username");
- String password = request.getParameter("password");
-
- if ((username != null) && (password != null)) {
- return authenticate(username, password, request, map);
- }
-
- return false;
- }
+ extends AbstractAuthenticatorAction {
- /**
- * DOCUMENT ME!
- *
- * @param username DOCUMENT ME!
- * @param password DOCUMENT ME!
- * @param request DOCUMENT ME!
- * @param map DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public abstract boolean authenticate(String username, String password, Request request, Map map)
- throws Exception;
+ /* (non-Javadoc)
+ * @see org.apache.lenya.cms.cocoon.acting.AbstractAuthenticatorAction#authenticate(org.apache.cocoon.environment.Request, org.apache.lenya.cms.publication.Publication)
+ */
+ public boolean authenticate(Request request, Publication publication)
+ throws Exception {
+ String username = request.getParameter("username");
+ String password = request.getParameter("password");
+
+ if ((username == null) || (password == null)) {
+ return false;
+ }
+
+ return authenticate(username, password, request, publication);
+ }
+
+ /**
+ * @param username
+ * @param password
+ * @param request
+ * @param publication
+ *
+ * @return
+ *
+ * @throws Exception
+ */
+ public abstract boolean authenticate(
+ String username,
+ String password,
+ Request request,
+ Publication publication)
+ throws Exception;
}
1.13 +147 -136 cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/IMLAuthenticatorAction.java
Index: IMLAuthenticatorAction.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/IMLAuthenticatorAction.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- IMLAuthenticatorAction.java 24 Apr 2003 13:52:38 -0000 1.12
+++ IMLAuthenticatorAction.java 12 Jun 2003 15:51:33 -0000 1.13
@@ -53,152 +53,163 @@
import org.w3c.dom.Document;
import org.apache.lenya.cms.ac.Identity;
-import org.apache.lenya.cms.ac.Password;
-
+import org.apache.lenya.cms.ac.User;
+import org.apache.lenya.cms.ac.UserManager;
+import org.apache.lenya.cms.publication.Publication;
import java.net.URL;
-import java.util.Map;
-
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-
/**
* DOCUMENT ME!
*
* @author Michael Wechner
* @version 2.1.6
*/
-public class IMLAuthenticatorAction extends AbstractUsernamePasswordAuthenticatorAction
- implements ThreadSafe {
- private String domain = null;
- private String port = null;
- private String context = null;
- private String passwd = null;
- private String type = null;
-
- /**
- * DOCUMENT ME!
- *
- * @param conf DOCUMENT ME!
- *
- * @throws ConfigurationException DOCUMENT ME!
- */
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
-
- Configuration domainConf = conf.getChild("domain");
- domain = domainConf.getValue("127.0.0.1");
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CONFIGURATION: domain=" + domain);
- }
-
- Configuration portConf = conf.getChild("port");
- port = portConf.getValue(null);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CONFIGURATION: port=" + port);
- }
-
- Configuration contextConf = conf.getChild("context");
- context = contextConf.getValue(null);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CONFIGURATION: context=" + context);
- }
-
- Configuration passwdConf = conf.getChild("passwd");
- passwd = passwdConf.getValue(null);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CONFIGURATION: passwd=" + passwd);
- }
-
- Configuration typeConf = conf.getChild("type");
- type = typeConf.getValue(null);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("CONFIGURATION: type=" + type);
- }
-
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param username DOCUMENT ME!
- * @param password DOCUMENT ME!
- * @param request DOCUMENT ME!
- * @param map DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
- */
- public boolean authenticate(String username, String password, Request request, Map map)
- throws Exception {
- if ((username != null) && (password != null)) {
- String passwordString = null;
- Document idoc = null;
-
- try {
- String context = request.getContextPath();
- int port = request.getServerPort();
- idoc = getIdentityDoc(username, port, context);
- passwordString = Identity.getPassword(idoc);
- } catch (Exception e) {
- getLogger().error(".authenticate(): " + e);
-
- return false;
- }
-
- if (Password.encrypt(password).equals(passwordString)) {
- Session session = request.getSession(true);
-
- if (session == null) {
- return false;
- }
-
- Identity identity = new Identity(idoc);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("IDENTITY: " + identity);
- }
-
- session.setAttribute("org.apache.lenya.cms.ac.Identity", identity);
-
- return true;
- }
- }
-
- return false;
- }
-
- /**
- *
- */
- private Document getIdentityDoc(String username, int port, String context)
- throws Exception {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- String imlURLString = "http://" + domain;
-
- if (this.port != null) {
- imlURLString = imlURLString + ":" + this.port;
- } else {
- imlURLString = imlURLString + ":" + port;
- }
-
- if (this.context != null) {
- imlURLString = imlURLString + this.context;
- } else {
- imlURLString = imlURLString + context;
- }
+public class IMLAuthenticatorAction
+ extends AbstractUsernamePasswordAuthenticatorAction
+ implements ThreadSafe {
+ private String domain = null;
+ private String port = null;
+ private String context = null;
+ private String passwd = null;
+ private String type = null;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param conf DOCUMENT ME!
+ *
+ * @throws ConfigurationException DOCUMENT ME!
+ */
+ public void configure(Configuration conf) throws ConfigurationException {
+ super.configure(conf);
+
+ Configuration domainConf = conf.getChild("domain");
+ domain = domainConf.getValue("127.0.0.1");
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CONFIGURATION: domain=" + domain);
+ }
+
+ Configuration portConf = conf.getChild("port");
+ port = portConf.getValue(null);
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CONFIGURATION: port=" + port);
+ }
+
+ Configuration contextConf = conf.getChild("context");
+ context = contextConf.getValue(null);
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CONFIGURATION: context=" + context);
+ }
+
+ Configuration passwdConf = conf.getChild("passwd");
+ passwd = passwdConf.getValue(null);
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CONFIGURATION: passwd=" + passwd);
+ }
+
+ Configuration typeConf = conf.getChild("type");
+ type = typeConf.getValue(null);
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CONFIGURATION: type=" + type);
+ }
+
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param username DOCUMENT ME!
+ * @param password DOCUMENT ME!
+ * @param request DOCUMENT ME!
+ * @param map DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
+ * @throws Exception DOCUMENT ME!
+ */
+ public boolean authenticate(
+ String username,
+ String password,
+ Request request,
+ Publication publication)
+ throws Exception {
+ if ((username != null) && (password != null)) {
+
+ UserManager manager = UserManager.instance(publication);
+ User user = manager.getUser(username);
+ getLogger().debug("User: " + user.getFullName());
+ getLogger().debug("passwd: " + password);
+ getLogger().debug("username: " + username);
+
+ Document idoc = null;
+
+ try {
+ String context = request.getContextPath();
+ int port = request.getServerPort();
+ idoc = getIdentityDoc(username, port, context);
+ } catch (Exception e) {
+ getLogger().error(".authenticate(): " + e);
+
+ return false;
+ }
+
+ if (user.authenticate(password)) {
+
+ Session session = request.getSession(true);
+
+ if (session == null) {
+ return false;
+ }
+
+ Identity identity = new Identity(idoc);
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("IDENTITY: " + identity);
+ }
+
+ session.setAttribute(
+ "org.apache.lenya.cms.ac.Identity",
+ identity);
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ *
+ */
+ private Document getIdentityDoc(String username, int port, String context)
+ throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ String imlURLString = "http://" + domain;
+
+ if (this.port != null) {
+ imlURLString = imlURLString + ":" + this.port;
+ } else {
+ imlURLString = imlURLString + ":" + port;
+ }
+
+ if (this.context != null) {
+ imlURLString = imlURLString + this.context;
+ } else {
+ imlURLString = imlURLString + context;
+ }
- imlURLString = imlURLString + "/" + passwd + username + ".iml";
- getLogger().debug(".getIdentity(): " + imlURLString);
+ imlURLString = imlURLString + "/" + passwd + username + ".iml";
+ getLogger().debug(".getIdentity(): " + imlURLString);
- return db.parse(new URL(imlURLString).openStream());
- }
+ return db.parse(new URL(imlURLString).openStream());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org