/[classpath]/inetlib/source/gnu/inet/util/SaslPlain.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/util/SaslPlain.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by dog, Thu Oct 21 15:21:55 2004 UTC revision 1.5 by dog, Thu Nov 25 22:15:05 2004 UTC
# Line 48  import javax.security.sasl.SaslException Line 48  import javax.security.sasl.SaslException
48   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>   * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
49   */   */
50  public class SaslPlain  public class SaslPlain
51  implements SaslClient    implements SaslClient
52  {  {
53    
54    private String username;    private String username;
55    private String password;    private String password;
56    private boolean complete;    private boolean complete;
57    
58    public SaslPlain (String username, String password)    public SaslPlain(String username, String password)
59    {    {
60      this.username = username;      this.username = username;
61      this.password = password;      this.password = password;
62    }    }
63    
64    public String getMechanismName ()    public String getMechanismName()
65    {    {
66      return "PLAIN";      return "PLAIN";
67    }    }
68    
69    public boolean hasInitialResponse ()    public boolean hasInitialResponse()
70    {    {
71      return true;      return true;
72    }    }
73    
74    public byte[] evaluateChallenge (byte[] challenge)    public byte[] evaluateChallenge(byte[] challenge)
75      throws SaslException      throws SaslException
76    {    {
77      try      try
78        {        {
79          byte[] a = username.getBytes ("UTF-8");          byte[] a = username.getBytes("UTF-8");
80          byte[] b = password.getBytes ("UTF-8");          byte[] b = password.getBytes("UTF-8");
81          byte[] c = new byte[(a.length * 2) + b.length + 2];          byte[] c = new byte[(a.length * 2) + b.length + 2];
82          System.arraycopy (a, 0, c, 0, a.length);          System.arraycopy(a, 0, c, 0, a.length);
83          System.arraycopy (a, 0, c, a.length + 1, a.length);          System.arraycopy(a, 0, c, a.length + 1, a.length);
84          System.arraycopy (b, 0, c, (a.length * 2) + 2, b.length);          System.arraycopy(b, 0, c, (a.length * 2) + 2, b.length);
85          complete = true;          complete = true;
86          return c;          return c;
87        }        }
88      catch (UnsupportedEncodingException e)      catch (UnsupportedEncodingException e)
89        {        {
90          String msg = "Username or password contains illegal UTF-8";          String msg = "Username or password contains illegal UTF-8";
91          throw new SaslException (msg, e);          throw new SaslException(msg, e);
92        }        }
93    }    }
94    
95    public boolean isComplete ()    public boolean isComplete()
96    {    {
97      return complete;      return complete;
98    }    }
99    
100    public byte[] unwrap (byte[] incoming, int off, int len)    public byte[] unwrap(byte[] incoming, int off, int len)
101      throws SaslException      throws SaslException
102    {    {
103      byte[] ret = new byte[len - off];      byte[] ret = new byte[len - off];
104      System.arraycopy (incoming, off, ret, 0, len);      System.arraycopy(incoming, off, ret, 0, len);
105      return ret;      return ret;
106    }    }
107    
108    public byte[] wrap (byte[] outgoing, int off, int len)    public byte[] wrap(byte[] outgoing, int off, int len)
109      throws SaslException      throws SaslException
110    {    {
111      byte[] ret = new byte[len - off];      byte[] ret = new byte[len - off];
112      System.arraycopy (outgoing, off, ret, 0, len);      System.arraycopy(outgoing, off, ret, 0, len);
113      return ret;      return ret;
114    }    }
115    
116    public Object getNegotiatedProperty (String name)    public Object getNegotiatedProperty(String name)
117    {    {
118      return null;      return null;
119    }    }
120    
121    public void dispose ()    public void dispose()
122    {    {
123    }    }
124        
125  }  }
126    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26