You can also find the following sample in a file named SampleLoginModule.java in /opt/SUNWstnr/sample/auth/com/sun/login/sample, where /opt is the directory in which it is installed by default.Missing Cross Reference Target shows a sample Java module
package com.sun.login.sample;
import java.util.*;
import com.sun.authd.*;
public class SampleLoginModule extends Login {
private String userTokenId;
private String firstName;
private String lastName;
public SampleLoginModule() throws LoginException{
System.out.println("SampleLoginModule()");
}
public void init() throws LoginException {
System.out.println("SampleLoginModule initialization");
}
public void validate() throws LoginException {
int currentState = getCurrentState();
if (currentState == 1) {
firstName = getToken(1);
lastName = getToken(2);
if (firstName.equals("") || lastName.equals("")) {
throw new LoginException("Sample failed names must not be\
empty");
}
return;
}
else if (currentState == 2) {
String pass = getToken(1);
System.out.println("Replace Text first: " + firstName + " last: "\
+ lastName);
setReplaceText(1, firstName);
setReplaceText(2, lastName);
return;
}
|
else if (currentState == 3) {
String[] tokens = getAllTokens();
for (int i=0; i<getNumberOfTokens(); i++) {
System.out.println("Token-> " + tokens[i]); }
return;
}
else if (currentState == 4) {
String[] tokens = getAllTokensForState(1);
for (int i=0; i<getNumberOfTokensForState(1); i++) {
System.out.println("Token-> " + tokens[i]);
}
}
userTokenId = firstName;
}
public String getUserTokenId() {
return userTokenId;
}
}
|