KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > remote > Authenticator


1 package org.sapia.regis.remote;
2
3 public class Authenticator {
4
5   private String JavaDoc _username, _password;
6   
7   Authenticator(String JavaDoc username, String JavaDoc password){
8     _username = username;
9     _password = password;
10   }
11   
12   void authenticate(String JavaDoc username, String JavaDoc password){
13     if(_username == null || _password == null){
14       return;
15     }
16     else{
17       if(_username == null){
18         throw new IllegalStateException JavaDoc("Registry server username not set");
19       }
20       if(username == null){
21         throw new SecurityException JavaDoc("Invalid access; username not specified");
22       }
23       if(!_username.equals(username)){
24         throw new SecurityException JavaDoc("Invalid access; username invalid");
25       }
26       if(_password != null){
27         if(password == null){
28           throw new SecurityException JavaDoc("Invalid access; password not specified");
29         }
30         if(!_password.equals(password)){
31           throw new SecurityException JavaDoc("Invalid access; password invalid");
32         }
33       }
34     }
35   }
36 }
37
Popular Tags