1 package org.jgroups.auth; 2 3 import org.jgroups.util.Util; 4 import org.jgroups.Message; 5 6 import java.io.DataOutputStream ; 7 import java.io.IOException ; 8 import java.io.DataInputStream ; 9 import java.util.Properties ; 10 21 public class SimpleToken extends AuthToken { 22 23 public static final String TOKEN_ATTR = "auth_value"; 24 private String token = null; 25 26 public SimpleToken(){ 27 } 29 30 public SimpleToken(String token){ 31 this.token = token; 32 } 33 34 public void setValue(Properties properties){ 35 this.token = (String )properties.get(SimpleToken.TOKEN_ATTR); 36 properties.remove(SimpleToken.TOKEN_ATTR); 37 } 38 39 public String getName(){ 40 return "org.jgroups.auth.SimpleToken"; 41 } 42 43 public boolean authenticate(AuthToken token, Message msg){ 44 if((token != null) && (token instanceof SimpleToken)){ 45 SimpleToken serverToken = (SimpleToken) token; 47 48 if((this.token != null) && (serverToken.token != null) && (this.token.equalsIgnoreCase(serverToken.token))){ 49 if(log.isDebugEnabled()){ 51 log.debug("SimpleToken match"); 52 } 53 return true; 54 }else{ 55 if(log.isWarnEnabled()){ 56 log.warn("Authentication failed on SimpleToken"); 57 } 58 return false; 59 } 60 } 61 62 if(log.isWarnEnabled()){ 63 log.warn("Invalid AuthToken instance - wrong type or null"); 64 } 65 return false; 66 } 67 72 public void writeTo(DataOutputStream out) throws IOException { 73 if(log.isDebugEnabled()){ 74 log.debug("SimpleToken writeTo()"); 75 } 76 Util.writeString(this.token, out); 77 } 78 85 public void readFrom(DataInputStream in) throws IOException , IllegalAccessException , InstantiationException { 86 if(log.isDebugEnabled()){ 87 log.debug("SimpleToken readFrom()"); 88 } 89 this.token = Util.readString(in); 90 } 91 } 92 | Popular Tags |