You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/08/21 14:06:16 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ac LDAPUser.java
andreas 2003/08/21 05:06:16
Modified: src/java/org/apache/lenya/cms/ac LDAPUser.java
Log:
fetching LDAP name in constructor
Revision Changes Path
1.12 +51 -50 cocoon-lenya/src/java/org/apache/lenya/cms/ac/LDAPUser.java
Index: LDAPUser.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/LDAPUser.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- LDAPUser.java 23 Jul 2003 13:21:16 -0000 1.11
+++ LDAPUser.java 21 Aug 2003 12:06:16 -0000 1.12
@@ -76,7 +76,6 @@
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
-
/**
* @author egli
*
@@ -87,8 +86,6 @@
private static Category log = Category.getInstance(LDAPUser.class);
public static final String LDAP_ID = "ldapid";
- public static final String CONFIG_PATH = File.separator + "config" + File.separator + "ac" +
- File.separator;
private static String PROVIDER_URL = "provider-url";
private static String MGR_DN = "mgr-dn";
private static String MGR_PW = "mgr-pw";
@@ -97,6 +94,8 @@
private static String SECURITY_PROTOCOL = "security-protocol";
private static String SECURITY_AUTHENTICATION = "security-authentication";
private String ldapId;
+
+ private String ldapName;
/**
* Creates a new LDAPUser object.
@@ -118,11 +117,7 @@
super(configurationDirectory, id, null, email, null);
this.ldapId = ldapId;
- try {
- readProperties();
- } catch (IOException e) {
- throw new ConfigurationException("Could not read properties", e);
- }
+ initialize();
}
/**
@@ -135,9 +130,42 @@
super.configure(config);
ldapId = config.getChild(LDAP_ID).getValue();
+ initialize();
+ }
+
+ /**
+ * Initializes this user.
+ * @throws ConfigurationException when something went wrong.
+ */
+ protected void initialize() throws ConfigurationException {
try {
readProperties();
- } catch (IOException e) {
+
+ String name = null;
+ LdapContext ctx;
+
+ ctx =
+ bind(defaultProperties.getProperty(MGR_DN), defaultProperties.getProperty(MGR_PW));
+
+ String[] attrs = new String[1];
+ attrs[0] = "gecos"; /* users full name */
+
+ Attributes answer = ctx.getAttributes("uid=m400032,ou=People", attrs);
+
+ if (answer != null) {
+ Attribute attr = answer.get("gecos");
+
+ if (attr != null) {
+ for (NamingEnumeration enum = attr.getAll(); enum.hasMore(); enum.next()) {
+ name = (String) attr.get();
+ }
+ }
+ }
+
+ close(ctx);
+
+ this.ldapName = name;
+ } catch (Exception e) {
throw new ConfigurationException("Could not read properties", e);
}
}
@@ -178,8 +206,8 @@
* @see org.apache.lenya.cms.ac.User#authenticate(java.lang.String)
*/
public boolean authenticate(String password) {
- String principal = "uid=" + getLdapId() + "," +
- defaultProperties.getProperty(PARTIAL_USER_DN);
+ String principal =
+ "uid=" + getLdapId() + "," + defaultProperties.getProperty(PARTIAL_USER_DN);
Context ctx;
try {
@@ -195,40 +223,11 @@
return true;
}
- /** (non-Javadoc)
- * @see org.apache.lenya.cms.ac.User#getName()
+ /**
+ * @see org.apache.lenya.cms.ac.Item#getName()
*/
public String getName() {
- String fullName = null;
- LdapContext ctx;
-
- try {
- ctx = bind(defaultProperties.getProperty(MGR_DN), defaultProperties.getProperty(MGR_PW));
-
- String[] attrs = new String[1];
- attrs[0] = "gecos"; /* users full name */
-
- Attributes answer = ctx.getAttributes("uid=m400032,ou=People", attrs);
-
- if (answer != null) {
- Attribute attr = answer.get("gecos");
-
- if (attr != null) {
- for (NamingEnumeration enum = attr.getAll(); enum.hasMore(); enum.next()) {
- fullName = (String) attr.get();
- }
- }
- }
-
- close(ctx);
-
- return fullName;
- } catch (NamingException e) {
- // log this failure
- e.printStackTrace();
-
- return null;
- }
+ return ldapName;
}
/**
@@ -269,18 +268,20 @@
* @return a <code>LdapContext</code>
* @throws NamingException if there are problems establishing the Ldap connection
*/
- private LdapContext bind(String principal, String credentials)
- throws NamingException {
+ private LdapContext bind(String principal, String credentials) throws NamingException {
Hashtable env = new Hashtable();
- System.setProperty("javax.net.ssl.trustStore",
- getConfigurationDirectory().getAbsolutePath() + File.separator +
- defaultProperties.getProperty(KEY_STORE));
+ System.setProperty(
+ "javax.net.ssl.trustStore",
+ getConfigurationDirectory().getAbsolutePath()
+ + File.separator
+ + defaultProperties.getProperty(KEY_STORE));
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, defaultProperties.getProperty(PROVIDER_URL));
env.put(Context.SECURITY_PROTOCOL, defaultProperties.getProperty(SECURITY_PROTOCOL));
- env.put(Context.SECURITY_AUTHENTICATION,
+ env.put(
+ Context.SECURITY_AUTHENTICATION,
defaultProperties.getProperty(SECURITY_AUTHENTICATION));
env.put(Context.SECURITY_PRINCIPAL, principal);
env.put(Context.SECURITY_CREDENTIALS, credentials);
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org