JAVA Source Code
ASP File: vbscript/general/vbscript/general/nwauth/NWAuthentication.java |
|
import java.util.*;
import com.novell.beans.NWDir.*;
public class NWAuthentication
{
NWDir nwDir;
String names[];
String layouts[];
public NWAuthentication()
{
nwDir = new NWDir();
}
public boolean
init(String treeName, String context) {
try {
nwDir.setFullName("NDS:\\\\" + treeName + "\\" + context);
}
catch(Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public boolean
login(String uid, String pwd) {
try {
NWEntry entry = nwDir.getEntry();
NWEntries entries = entry.getEntries();
while(entries.hasMoreElements()) {
try {
entry = (NWEntry)entries.nextElement();
if(!entry.getLayoutName().equals("User"))
continue;
if(!entry.getShortName().equalsIgnoreCase(uid))
continue;
if(entry.validatePassword(pwd)) {
getInfos();
return true;
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}
catch(Exception e) {
e.printStackTrace();
}
return false;
}
public boolean
getUsers(Hashtable hash) {
try {
NWEntry entry = nwDir.getEntry();
NWEntries entries = entry.getEntries();
while(entries.hasMoreElements()) {
try {
entry = (NWEntry)entries.nextElement();
hash.put(entry.getShortName(), entry.getLayoutName());
}
catch(Exception e) {
e.printStackTrace();
}
}
}
catch(Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public boolean
getInfos() {
try {
NWEntry entry = nwDir.getEntry();
NWEntries entries = entry.getEntries();
Vector v_names = new Vector();
Vector v_layouts = new Vector();
while(entries.hasMoreElements()) {
try {
entry = (NWEntry)entries.nextElement();
v_names.addElement(entry.getShortName());
v_layouts.addElement(entry.getLayoutName());
}
catch(Exception e) {
e.printStackTrace();
}
}
int n = v_names.size();
names = new String[n];
layouts = new String[n];
v_names.copyInto((Object[])names);
v_layouts.copyInto((Object[])layouts);
}
catch(Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public String[]
getNames() {
return names;
}
public String[]
getLayouts() {
return layouts;
}
public static void
getAllUsers(NWEntry anEntry, Vector userList) {
NWEntries children = anEntry.getEntries();
while (children.hasMoreElements()) {
NWEntry child = (NWEntry)children.nextElement();
userList.addElement(child);
getAllUsers(child, userList);
}
}
public static void
main(String[] args) {
try {
NWAuthentication auth = new NWAuthentication();
if(!auth.init(args[0], args[1])) {
System.out.println("Error while connecting to NDS");
return;
}
if(auth.login(args[2], args[3]))
System.out.println("granted");
else
System.out.println("not granted");
String[] names = auth.getNames();
String[] layouts = auth.getLayouts();
for(int i = 0; i < names.length; i++)
System.out.println(names[i] + ", " + layouts[i]);
System.out.println("getInfo() not called");
}
catch(Exception e) {
e.printStackTrace();
}
}
}