1 20 21 package org.apache.directory.ldapstudio.valueeditors.password; 22 23 24 import org.apache.directory.ldapstudio.browser.common.dialogs.TextDialog; 25 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 26 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 27 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 28 import org.apache.directory.ldapstudio.browser.core.model.IValue; 29 import org.apache.directory.ldapstudio.valueeditors.AbstractDialogBinaryValueEditor; 30 import org.eclipse.swt.widgets.Shell; 31 32 33 39 public class PasswordValueEditor extends AbstractDialogBinaryValueEditor 40 { 41 42 47 protected boolean openDialog( Shell shell ) 48 { 49 Object value = getValue(); 50 if ( value != null && value instanceof PasswordValueEditorRawValueWrapper ) 51 { 52 PasswordValueEditorRawValueWrapper wrapper = ( PasswordValueEditorRawValueWrapper ) value; 53 if ( wrapper.password != null && wrapper.password instanceof byte[] ) 54 { 55 byte[] pw = ( byte[] ) wrapper.password; 56 PasswordDialog dialog = new PasswordDialog( shell, pw, wrapper.entry ); 57 if ( dialog.open() == TextDialog.OK ) 58 { 59 setValue( dialog.getNewPassword() ); 60 return true; 61 } 62 } 63 } 64 return false; 65 } 66 67 68 76 public String getDisplayValue( IValue value ) 77 { 78 if ( showRawValues() ) 79 { 80 return getPrintableString( value ); 81 } 82 else 83 { 84 if ( value == null ) 85 { 86 return "NULL"; 87 } 88 89 String password = value.getStringValue();; 90 if ( password == null ) 91 { 92 return "NULL"; 93 } 94 else 95 { 96 String text; 97 if ( "".equals( password ) ) 98 { 99 text = "Empty password"; 100 } 101 else if ( password.indexOf( '{' ) == 0 && password.indexOf( '}' ) > 0 ) 102 { 103 String encryptionMethod = password.substring( password.indexOf( '{' ) + 1, password.indexOf( '}' ) ); 104 text = encryptionMethod + " encrypted password"; 105 } 106 else 107 { 108 text = "Plain text password"; 109 } 110 return text; 111 } 112 } 113 } 114 115 116 122 protected Object getEmptyRawValue( IAttribute attribute ) 123 { 124 return new PasswordValueEditorRawValueWrapper( new byte[0], attribute.getEntry() ); 125 } 126 127 128 133 public Object getRawValue( IValue value ) 134 { 135 Object password = super.getRawValue( value ); 136 return new PasswordValueEditorRawValueWrapper( password, value.getAttribute().getEntry() ); 137 } 138 139 140 146 public Object getRawValue( IConnection connection, Object value ) 147 { 148 Object password = super.getRawValue( connection, value ); 149 return new PasswordValueEditorRawValueWrapper( password, null ); 150 } 151 152 159 private class PasswordValueEditorRawValueWrapper 160 { 161 162 private Object password; 163 164 165 private IEntry entry; 166 167 168 174 private PasswordValueEditorRawValueWrapper( Object password, IEntry entry ) 175 { 176 this.password = password; 177 this.entry = entry; 178 } 179 } 180 181 } 182 | Popular Tags |