588
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.core.ant.taskdefs;
|
|
19 |
|
628
|
20 |
import org.apache.tools.ant.BuildException;
|
|
21 |
import org.apache.tools.ant.Project;
|
588
|
22 |
import org.apache.tools.ant.Task;
|
628
|
23 |
|
|
24 |
import com.nokia.helium.core.LDAPException;
|
|
25 |
import com.nokia.helium.core.LDAPHelper;
|
588
|
26 |
|
|
27 |
/**
|
|
28 |
* Task is to search data from LDAP server.
|
|
29 |
*
|
|
30 |
* <pre>
|
|
31 |
* Usage: <hlm:ldap url="${ldap.server.url}"
|
|
32 |
* rootdn="${ldap.root.dn}"
|
|
33 |
* filter="uid=${env.USERNAME}"
|
|
34 |
* outputproperty="email.from"
|
|
35 |
* key="mail"/>
|
|
36 |
* </pre>
|
|
37 |
* @ant.task name="ldap" category="Core"
|
|
38 |
*/
|
|
39 |
public class LDAPTask extends Task {
|
|
40 |
private String url;
|
|
41 |
private String rootdn;
|
|
42 |
private String filter;
|
|
43 |
private String key;
|
|
44 |
private String property;
|
628
|
45 |
private boolean failOnError = true;
|
588
|
46 |
|
|
47 |
/**
|
|
48 |
* Method executes current task.
|
|
49 |
*/
|
|
50 |
public void execute() {
|
628
|
51 |
if (url == null) {
|
588
|
52 |
throw new BuildException("'url' attribute is not defined");
|
628
|
53 |
}
|
|
54 |
if (rootdn == null) {
|
588
|
55 |
throw new BuildException("'rootdn' attribute is not defined");
|
628
|
56 |
}
|
|
57 |
if (filter == null) {
|
588
|
58 |
throw new BuildException("'filter' attribute is not defined");
|
628
|
59 |
}
|
|
60 |
if (property == null) {
|
588
|
61 |
throw new BuildException("'property' attribute is not defined");
|
628
|
62 |
}
|
|
63 |
if (key == null) {
|
588
|
64 |
throw new BuildException("'key' attribute is not defined");
|
628
|
65 |
}
|
588
|
66 |
|
|
67 |
try {
|
628
|
68 |
LDAPHelper helper = new LDAPHelper(url, rootdn);
|
|
69 |
String value = helper.getAttributeAsString(filter, key);
|
|
70 |
if (value != null) {
|
|
71 |
getProject().setNewProperty(property, value);
|
|
72 |
} else {
|
|
73 |
log("Could not find value for key: " + key, Project.MSG_WARN);
|
588
|
74 |
}
|
628
|
75 |
} catch (LDAPException exc) {
|
|
76 |
log(exc.getMessage(), Project.MSG_ERR);
|
|
77 |
if (failOnError) {
|
|
78 |
throw new BuildException(exc.getMessage(), exc);
|
|
79 |
}
|
588
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Return the LDAP server URL.
|
|
85 |
*
|
|
86 |
* @return the LDAP server URL.
|
|
87 |
*/
|
|
88 |
public String getUrl() {
|
|
89 |
return url;
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Set LDAP server URL.
|
|
94 |
*
|
|
95 |
* @param url is the LDAP server URL to set.
|
|
96 |
* @ant.required
|
|
97 |
*/
|
|
98 |
public void setUrl(String url) {
|
|
99 |
this.url = url;
|
|
100 |
}
|
|
101 |
|
|
102 |
/**
|
|
103 |
* Return LDAP root distinguished name.
|
|
104 |
*
|
|
105 |
* @return LDAP root distinguished name
|
|
106 |
*/
|
|
107 |
public String getRootdn() {
|
|
108 |
return rootdn;
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Set LDAP root distinguished name.
|
|
113 |
*
|
|
114 |
* @param rootdn is the LDAP root distinguished name to set.
|
|
115 |
* @ant.required
|
|
116 |
*/
|
|
117 |
public void setRootdn(String rootdn) {
|
|
118 |
this.rootdn = rootdn;
|
|
119 |
}
|
|
120 |
|
|
121 |
/**
|
|
122 |
* Return object name to search in the LDAP.
|
|
123 |
*
|
|
124 |
* @return the object name to search in the LDAP
|
|
125 |
*/
|
|
126 |
public String getFilter() {
|
|
127 |
return filter;
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* Set the object name to search in the LDAP.
|
|
132 |
*
|
|
133 |
* @param filter is the object name to set.
|
|
134 |
* @ant.required
|
|
135 |
*/
|
|
136 |
public void setFilter(String filter) {
|
|
137 |
this.filter = filter;
|
|
138 |
}
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Return the output property to set.
|
|
142 |
*
|
|
143 |
* @return is the output property to set.
|
|
144 |
*/
|
|
145 |
public String getOutputProperty() {
|
|
146 |
return property;
|
|
147 |
}
|
|
148 |
|
|
149 |
/**
|
|
150 |
* Set the output property if the user found.
|
|
151 |
*
|
|
152 |
* @param property is the property to be set.
|
|
153 |
* @ant.required
|
|
154 |
*/
|
|
155 |
public void setOutputProperty(String property) {
|
|
156 |
this.property = property;
|
|
157 |
}
|
|
158 |
|
|
159 |
/**
|
|
160 |
* Return the key search element to search user information.
|
|
161 |
*
|
|
162 |
* @return the key search element.
|
|
163 |
*/
|
|
164 |
public String getKey() {
|
|
165 |
return key;
|
|
166 |
}
|
|
167 |
|
|
168 |
/**
|
|
169 |
* Set the key search element to search the user information.
|
|
170 |
*
|
|
171 |
* @param key is the key search element to set.
|
|
172 |
* @ant.required
|
|
173 |
*/
|
|
174 |
public void setKey(String key) {
|
|
175 |
this.key = key;
|
|
176 |
}
|
628
|
177 |
|
|
178 |
/**
|
|
179 |
* Defines if the task should fail on error or not found.
|
|
180 |
* @param failOnError
|
|
181 |
* @ant.not-required Default is true
|
|
182 |
*/
|
|
183 |
public void setFailOnError(boolean failOnError) {
|
|
184 |
this.failOnError = failOnError;
|
|
185 |
}
|
|
186 |
|
588
|
187 |
}
|