Question about AuthContext class and its login method
Hi
Thank you for reading my post
I have a question about AuthContext methods, I looked at javaDocs and it was not helpful.
1-What is its constructor parameter, when we pass just one string to this method?
2-when we use login method we pass two parameters to it, first one is an indexType and second one is an String
what that string means and what is its relation with indextype?
Thanks
[429 byte] By [
Legolas.wa] at [2007-11-27 4:36:39]

# 1
> Hi
> Thank you for reading my post
> I have a question about AuthContext methods, I looked
> at javaDocs and it was not helpful.
>
> 1-What is its constructor parameter, when we pass
> just one string to this method?
greetings, Legolas,
assuming you're using AM7.1...
the String argument to AuthContext is the "realm" name. for instance, if the root realm, then you may pass "/". if you have a subrealm, "realm1", then use "/realm1".
> 2-when we use login method we pass two parameters to
> it, first one is an indexType and second one is an
> String
> what that string means and what is its relation with
> indextype?
the index type indicates what the index name "means". if you're doing module-based authentication, then indextype MODULE_INSTANCE, and (e.g.) index name "LDAP".
if you just want to do userid-based auth using the defined auth in a given realm, you can do something like (try and catch blocks ignored):
AuthContext lc = new AuthContext("/realm1");
lc.login();
userID = userid;
Callback[] callbacks = null;
Hashtable values = new Hashtable();
values.put(AuthXMLTags.NAME_CALLBACK, userid);
values.put(AuthXMLTags.PASSWORD_CALLBACK, password);
while (lc.hasMoreRequirements()) {
callbacks = lc.getRequirements();
fillCallbacks(callbacks, values);
lc.submitRequirements(callbacks);
}
AuthContext.Status istat = lc.getStatus();
if (istat == AuthContext.Status.SUCCESS) {
...
}
protected void fillCallbacks(Callback[] callbacks, Hashtable values)
throws Exception
{
for (int i = 0; i < callbacks.length; i++) {
if (callbacks instanceof NameCallback) {
NameCallback nc = (NameCallback) callbacks;
nc.setName((String)values.get(AuthXMLTags.NAME_CALLBACK));
} else if (callbacks instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback) callbacks;
pc.setPassword(((String)values.get(
AuthXMLTags.PASSWORD_CALLBACK)).toCharArray());
} else if (callbacks instanceof TextInputCallback) {
TextInputCallback tic = (TextInputCallback) callbacks;
tic.setText((String)values.get(
AuthXMLTags.TEXT_INPUT_CALLBACK));
} else if (callbacks instanceof ChoiceCallback) {
ChoiceCallback cc = (ChoiceCallback) callbacks;
cc.setSelectedIndex(Integer.parseInt((String)values.get(
AuthXMLTags.CHOICE_CALLBACK)));
}
}
}
this stuff is taken from the idrepo sample program, IdRepoSampleUtils.java (IdRepoSample.java, IdRepoSample*.java)
hth.
>
>
> Thanks