package lava.net.psyc.packages; import lava.net.common.UNL; import lava.net.common.Value; import lava.net.common.VariableModifier; import lava.net.psyc.PSYCDeliveryException; import lava.net.psyc.PSYCMessageCenter; import lava.net.psyc.PSYCPackage; /** * **/ public class AuthenticationServer extends Skeleton { /** * **/ public final static String PackageName = "AuthenticationServer"; class DummyListener implements AuthenticationServerListener { /** * **/ public void authenticationGotPassword(UNL client, String password) { } } /** * **/ private AuthenticationServerListener listener = new DummyListener(); /** * **/ public AuthenticationServer(AuthenticationServerListener listener) { super(); setPackageName(PackageName); addPackageMethod(Authentication.queryPasswordTag,// Authentication.queryPasswordAliases,false); addPackageMethod(Authentication.setPasswordTag,// Authentication.setPasswordAliases,false); addPackageMethod(Authentication.errorInvalidPasswordTag,// Authentication.errorInvalidPasswordAliases,false); addPackageVariable(Authentication.passwordTag,// Authentication.passwordAliases,true); if(listener != null) this.listener = listener; } /** * **/ public boolean understands() { return !(listener instanceof DummyListener); } /** * **/ public void variableChanged(UNL source, VariableModifier modifier) { char glyph = modifier.getGlyph(); String name = modifier.getName(); if(name.equals(Authentication.passwordTag)) { if(glyph == VariableModifier.GLYPH_SET || // glyph == VariableModifier.GLYPH_ASSIGN) { Value value = modifier.getValue(); if(value == null) return; listener.authenticationGotPassword(source,value.toString()); } } } /** * **/ public String getPassword(UNL client) { Value v = center.getValue(client,Authentication.passwordTag); if(v != null) return v.toString(); return null; } /** * **/ public void queryPassword(UNL client, String body) // throws PSYCDeliveryException { center.sendChecked(client,Authentication.PackageName,// Authentication.queryPasswordTag,body); } /** * **/ public void queryPassword(UNL client) throws PSYCDeliveryException { queryPassword(client,null); } /** * **/ public void invalidPassword(UNL client, String body) // throws PSYCDeliveryException { center.sendChecked(client,Authentication.PackageName,// Authentication.errorInvalidPasswordTag,body); } /** * **/ public void invalidPassword(UNL client) throws PSYCDeliveryException { invalidPassword(client,null); } }