KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > BrowserCommonAuthHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common;
22
23
24 import org.apache.directory.ldapstudio.browser.common.dialogs.CredentialsDialog;
25 import org.apache.directory.ldapstudio.browser.core.internal.model.Credentials;
26 import org.apache.directory.ldapstudio.browser.core.model.ConnectionParameter;
27 import org.apache.directory.ldapstudio.browser.core.model.IAuthHandler;
28 import org.apache.directory.ldapstudio.browser.core.model.ICredentials;
29
30 import org.eclipse.ui.PlatformUI;
31
32
33 public class BrowserCommonAuthHandler implements IAuthHandler
34 {
35
36     public ICredentials getCredentials( final ConnectionParameter connectionParameter )
37     {
38
39         if ( connectionParameter.getBindPrincipal() == null || "".equals( connectionParameter.getBindPrincipal() ) )
40         {
41             return new Credentials( "", "", connectionParameter );
42         }
43         else if ( connectionParameter.getBindPassword() != null && !"".equals( connectionParameter.getBindPassword() ) )
44         {
45             return new Credentials( connectionParameter.getBindPrincipal(), connectionParameter.getBindPassword(),
46                 connectionParameter );
47         }
48         else
49         {
50             final String JavaDoc[] pw = new String JavaDoc[1];
51             PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable JavaDoc()
52             {
53                 public void run()
54                 {
55                     CredentialsDialog dialog = new CredentialsDialog( PlatformUI.getWorkbench().getDisplay()
56                         .getActiveShell(), "Enter Password for '" + connectionParameter.getName() + "'",
57                         "Please enter password of user " + connectionParameter.getBindPrincipal() + ":", "", null );
58                     if ( dialog.open() == CredentialsDialog.OK )
59                     {
60                         pw[0] = dialog.getValue();
61                     }
62                     else
63                     {
64                         pw[0] = null;
65                     }
66                 }
67             } );
68
69             if ( pw[0] == null )
70             {
71                 return null;
72             }
73             else
74             {
75                 return new Credentials( connectionParameter.getBindPrincipal(), pw[0], connectionParameter );
76             }
77         }
78
79     }
80
81 }
82
Popular Tags