2014-04-10 55 views
0

我想要做的是創建一個可以用來實現連接類的接口。我應該能夠使用這個不同的認證,如LDAP,OpenId等;所以我想通過用戶名,密碼和可變數量的參數。我該怎麼做..我試過這個。我正朝着正確的方向前進嗎?如果是這樣,我如何初始化該對象來保存可變參數。新手到java。將非常感謝幫助。謝謝!如何在java中傳遞可變參數/持有可變參數的對象?

package com.cerner.jira.plugins.esig.servicemanager; 
import javax.naming.AuthenticationException; 

public interface AuthenticationServiceManager { 

    /** 
    * Creates the Connection for the specific user logging in, and binds the 
    * user's credentials to object. 
    * 
    * @param userName 
    *   The user name to authenticate . 
    * @param password 
    *   The user's password to check . 
    * @param args 
    *   is an object that holds variable arguments which can be used 
    *   to authenticate using both LDAP and OpenId 
    * @return boolean The connection status showing whether the user has been 
    *   successfully authenticated or not. 
    * @throws AuthenticationException 
    *    If there is an error authenticating with the passed 
    *    parameters 
    **/ 

    boolean authenticate(String username, String password, Object... args) 
     throws AuthenticationException; 

    /** 
    * Disconnects the connection. 
    */ 
    void disconnect(); 
} 
+0

您是否正在使用java 5或以上版本?你會得到什麼確切的錯誤?如果沒有錯誤,請繼續。儘快啓動並測試。 – Snicolas

+0

我正在使用Java 6 ...因爲我是新的,我只是想確保..看看是否有替代或更好的方式來做到這一點 – user3438489

+0

該機器是你的[奧卡姆剃刀](http:// en.wikipedia.org/wiki/Occam's_razor),而不是SOF。 – Snicolas

回答

0

看起來像你已經得到它。你這樣稱呼它:

authenticate(username, password, someOtherArgument, yetAnotherArgument, stillAnotherArgument); 

然後你的方法裏面,args[0]將包含someOtherArgumentargs[1]將包含yetAnotherArgumentargs[2]將包含stillAnotherArgument

+0

謝謝Mike!這有助於... – user3438489

+0

那麼,如果我想在實現類的身份驗證方法中傳遞用戶名和密碼。我應該讓課堂摘要? – user3438489

+0

你仍然可以調用'authenticate(username,password);','args'然後是一個空的'Object []'。 –

相關問題