repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/ConnectionViewActionProxy.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/ConnectionViewActionProxy.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import org.eclipse.jface.viewers.Viewer; /** * The ConnectionViewActionProxy is a proxy for a real action. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionViewActionProxy extends StudioActionProxy { /** * Creates a new instance of ConnectionViewActionProxy. * * @param viewer the viewer * @param actionHandlerManager the action handler manager, * used to deactivate and activate the action handlers and key bindings * @param action the real action */ public ConnectionViewActionProxy( Viewer viewer, ActionHandlerManager actionHandlerManager, StudioAction action ) { super( viewer, actionHandlerManager, action ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/Messages.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * A private constructor : this is an utility class */ private Messages() { } /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CopyAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCoreConstants; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.ui.ConnectionParameterPage; import org.apache.directory.studio.connection.ui.ConnectionParameterPageManager; import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.IWorkbenchCommandConstants; import org.eclipse.ui.PlatformUI; /** * This class implements the Copy Action * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CopyAction extends StudioAction { /** The Paste action proxy */ private StudioActionProxy pasteActionProxy; /** * Creates a new instance of CopyAction. * * @param pasteActionProxy * the associated Paste Action */ public CopyAction( StudioActionProxy pasteActionProxy ) { super(); this.pasteActionProxy = pasteActionProxy; } /** * {@inheritDoc} */ public String getText() { Connection[] connections = getSelectedConnections(); ConnectionFolder[] connectionFolders = getSelectedConnectionFolders(); if ( ( connections.length ) > 0 && ( connectionFolders.length == 0 ) ) { if ( connections.length > 1 ) { return Messages.getString( "CopyAction.CopyConnections" ); } else { return Messages.getString( "CopyAction.CopyConnection" ); } } else if ( ( connectionFolders.length > 0 ) && ( connections.length == 0 ) ) { if ( connectionFolders.length > 1 ) { return Messages.getString( "CopyAction.CopyFolders" ); } else { return Messages.getString( "CopyAction.CopyFolder" ); } } else { return Messages.getString( "CopyAction.Copy" ); //$NON-NLS-1$ } } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_TOOL_COPY ); } /** * {@inheritDoc} */ public String getCommandId() { return IWorkbenchCommandConstants.EDIT_COPY; } /** * {@inheritDoc} */ public void run() { Connection[] connections = getSelectedConnections(); ConnectionFolder[] connectionFolders = getSelectedConnectionFolders(); List<Object> objects = new ArrayList<>(); objects.addAll( Arrays.asList( connections ) ); objects.addAll( Arrays.asList( connectionFolders ) ); String urls = getSelectedConnectionUrls(); // copy to clipboard if ( !objects.isEmpty() ) { if ( urls != null && urls.length() > 0 ) { copyToClipboard( new Object[] { objects.toArray(), urls }, new Transfer[] { ConnectionTransfer.getInstance(), TextTransfer.getInstance() } ); } else { copyToClipboard( new Object[] { objects.toArray() }, new Transfer[] { ConnectionTransfer.getInstance() } ); } } // update paste action if ( pasteActionProxy != null ) { pasteActionProxy.updateAction(); } } /** * Copies data to Clipboard * * @param data the data to be set in the clipboard * @param dataTypes the transfer agents that will convert the data to its platform specific format; * each entry in the data array must have a corresponding dataType */ public static void copyToClipboard( Object[] data, Transfer[] dataTypes ) { Clipboard clipboard = null; try { clipboard = new Clipboard( Display.getCurrent() ); clipboard.setContents( data, dataTypes ); } finally { if ( clipboard != null ) { clipboard.dispose(); } } } /** * {@inheritDoc} */ public boolean isEnabled() { return getSelectedConnections().length + getSelectedConnectionFolders().length > 0; } /** * Gets the selected connections as URLs, multiple URLs * are separated by a line break. * * @return the selected connections as URLs */ private String getSelectedConnectionUrls() { StringBuilder buffer = new StringBuilder(); Connection[] connections = getSelectedConnections(); ConnectionParameterPage[] connectionParameterPages = ConnectionParameterPageManager.getConnectionParameterPages(); for ( Connection connection : connections ) { ConnectionParameter parameter = connection.getConnectionParameter(); LdapUrl ldapUrl = new LdapUrl(); ldapUrl.setDn( Dn.EMPTY_DN ); for ( ConnectionParameterPage connectionParameterPage : connectionParameterPages ) { connectionParameterPage.mergeParametersToLdapURL( parameter, ldapUrl ); } buffer.append( ldapUrl.toString() ); buffer.append( ConnectionCoreConstants.LINE_SEPARATOR ); } return buffer.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/SelectionUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; /** * The SelectionUtils are used to extract specific beans from the current * selection (org.eclipse.jface.viewers.ISelection). * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SelectionUtils { /** * Gets the Strings contained in the given selection. * * @param selection the selection * @return an array with Strings, may be empty. */ public static String[] getProperties( ISelection selection ) { List<Object> list = getTypes( selection, String.class ); return list.toArray( new String[list.size()] ); } /** * Gets all beans of the requested type contained in the given selection. * * @param selection the selection * @param type the requested type * @return a list containg beans of the requesten type */ private static List<Object> getTypes( ISelection selection, Class<?> type ) { List<Object> list = new ArrayList<>(); if ( selection instanceof IStructuredSelection ) { IStructuredSelection structuredSelection = ( IStructuredSelection ) selection; for ( Object object : structuredSelection.toList() ) { if ( type.isInstance( object ) ) { list.add( object ); } } } return list; } /** * Gets the Connection beans contained in the given selection. * * @param selection the selection * @return an array with Connection beans, may be empty. */ public static Connection[] getConnections( ISelection selection ) { List<Object> list = getTypes( selection, Connection.class ); return list.toArray( new Connection[list.size()] ); } /** * Gets the ConnectionFolder beans contained in the given selection. * * @param selection the selection * @return an array with ConnectionFolder beans, may be empty. */ public static ConnectionFolder[] getConnectionFolders( ISelection selection ) { List<Object> list = getTypes( selection, ConnectionFolder.class ); return list.toArray( new ConnectionFolder[list.size()] ); } /** * Gets the objects contained in the given selection. * * @param selection the selection * @return an array with object, may be empty. */ public static Object[] getObjects( ISelection selection ) { List<Object> list = getTypes( selection, Object.class ); return list.toArray( new Object[list.size()] ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/StudioAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; /** * This abstract class must be extended by each Action related to the Browser. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class StudioAction implements IWorkbenchWindowActionDelegate { /** The selected Connections */ private Connection[] selectedConnections; /** The selected connection folders */ private ConnectionFolder[] selectedConnectionFolders; /** The input */ private Object input; /** * Creates a new instance of BrowserAction. */ protected StudioAction() { this.init(); } /** * Gets the style. * * @return the style */ public int getStyle() { return Action.AS_PUSH_BUTTON; } /** * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) */ public void init( IWorkbenchWindow window ) { this.init(); } /** * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run( IAction action ) { this.run(); } /** * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged( IAction action, ISelection selection ) { setSelectedConnections( SelectionUtils.getConnections( selection ) ); setSelectedConnectionFolders( SelectionUtils.getConnectionFolders( selection ) ); action.setEnabled( isEnabled() ); action.setText( CommonUIUtils.getTextValue( getText() ) ); action.setToolTipText( CommonUIUtils.getTextValue( getText() ) ); } /** * Returns the text for this action. * <p> * This method is associated with the <code>TEXT</code> property; * property change events are reported when its value changes. * </p> * * @return the text, or <code>null</code> if none */ public abstract String getText(); /** * Returns the image for this action as an image descriptor. * <p> * This method is associated with the <code>IMAGE</code> property; * property change events are reported when its value changes. * </p> * * @return the image, or <code>null</code> if this action has no image */ public abstract ImageDescriptor getImageDescriptor(); /** * Returns the command identifier. * * @return the command identifier */ public abstract String getCommandId(); /** * Returns whether this action is enabled. * <p> * This method is associated with the <code>ENABLED</code> property; * property change events are reported when its value changes. * </p> * * @return <code>true</code> if enabled, and * <code>false</code> if disabled */ public abstract boolean isEnabled(); /** * Runs this action. * Each action implementation must define the steps needed to carry out this action. * The default implementation of this method in <code>Action</code> * does nothing. */ public abstract void run(); /** * Returns weather this action is checked. * The default implementations returns false. * * @return */ public boolean isChecked() { return false; } /** * Initializes this action */ private void init() { this.selectedConnections = new Connection[0]; this.selectedConnectionFolders = new ConnectionFolder[0]; this.input = null; } /** * {@inheritDoc} */ public void dispose() { this.selectedConnections = new Connection[0]; this.selectedConnectionFolders = new ConnectionFolder[0]; this.input = null; } /** * Returns the current active shell * * @return the current active shell */ protected Shell getShell() { return PlatformUI.getWorkbench().getDisplay().getActiveShell(); } /** * Gets the selected Connections. * * @return the selected Connections */ public Connection[] getSelectedConnections() { return selectedConnections; } /** * Sets the selected Connections. * * @param selectedConnections the selected Connections to set */ public void setSelectedConnections( Connection[] selectedConnections ) { this.selectedConnections = selectedConnections; } /** * Gets the selected connection folders. * * @return the selected connection folders */ public ConnectionFolder[] getSelectedConnectionFolders() { return selectedConnectionFolders; } /** * Sets the selected connection folders. * * @param selectedConnectionFolders the selected connections folders to set */ public void setSelectedConnectionFolders( ConnectionFolder[] selectedConnectionFolders ) { this.selectedConnectionFolders = selectedConnectionFolders; } /** * Gets the input. * * @return the input */ public Object getInput() { return input; } /** * Sets the input. * * @param input the input to set */ public void setInput( Object input ) { this.input = input; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/OpenConnectionAction.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/OpenConnectionAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.jobs.OpenConnectionsRunnable; import org.apache.directory.studio.connection.core.jobs.StudioConnectionJob; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.jface.resource.ImageDescriptor; /** * This Action opens a Connection. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenConnectionAction extends StudioAction { /** * {@inheritDoc} */ public void run() { new StudioConnectionJob( new OpenConnectionsRunnable( getSelectedConnections() ) ).execute(); } /** * {@inheritDoc} */ public String getText() { if ( getSelectedConnections().length > 1 ) { return Messages.getString( "OpenConnectionAction.OpenConnections" ); } else { return Messages.getString( "OpenConnectionAction.OpenConnection" ); //$NON-NLS-1$ //$NON-NLS-2$ } } /** * {@inheritDoc} */ public ImageDescriptor getImageDescriptor() { return ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_CONNECTION_CONNECT ); } /** * {@inheritDoc} */ public String getCommandId() { return null; } /** * {@inheritDoc} */ public boolean isEnabled() { boolean canOpen = false; for ( Connection connection : getSelectedConnections() ) { if ( !connection.getConnectionWrapper().isConnected() ) { canOpen = true; break; } } return getSelectedConnections().length > 0 && canOpen; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/ExpandAllAction.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/ExpandAllAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.TreeViewer; /** * This action expands all nodes of the viewer's tree, starting with the root. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExpandAllAction extends Action { /** The Tree viewer */ protected TreeViewer viewer; /** * Creates a new instance of ExpandAllAction. * * @param viewer the attached Viewer */ public ExpandAllAction( TreeViewer viewer ) { super( Messages.getString( "ExpandAllAction.ExpandAll" ), ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_EXPANDALL ) ); //$NON-NLS-1$ setToolTipText( getText() ); setEnabled( true ); this.viewer = viewer; } /** * {@inheritDoc} */ @Override public void run() { viewer.expandAll(); } /** * {@inheritDoc} */ public void dispose() { viewer = null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CollapseAllAction.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/actions/CollapseAllAction.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.actions; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.TreeViewer; /** * This action collapses all nodes of the viewer's tree, starting with the root. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CollapseAllAction extends Action { /** The Tree viewer */ protected TreeViewer viewer; /** * Creates a new instance of CollapseAllAction. * * @param viewer the attached Viewer */ public CollapseAllAction( TreeViewer viewer ) { super( Messages.getString( "CollapseAllAction.CollapseAll" ), ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_COLLAPSEALL ) ); //$NON-NLS-1$ setToolTipText( getText() ); setEnabled( true ); this.viewer = viewer; } /** * {@inheritDoc} */ @Override public void run() { this.viewer.collapseAll(); } /** * Disposes the action delegate. */ public void dispose() { this.viewer = null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/properties/Messages.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/properties/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.properties; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * A private constructor : this is an utility class */ private Messages() { } /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/properties/ConnectionPropertyPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.properties; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.core.PasswordsKeyStoreManager; import org.apache.directory.studio.connection.core.Utils; import org.apache.directory.studio.connection.core.jobs.CloseConnectionsRunnable; import org.apache.directory.studio.connection.core.jobs.StudioConnectionJob; import org.apache.directory.studio.connection.ui.ConnectionParameterPage; import org.apache.directory.studio.connection.ui.ConnectionParameterPageManager; import org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.PasswordsKeyStoreManagerUtils; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.PropertyPage; /** * The ConnectionPropertyPage displays the properties of a {@link Connection}, in a popup containing * tabs : * * <pre> * +-------------------------------------------------------------------------------------+ * | Connection <- -> v | * +-------------------------------------------------------------------------------------+ * | .-------------------.----------------.-----------------.--------------. | * | .-----| Network Parameter | Authentication | Browser Options | edit Options |-----. | * | | `-------------------'----------------'-----------------'--------------' | | * | | | | * ....................................................................................... * | | | | * | `---------------------------------------------------------------------------------' | * | [] Read-Only (prevents any add, delete, modify or rename operations | * +-------------------------------------------------------------------------------------+ * * </pe> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionPropertyPage extends PropertyPage implements ConnectionParameterPageModifyListener { /** The tab folder. */ private TabFolder tabFolder; /** The connection property pages. */ private ConnectionParameterPage[] pages; /** * Creates a new instance of ConnectionPropertyPage. */ public ConnectionPropertyPage() { super(); super.noDefaultAndApplyButton(); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#connectionParameterPageModified() */ public void connectionParameterPageModified() { validate(); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#getTestConnectionParameters() */ public ConnectionParameter getTestConnectionParameters() { ConnectionParameter connectionParameter = new ConnectionParameter(); for ( ConnectionParameterPage page : pages ) { page.saveParameters( connectionParameter ); } return connectionParameter; } /** * @see org.eclipse.jface.dialogs.DialogPage#setMessage(java.lang.String) */ @Override public void setMessage( String message ) { super.setMessage( message, PropertyPage.WARNING ); } /** * Validates the dialog. */ private void validate() { int index = tabFolder.getSelectionIndex(); if ( index >= 0 ) { ConnectionParameterPage page = pages[tabFolder.getSelectionIndex()]; if ( page.getMessage() != null ) { setMessage( page.getMessage() ); } else if ( page.getInfoMessage() != null ) { setMessage( page.getInfoMessage() ); } else { setMessage( null ); } if ( page.getErrorMessage() != null ) { setErrorMessage( page.getErrorMessage() ); } setValid( page.isValid() ); } else { for ( ConnectionParameterPage page : pages ) { if ( page.getMessage() != null ) { setMessage( page.getMessage() ); } else if ( page.getInfoMessage() != null ) { setMessage( page.getInfoMessage() ); } else { setMessage( null ); } if ( page.getErrorMessage() != null ) { setErrorMessage( page.getErrorMessage() ); setValid( page.isValid() ); return; } } setMessage( null ); setErrorMessage( null ); setValid( true ); } } static Connection getConnection( Object element ) { Connection connection = null; if ( element instanceof IAdaptable ) { connection = ( ( IAdaptable ) element ).getAdapter( Connection.class ); } return connection; } /** * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) */ protected Control createContents( Composite parent ) { PlatformUI.getWorkbench().getHelpSystem().setHelp( parent, ConnectionUIConstants.PLUGIN_ID + "." + "tools_connection_properties" ); //$NON-NLS-1$ //$NON-NLS-2$ // Checking of the connection passwords keystore is enabled if ( PasswordsKeyStoreManagerUtils.isPasswordsKeystoreEnabled() ) { // Getting the passwords keystore manager PasswordsKeyStoreManager passwordsKeyStoreManager = ConnectionCorePlugin.getDefault() .getPasswordsKeyStoreManager(); // Checking if the keystore is not loaded // Asking the user to load the keystore if ( !passwordsKeyStoreManager.isLoaded() && !PasswordsKeyStoreManagerUtils.askUserToLoadKeystore() ) { // The user failed to load the keystore and cancelled return BaseWidgetUtils .createLabel( parent, Messages .getString( "ConnectionPropertyPage.AccessToPasswordsKeystoreRequiredToViewProperties" ), 1 ); //$NON-NLS-1$ } } // Select the connection in the tree Connection connection = getConnection( getElement() ); if ( connection != null ) { // Create the tabs for this connection super .setMessage( Messages.getString( "ConnectionPropertyPage.Connection" ) + Utils.shorten( connection.getName(), 30 ) ); //$NON-NLS-1$ pages = ConnectionParameterPageManager.getConnectionParameterPages(); tabFolder = new TabFolder( parent, SWT.TOP ); TabItem[] tabs = new TabItem[pages.length]; for ( int i = 0; i < pages.length; i++ ) { Composite composite = new Composite( tabFolder, SWT.NONE ); GridLayout gl = new GridLayout( 1, false ); composite.setLayout( gl ); pages[i].init( composite, this, connection.getConnectionParameter() ); tabs[i] = new TabItem( tabFolder, SWT.NONE ); tabs[i].setText( pages[i].getPageName() ); tabs[i].setControl( composite ); } return tabFolder; } else { return BaseWidgetUtils.createLabel( parent, Messages.getString( "ConnectionPropertyPage.NoConnection" ), 1 ); //$NON-NLS-1$ } } /** * @see org.eclipse.jface.preference.PreferencePage#performOk() */ public boolean performOk() { // Checking of the connection passwords keystore is enabled if ( PasswordsKeyStoreManagerUtils.isPasswordsKeystoreEnabled() ) { // Checking if the keystore is not loaded if ( !ConnectionCorePlugin.getDefault().getPasswordsKeyStoreManager().isLoaded() ) { return true; } } // get current connection parameters Connection connection = getConnection( getElement() ); // save modified parameters boolean parametersModified = false; boolean reconnectionRequired = false; ConnectionParameter connectionParameter = new ConnectionParameter(); connectionParameter.setId( connection.getConnectionParameter().getId() ); for ( ConnectionParameterPage page : pages ) { page.saveParameters( connectionParameter ); page.saveDialogSettings(); parametersModified |= page.areParametersModifed(); reconnectionRequired |= page.isReconnectionRequired(); } if ( parametersModified ) { // update connection parameters connection.setConnectionParameter( connectionParameter ); if ( reconnectionRequired ) { // close connection new StudioConnectionJob( new CloseConnectionsRunnable( connection ) ).execute(); } } return true; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateListComposite.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import java.io.ByteArrayInputStream; import java.io.File; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.Iterator; import org.apache.directory.api.util.FileUtils; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.StudioKeyStoreManager; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.apache.directory.studio.connection.ui.dialogs.CertificateInfoDialog; import org.apache.directory.studio.connection.ui.wizards.ExportCertificateWizard; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; /** * This composite displays a list of certificates and buttons * to add, delete and view certificates : * * <pre> * +-------------------------------------------------+ * | +------------------------------------+ | * | | abc | (View) | * | | xyz | (Add) | * | | | (Remove) | * | | | (Export) | * | +------------------------------------+ | * +-------------------------------------------------+ * </pre> * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CertificateListComposite extends Composite { /** The KeyStore wrapper */ private StudioKeyStoreManager keyStoreManager; /** The table containing the KeyStore elements */ private TableViewer tableViewer; /** The View action button */ private Button viewButton; /** The Add action button */ private Button addButton; /** The Remove action button */ private Button removeButton; /** The Export action button */ private Button exportButton; /** * The listener called when the table selection has changed */ private ISelectionChangedListener tableViewerSelectionListener = event -> { // Enable and disable the button accordingly to the selection : // - 1 line selected : enable remove, view and export // - N lines selected : enable remove, disable view and export // - nothing selected, disable view, remove and exprt viewButton.setEnabled( ( ( IStructuredSelection ) event.getSelection() ).size() == 1 ); removeButton.setEnabled( !event.getSelection().isEmpty() ); exportButton.setEnabled( ( ( IStructuredSelection ) event.getSelection() ).size() == 1 ); }; /** * The listener called when a line is double-clicked in the table : we will * open the Certificate dialog. */ private IDoubleClickListener tableViewerDoubleClickListener = event -> openCertificate( event.getSelection() ); /** * A selection listener on the View button : we will open the Certificate Dialog */ private SelectionAdapter viewButtonSelectionListener = new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { openCertificate( tableViewer.getSelection() ); } }; /** * A selection listener on the Add button : we will open the File Dialog * and let the user select the KeyStore location to add in the table */ private SelectionAdapter addButtonSelectionListener = new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { // Asking the user for the certificate file FileDialog dialog = new FileDialog( getShell(), SWT.OPEN ); dialog.setText( Messages.getString( "CertificateListComposite.LoadCertificate" ) ); //$NON-NLS-1$ String returnedFileName = dialog.open(); if ( returnedFileName != null ) { try { // Reading the certificate X509Certificate certificate = generateCertificate( FileUtils.readFileToByteArray( new File( returnedFileName ) ) ); // Adding the certificate keyStoreManager.addCertificate( certificate ); // Refreshing the table viewer tableViewer.refresh(); tableViewer.setSelection( new StructuredSelection( certificate ) ); } catch ( Exception ex ) { MessageDialog.openError( addButton.getShell(), Messages.getString( "CertificateListComposite.ErrorDialogTitle" ), //$NON-NLS-1$ NLS.bind( Messages.getString( "CertificateListComposite.ErrorDialogMessage" ), //$NON-NLS-1$ ex.getMessage() ) ); } } } }; /** * A selection listener on the Remove button. */ private SelectionAdapter removeButtonSelectionListener = new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { IStructuredSelection selection = ( IStructuredSelection ) tableViewer.getSelection(); Iterator<?> iterator = selection.iterator(); while ( iterator.hasNext() ) { X509Certificate certificate = ( X509Certificate ) iterator.next(); try { keyStoreManager.removeCertificate( certificate ); } catch ( CertificateException ce ) { throw new RuntimeException( ce ); } } tableViewer.refresh(); } }; /** * A selection listener on the Export button. We will open the Export wizard. */ private SelectionAdapter exportButtonSelectionListener = new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { X509Certificate certificate = ( X509Certificate ) ( ( IStructuredSelection ) tableViewer.getSelection() ) .getFirstElement(); WizardDialog dialog = new WizardDialog( getShell(), new ExportCertificateWizard( certificate ) ); dialog.open(); } }; /** * Creates a new instance of CertificateInfoComposite. * * @param parent The paren'ts composite * @param style The widget's style */ public CertificateListComposite( Composite parent, int style ) { super( parent, style ); GridLayout layout = new GridLayout( 1, false ); layout.marginWidth = 0; layout.marginHeight = 0; setLayout( layout ); setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); Composite container = new Composite( this, SWT.NONE ); layout = new GridLayout( 2, false ); container.setLayout( layout ); container.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); // Create the Table Viewer tableViewer = new TableViewer( container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true ); gridData.widthHint = 360; gridData.heightHint = 10; tableViewer.getTable().setLayoutData( gridData ); tableViewer.setContentProvider( new KeyStoreContentProvider() ); tableViewer.setLabelProvider( new KeyStoreLabelProvider() ); tableViewer.addSelectionChangedListener( tableViewerSelectionListener ); tableViewer.addDoubleClickListener( tableViewerDoubleClickListener ); createButtons( container ); } /** * Creates the 4 buttons for this widget : * * <pre> * (view) * (Add) * (Remove) * (Export) * </pre> */ private void createButtons( Composite container ) { Composite buttonContainer = BaseWidgetUtils.createColumnContainer( container, 1, 1 ); buttonContainer.setLayoutData( new GridData( GridData.FILL, GridData.FILL, false, false ) ); // The View Button viewButton = BaseWidgetUtils.createButton( buttonContainer, Messages .getString( "CertificateListComposite.ViewButton" ), 1 );//$NON-NLS-1$ viewButton.setEnabled( false ); viewButton.addSelectionListener( viewButtonSelectionListener ); // The Add button addButton = BaseWidgetUtils.createButton( buttonContainer, Messages .getString( "CertificateListComposite.AddButton" ), 1 ); //$NON-NLS-1$ addButton.addSelectionListener( addButtonSelectionListener ); // The remove button removeButton = BaseWidgetUtils.createButton( buttonContainer, Messages .getString( "CertificateListComposite.RemoveButton" ), 1 ); //$NON-NLS-1$ removeButton.setEnabled( false ); removeButton.addSelectionListener( removeButtonSelectionListener ); // The export button exportButton = BaseWidgetUtils.createButton( buttonContainer, Messages .getString( "CertificateListComposite.ExportButton" ), 1 ); //$NON-NLS-1$ exportButton.setEnabled( false ); exportButton.addSelectionListener( exportButtonSelectionListener ); } /** * Creates a certificate from a byte[]. */ private static X509Certificate generateCertificate( byte[] data ) throws CertificateException { CertificateFactory certificateFactory = CertificateFactory.getInstance( "X.509" ); //$NON-NLS-1$ Certificate certificate = certificateFactory.generateCertificate( new ByteArrayInputStream( data ) ); if ( certificate instanceof X509Certificate ) { return ( X509Certificate ) certificate; } return null; } /** * Sets the input for this composite. * * @param keyStoreManager the key store manager */ public void setInput( StudioKeyStoreManager keyStoreManager ) { this.keyStoreManager = keyStoreManager; tableViewer.setInput( keyStoreManager ); } /** * This class is used to give back the content of teh Table viewer */ private class KeyStoreContentProvider implements IStructuredContentProvider { /** * Gets the list of Certificates stored into the selected KeyStore * {@inheritDoc} */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof StudioKeyStoreManager ) { try { return ( ( StudioKeyStoreManager ) inputElement ).getCertificates(); } catch ( CertificateException e ) { throw new RuntimeException( e ); } } return new Object[] {}; } /** * {@inheritDoc} */ @Override public void dispose() { } /** * {@inheritDoc} */ @Override public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } } /** * This helper class is used to decorate the elements in the table : we use the certificate name if any. * @author elecharny * */ class KeyStoreLabelProvider extends LabelProvider { /** * {@inheritDoc} */ @Override public String getText( Object element ) { if ( element instanceof X509Certificate ) { X509Certificate certificate = ( X509Certificate ) element; String certificateName = certificate.getSubjectX500Principal().getName(); if ( Strings.isEmpty( certificateName ) ) { return Messages.getString( "CertificateListComposite.UntitledCertificate" ); //$NON-NLS-1$ } else { return certificateName; } } return super.getText( element ); } /** * {@inheritDoc} */ @Override public Image getImage( Object element ) { if ( element instanceof X509Certificate ) { return ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CERTIFICATE ); } return super.getImage( element ); } } /** * A private method that opens the Certificate Dialog * @param selection */ private void openCertificate( ISelection selection ) { IStructuredSelection structuredSelection = ( IStructuredSelection ) selection; X509Certificate certificate = ( X509Certificate ) structuredSelection.getFirstElement(); new CertificateInfoDialog( getShell(), new X509Certificate[] { certificate } ).open(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionLabelProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import org.apache.commons.lang3.StringUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; /** * The ConnectionLabelProvider represents the label provider for * the connection widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionLabelProvider extends LabelProvider { /** * {@inheritDoc} * * This implementation returns the connection name and appends information * about the used encryption method. */ @Override public String getText( Object obj ) { if ( obj instanceof ConnectionFolder ) { ConnectionFolder folder = ( ConnectionFolder ) obj; return folder.getName(); } if ( obj instanceof Connection ) { Connection conn = ( Connection ) obj; boolean isConnected = conn.getConnectionWrapper().isConnected(); boolean isSecured = conn.getConnectionWrapper().isSecured(); String unsecuredWarning = isConnected && !isSecured ? " UNSECURED! " : ""; //$NON-NLS-1$ //$NON-NLS-2$ if ( conn.getEncryptionMethod() == EncryptionMethod.LDAPS ) { return conn.getName() + unsecuredWarning + " (LDAPS)"; //$NON-NLS-1$ } else if ( conn.getEncryptionMethod() == EncryptionMethod.START_TLS ) { return conn.getName() + unsecuredWarning + " (StartTLS)"; //$NON-NLS-1$ } else { return conn.getName(); } } else if ( obj == null ) { return StringUtils.EMPTY; //$NON-NLS-1$ } else { return obj.toString(); } } /** * {@inheritDoc} * * This implementation returns a icon for connected or disconnected state. */ @Override public Image getImage( Object obj ) { if ( obj instanceof ConnectionFolder ) { return ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CONNECTION_FOLDER ); } else if ( obj instanceof Connection ) { Connection conn = ( Connection ) obj; boolean isConnected = conn.getConnectionWrapper().isConnected(); boolean isSecured = conn.getConnectionWrapper().isSecured(); boolean isEncryptionConfigured = conn.getEncryptionMethod().isEncrytped(); if ( isConnected ) { return isSecured ? ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CONNECTION_SSL_CONNECTED ) : ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CONNECTION_CONNECTED ); } else { return isEncryptionConfigured ? ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CONNECTION_SSL_DISCONNECTED ) : ConnectionUIPlugin.getDefault().getImage( ConnectionUIConstants.IMG_CONNECTION_DISCONNECTED ); } } else { return null; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import org.apache.directory.studio.common.ui.widgets.ViewFormWidget; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Tree; import org.eclipse.ui.IActionBars; /** * The ConnectionWidget is a reusable widget that displays all connections * in a table viewer. It is used by * org.apache.directory.studio.ldapbrowser.ui.views.connection.ConnectionView, * org.apache.directory.studio.ldapbrowser.common.dialogs.SelectConnectionDialog and * org.apache.directory.studio.ldapbrowser.common.dialogs.SelectReferralConnectionDialog. * * It includes a content and label provider to display connections with a nice icon. * * Further is provides a context menu and a local toolbar with actions to * add, modify, delete, open and close connections. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionWidget extends ViewFormWidget { /** The widget's configuration with the content provider, label provider and menu manager */ private ConnectionConfiguration configuration; /** The action bars */ private IActionBars actionBars; /** The tree widget used by the tree viewer */ private Tree tree; /** The tree viewer */ private TreeViewer viewer; /** * Creates a new instance of ConnectionWidget. * * @param configuration the configuration * @param actionBars the action bars */ public ConnectionWidget( ConnectionConfiguration configuration, IActionBars actionBars ) { super(); this.configuration = configuration; this.actionBars = actionBars; } /** * {@inheritDoc} */ @Override public void createWidget( Composite parent ) { if ( actionBars == null ) { super.createWidget( parent ); } else { createContent( parent ); } } /** * {@inheritDoc} */ @Override public IToolBarManager getToolBarManager() { if ( actionBars == null ) { return super.getToolBarManager(); } else { return actionBars.getToolBarManager(); } } /** * {@inheritDoc} */ @Override public IMenuManager getMenuManager() { if ( actionBars == null ) { return super.getMenuManager(); } else { return actionBars.getMenuManager(); } } /** * {@inheritDoc} */ @Override public IMenuManager getContextMenuManager() { if ( actionBars == null ) { return super.getContextMenuManager(); } else { return configuration.getContextMenuManager( viewer ); } } /** * {@inheritDoc} */ protected Control createContent( Composite parent ) { tree = new Tree( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER ); GridData data = new GridData( GridData.FILL_BOTH ); data.widthHint = 450; data.heightHint = 250; tree.setLayoutData( data ); viewer = new TreeViewer( tree ); // setup sorter configuration.getSorter().connect( viewer ); // setup providers viewer.setContentProvider( configuration.getContentProvider( viewer ) ); viewer.setLabelProvider( configuration.getLabelProvider( viewer ) ); return tree; } /** * Sets the input to the table viewer. * * @param input the input */ public void setInput( Object input ) { viewer.setInput( input ); } /** * Sets focus to the table viewer. */ public void setFocus() { viewer.getTree().setFocus(); } /** * {@inheritDoc} */ @Override public void dispose() { if ( viewer != null ) { configuration.dispose(); configuration = null; tree.dispose(); tree = null; viewer = null; } } /** * Gets the tree viewer. * * @return the tree viewer */ public TreeViewer getViewer() { return viewer; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionActionGroup.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.actions.ActionHandlerManager; import org.apache.directory.studio.connection.ui.actions.CloseConnectionAction; import org.apache.directory.studio.connection.ui.actions.CollapseAllAction; import org.apache.directory.studio.connection.ui.actions.ConnectionViewActionProxy; import org.apache.directory.studio.connection.ui.actions.CopyAction; import org.apache.directory.studio.connection.ui.actions.DeleteAction; import org.apache.directory.studio.connection.ui.actions.ExpandAllAction; import org.apache.directory.studio.connection.ui.actions.NewConnectionAction; import org.apache.directory.studio.connection.ui.actions.NewConnectionFolderAction; import org.apache.directory.studio.connection.ui.actions.OpenConnectionAction; import org.apache.directory.studio.connection.ui.actions.PasteAction; import org.apache.directory.studio.connection.ui.actions.PropertiesAction; import org.apache.directory.studio.connection.ui.actions.RenameAction; import org.apache.directory.studio.connection.ui.actions.StudioActionProxy; import org.apache.directory.studio.connection.ui.dnd.ConnectionTransfer; import org.apache.directory.studio.connection.ui.dnd.DragConnectionListener; import org.apache.directory.studio.connection.ui.dnd.DropConnectionListener; import org.apache.directory.studio.utils.ActionUtils; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.Transfer; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionFactory; /** * This class manages all the actions of the connection widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionActionGroup implements ActionHandlerManager, IMenuListener { /** The collapse all action. */ private CollapseAllAction collapseAllAction; /** The expand all action. */ private ExpandAllAction expandAllAction; /** The Constant newConnectionAction. */ protected static final String NEW_CONNECTION_ACTION = "newConnectionAction"; //$NON-NLS-1$ /** The Constant newConnectionFolderAction. */ protected static final String NEW_CONNECTION_FOLDER_ACTION = "newConnectionFolderAction"; //$NON-NLS-1$ /** The Constant openConnectionAction. */ protected static final String OPEN_CONNECTION_ACTION = "openConnectionAction"; //$NON-NLS-1$ /** The Constant closeConnectionAction. */ protected static final String CLOSE_CONNECTION_ACTION = "closeConnectionAction"; //$NON-NLS-1$ /** The Constant copyConnectionAction. */ protected static final String COPY_CONNECTION_ACTION = "copyConnectionAction"; //$NON-NLS-1$ /** The Constant pasteConnectionAction. */ protected static final String PASTE_CONNECTION_ACTION = "pasteConnectionAction"; //$NON-NLS-1$ /** The Constant deleteConnectionAction. */ protected static final String DELETE_CONNECTION_ACTION = "deleteConnectionAction"; //$NON-NLS-1$ /** The Constant renameConnectionAction. */ protected static final String RENAME_CONNECTION_ACTION = "renameConnectionAction"; //$NON-NLS-1$ /** The Constant propertyDialogAction. */ protected static final String PROPERTY_DIALOG_ACTION = "propertyDialogAction"; //$NON-NLS-1$ /** The drag connection listener. */ private DragConnectionListener dragConnectionListener; /** The drop connection listener. */ private DropConnectionListener dropConnectionListener; /** The action map. */ protected Map<String, ConnectionViewActionProxy> connectionActionMap; /** The action bars. */ protected IActionBars actionBars; /** The connection main widget. */ protected ConnectionWidget mainWidget; /** * Creates a new instance of ConnectionActionGroup. * * @param mainWidget the connection main widget * @param configuration the connection widget configuration */ public ConnectionActionGroup( ConnectionWidget mainWidget, ConnectionConfiguration configuration ) { this.mainWidget = mainWidget; TreeViewer viewer = mainWidget.getViewer(); collapseAllAction = new CollapseAllAction( viewer ); expandAllAction = new ExpandAllAction( viewer ); connectionActionMap = new HashMap<>(); connectionActionMap.put( NEW_CONNECTION_ACTION, new ConnectionViewActionProxy( viewer, this, new NewConnectionAction() ) ); connectionActionMap.put( NEW_CONNECTION_FOLDER_ACTION, new ConnectionViewActionProxy( viewer, this, new NewConnectionFolderAction() ) ); connectionActionMap.put( OPEN_CONNECTION_ACTION, new ConnectionViewActionProxy( viewer, this, new OpenConnectionAction() ) ); connectionActionMap.put( CLOSE_CONNECTION_ACTION, new ConnectionViewActionProxy( viewer, this, new CloseConnectionAction() ) ); connectionActionMap .put( PASTE_CONNECTION_ACTION, new ConnectionViewActionProxy( viewer, this, new PasteAction() ) ); connectionActionMap.put( COPY_CONNECTION_ACTION, new ConnectionViewActionProxy( viewer, this, new CopyAction( ( StudioActionProxy ) connectionActionMap.get( PASTE_CONNECTION_ACTION ) ) ) ); connectionActionMap.put( DELETE_CONNECTION_ACTION, new ConnectionViewActionProxy( viewer, this, new DeleteAction() ) ); connectionActionMap.put( RENAME_CONNECTION_ACTION, new ConnectionViewActionProxy( viewer, this, new RenameAction() ) ); connectionActionMap.put( PROPERTY_DIALOG_ACTION, new ConnectionViewActionProxy( viewer, this, new PropertiesAction() ) ); // DND support dropConnectionListener = new DropConnectionListener(); dragConnectionListener = new DragConnectionListener( viewer ); int ops = DND.DROP_COPY | DND.DROP_MOVE; Transfer[] transfers = new Transfer[] { ConnectionTransfer.getInstance() }; viewer.addDragSupport( ops, transfers, dragConnectionListener ); viewer.addDropSupport( ops, transfers, dropConnectionListener ); } /** * Disposes this action group. */ public void dispose() { if ( mainWidget != null ) { for ( Iterator<String> it = connectionActionMap.keySet().iterator(); it.hasNext(); ) { String key = it.next(); ConnectionViewActionProxy action = this.connectionActionMap.get( key ); action.dispose(); it.remove(); } collapseAllAction.dispose(); collapseAllAction = null; expandAllAction.dispose(); expandAllAction = null; connectionActionMap.clear(); connectionActionMap = null; actionBars = null; mainWidget = null; dragConnectionListener = null; dropConnectionListener = null; } } /** * Enables the action handlers. * * @param actionBars the action bars */ public void enableGlobalActionHandlers( IActionBars actionBars ) { this.actionBars = actionBars; activateGlobalActionHandlers(); } /** * Fills the tool bar. * * @param toolBarManager the tool bar manager */ public void fillToolBar( IToolBarManager toolBarManager ) { toolBarManager.add( ( IAction ) this.connectionActionMap.get( NEW_CONNECTION_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( ( IAction ) this.connectionActionMap.get( OPEN_CONNECTION_ACTION ) ); toolBarManager.add( ( IAction ) this.connectionActionMap.get( CLOSE_CONNECTION_ACTION ) ); toolBarManager.add( new Separator() ); toolBarManager.add( expandAllAction ); toolBarManager.add( collapseAllAction ); toolBarManager.update( true ); } /** * Fills the local menu. * * @param menuManager the local menu manager */ public void fillMenu( IMenuManager menuManager ) { } /** * Fills the context menu. * * @param menuManager the context menu manager */ public void fillContextMenu( IMenuManager menuManager ) { menuManager.setRemoveAllWhenShown( true ); menuManager.addMenuListener( this ); } /** * {@inheritDoc} * * This implementation fills the context menu. */ public void menuAboutToShow( IMenuManager menuManager ) { // add menuManager.add( ( IAction ) connectionActionMap.get( NEW_CONNECTION_ACTION ) ); menuManager.add( ( IAction ) connectionActionMap.get( NEW_CONNECTION_FOLDER_ACTION ) ); menuManager.add( new Separator() ); // open/close if ( ( connectionActionMap.get( CLOSE_CONNECTION_ACTION ) ).isEnabled() ) { menuManager.add( ( IAction ) connectionActionMap.get( CLOSE_CONNECTION_ACTION ) ); } else if ( ( connectionActionMap.get( OPEN_CONNECTION_ACTION ) ).isEnabled() ) { menuManager.add( ( IAction ) connectionActionMap.get( OPEN_CONNECTION_ACTION ) ); } menuManager.add( new Separator() ); // copy/paste/... menuManager.add( ( IAction ) connectionActionMap.get( COPY_CONNECTION_ACTION ) ); menuManager.add( ( IAction ) connectionActionMap.get( PASTE_CONNECTION_ACTION ) ); menuManager.add( ( IAction ) connectionActionMap.get( DELETE_CONNECTION_ACTION ) ); menuManager.add( ( IAction ) connectionActionMap.get( RENAME_CONNECTION_ACTION ) ); menuManager.add( new Separator() ); // additions menuManager.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); menuManager.add( new Separator() ); // properties menuManager.add( ( IAction ) connectionActionMap.get( PROPERTY_DIALOG_ACTION ) ); } /** * Activates the action handlers. */ public void activateGlobalActionHandlers() { if ( actionBars == null ) { IAction copyConnectionAction = connectionActionMap.get( COPY_CONNECTION_ACTION ); copyConnectionAction.setActionDefinitionId( ConnectionUIConstants.CMD_COPY ); ActionUtils.activateActionHandler( copyConnectionAction ); IAction pasteConnectionAction = connectionActionMap.get( PASTE_CONNECTION_ACTION ); pasteConnectionAction.setActionDefinitionId( ConnectionUIConstants.CMD_PASTE ); ActionUtils.activateActionHandler( pasteConnectionAction ); IAction deleteConnectionAction = connectionActionMap.get( DELETE_CONNECTION_ACTION ); deleteConnectionAction.setActionDefinitionId( ConnectionUIConstants.CMD_DELETE ); ActionUtils.activateActionHandler( deleteConnectionAction ); IAction propertyDialogAction = connectionActionMap.get( PROPERTY_DIALOG_ACTION ); propertyDialogAction.setActionDefinitionId( ConnectionUIConstants.CMD_PROPERTIES ); ActionUtils.activateActionHandler( propertyDialogAction ); } else { actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), ( IAction ) connectionActionMap .get( COPY_CONNECTION_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), ( IAction ) connectionActionMap .get( PASTE_CONNECTION_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), ( IAction ) connectionActionMap .get( DELETE_CONNECTION_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.RENAME.getId(), ( IAction ) connectionActionMap .get( RENAME_CONNECTION_ACTION ) ); actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), ( IAction ) connectionActionMap .get( PROPERTY_DIALOG_ACTION ) ); actionBars.updateActionBars(); } } /** * Deactivates the action handlers. */ public void deactivateGlobalActionHandlers() { if ( actionBars == null ) { IAction copyConnectionAction = connectionActionMap.get( COPY_CONNECTION_ACTION ); ActionUtils.deactivateActionHandler( copyConnectionAction ); IAction pasteConnectionAction = connectionActionMap.get( PASTE_CONNECTION_ACTION ); ActionUtils.deactivateActionHandler( pasteConnectionAction ); IAction deleteConnectionAction = connectionActionMap.get( DELETE_CONNECTION_ACTION ); ActionUtils.deactivateActionHandler( deleteConnectionAction ); IAction propertyDialogAction = connectionActionMap.get( PROPERTY_DIALOG_ACTION ); ActionUtils.deactivateActionHandler( propertyDialogAction ); } else { actionBars.setGlobalActionHandler( ActionFactory.COPY.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.PASTE.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.DELETE.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.RENAME.getId(), null ); actionBars.setGlobalActionHandler( ActionFactory.PROPERTIES.getId(), null ); actionBars.updateActionBars(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ExtendedContentAssistCommandAdapter.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ExtendedContentAssistCommandAdapter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import org.eclipse.jface.fieldassist.ContentProposalAdapter; import org.eclipse.jface.fieldassist.IContentProposalProvider; import org.eclipse.jface.fieldassist.IControlContentAdapter; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; /** * The ExtendedContentAssistCommandAdapter extends the ContentAssistCommandAdapter * and provides public {@link #closeProposalPopup()} and {@link #openProposalPopup()} * methods for more controls when proposal popup is opened and closed. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExtendedContentAssistCommandAdapter extends ContentAssistCommandAdapter { /** * Creates a new instance of ExtendedContentAssistCommandAdapter * with the following settings: * <ul> * <li>setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE )</li> * <li>setFilterStyle( ContentProposalAdapter.FILTER_NONE )</li> * <li>setAutoActivationCharacters( null )</li> * <li>setAutoActivationDelay( 0 )</li> * </ul> * * @param control the control * @param controlContentAdapter the control content adapter * @param proposalProvider the proposal provider * @param commandId the command id * @param autoActivationCharacters the auto activation characters * @param installDecoration the install decoration */ public ExtendedContentAssistCommandAdapter( Control control, IControlContentAdapter controlContentAdapter, IContentProposalProvider proposalProvider, String commandId, char[] autoActivationCharacters, boolean installDecoration ) { super( control, controlContentAdapter, proposalProvider, commandId, autoActivationCharacters, installDecoration ); setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE ); setFilterStyle( ContentProposalAdapter.FILTER_NONE ); setAutoActivationCharacters( null ); setAutoActivationDelay( 0 ); } /** * {@inheritDoc} */ @Override public void closeProposalPopup() { super.closeProposalPopup(); } /** * {@inheritDoc} */ @Override public void openProposalPopup() { super.openProposalPopup(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/Messages.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle .getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * Make the constructor private to make this class an utility class */ private Messages() { } /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionContentProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import java.util.ArrayList; import java.util.List; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.apache.directory.studio.connection.core.ConnectionFolderManager; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; /** * The ConnectionContentProvider represents the content provider for * the connection widget. It accepts the ConnectionManager as input * and returns its connections as elements. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionContentProvider implements ITreeContentProvider { /** * @see org.eclipse.jface.viewers.IContentProvider# * inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) */ @Override public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } /** * @see org.eclipse.jface.viewers.IContentProvider#dispose() */ @Override public void dispose() { } /** * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) */ public Object[] getElements( Object inputElement ) { if ( inputElement instanceof ConnectionFolderManager ) { ConnectionFolderManager cfm = ( ConnectionFolderManager ) inputElement; ConnectionFolder rootConnectionFolder = cfm.getRootConnectionFolder(); return getChildren( rootConnectionFolder ); } else { return getChildren( inputElement ); } } /** * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) */ public Object[] getChildren( Object parentElement ) { if ( parentElement instanceof ConnectionFolder ) { List<Object> children = new ArrayList<>(); ConnectionFolder folder = ( ConnectionFolder ) parentElement; List<String> subFolderIds = folder.getSubFolderIds(); List<String> connectionIds = folder.getConnectionIds(); for ( String subFolderId : subFolderIds ) { ConnectionFolder subFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager() .getConnectionFolderById( subFolderId ); if ( subFolder != null ) { children.add( subFolder ); } } for ( String connectionId : connectionIds ) { Connection conn = ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionById( connectionId ); if ( conn != null ) { children.add( conn ); } } return children.toArray(); } return null; } /** * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) */ public Object getParent( Object element ) { if ( element instanceof ConnectionFolder ) { return ConnectionCorePlugin.getDefault().getConnectionFolderManager().getParentConnectionFolder( ( ConnectionFolder ) element ); } else if ( element instanceof Connection ) { return ConnectionCorePlugin.getDefault().getConnectionFolderManager().getParentConnectionFolder( ( Connection ) element ); } else { return null; } } /** * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) */ public boolean hasChildren( Object element ) { Object[] children = getChildren( element ); return children != null && children.length > 0; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateInfoComposite.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/CertificateInfoComposite.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import java.io.IOException; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; import java.util.Set; import javax.security.auth.x500.X500Principal; import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.bouncycastle.asn1.ASN1Object; import org.bouncycastle.x509.extension.X509ExtensionUtil; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; /** * This composite contains the tabs with general and detail of an certificate. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CertificateInfoComposite extends Composite { /** The default attributes of an X500Principal: CN, L, ST, O, OU, C, STREET, DC, UID */ private static final String[] ATTRIBUTES = { "CN", //$NON-NLS-1$ "L", //$NON-NLS-1$ "ST", //$NON-NLS-1$ "O", //$NON-NLS-1$ "OU", //$NON-NLS-1$ "C", //$NON-NLS-1$ "STREET", //$NON-NLS-1$ "DC", //$NON-NLS-1$ "UID" //$NON-NLS-1$ }; /** The index of the general tab */ public static final int GENERAL_TAB_INDEX = 0; /** The index of the details tab */ public static final int DETAILS_TAB_INDEX = 1; /** The tab folder */ private TabFolder tabFolder; /** The general tab */ private Text issuedToCN; private Text issuedToO; private Text issuedToOU; private Text serialNumber; private Text issuedByCN; private Text issuedByO; private Text issuedByOU; private Text issuesOn; private Text expiresOn; private Text fingerprintSHA1; private Text fingerprintMD5; private TreeViewer hierarchyTreeViewer; private Tree certificateTree; private Text valueText; /** * Creates a new instance of CertificateInfoComposite. * * @param parent * @param style */ public CertificateInfoComposite( Composite parent, int style ) { super( parent, style ); setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); GridLayout layout = new GridLayout( 1, false ); layout.marginWidth = 0; layout.marginHeight = 0; setLayout( layout ); createTabFolder(); createGeneralTab(); createDetailsTab(); } /** * Creates the tab folder. */ private void createTabFolder() { tabFolder = new TabFolder( this, SWT.TOP ); GridLayout mainLayout = new GridLayout(); mainLayout.marginWidth = 50; mainLayout.marginHeight = 50; tabFolder.setLayout( mainLayout ); tabFolder.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); } /** * Creates the general tab. */ private void createGeneralTab() { // create inner container Composite generalContainer = new Composite( tabFolder, SWT.NONE ); GridLayout currentLayout = new GridLayout( 1, false ); currentLayout.marginHeight = 10; currentLayout.marginWidth = 10; generalContainer.setLayout( currentLayout ); generalContainer.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); // issues to section Group issuedToGroup = BaseWidgetUtils.createGroup( generalContainer, Messages .getString( "CertificateInfoComposite.IssuedToLabel" ), 1 ); //$NON-NLS-1$ issuedToGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); Composite issuedToComposite = BaseWidgetUtils.createColumnContainer( issuedToGroup, 2, 1 ); BaseWidgetUtils.createLabel( issuedToComposite, Messages.getString( "CertificateInfoComposite.CommonNameLabel" ), 1 ); //$NON-NLS-1$ issuedToCN = BaseWidgetUtils.createLabeledText( issuedToComposite, StringUtils.EMPTY, 1 ); BaseWidgetUtils.createLabel( issuedToComposite, Messages .getString( "CertificateInfoComposite.OrganizationLabel" ), 1 ); //$NON-NLS-1$ issuedToO = BaseWidgetUtils.createLabeledText( issuedToComposite, StringUtils.EMPTY, 1 ); BaseWidgetUtils.createLabel( issuedToComposite, Messages .getString( "CertificateInfoComposite.OrganizationalUnitLabel" ), 1 ); //$NON-NLS-1$ issuedToOU = BaseWidgetUtils.createLabeledText( issuedToComposite, StringUtils.EMPTY, 1 ); BaseWidgetUtils.createLabel( issuedToComposite, Messages .getString( "CertificateInfoComposite.SerialNumberLabel" ), 1 ); //$NON-NLS-1$ serialNumber = BaseWidgetUtils.createLabeledText( issuedToComposite, StringUtils.EMPTY, 1 ); // issuer section Group issuedFromGroup = BaseWidgetUtils.createGroup( generalContainer, Messages .getString( "CertificateInfoComposite.IssuedByLabel" ), 1 ); //$NON-NLS-1$ issuedFromGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); Composite issuedFromComposite = BaseWidgetUtils.createColumnContainer( issuedFromGroup, 2, 1 ); BaseWidgetUtils.createLabel( issuedFromComposite, Messages .getString( "CertificateInfoComposite.CommonNameLabel" ), 1 ); //$NON-NLS-1$ issuedByCN = BaseWidgetUtils.createLabeledText( issuedFromComposite, StringUtils.EMPTY, 1 ); BaseWidgetUtils.createLabel( issuedFromComposite, Messages .getString( "CertificateInfoComposite.OrganizationLabel" ), 1 ); //$NON-NLS-1$ issuedByO = BaseWidgetUtils.createLabeledText( issuedFromComposite, StringUtils.EMPTY, 1 ); BaseWidgetUtils.createLabel( issuedFromComposite, Messages .getString( "CertificateInfoComposite.OrganizationalUnitLabel" ), 1 ); //$NON-NLS-1$ issuedByOU = BaseWidgetUtils.createLabeledText( issuedFromComposite, StringUtils.EMPTY, 1 ); // validity section Group validityGroup = BaseWidgetUtils.createGroup( generalContainer, Messages .getString( "CertificateInfoComposite.ValidityLabel" ), 1 ); //$NON-NLS-1$ validityGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); Composite generalComposite = BaseWidgetUtils.createColumnContainer( validityGroup, 2, 1 ); BaseWidgetUtils.createLabel( generalComposite, Messages.getString( "CertificateInfoComposite.IssuedOnLabel" ), 1 ); //$NON-NLS-1$ issuesOn = BaseWidgetUtils.createLabeledText( generalComposite, StringUtils.EMPTY, 1 ); BaseWidgetUtils.createLabel( generalComposite, Messages.getString( "CertificateInfoComposite.ExpiresOnLabel" ), 1 ); //$NON-NLS-1$ expiresOn = BaseWidgetUtils.createLabeledText( generalComposite, StringUtils.EMPTY, 1 ); // fingerprint section Group fingerprintsGroup = BaseWidgetUtils.createGroup( generalContainer, Messages .getString( "CertificateInfoComposite.FingerprintsLabel" ), 1 ); //$NON-NLS-1$ fingerprintsGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); Composite fingerprintsComposite = BaseWidgetUtils.createColumnContainer( fingerprintsGroup, 2, 1 ); BaseWidgetUtils.createLabel( fingerprintsComposite, Messages .getString( "CertificateInfoComposite.SHA1FingerprintLabel" ), 1 ); //$NON-NLS-1$ fingerprintSHA1 = BaseWidgetUtils.createLabeledText( fingerprintsComposite, StringUtils.EMPTY, 1 ); BaseWidgetUtils.createLabel( fingerprintsComposite, Messages .getString( "CertificateInfoComposite.MD5FingerprintLabel" ), 1 ); //$NON-NLS-1$ fingerprintMD5 = BaseWidgetUtils.createLabeledText( fingerprintsComposite, StringUtils.EMPTY, 1 ); // create tab TabItem generalTab = new TabItem( tabFolder, SWT.NONE, GENERAL_TAB_INDEX ); generalTab.setText( Messages.getString( "CertificateInfoComposite.General" ) ); //$NON-NLS-1$ generalTab.setControl( generalContainer ); } /** * Creates the details tab. */ private void createDetailsTab() { SashForm detailsForm = new SashForm( tabFolder, SWT.VERTICAL ); detailsForm.setLayout( new FillLayout() ); Composite hierarchyContainer = new Composite( detailsForm, SWT.NONE ); GridLayout hierarchyLayout = new GridLayout( 1, false ); hierarchyLayout.marginTop = 10; hierarchyLayout.marginWidth = 10; hierarchyContainer.setLayout( hierarchyLayout ); BaseWidgetUtils.createLabel( hierarchyContainer, Messages .getString( "CertificateInfoComposite.CertificateHierarchyLabel" ), 1 ); //$NON-NLS-1$ hierarchyTreeViewer = new TreeViewer( hierarchyContainer ); hierarchyTreeViewer.getTree().setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); hierarchyTreeViewer.setContentProvider( new HierarchyContentProvider() ); hierarchyTreeViewer.setLabelProvider( new HierarchyLabelProvider() ); hierarchyTreeViewer.addSelectionChangedListener( event -> populateCertificateTree() ); Composite certificateContainer = new Composite( detailsForm, SWT.NONE ); GridLayout certificateLayout = new GridLayout( 1, false ); certificateLayout.marginWidth = 10; certificateContainer.setLayout( certificateLayout ); BaseWidgetUtils.createLabel( certificateContainer, Messages .getString( "CertificateInfoComposite.CertificateFieldsLabel" ), 1 ); //$NON-NLS-1$ certificateTree = new Tree( certificateContainer, SWT.BORDER ); certificateTree.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); certificateTree.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( final SelectionEvent event ) { TreeItem item = ( TreeItem ) event.item; if ( ( item == null ) || ( item.getData() == null ) ) { valueText.setText( StringUtils.EMPTY ); } else { valueText.setText( item.getData().toString() ); } } } ); Composite valueContainer = new Composite( detailsForm, SWT.NONE ); GridLayout valueLayout = new GridLayout( 1, false ); valueLayout.marginWidth = 10; valueLayout.marginBottom = 10; valueContainer.setLayout( valueLayout ); BaseWidgetUtils.createLabel( valueContainer, Messages.getString( "CertificateInfoComposite.FieldValuesLabel" ), 1 ); //$NON-NLS-1$ valueText = new Text( valueContainer, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY ); valueText.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); valueText.setFont( JFaceResources.getFont( JFaceResources.TEXT_FONT ) ); valueText.setBackground( detailsForm.getBackground() ); // create tab detailsForm.setWeights( new int[] { 1, 2, 1 } ); TabItem detailsTab = new TabItem( tabFolder, SWT.NONE, DETAILS_TAB_INDEX ); detailsTab.setText( Messages.getString( "CertificateInfoComposite.Details" ) ); //$NON-NLS-1$ detailsTab.setControl( detailsForm ); } /** * Sets the input for this composite. * * @param certificateChain certificate chain input */ public void setInput( X509Certificate[] certificateChain ) { X509Certificate certificate = certificateChain[0]; X500Principal issuedToPrincipal = certificate.getSubjectX500Principal(); Map<String, String> issuedToAttributes = getAttributeMap( issuedToPrincipal ); issuedToCN.setText( issuedToAttributes.get( "CN" ) ); //$NON-NLS-1$ issuedToO.setText( issuedToAttributes.get( "O" ) ); //$NON-NLS-1$ issuedToOU.setText( issuedToAttributes.get( "OU" ) ); //$NON-NLS-1$ serialNumber.setText( certificate.getSerialNumber().toString( 16 ) ); X500Principal issuedFromPrincipal = certificate.getIssuerX500Principal(); Map<String, String> issuedFromAttributes = getAttributeMap( issuedFromPrincipal ); issuedByCN.setText( issuedFromAttributes.get( "CN" ) ); //$NON-NLS-1$ issuedByO.setText( issuedFromAttributes.get( "O" ) ); //$NON-NLS-1$ issuedByOU.setText( issuedFromAttributes.get( "OU" ) ); //$NON-NLS-1$ issuesOn.setText( DateFormatUtils.ISO_DATE_FORMAT.format( certificate.getNotBefore() ) ); expiresOn.setText( DateFormatUtils.ISO_DATE_FORMAT.format( certificate.getNotAfter() ) ); byte[] encoded2 = null; try { encoded2 = certificate.getEncoded(); } catch ( CertificateEncodingException e ) { } byte[] md5 = DigestUtils.md5( encoded2 ); String md5HexString = getHexString( md5 ); fingerprintMD5.setText( md5HexString ); byte[] sha = DigestUtils.sha( encoded2 ); String shaHexString = getHexString( sha ); fingerprintSHA1.setText( shaHexString ); // Details: certificate chain CertificateChainItem parentItem = null; CertificateChainItem certificateItem = null; for ( X509Certificate cert : certificateChain ) { CertificateChainItem item = new CertificateChainItem( cert ); if ( parentItem != null ) { item.child = parentItem; parentItem.parent = item; } if ( certificateItem == null ) { certificateItem = item; } parentItem = item; } hierarchyTreeViewer.setInput( new CertificateChainItem[] { parentItem } ); hierarchyTreeViewer.expandAll(); hierarchyTreeViewer.setSelection( new StructuredSelection( certificateItem ), true ); // Details: certificateTree.removeAll(); populateCertificateTree(); valueText.setText( StringUtils.EMPTY ); } private void populateCertificateTree() { certificateTree.removeAll(); valueText.setText( StringUtils.EMPTY ); IStructuredSelection selection = ( IStructuredSelection ) hierarchyTreeViewer.getSelection(); if ( selection.size() != 1 ) { return; } CertificateChainItem certificateItem = ( CertificateChainItem ) selection.getFirstElement(); X509Certificate certificate = certificateItem.certificate; TreeItem rootItem = new TreeItem( certificateTree, SWT.NONE ); Map<String, String> attributeMap = getAttributeMap( certificate.getSubjectX500Principal() ); rootItem.setText( attributeMap.get( "CN" ) ); //$NON-NLS-1$ TreeItem certItem = createTreeItem( rootItem, Messages.getString( "CertificateInfoComposite.Certificate" ), StringUtils.EMPTY ); //$NON-NLS-1$ createTreeItem( certItem, Messages.getString( "CertificateInfoComposite.Version" ), String.valueOf( certificate.getVersion() ) ); //$NON-NLS-1$ createTreeItem( certItem, Messages.getString( "CertificateInfoComposite.SerialNumber" ), //$NON-NLS-1$ certificate.getSerialNumber().toString( 16 ) ); createTreeItem( certItem, Messages.getString( "CertificateInfoComposite.Signature" ), certificate.getSigAlgName() ); //$NON-NLS-1$ createTreeItem( certItem, Messages.getString( "CertificateInfoComposite.Issuer" ), certificate.getIssuerX500Principal().getName() ); //$NON-NLS-1$ TreeItem validityItem = createTreeItem( certItem, Messages.getString( "CertificateInfoComposite.Validity" ), StringUtils.EMPTY ); //$NON-NLS-1$ createTreeItem( validityItem, Messages.getString( "CertificateInfoComposite.NotBefore" ), certificate.getNotBefore().toString() ); //$NON-NLS-1$ createTreeItem( validityItem, Messages.getString( "CertificateInfoComposite.NotAfter" ), certificate.getNotAfter().toString() ); //$NON-NLS-1$ createTreeItem( certItem, Messages.getString( "CertificateInfoComposite.Subject" ), certificate.getSubjectX500Principal().getName() ); //$NON-NLS-1$ TreeItem pkiItem = createTreeItem( certItem, Messages .getString( "CertificateInfoComposite.SubjectPublicKeyInfo" ), StringUtils.EMPTY ); //$NON-NLS-1$ createTreeItem( pkiItem, Messages.getString( "CertificateInfoComposite.SubjectPublicKeyAlgorithm" ), //$NON-NLS-1$ certificate.getPublicKey().getAlgorithm() ); createTreeItem( pkiItem, Messages.getString( "CertificateInfoComposite.SubjectPublicKey" ), //$NON-NLS-1$ new String( Hex.encodeHex( certificate.getPublicKey() .getEncoded() ) ) ); TreeItem extItem = createTreeItem( certItem, Messages.getString( "CertificateInfoComposite.Extensions" ), StringUtils.EMPTY ); //$NON-NLS-1$ populateExtensions( extItem, certificate, true ); populateExtensions( extItem, certificate, false ); createTreeItem( rootItem, Messages.getString( "CertificateInfoComposite.SignatureAlgorithm" ), certificate.getSigAlgName() ); //$NON-NLS-1$ createTreeItem( rootItem, Messages.getString( "CertificateInfoComposite.Signature" ), //$NON-NLS-1$ new String( Hex.encodeHex( certificate.getSignature() ) ) ); rootItem.setExpanded( true ); certItem.setExpanded( true ); validityItem.setExpanded( true ); pkiItem.setExpanded( true ); extItem.setExpanded( true ); } private TreeItem createTreeItem( final TreeItem parent, final String field, final String value ) { TreeItem item = new TreeItem( parent, SWT.NONE ); item.setText( field ); item.setData( value ); return item; } private void populateExtensions( final TreeItem extensionsItem, final X509Certificate certificate, boolean critical ) { Set<String> oids = critical ? certificate.getCriticalExtensionOIDs() : certificate .getNonCriticalExtensionOIDs(); if ( oids != null ) { for ( String oid : oids ) { // try to parse the extension value byte[] to an ASN1 object byte[] extensionValueBin = certificate.getExtensionValue( oid ); String extensionValue = null; try { ASN1Object extension = X509ExtensionUtil.fromExtensionValue( extensionValueBin ); extensionValue = extension.toString(); } catch ( IOException e ) { extensionValue = new String( Hex.encodeHex( extensionValueBin ) ); } String value = Messages.getString( "CertificateInfoComposite.ExtensionOIDColon" ) + oid + '\n'; //$NON-NLS-1$ value += Messages.getString( "CertificateInfoComposite.CriticalColon" ) + Boolean.toString( critical ) //$NON-NLS-1$ + '\n'; value += Messages.getString( "CertificateInfoComposite.ExtensionValueColon" ) + extensionValue + '\n'; //$NON-NLS-1$ // TODO: OID descriptions // TODO: formatting of extension value TreeItem item = createTreeItem( extensionsItem, oid, value ); createTreeItem( item, Messages.getString( "CertificateInfoComposite.ExtensionOID" ), oid ); //$NON-NLS-1$ createTreeItem( item, Messages.getString( "CertificateInfoComposite.Critical" ), Boolean.toString( critical ) ); //$NON-NLS-1$ createTreeItem( item, Messages.getString( "CertificateInfoComposite.ExtensionValue" ), extensionValue ); //$NON-NLS-1$ } } } private String getHexString( byte[] bytes ) { char[] hex = Hex.encodeHex( bytes ); StringBuilder buffer = new StringBuilder(); for ( int i = 0; i < hex.length; i++ ) { if ( i % 2 == 0 && i > 0 ) { buffer.append( ':' ); } buffer.append( Character.toUpperCase( hex[i] ) ); } return buffer.toString(); } /** * Converts the distinguished name of the principal * to a map containing the attribute types and values, * one for each relative distinguished name. * * @param principal the principal * @return the map containing attribute types and values */ private Map<String, String> getAttributeMap( X500Principal principal ) { Map<String, String> map = new HashMap<>(); // populate map with default values for ( String attribute : ATTRIBUTES ) { map.put( attribute, "-" ); //$NON-NLS-1$ } // populate map with principal's name try { String name = principal.getName(); Dn dn = new Dn( name ); for ( Rdn rdn : dn ) { map.put( rdn.getType().toUpperCase(), rdn.getValue() ); } } catch ( LdapInvalidDnException lide ) { map.put( "CN", lide.getMessage() ); //$NON-NLS-1$ } return map; } class HierarchyContentProvider implements ITreeContentProvider { public Object[] getChildren( Object parentElement ) { if ( parentElement instanceof CertificateChainItem ) { CertificateChainItem item = ( CertificateChainItem ) parentElement; if ( item.child != null ) { return new CertificateChainItem[] { item.child }; } } return new Object[0]; } public Object getParent( Object element ) { if ( element instanceof CertificateChainItem ) { CertificateChainItem item = ( CertificateChainItem ) element; return item.parent; } return null; } public boolean hasChildren( Object element ) { return getChildren( element ).length > 0; } public Object[] getElements( Object inputElement ) { if ( inputElement instanceof CertificateChainItem[] ) { return ( CertificateChainItem[] ) inputElement; } return getChildren( inputElement ); } @Override public void dispose() { } @Override public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) { } } class HierarchyLabelProvider extends LabelProvider { @Override public String getText( Object element ) { if ( element instanceof CertificateChainItem ) { CertificateChainItem item = ( CertificateChainItem ) element; Map<String, String> attributeMap = getAttributeMap( item.certificate.getSubjectX500Principal() ); return attributeMap.get( "CN" ); //$NON-NLS-1$ } return null; } } private class CertificateChainItem { private X509Certificate certificate; private CertificateChainItem parent; private CertificateChainItem child; public CertificateChainItem( X509Certificate certificate ) { this.certificate = certificate; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionSorter.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionSorter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.ViewerSorter; /** * The ConnectionSorter implements the sorter for the connection widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionSorter extends ViewerSorter { /** * Connects the tree viewer to this sorter. * * @param viewer the tree viewer */ public void connect( TreeViewer viewer ) { viewer.setSorter( this ); } /** * Disposes this sorter. */ public void dispose() { // Nothing to do } /** * {@inheritDoc} * * This method is used to categorize connection folders and connections. */ @Override public int category( Object element ) { if ( element instanceof ConnectionFolder ) { return 1; } else { return 2; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionUniversalListener.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.apache.directory.studio.connection.core.event.ConnectionEventRegistry; import org.apache.directory.studio.connection.core.event.ConnectionUpdateListener; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; /** * The ConnectionUniversalListener manages all events for the connection widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionUniversalListener implements ConnectionUpdateListener { /** The tree viewer */ protected TreeViewer viewer; /** This listener expands/collapses a connection folder when double clicking */ private IDoubleClickListener viewerDoubleClickListener = event -> { if ( event.getSelection() instanceof IStructuredSelection ) { Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement(); if ( obj instanceof ConnectionFolder ) { if ( viewer.getExpandedState( obj ) ) { viewer.collapseToLevel( obj, 1 ); } else if ( ( ( ITreeContentProvider ) viewer.getContentProvider() ).hasChildren( obj ) ) { viewer.expandToLevel( obj, 1 ); } } } }; /** * Creates a new instance of ConnectionUniversalListener. * * @param viewer the tree viewer */ public ConnectionUniversalListener( TreeViewer viewer ) { this.viewer = viewer; this.viewer.addDoubleClickListener( viewerDoubleClickListener ); ConnectionEventRegistry.addConnectionUpdateListener( this, ConnectionUIPlugin.getDefault().getEventRunner() ); } /** * Disposes this universal listener. */ public void dispose() { if ( viewer != null ) { ConnectionEventRegistry.removeConnectionUpdateListener( this ); viewer = null; } } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionUpdated(org.apache.directory.studio.connection.core.Connection) */ public void connectionUpdated( Connection connection ) { if ( viewer != null ) { viewer.refresh(); } } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionAdded(org.apache.directory.studio.connection.core.Connection) */ public void connectionAdded( Connection connection ) { connectionUpdated( connection ); if ( viewer != null ) { viewer.setSelection( new StructuredSelection( connection ), true ); } } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionRemoved(org.apache.directory.studio.connection.core.Connection) */ public void connectionRemoved( Connection connection ) { connectionUpdated( connection ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionOpened(org.apache.directory.studio.connection.core.Connection) */ public void connectionOpened( Connection connection ) { connectionUpdated( connection ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionClosed(org.apache.directory.studio.connection.core.Connection) */ public void connectionClosed( Connection connection ) { connectionUpdated( connection ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionFolderModified(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderModified( ConnectionFolder connectionFolder ) { connectionUpdated( null ); } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionFolderAdded(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderAdded( ConnectionFolder connectionFolder ) { connectionUpdated( null ); if ( viewer != null ) { viewer.setSelection( new StructuredSelection( connectionFolder ), true ); } } /** * @see org.apache.directory.studio.connection.core.event.ConnectionUpdateListener# * connectionFolderRemoved(org.apache.directory.studio.connection.core.ConnectionFolder) */ public void connectionFolderRemoved( ConnectionFolder connectionFolder ) { connectionUpdated( null ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/NetworkParameterPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.text.SimpleDateFormat; import java.util.Date; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.api.ldap.model.url.LdapUrl.Extension; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.common.ui.HistoryUtils; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCoreConstants; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.core.ConnectionParameter.EncryptionMethod; import org.apache.directory.studio.connection.core.jobs.CheckNetworkParameterRunnable; import org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.apache.directory.studio.connection.ui.RunnableContextRunner; import org.apache.directory.studio.connection.ui.dialogs.CertificateInfoDialog; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.PreferencesUtil; /** * The NetworkParameterPage is used the edit the network parameters of a * connection. This is a tab in the connection property widget : * * <pre> * .---------------------------------------------------------------------------. * | Connection | * +---------------------------------------------------------------------------+ * | .---[Network Parameter]|Authentication||Browser Options||Edit Options|--. | * | | | | * | | Connection name : [-------------------------------------] | | * | | | | * | | Network Parameter | | * | | .-------------------------------------------------------------------. | | * | | | | | | * | | | Hostname : [----------------------------------------|v] | | | * | | | Port : [----------------------------------------|v] | | | * | | | Timeout : [ ] | | | * | | | Encryption method : [-No encryption--------------------------|v] | | | * | | | Server certificates for LDAP connections can | | | * | | | managed in the '<certificate validation>' | | | * | | | preference page. | | | * | | | | | | * | | | (Check Network Parameter) | | | * | | +-------------------------------------------------------------------+ | | * | | | | * | | [] Read-Only (prevents any add, delete, modify or rename operation) | | * | | | | * | +-----------------------------------------------------------------------+ | * +---------------------------------------------------------------------------+ * </pre> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NetworkParameterPage extends AbstractConnectionParameterPage { private static final String X_CONNECTION_NAME = "X-CONNECTION-NAME"; //$NON-NLS-1$ private static final String X_ENCRYPTION = "X-ENCRYPTION"; //$NON-NLS-1$ private static final String X_ENCRYPTION_LDAPS = "ldaps"; //$NON-NLS-1$ private static final String X_ENCRYPTION_START_TLS = "StartTLS"; //$NON-NLS-1$ /** The connection name text widget */ private Text nameText; /** The host name combo with the history of recently used host names */ private Combo hostCombo; /** The host combo with the history of recently used ports */ private Combo portCombo; /** The combo to select the encryption method */ private Combo encryptionMethodCombo; /** The button to fetch and show the server's certificate */ private Button viewServerCertificateButton; /** The button to check the connection parameters */ private Button checkConnectionButton; /** The checkbox to make the connection read-only */ private Button readOnlyConnectionCheckbox; /** A timeout for the connection. Default to 30s */ private Text timeoutSecondsText; /** * A listener for the Link data widget. It will open the CertificateValidationPreference dialog. */ private SelectionAdapter linkDataWidgetListener = new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { String certificateValidationPreferencePageId = ConnectionUIPlugin.getDefault() .getPluginProperties().getString( "PrefPage_CertificateValidationPreferencePage_id" ); //$NON-NLS-1$ PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( Display.getDefault() .getActiveShell(), certificateValidationPreferencePageId, new String[] { certificateValidationPreferencePageId }, null ); dialog.open(); } }; /** * Gets the connection name. * * @return the connectio name */ private String getName() { return nameText.getText(); } /** * Gets the host name. * * @return the host name */ private String getHostName() { return hostCombo.getText(); } /** * Gets the port. * * @return the port */ private int getPort() { return Integer.parseInt( portCombo.getText() ); } /** * Gets the timeout in seconds. * * @return The timeout in seconds */ private int getTimeoutSeconds() { String timeoutSecondsString = timeoutSecondsText.getText(); if ( Strings.isEmpty( timeoutSecondsString ) ) { return 30; } else { return Integer.parseInt( timeoutSecondsString ); } } /** * Gets the encyrption method. * * @return the encyrption method */ private ConnectionParameter.EncryptionMethod getEncyrptionMethod() { switch ( encryptionMethodCombo.getSelectionIndex() ) { case 1: return ConnectionParameter.EncryptionMethod.LDAPS; case 2: return ConnectionParameter.EncryptionMethod.START_TLS; default: return ConnectionParameter.EncryptionMethod.NONE; } } /** * Gets a temporary connection with all connection parameter * entered in this page. * * @return a test connection */ private Connection getTestConnection() { ConnectionParameter connectionParameter = new ConnectionParameter( null, getHostName(), getPort(), getEncyrptionMethod(), ConnectionParameter.AuthenticationMethod.NONE, null, null, null, true, null, 30000L ); return new Connection( connectionParameter ); } /** * Gets read only flag. * * @return the read only flag */ private boolean isReadOnly() { return readOnlyConnectionCheckbox.getSelection(); } /** * {@inheritDoc} */ @Override protected void createComposite( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Composite nameComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); BaseWidgetUtils.createLabel( nameComposite, Messages.getString( "NetworkParameterPage.ConnectionName" ), 1 ); //$NON-NLS-1$ nameText = BaseWidgetUtils.createText( nameComposite, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ BaseWidgetUtils.createSpacer( composite, 1 ); Group group = BaseWidgetUtils.createGroup( composite, Messages .getString( "NetworkParameterPage.NetworkParameter" ), 1 ); //$NON-NLS-1$ IDialogSettings dialogSettings = ConnectionUIPlugin.getDefault().getDialogSettings(); // The network hostname Composite groupComposite = BaseWidgetUtils.createColumnContainer( group, 3, 1 ); BaseWidgetUtils.createLabel( groupComposite, Messages.getString( "NetworkParameterPage.HostName" ), 1 ); //$NON-NLS-1$ String[] hostHistory = HistoryUtils.load( dialogSettings, ConnectionUIConstants.DIALOGSETTING_KEY_HOST_HISTORY ); hostCombo = BaseWidgetUtils.createCombo( groupComposite, hostHistory, -1, 2 ); // The network port BaseWidgetUtils.createLabel( groupComposite, Messages.getString( "NetworkParameterPage.Port" ), 1 ); //$NON-NLS-1$ String[] portHistory = HistoryUtils.load( dialogSettings, ConnectionUIConstants.DIALOGSETTING_KEY_PORT_HISTORY ); portCombo = BaseWidgetUtils.createCombo( groupComposite, portHistory, -1, 2 ); portCombo.setTextLimit( 5 ); portCombo.setText( "389" ); //$NON-NLS-1$ // The timeout BaseWidgetUtils.createLabel( groupComposite, Messages.getString( "NetworkParameterPage.Timeout" ), 2 ); //$NON-NLS-1$ timeoutSecondsText = BaseWidgetUtils.createText( groupComposite, "30", 1 ); //$NON-NLS-1$ timeoutSecondsText.setTextLimit( 7 ); String[] encMethods = new String[] { Messages.getString( "NetworkParameterPage.NoEncryption" ), //$NON-NLS-1$ Messages.getString( "NetworkParameterPage.UseSSLEncryption" ), //$NON-NLS-1$ Messages.getString( "NetworkParameterPage.UseStartTLS" ) //$NON-NLS-1$ }; BaseWidgetUtils.createLabel( groupComposite, Messages.getString( "NetworkParameterPage.EncryptionMethod" ), 1 ); //$NON-NLS-1$ encryptionMethodCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, encMethods, 0, 2 ); boolean validateCertificates = ConnectionCorePlugin.getDefault().getPluginPreferences().getBoolean( ConnectionCoreConstants.PREFERENCE_VALIDATE_CERTIFICATES ); if ( validateCertificates ) { BaseWidgetUtils.createSpacer( groupComposite, 1 ); Link link = BaseWidgetUtils.createLink( groupComposite, Messages.getString( "NetworkParameterPage.CertificateValidationLink" ), 2 ); //$NON-NLS-1$ GridData linkGridData = new GridData( GridData.FILL_HORIZONTAL ); linkGridData.horizontalSpan = 2; linkGridData.widthHint = 100; link.setLayoutData( linkGridData ); link.addSelectionListener( linkDataWidgetListener ); } else { BaseWidgetUtils.createSpacer( groupComposite, 1 ); BaseWidgetUtils.createLabel( groupComposite, Messages .getString( "NetworkParameterPage.WarningCertificateValidation" ), 2 ); //$NON-NLS-1$ } BaseWidgetUtils.createSpacer( groupComposite, 1 ); GridData gridData = new GridData(); gridData.horizontalAlignment = SWT.RIGHT; gridData.verticalAlignment = SWT.BOTTOM; viewServerCertificateButton = new Button( groupComposite, SWT.PUSH ); viewServerCertificateButton.setLayoutData( gridData ); viewServerCertificateButton.setText( Messages.getString( "NetworkParameterPage.ViewCertificate" ) ); //$NON-NLS-1$ checkConnectionButton = new Button( groupComposite, SWT.PUSH ); checkConnectionButton.setLayoutData( gridData ); checkConnectionButton.setText( Messages.getString( "NetworkParameterPage.CheckNetworkParameter" ) ); //$NON-NLS-1$ readOnlyConnectionCheckbox = BaseWidgetUtils.createCheckbox( composite, Messages.getString( "NetworkParameterPage.ReadOnly" ), 1 ); //$NON-NLS-1$ BaseWidgetUtils.createSpacer( composite, 1 ); nameText.setFocus(); } /** * {@inheritDoc} */ @Override protected void validate() { // set enabled/disabled state of check connection button checkConnectionButton.setEnabled( !hostCombo.getText().equals( StringUtils.EMPTY ) && !portCombo.getText().equals( StringUtils.EMPTY ) ); // set enabled/disabled state of show server certificate button viewServerCertificateButton.setEnabled( checkConnectionButton.isEnabled() && getEncyrptionMethod() != EncryptionMethod.NONE ); // validate input fields message = null; infoMessage = null; errorMessage = null; if ( Strings.isEmpty( portCombo.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "NetworkParameterPage.PleaseEnterPort" ); //$NON-NLS-1$ } if ( Strings.isEmpty( hostCombo.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "NetworkParameterPage.PleaseEnterHostname" ); //$NON-NLS-1$ } if ( Strings.isEmpty( nameText.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "NetworkParameterPage.PleaseEnterConnectionName" ); //$NON-NLS-1$ } if ( Strings.isEmpty( timeoutSecondsText.getText() ) ) //$NON-NLS-1$ { timeoutSecondsText.setText( "30" ); } if ( ConnectionCorePlugin.getDefault().getConnectionManager().getConnectionByName( nameText.getText() ) != null && ( ( connectionParameter == null ) || !nameText.getText().equals( connectionParameter.getName() ) ) ) { errorMessage = NLS.bind( Messages.getString( "NetworkParameterPage.ConnectionExists" ), new String[] //$NON-NLS-1$ { nameText.getText() } ); } } /** * {@inheritDoc} */ @Override protected void loadParameters( ConnectionParameter parameter ) { connectionParameter = parameter; nameText.setText( CommonUIUtils.getTextValue( parameter.getName() ) ); hostCombo.setText( CommonUIUtils.getTextValue( parameter.getHost() ) ); portCombo.setText( Integer.toString( parameter.getPort() ) ); int encryptionMethodIndex = 0; if ( parameter.getEncryptionMethod() == EncryptionMethod.LDAPS ) { encryptionMethodIndex = 1; } else if ( parameter.getEncryptionMethod() == EncryptionMethod.START_TLS ) { encryptionMethodIndex = 2; } encryptionMethodCombo.select( encryptionMethodIndex ); readOnlyConnectionCheckbox.setSelection( parameter.isReadOnly() ); timeoutSecondsText.setText( Long.toString( parameter.getTimeoutMillis() / 1000L ) ); } /** * {@inheritDoc} */ @Override protected void initListeners() { nameText.addModifyListener( event -> connectionPageModified() ); hostCombo.addModifyListener( event -> connectionPageModified() ); portCombo.addVerifyListener( event -> { if ( !event.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { event.doit = false; } } ); portCombo.addModifyListener( event -> connectionPageModified() ); encryptionMethodCombo.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { connectionPageModified(); } } ); checkConnectionButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { Connection connection = getTestConnection(); CheckNetworkParameterRunnable runnable = new CheckNetworkParameterRunnable( connection ); IStatus status = RunnableContextRunner.execute( runnable, runnableContext, true ); if ( status.isOK() ) { String title = Messages.getString( "NetworkParameterPage.CheckNetworkParameter" ); //$NON-NLS-1$ String message = Messages.getString( "NetworkParameterPage.ConnectionEstablished" ); //$NON-NLS-1$ SSLSession sslSession = runnable.getSslSession(); if ( sslSession != null ) { message += "\n\nProtocol: " + sslSession.getProtocol(); message += "\nCipher Suite: " + sslSession.getCipherSuite(); } MessageDialog.openInformation( Display.getDefault().getActiveShell(), title, message ); } } } ); viewServerCertificateButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { Connection connection = getTestConnection(); CheckNetworkParameterRunnable runnable = new CheckNetworkParameterRunnable( connection ); IStatus status = RunnableContextRunner.execute( runnable, runnableContext, true ); if ( status.isOK() ) { try { SSLSession sslSession = runnable.getSslSession(); Certificate[] certificates = sslSession.getPeerCertificates(); X509Certificate[] serverCertificates = new X509Certificate[certificates.length]; for ( int i = 0; i < certificates.length; i++ ) { serverCertificates[i] = ( X509Certificate ) certificates[i]; } new CertificateInfoDialog( Display.getDefault().getActiveShell(), serverCertificates ).open(); } catch ( SSLPeerUnverifiedException e ) { throw new RuntimeException( e ); } } } } ); readOnlyConnectionCheckbox.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { connectionPageModified(); } } ); // The timeout events timeoutSecondsText.addModifyListener( event -> connectionPageModified() ); timeoutSecondsText.addVerifyListener( event -> { if ( !event.text.matches( "[0-9]*" ) ) //$NON-NLS-1$ { event.doit = false; } } ); } /** * {@inheritDoc} */ @Override public void saveParameters( ConnectionParameter parameter ) { parameter.setName( getName() ); parameter.setHost( getHostName() ); parameter.setPort( getPort() ); parameter.setEncryptionMethod( getEncyrptionMethod() ); parameter.setReadOnly( isReadOnly() ); parameter.setTimeoutMillis( getTimeoutSeconds() * 1000L ); } /** * {@inheritDoc} */ @Override public void saveDialogSettings() { IDialogSettings dialogSettings = ConnectionUIPlugin.getDefault().getDialogSettings(); HistoryUtils.save( dialogSettings, ConnectionUIConstants.DIALOGSETTING_KEY_HOST_HISTORY, hostCombo.getText() ); HistoryUtils.save( dialogSettings, ConnectionUIConstants.DIALOGSETTING_KEY_PORT_HISTORY, portCombo.getText() ); } /** * {@inheritDoc} */ @Override public void setFocus() { nameText.setFocus(); } /** * {@inheritDoc} */ @Override public boolean areParametersModifed() { return isReconnectionRequired() || !StringUtils.equals( connectionParameter.getName(), getName() ); } /** * {@inheritDoc} */ @Override public boolean isReconnectionRequired() { return ( connectionParameter == null ) || ( !StringUtils.equals( connectionParameter.getHost(), getHostName() ) ) || ( connectionParameter.getPort() != getPort() ) || ( connectionParameter.getEncryptionMethod() != getEncyrptionMethod() ) || ( connectionParameter.isReadOnly() != isReadOnly() ) || ( connectionParameter.getTimeoutMillis() != getTimeoutSeconds() * 1000L ); } /** * {@inheritDoc} */ @Override public void mergeParametersToLdapURL( ConnectionParameter parameter, LdapUrl ldapUrl ) { ldapUrl.getExtensions().add( new Extension( false, X_CONNECTION_NAME, parameter.getName() ) ); ldapUrl.setHost( parameter.getHost() ); ldapUrl.setPort( parameter.getPort() ); switch ( parameter.getEncryptionMethod() ) { case NONE: // default break; case LDAPS: ldapUrl.getExtensions().add( new Extension( false, X_ENCRYPTION, X_ENCRYPTION_LDAPS ) ); break; case START_TLS: ldapUrl.getExtensions().add( new Extension( false, X_ENCRYPTION, X_ENCRYPTION_START_TLS ) ); break; } } /** * {@inheritDoc} */ @Override public void mergeLdapUrlToParameters( LdapUrl ldapUrl, ConnectionParameter parameter ) { // connection name, current date if absent String name = ldapUrl.getExtensionValue( X_CONNECTION_NAME ); if ( StringUtils.isEmpty( name ) ) { name = new SimpleDateFormat( "yyyy-MM-dd HH-mm-ss" ).format( new Date() ); //$NON-NLS-1$ } parameter.setName( name ); // host parameter.setHost( ldapUrl.getHost() ); // port parameter.setPort( ldapUrl.getPort() ); // encryption method, none if unknown or absent String encryption = ldapUrl.getExtensionValue( X_ENCRYPTION ); if ( StringUtils.isNotEmpty( encryption ) && X_ENCRYPTION_LDAPS.equalsIgnoreCase( encryption ) ) { parameter.setEncryptionMethod( ConnectionParameter.EncryptionMethod.LDAPS ); } else if ( StringUtils.isNotEmpty( encryption ) && X_ENCRYPTION_START_TLS.equalsIgnoreCase( encryption ) ) { parameter.setEncryptionMethod( ConnectionParameter.EncryptionMethod.START_TLS ); } else { parameter.setEncryptionMethod( ConnectionParameter.EncryptionMethod.NONE ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/AuthenticationParameterPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.ldap.model.constants.SaslQoP; import org.apache.directory.api.ldap.model.constants.SaslSecurityStrength; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.api.ldap.model.url.LdapUrl.Extension; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.common.ui.HistoryUtils; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCoreConstants; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.core.ConnectionParameter.AuthenticationMethod; import org.apache.directory.studio.connection.core.ConnectionParameter.Krb5Configuration; import org.apache.directory.studio.connection.core.ConnectionParameter.Krb5CredentialConfiguration; import org.apache.directory.studio.connection.core.PasswordsKeyStoreManager; import org.apache.directory.studio.connection.core.jobs.CheckBindRunnable; import org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.apache.directory.studio.connection.ui.PasswordsKeyStoreManagerUtils; import org.apache.directory.studio.connection.ui.RunnableContextRunner; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.events.ExpansionAdapter; import org.eclipse.ui.forms.events.ExpansionEvent; import org.eclipse.ui.forms.widgets.ExpandableComposite; /** * The AuthenticationParameterPage is used the edit the authentication parameters of a * connection. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AuthenticationParameterPage extends AbstractConnectionParameterPage { /** The URL X_AUTH_METHOD constant */ private static final String X_AUTH_METHOD = "X-AUTH-METHOD"; //$NON-NLS-1$ /** The URL anonymous constant */ private static final String X_AUTH_METHOD_ANONYMOUS = "Anonymous"; //$NON-NLS-1$ /** The URL simple constant */ private static final String X_AUTH_METHOD_SIMPLE = "Simple"; //$NON-NLS-1$ /** The URL DIGEST-MD5 constant */ private static final String X_AUTH_METHOD_DIGEST_MD5 = "DIGEST-MD5"; //$NON-NLS-1$ /** The URL CRAM-MD5 constant */ private static final String X_AUTH_METHOD_CRAM_MD5 = "CRAM-MD5"; //$NON-NLS-1$ /** The URL GSSAPI constant */ private static final String X_AUTH_METHOD_GSSAPI = "GSSAPI"; //$NON-NLS-1$ /** The URL X_BIND_USER constant */ private static final String X_BIND_USER = "X-BIND-USER"; //$NON-NLS-1$ /** The URL X_BIND_PASSWORD constant */ private static final String X_BIND_PASSWORD = "X-BIND-PASSWORD"; //$NON-NLS-1$ /** The SASL REALM constant */ private static final String X_SASL_REALM = "X-SASL-REALM"; //$NON-NLS-1$ /** The SASL QOP constant */ private static final String X_SASL_QOP = "X-SASL-QOP"; //$NON-NLS-1$ /** The SASL QOP AUTH-INT constant */ private static final String X_SASL_QOP_AUTH_INT = "AUTH-INT"; //$NON-NLS-1$ /** The SASL QOP AUTH-INT PROV constant */ private static final String X_SASL_QOP_AUTH_INT_PRIV = "AUTH-INT-PRIV"; //$NON-NLS-1$ /** The SASL Security Strength constant */ private static final String X_SASL_SEC_STRENGTH = "X-SASL-SEC-STRENGTH"; //$NON-NLS-1$ /** The SASL Medium security constant */ private static final String X_SASL_SEC_STRENGTH_MEDIUM = "MEDIUM"; //$NON-NLS-1$ /** The SASL Low security constant */ private static final String X_SASL_SEC_STRENGTH_LOW = "LOW"; //$NON-NLS-1$ /** The SASL no-mutual-auth constant */ private static final String X_SASL_NO_MUTUAL_AUTH = "X-SASL-NO-MUTUAL-AUTH"; //$NON-NLS-1$ private static final String X_KRB5_CREDENTIALS_CONF = "X-KRB5-CREDENTIALS-CONF"; //$NON-NLS-1$ private static final String X_KRB5_CREDENTIALS_CONF_OBTAIN_TGT = "OBTAIN-TGT"; //$NON-NLS-1$ private static final String X_KRB5_CONFIG = "X-KRB5-CONFIG"; //$NON-NLS-1$ private static final String X_KRB5_CONFIG_FILE = "FILE"; //$NON-NLS-1$ private static final String X_KRB5_CONFIG_FILE_FILE = "X-KRB5-CONFIG-FILE"; //$NON-NLS-1$ private static final String X_KRB5_CONFIG_MANUAL = "MANUAL"; //$NON-NLS-1$ private static final String X_KRB5_CONFIG_MANUAL_REALM = "X-KRB5-REALM"; //$NON-NLS-1$ private static final String X_KRB5_CONFIG_MANUAL_KDC_HOST = "X-KRB5-KDC-HOST"; //$NON-NLS-1$ private static final String X_KRB5_CONFIG_MANUAL_KDC_PORT = "X-KRB5-KDC-PORT"; //$NON-NLS-1$ /** The combo to select the authentication method */ private Combo authenticationMethodCombo; /** The bind user combo with the history of recently used bind users */ private Combo bindPrincipalCombo; /** The text widget to input bind password */ private Text bindPasswordText; /** The checkbox to choose if the bind password should be saved on disk */ private Button saveBindPasswordButton; /** The button to check the authentication parameters */ private Button checkPrincipalPasswordAuthButton; // SASL stuff private Composite saslComposite; private Combo saslRealmText; private Combo saslQopCombo; private Combo saslSecurityStrengthCombo; private Button saslMutualAuthenticationButton; // Kerberos stuff private Composite krb5Composite; private Button krb5CredentialConfigurationUseNativeButton; private Button krb5CredentialConfigurationObtainTgtButton; private Button krb5ConfigDefaultButton; private Button krb5ConfigFileButton; private Text krb5ConfigFileText; private Button krb5ConfigManualButton; private Text krb5ConfigManualRealmText; private Text krb5ConfigManualHostText; private Text krb5ConfigManualPortText; /** * Gets the authentication method. * * @return the authentication method */ private ConnectionParameter.AuthenticationMethod getAuthenticationMethod() { switch ( authenticationMethodCombo.getSelectionIndex() ) { case 1: return ConnectionParameter.AuthenticationMethod.SIMPLE; case 2: return ConnectionParameter.AuthenticationMethod.SASL_DIGEST_MD5; case 3: return ConnectionParameter.AuthenticationMethod.SASL_CRAM_MD5; case 4: return ConnectionParameter.AuthenticationMethod.SASL_GSSAPI; default: return ConnectionParameter.AuthenticationMethod.NONE; } } /** * Gets the bind principal. * * @return the bind principal */ private String getBindPrincipal() { return bindPrincipalCombo.getText(); } /** * Gets the bind password. * * @return the bind password, null if saving of bind password is disabled */ private String getBindPassword() { return isSaveBindPassword() ? bindPasswordText.getText() : null; } private String getSaslRealm() { return Strings.isEmpty( saslRealmText.getText() ) ? null : saslRealmText.getText(); } private SaslQoP getSaslQop() { switch ( saslQopCombo.getSelectionIndex() ) { case 1: return SaslQoP.AUTH_INT; case 2: return SaslQoP.AUTH_CONF; default: return SaslQoP.AUTH; } } private SaslSecurityStrength getSaslSecurityStrength() { switch ( saslSecurityStrengthCombo.getSelectionIndex() ) { case 1: return SaslSecurityStrength.MEDIUM; case 2: return SaslSecurityStrength.LOW; default: return SaslSecurityStrength.HIGH; } } private Krb5CredentialConfiguration getKrb5CredentialProvider() { if ( krb5CredentialConfigurationUseNativeButton.getSelection() ) { return Krb5CredentialConfiguration.USE_NATIVE; } else { return Krb5CredentialConfiguration.OBTAIN_TGT; } } private Krb5Configuration getKrb5Configuration() { if ( krb5ConfigDefaultButton.getSelection() ) { return Krb5Configuration.DEFAULT; } else if ( krb5ConfigFileButton.getSelection() ) { return Krb5Configuration.FILE; } else { return Krb5Configuration.MANUAL; } } private int getKdcPort() { String krb5ConfigPort = krb5ConfigManualPortText.getText(); if ( Strings.isEmpty( krb5ConfigPort ) ) { return 0; } else { return Integer.parseInt( krb5ConfigPort ); } } /** * Returns true if the bind password should be saved on disk. * * @return true, if the bind password should be saved on disk */ public boolean isSaveBindPassword() { return saveBindPasswordButton.getSelection(); } /** * Gets a temporary connection with all conection parameter * entered in this page. * * @return a test connection */ private Connection getTestConnection() { ConnectionParameter connectionParameter = connectionParameterPageModifyListener.getTestConnectionParameters(); return new Connection( connectionParameter ); } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage# * createComposite(org.eclipse.swt.widgets.Composite) */ protected void createComposite( Composite parent ) { // Authentication Method Composite composite1 = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Group group1 = BaseWidgetUtils.createGroup( composite1, Messages .getString( "AuthenticationParameterPage.AuthenticationMethod" ), 1 ); //$NON-NLS-1$ Composite groupComposite = BaseWidgetUtils.createColumnContainer( group1, 1, 1 ); String[] authMethods = new String[] { Messages.getString( "AuthenticationParameterPage.AnonymousAuthentication" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.SimpleAuthentication" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.DigestMD5" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.CramMD5" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.GSSAPI" ) //$NON-NLS-1$ }; authenticationMethodCombo = BaseWidgetUtils.createReadonlyCombo( groupComposite, authMethods, 1, 2 ); // Authentication Parameter Composite composite2 = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); Group group2 = BaseWidgetUtils.createGroup( composite2, Messages .getString( "AuthenticationParameterPage.AuthenticationParameter" ), 1 ); //$NON-NLS-1$ Composite composite = BaseWidgetUtils.createColumnContainer( group2, 3, 1 ); BaseWidgetUtils.createLabel( composite, Messages.getString( "AuthenticationParameterPage.BindDNOrUser" ), 1 ); //$NON-NLS-1$ String[] dnHistory = HistoryUtils.load( ConnectionUIPlugin.getDefault().getDialogSettings(), ConnectionUIConstants.DIALOGSETTING_KEY_PRINCIPAL_HISTORY ); bindPrincipalCombo = BaseWidgetUtils.createCombo( composite, dnHistory, -1, 2 ); BaseWidgetUtils.createLabel( composite, Messages.getString( "AuthenticationParameterPage.BindPassword" ), 1 ); //$NON-NLS-1$ bindPasswordText = BaseWidgetUtils.createPasswordText( composite, StringUtils.EMPTY, 2 ); //$NON-NLS-1$ BaseWidgetUtils.createSpacer( composite, 1 ); saveBindPasswordButton = BaseWidgetUtils.createCheckbox( composite, Messages .getString( "AuthenticationParameterPage.SavePassword" ), 1 ); //$NON-NLS-1$ saveBindPasswordButton.setSelection( true ); checkPrincipalPasswordAuthButton = new Button( composite, SWT.PUSH ); GridData gridData = new GridData( GridData.FILL_HORIZONTAL ); gridData.horizontalAlignment = SWT.RIGHT; checkPrincipalPasswordAuthButton.setLayoutData( gridData ); checkPrincipalPasswordAuthButton.setText( Messages .getString( "AuthenticationParameterPage.CheckAuthentication" ) ); //$NON-NLS-1$ checkPrincipalPasswordAuthButton.setEnabled( false ); ScrolledComposite scrolledComposite = new ScrolledComposite( parent, SWT.H_SCROLL | SWT.V_SCROLL ); scrolledComposite.setLayout( new GridLayout() ); scrolledComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); Composite contentComposite = BaseWidgetUtils.createColumnContainer( scrolledComposite, 1, 1 ); scrolledComposite.setContent( contentComposite ); ExpandableComposite saslExpandableComposite = createExpandableSection( contentComposite, Messages .getString( "AuthenticationParameterPage.SaslOptions" ), 1 ); //$NON-NLS-1$ saslComposite = BaseWidgetUtils.createColumnContainer( saslExpandableComposite, 2, 1 ); saslExpandableComposite.setClient( saslComposite ); createSaslControls(); ExpandableComposite krb5ExpandableComposite = createExpandableSection( contentComposite, Messages .getString( "AuthenticationParameterPage.Krb5Options" ), 1 ); //$NON-NLS-1$ krb5Composite = BaseWidgetUtils.createColumnContainer( krb5ExpandableComposite, 1, 1 ); krb5ExpandableComposite.setClient( krb5Composite ); createKrb5Controls(); contentComposite.setSize( contentComposite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } protected ExpandableComposite createExpandableSection( Composite parent, String label, int nColumns ) { ExpandableComposite excomposite = new ExpandableComposite( parent, SWT.NONE, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT ); excomposite.setText( label ); excomposite.setExpanded( false ); excomposite.setFont( JFaceResources.getFontRegistry().getBold( JFaceResources.DIALOG_FONT ) ); excomposite.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, false, nColumns, 1 ) ); excomposite.addExpansionListener( new ExpansionAdapter() { /** * {@inheritDoc} */ @Override public void expansionStateChanged( ExpansionEvent event ) { ExpandableComposite excomposite = ( ExpandableComposite ) event.getSource(); excomposite.getParent().setSize( excomposite.getParent().computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } } ); return excomposite; } private void createSaslControls() { BaseWidgetUtils.createLabel( saslComposite, Messages.getString( "AuthenticationParameterPage.SaslRealm" ), 1 ); //$NON-NLS-1$ String[] saslHistory = HistoryUtils.load( ConnectionUIPlugin.getDefault().getDialogSettings(), ConnectionUIConstants.DIALOGSETTING_KEY_REALM_HISTORY ); saslRealmText = BaseWidgetUtils.createCombo( saslComposite, saslHistory, -1, 1 ); BaseWidgetUtils.createLabel( saslComposite, Messages.getString( "AuthenticationParameterPage.SaslQop" ), 1 ); //$NON-NLS-1$ String[] qops = new String[] { Messages.getString( "AuthenticationParameterPage.SaslQopAuth" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.SaslQopAuthInt" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.SaslQopAuthIntPriv" ) //$NON-NLS-1$ }; saslQopCombo = BaseWidgetUtils.createReadonlyCombo( saslComposite, qops, 0, 1 ); BaseWidgetUtils.createLabel( saslComposite, Messages .getString( "AuthenticationParameterPage.SaslSecurityStrength" ), 1 ); //$NON-NLS-1$ String[] securityStrengths = new String[] { Messages.getString( "AuthenticationParameterPage.SaslSecurityStrengthHigh" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.SaslSecurityStrengthMedium" ), //$NON-NLS-1$ Messages.getString( "AuthenticationParameterPage.SaslSecurityStrengthLow" ) //$NON-NLS-1$ }; saslSecurityStrengthCombo = BaseWidgetUtils.createReadonlyCombo( saslComposite, securityStrengths, 0, 1 ); saslMutualAuthenticationButton = BaseWidgetUtils.createCheckbox( saslComposite, Messages .getString( "AuthenticationParameterPage.SaslMutualAuthentication" ), 2 ); //$NON-NLS-1$ } private void createKrb5Controls() { Group credentialProviderGroup = BaseWidgetUtils.createGroup( krb5Composite, Messages .getString( "AuthenticationParameterPage.Krb5CredentialConf" ), 1 ); //$NON-NLS-1$ Composite credentialProviderComposite = BaseWidgetUtils.createColumnContainer( credentialProviderGroup, 1, 1 ); krb5CredentialConfigurationUseNativeButton = BaseWidgetUtils.createRadiobutton( credentialProviderComposite, Messages.getString( "AuthenticationParameterPage.Krb5CredentialConfUseNative" ), 1 ); //$NON-NLS-1$ krb5CredentialConfigurationUseNativeButton.setToolTipText( Messages .getString( "AuthenticationParameterPage.Krb5CredentialConfUseNativeTooltip" ) ); //$NON-NLS-1$ krb5CredentialConfigurationUseNativeButton.setSelection( true ); krb5CredentialConfigurationObtainTgtButton = BaseWidgetUtils.createRadiobutton( credentialProviderComposite, Messages.getString( "AuthenticationParameterPage.Krb5CredentialConfObtainTgt" ), 1 ); //$NON-NLS-1$ krb5CredentialConfigurationObtainTgtButton.setToolTipText( Messages .getString( "AuthenticationParameterPage.Krb5CredentialConfObtainTgtTooltip" ) ); //$NON-NLS-1$ Group configGroup = BaseWidgetUtils.createGroup( krb5Composite, Messages .getString( "AuthenticationParameterPage.Krb5Config" ), 1 ); //$NON-NLS-1$ Composite configComposite = BaseWidgetUtils.createColumnContainer( configGroup, 3, 1 ); krb5ConfigDefaultButton = BaseWidgetUtils.createRadiobutton( configComposite, Messages .getString( "AuthenticationParameterPage.Krb5ConfigDefault" ), 3 ); //$NON-NLS-1$ krb5ConfigDefaultButton.setSelection( true ); krb5ConfigFileButton = BaseWidgetUtils.createRadiobutton( configComposite, Messages .getString( "AuthenticationParameterPage.Krb5ConfigFile" ), 1 ); //$NON-NLS-1$ krb5ConfigFileText = BaseWidgetUtils.createText( configComposite, StringUtils.EMPTY, 2 ); //$NON-NLS-1$ krb5ConfigManualButton = BaseWidgetUtils.createRadiobutton( configComposite, Messages .getString( "AuthenticationParameterPage.Krb5ConfigManual" ), 1 ); //$NON-NLS-1$ BaseWidgetUtils.createLabel( configComposite, Messages.getString( "AuthenticationParameterPage.Krb5Realm" ), //$NON-NLS-1$ 1 ); krb5ConfigManualRealmText = BaseWidgetUtils.createText( configComposite, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ BaseWidgetUtils.createSpacer( configComposite, 1 ); BaseWidgetUtils.createLabel( configComposite, Messages.getString( "AuthenticationParameterPage.Krb5KdcHost" ), 1 ); //$NON-NLS-1$ krb5ConfigManualHostText = BaseWidgetUtils.createText( configComposite, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ BaseWidgetUtils.createSpacer( configComposite, 1 ); BaseWidgetUtils.createLabel( configComposite, Messages.getString( "AuthenticationParameterPage.Krb5KdcPort" ), 1 ); //$NON-NLS-1$ krb5ConfigManualPortText = BaseWidgetUtils.createText( configComposite, "88", 1 ); //$NON-NLS-1$ krb5ConfigManualPortText.setTextLimit( 5 ); } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#validate() */ protected void validate() { // set enabled/disabled state of fields and buttons if ( saslComposite != null ) { for ( Control c : saslComposite.getChildren() ) { c.setEnabled( isSaslEnabled() ); } saslRealmText.setEnabled( isSaslRealmTextEnabled() ); } // TODO: get setting from global preferences. Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences(); boolean useKrb5SystemProperties = preferences .getBoolean( ConnectionCoreConstants.PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES ); if ( krb5Composite != null ) { krb5CredentialConfigurationUseNativeButton.setEnabled( isGssapiEnabled() && !useKrb5SystemProperties ); krb5CredentialConfigurationObtainTgtButton.setEnabled( isGssapiEnabled() && !useKrb5SystemProperties ); krb5ConfigDefaultButton.setEnabled( isGssapiEnabled() && !useKrb5SystemProperties ); krb5ConfigFileButton.setEnabled( isGssapiEnabled() && !useKrb5SystemProperties ); krb5ConfigManualButton.setEnabled( isGssapiEnabled() && !useKrb5SystemProperties ); krb5ConfigFileText.setEnabled( isGssapiEnabled() && krb5ConfigFileButton.getSelection() && !useKrb5SystemProperties ); krb5ConfigManualRealmText.setEnabled( isGssapiEnabled() && krb5ConfigManualButton.getSelection() && !useKrb5SystemProperties ); krb5ConfigManualHostText.setEnabled( isGssapiEnabled() && krb5ConfigManualButton.getSelection() && !useKrb5SystemProperties ); krb5ConfigManualPortText.setEnabled( isGssapiEnabled() && krb5ConfigManualButton.getSelection() && !useKrb5SystemProperties ); } bindPrincipalCombo.setEnabled( isPrincipalPasswordEnabled() ); bindPasswordText.setEnabled( isPrincipalPasswordEnabled() && isSaveBindPassword() ); saveBindPasswordButton.setEnabled( isPrincipalPasswordEnabled() ); checkPrincipalPasswordAuthButton .setEnabled( ( isPrincipalPasswordEnabled() && isSaveBindPassword() && !bindPrincipalCombo.getText().equals( StringUtils.EMPTY ) && !bindPasswordText.getText().equals( StringUtils.EMPTY ) ) || isGssapiEnabled() ); //$NON-NLS-1$ //$NON-NLS-2$ // validate input fields message = null; infoMessage = null; errorMessage = null; if ( isPrincipalPasswordEnabled() ) { if ( isSaveBindPassword() && Strings.isEmpty( bindPasswordText.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "AuthenticationParameterPage.PleaseEnterBindPassword" ); //$NON-NLS-1$ } if ( Strings.isEmpty( bindPrincipalCombo.getText() ) && !isGssapiEnabled() ) //$NON-NLS-1$ { message = Messages.getString( "AuthenticationParameterPage.PleaseEnterBindDNOrUser" ); //$NON-NLS-1$ } } if ( isSaslRealmTextEnabled() && Strings.isEmpty( saslRealmText.getText() ) ) //$NON-NLS-1$ { infoMessage = Messages.getString( "AuthenticationParameterPage.PleaseEnterSaslRealm" ); //$NON-NLS-1$ } if ( isGssapiEnabled() && krb5ConfigFileButton.getSelection() && Strings.isEmpty( krb5ConfigFileText.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "AuthenticationParameterPage.PleaseEnterKrb5ConfigFile" ); //$NON-NLS-1$ } if ( isGssapiEnabled() && krb5ConfigManualButton.getSelection() ) { if ( Strings.isEmpty( krb5ConfigManualPortText.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "AuthenticationParameterPage.PleaseEnterKrb5Port" ); //$NON-NLS-1$ } if ( Strings.isEmpty( krb5ConfigManualHostText.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "AuthenticationParameterPage.PleaseEnterKrb5Host" ); //$NON-NLS-1$ } if ( Strings.isEmpty( krb5ConfigManualRealmText.getText() ) ) //$NON-NLS-1$ { message = Messages.getString( "AuthenticationParameterPage.PleaseEnterKrb5Realm" ); //$NON-NLS-1$ } } } /** * Checks if is principal password enabled. * * @return true, if is principal password enabled */ private boolean isPrincipalPasswordEnabled() { return ( getAuthenticationMethod() == AuthenticationMethod.SIMPLE ) || ( getAuthenticationMethod() == AuthenticationMethod.SASL_DIGEST_MD5 ) || ( getAuthenticationMethod() == AuthenticationMethod.SASL_CRAM_MD5 ) || ( getAuthenticationMethod() == AuthenticationMethod.SASL_GSSAPI && krb5CredentialConfigurationObtainTgtButton .getSelection() ); } private boolean isSaslRealmTextEnabled() { return getAuthenticationMethod() == AuthenticationMethod.SASL_DIGEST_MD5; } private boolean isSaslEnabled() { AuthenticationMethod authenticationMethod = getAuthenticationMethod(); return ( authenticationMethod == AuthenticationMethod.SASL_DIGEST_MD5 ) || ( authenticationMethod == AuthenticationMethod.SASL_CRAM_MD5 ) || ( authenticationMethod == AuthenticationMethod.SASL_GSSAPI ); } private boolean isGssapiEnabled() { return getAuthenticationMethod() == AuthenticationMethod.SASL_GSSAPI; } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage# * loadParameters(org.apache.directory.studio.connection.core.ConnectionParameter) */ protected void loadParameters( ConnectionParameter parameter ) { connectionParameter = parameter; AuthenticationMethod authenticationMethod = parameter.getAuthMethod(); int index = authenticationMethod.getValue(); authenticationMethodCombo.select( index ); bindPrincipalCombo.setText( CommonUIUtils.getTextValue( parameter.getBindPrincipal() ) ); String bindPassword = null; // Checking of the connection passwords keystore is enabled if ( PasswordsKeyStoreManagerUtils.isPasswordsKeystoreEnabled() ) { // Getting the password keystore manager PasswordsKeyStoreManager passwordsKeyStoreManager = ConnectionCorePlugin.getDefault() .getPasswordsKeyStoreManager(); // Checking if the keystore is loaded if ( passwordsKeyStoreManager.isLoaded() ) { bindPassword = passwordsKeyStoreManager.getConnectionPassword( parameter.getId() ); } } else { bindPassword = parameter.getBindPassword(); } bindPasswordText.setText( CommonUIUtils.getTextValue( bindPassword ) ); // The Save Bind Password Button saveBindPasswordButton.setSelection( bindPassword != null ); // The SASL realm saslRealmText.setText( CommonUIUtils.getTextValue( parameter.getSaslRealm() ) ); // The SASL QOP combo int qopIndex; SaslQoP saslQop = parameter.getSaslQop(); switch ( saslQop ) { case AUTH_INT: qopIndex = 1; break; case AUTH_CONF: qopIndex = 2; break; default: qopIndex = 0; break; } saslQopCombo.select( qopIndex ); // The Security Strength int securityStrengthIndex; SaslSecurityStrength securityStrength = parameter.getSaslSecurityStrength(); switch ( securityStrength ) { case MEDIUM: securityStrengthIndex = 1; break; case LOW: securityStrengthIndex = 2; break; default: securityStrengthIndex = 0; break; } saslSecurityStrengthCombo.select( securityStrengthIndex ); // The Mutual Authentication Button saslMutualAuthenticationButton.setSelection( parameter.isSaslMutualAuthentication() ); krb5CredentialConfigurationUseNativeButton .setSelection( parameter.getKrb5CredentialConfiguration() == Krb5CredentialConfiguration.USE_NATIVE ); krb5CredentialConfigurationObtainTgtButton .setSelection( parameter.getKrb5CredentialConfiguration() == Krb5CredentialConfiguration.OBTAIN_TGT ); krb5ConfigDefaultButton.setSelection( parameter.getKrb5Configuration() == Krb5Configuration.DEFAULT ); krb5ConfigFileButton.setSelection( parameter.getKrb5Configuration() == Krb5Configuration.FILE ); krb5ConfigManualButton.setSelection( parameter.getKrb5Configuration() == Krb5Configuration.MANUAL ); krb5ConfigFileText.setText( CommonUIUtils.getTextValue( parameter.getKrb5ConfigurationFile() ) ); //$NON-NLS-1$ krb5ConfigManualRealmText.setText( CommonUIUtils.getTextValue( parameter.getKrb5Realm() ) ); //$NON-NLS-1$ krb5ConfigManualHostText.setText( CommonUIUtils.getTextValue( parameter.getKrb5KdcHost() ) ); //$NON-NLS-1$ krb5ConfigManualPortText.setText( CommonUIUtils.getTextValue( parameter.getKrb5KdcPort() ) ); //$NON-NLS-1$ //$NON-NLS-2$ } /** * @see org.apache.directory.studio.connection.ui.AbstractConnectionParameterPage#initListeners() */ protected void initListeners() { authenticationMethodCombo.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { connectionPageModified(); } } ); bindPrincipalCombo.addModifyListener( event -> connectionPageModified() ); bindPasswordText.addModifyListener( event -> connectionPageModified() ); saveBindPasswordButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { if ( !saveBindPasswordButton.getSelection() ) { // Reseting the previously saved password (if any) bindPasswordText.setText( StringUtils.EMPTY ); //$NON-NLS-1$
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/widgets/ConnectionConfiguration.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.widgets; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Menu; /** * The ConnectionConfiguration contains the content provider, the * label provider and the context menu manager for the * connection widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionConfiguration { /** The disposed flag */ private boolean disposed = false; /** The content provider. */ private ConnectionContentProvider contentProvider; /** The label provider. */ private ConnectionLabelProvider labelProvider; /** The sorter. */ private ConnectionSorter sorter; /** The context menu manager. */ private MenuManager contextMenuManager; /** * Disposes this configuration. */ public void dispose() { if ( !disposed ) { if ( contentProvider != null ) { contentProvider.dispose(); contentProvider = null; } if ( labelProvider != null ) { labelProvider.dispose(); labelProvider = null; } if ( contextMenuManager != null ) { contextMenuManager.dispose(); contextMenuManager = null; } disposed = true; } } /** * Gets the context menu manager. * * @param viewer the connection widget's table viewer * * @return the context menu manager */ public IMenuManager getContextMenuManager( TreeViewer viewer ) { if ( contextMenuManager == null ) { contextMenuManager = new MenuManager(); Menu menu = contextMenuManager.createContextMenu( viewer.getControl() ); viewer.getControl().setMenu( menu ); } return contextMenuManager; } /** * Gets the content provider. * * @param viewer the connection widget's table viewer * * @return the content provider */ public ConnectionContentProvider getContentProvider( TreeViewer viewer ) { if ( contentProvider == null ) { contentProvider = new ConnectionContentProvider(); } return contentProvider; } /** * Gets the label provider. * * @param viewer the connection widget's table viewer * * @return the label provider */ public ConnectionLabelProvider getLabelProvider( TreeViewer viewer ) { if ( labelProvider == null ) { labelProvider = new ConnectionLabelProvider(); } return labelProvider; } /** * Gets the sorter. * * @return the sorter */ public ConnectionSorter getSorter() { if ( sorter == null ) { sorter = new ConnectionSorter(); } return sorter; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CertificateTrustDialog.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CertificateTrustDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import java.security.cert.CertPathValidatorException.BasicReason; import java.security.cert.CertPathValidatorException.Reason; import java.security.cert.X509Certificate; import java.util.Collection; import org.apache.directory.api.ldap.model.exception.LdapTlsHandshakeFailCause; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.ICertificateHandler; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * Dialog to ask for certificate trust. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CertificateTrustDialog extends Dialog { /** The title. */ private String title; /** The trust level. */ private ICertificateHandler.TrustLevel trustLevel; /** The host */ private String host; /** The certificate chain. */ private X509Certificate[] certificateChain; /** The causes of failed certificate validation. */ private Collection<LdapTlsHandshakeFailCause> failCauses; /** * Creates a new instance of CertificateTrustDialog. * * @param parentShell the parent shell * @param host the host * @param certificateChain the certificate chain * @param failCauses the causes of failed certificate validation */ public CertificateTrustDialog( Shell parentShell, String host, X509Certificate[] certificateChain, Collection<LdapTlsHandshakeFailCause> failCauses ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); title = Messages.getString( "CertificateTrustDialog.CertificateTrust" ); //$NON-NLS-1$ this.host = host; this.certificateChain = certificateChain; this.failCauses = failCauses; trustLevel = null; } /** * {@inheritDoc} */ @Override protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( title ); } /** * {@inheritDoc} */ @Override protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.DETAILS_ID, Messages .getString( "CertificateTrustDialog.ViewCertificate" ), false ); //$NON-NLS-1$ createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false ); } /** * {@inheritDoc} */ @Override protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.DETAILS_ID ) { new CertificateInfoDialog( getShell(), certificateChain ).open(); } super.buttonPressed( buttonId ); } /** * {@inheritDoc} */ @Override protected Control createDialogArea( final Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gridData = new GridData( GridData.FILL_BOTH ); gridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); gridData.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 ); composite.setLayoutData( gridData ); BaseWidgetUtils.createWrappedLabel( composite, NLS.bind( Messages .getString( "CertificateTrustDialog.InvalidCertificate" ), host ), 1 ); //$NON-NLS-1$ // failed cause Composite failedCauseContainer = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); for ( LdapTlsHandshakeFailCause failCause : failCauses ) { Reason reason = failCause.getReason(); if ( reason == BasicReason.EXPIRED ) { BaseWidgetUtils.createWrappedLabel( failedCauseContainer, Messages .getString( "CertificateTrustDialog.CertificateExpired" ), 1 ); //$NON-NLS-1$ } else if ( reason == BasicReason.NOT_YET_VALID ) { BaseWidgetUtils.createWrappedLabel( failedCauseContainer, Messages .getString( "CertificateTrustDialog.CertificateNotYetValid" ), 1 ); //$NON-NLS-1$ } else if ( reason == LdapTlsHandshakeFailCause.LdapApiReason.HOST_NAME_VERIFICATION_FAILED ) { BaseWidgetUtils.createWrappedLabel( failedCauseContainer, Messages .getString( "CertificateTrustDialog.HostnameVerificationFailed" ), 1 ); //$NON-NLS-1$ } else if ( reason == LdapTlsHandshakeFailCause.LdapApiReason.NO_VALID_CERTIFICATION_PATH ) { BaseWidgetUtils.createWrappedLabel( failedCauseContainer, Messages .getString( "CertificateTrustDialog.NoValidCertificationPath" ), 1 ); //$NON-NLS-1$ } else if ( reason == LdapTlsHandshakeFailCause.LdapApiReason.SELF_SIGNED ) { BaseWidgetUtils.createWrappedLabel( failedCauseContainer, Messages .getString( "CertificateTrustDialog.SelfSignedCertificate" ), 1 ); //$NON-NLS-1$ } else { BaseWidgetUtils.createWrappedLabel( failedCauseContainer, "- " + failCause.getMessage(), 1 ); } } BaseWidgetUtils.createSpacer( composite, 1 ); BaseWidgetUtils.createSpacer( composite, 1 ); BaseWidgetUtils.createWrappedLabel( composite, NLS.bind( Messages .getString( "CertificateTrustDialog.ChooseTrustLevel" ), host ), 1 ); //$NON-NLS-1$ // The "Don't trust" button Button trustNotButton = BaseWidgetUtils.createRadiobutton( composite, Messages .getString( "CertificateTrustDialog.DoNotTrust" ), 1 ); //$NON-NLS-1$ trustNotButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( final SelectionEvent event ) { CertificateTrustDialog.this.trustLevel = ICertificateHandler.TrustLevel.Not; } } ); // The "Trust in current session" button. Button trustSessionButton = BaseWidgetUtils.createRadiobutton( composite, Messages .getString( "CertificateTrustDialog.TrustForThisSession" ), 1 ); //$NON-NLS-1$ trustSessionButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( final SelectionEvent event ) { CertificateTrustDialog.this.trustLevel = ICertificateHandler.TrustLevel.Session; } } ); // The "Trust permanent" button. Button trustPermanentButton = BaseWidgetUtils.createRadiobutton( composite, Messages .getString( "CertificateTrustDialog.AlwaysTrust" ), 1 ); //$NON-NLS-1$ trustPermanentButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( final SelectionEvent event ) { CertificateTrustDialog.this.trustLevel = ICertificateHandler.TrustLevel.Permanent; } } ); // default settings trustNotButton.setSelection( true ); trustLevel = ICertificateHandler.TrustLevel.Not; return composite; } /** * Gets the trust level. * * @return the trust level */ public ICertificateHandler.TrustLevel getTrustLevel() { return trustLevel; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CertificateInfoDialog.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/CertificateInfoDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import java.security.cert.X509Certificate; import org.apache.directory.studio.connection.ui.widgets.CertificateInfoComposite; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * Dialog to show certificate information. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CertificateInfoDialog extends Dialog { /** The title. */ private String title; /** The certificate chain. */ private X509Certificate[] certificateChain; /** * Creates a new instance of CertificateInfoDialog. * * @param parentShell the parent shell * @param certificateChain the certificate chain */ public CertificateInfoDialog( Shell parentShell, X509Certificate[] certificateChain ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.title = Messages.getString( "CertificateInfoDialog.CertificateViewer" ); //$NON-NLS-1$ this.certificateChain = certificateChain; } /** * {@inheritDoc} */ @Override protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( title ); } /** * {@inheritDoc} */ @Override protected void createButtonsForButtonBar( Composite parent ) { createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CLOSE_LABEL, false ); } /** * {@inheritDoc} */ @Override protected Control createDialogArea( final Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridData gridData = new GridData( GridData.FILL_BOTH ); gridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH * 3 / 2 ); gridData.heightHint = convertVerticalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( gridData ); CertificateInfoComposite certificateInfoComposite = new CertificateInfoComposite( composite, SWT.NONE ); certificateInfoComposite.setInput( certificateChain ); applyDialogFont( composite ); return composite; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ResetPasswordDialog.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ResetPasswordDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * The ResetPasswordDialog is used to ask the user his current password * (for verification purposes) and a new (verified) password. * <p> * It has a useful checkbox that can show/hide the typed passwords. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ResetPasswordDialog extends Dialog { /** The title of the dialog */ private String title; /** The message to display, or <code>null</code> if none */ private String message; /** The current password value; the empty string by default */ private String currentPassword = StringUtils.EMPTY; //$NON-NLS-1$ /** The new password value; the empty string by default */ private String newPassword = StringUtils.EMPTY; //$NON-NLS-1$ // UI Widgets /** The OK button */ private Button okButton; /** The Current Password Text */ private Text currentPasswordText; /** The Show Current Password Checkbox */ private Button showCurrentPasswordCheckbox; /** The New Password Text */ private Text newPasswordText; /** The Show New Password checkbox */ private Button showNewPasswordCheckbox; /** The Verify New Password Text */ private Text verifyNewPasswordText; /** The Show Verify New Password button */ private Button showVerifyNewPasswordCheckbox; /** * Creates a new instance of CredentialsDialog. * * @param parentShell the parent shell * @param title the title * @param message the dialog message * @param initialValue the initial value */ public ResetPasswordDialog( Shell parentShell, String title, String message, String initialValue ) { super( parentShell ); this.title = title; this.message = message; if ( initialValue == null ) { currentPassword = StringUtils.EMPTY; //$NON-NLS-1$ } else { currentPassword = initialValue; } } /** * {@inheritDoc} */ @Override protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( CommonUIUtils.getTextValue( title ) ); } /** * {@inheritDoc} */ @Override protected void createButtonsForButtonBar( Composite parent ) { okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); validate(); } /** * {@inheritDoc} */ @Override protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { currentPassword = currentPasswordText.getText(); newPassword = newPasswordText.getText(); } else { currentPassword = null; newPassword = null; } super.buttonPressed( buttonId ); } /** * {@inheritDoc} */ @Override protected Control createDialogArea( Composite parent ) { // Composite Composite composite = new Composite( parent, SWT.NONE ); GridLayout layout = new GridLayout(); layout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN ); layout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN ); layout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING ); layout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING ); composite.setLayout( layout ); GridData compositeGridData = new GridData( SWT.FILL, SWT.FILL, true, true ); compositeGridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( compositeGridData ); // Message if ( message != null ) { Label messageLabel = BaseWidgetUtils.createWrappedLabel( composite, message, 1 ); GridData messageLabelGridData = new GridData( SWT.FILL, SWT.CENTER, true, true, 2, 1 ); messageLabelGridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); messageLabel.setLayoutData( messageLabelGridData ); } // Current Password Group Group currentPasswordGroup = BaseWidgetUtils.createGroup( composite, Messages.getString( "ResetPasswordDialog.CurrentPassword" ), 1 ); //$NON-NLS-1$ currentPasswordGroup.setLayout( new GridLayout( 2, false ) ); // Current Password Text BaseWidgetUtils.createLabel( currentPasswordGroup, Messages.getString( "ResetPasswordDialog.CurrentPasswordColon" ), 1 ); //$NON-NLS-1$ currentPasswordText = BaseWidgetUtils.createText( currentPasswordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ currentPasswordText.setEchoChar( '\u2022' ); currentPasswordText.addModifyListener( event -> validate() ); // Show Current Password Checkbox BaseWidgetUtils.createLabel( currentPasswordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ showCurrentPasswordCheckbox = BaseWidgetUtils.createCheckbox( currentPasswordGroup, Messages.getString( "ResetPasswordDialog.ShowPassword" ), 1 ); //$NON-NLS-1$ showCurrentPasswordCheckbox.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { if ( showCurrentPasswordCheckbox.getSelection() ) { currentPasswordText.setEchoChar( '\0' ); } else { currentPasswordText.setEchoChar( '\u2022' ); } } } ); // New Password Group Group newPasswordGroup = BaseWidgetUtils.createGroup( composite, Messages.getString( "ResetPasswordDialog.NewPassword" ), 1 ); //$NON-NLS-1$ newPasswordGroup.setLayout( new GridLayout( 2, false ) ); // New Password Text BaseWidgetUtils.createLabel( newPasswordGroup, Messages.getString( "ResetPasswordDialog.NewPasswordColon" ), 1 ); //$NON-NLS-1$ newPasswordText = BaseWidgetUtils.createText( newPasswordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ newPasswordText.setEchoChar( '\u2022' ); newPasswordText.addModifyListener( event -> validate() ); // Show New Password Checkbox BaseWidgetUtils.createLabel( newPasswordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ showNewPasswordCheckbox = BaseWidgetUtils.createCheckbox( newPasswordGroup, Messages.getString( "ResetPasswordDialog.ShowPassword" ), 1 ); //$NON-NLS-1$ showNewPasswordCheckbox.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { if ( showNewPasswordCheckbox.getSelection() ) { newPasswordText.setEchoChar( '\0' ); } else { newPasswordText.setEchoChar( '\u2022' ); } } } ); // Verify Text BaseWidgetUtils.createLabel( newPasswordGroup, Messages.getString( "ResetPasswordDialog.VerifyNewPasswordColon" ), 1 ); //$NON-NLS-1$ verifyNewPasswordText = BaseWidgetUtils.createText( newPasswordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ verifyNewPasswordText.setEchoChar( '\u2022' ); verifyNewPasswordText.addModifyListener( event -> validate() ); // Show Verify New Password Checkbox BaseWidgetUtils.createLabel( newPasswordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ showVerifyNewPasswordCheckbox = BaseWidgetUtils.createCheckbox( newPasswordGroup, Messages.getString( "ResetPasswordDialog.ShowPassword" ), 1 ); //$NON-NLS-1$ showVerifyNewPasswordCheckbox.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { if ( showVerifyNewPasswordCheckbox.getSelection() ) { verifyNewPasswordText.setEchoChar( '\0' ); } else { verifyNewPasswordText.setEchoChar( '\u2022' ); } } } ); // Setting focus currentPasswordGroup.setFocus(); applyDialogFont( composite ); return composite; } /** * Returns current password. * * @return the current password */ public String getCurrentPassword() { return currentPassword; } /** * Returns new password. * * @return the new password */ public String getNewPassword() { return newPassword; } /** * Validates the input. */ private void validate() { String currentPwd = currentPasswordText.getText(); String newPwd = newPasswordText.getText(); String verifyNewPwd = verifyNewPasswordText.getText(); okButton.setEnabled( !Strings.isEmpty( currentPwd ) && !Strings.isEmpty( newPwd ) && newPwd.equals( verifyNewPwd ) && !currentPwd.equals( newPwd ) ); //$NON-NLS-1$ //$NON-NLS-2$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SetupPasswordDialog.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SetupPasswordDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * The SetupPasswordDialog is used to ask the user for a setup password * with a second text widget for verification purposes. * <p> * It has a useful checkbox that can show/hide the typed passwords. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SetupPasswordDialog extends Dialog { /** The title of the dialog */ private String title; /** The message to display, or <code>null</code> if none */ private String message; /** The input value; the empty string by default */ private String value = StringUtils.EMPTY;//$NON-NLS-1$ // UI Widgets /** The OK button */ private Button okButton; /** The Password Text */ private Text passwordText; /** The Show Password Checkbox */ private Button showPasswordCheckbox; /** The Verify Password Text */ private Text verifyPasswordText; /** The Show Verify Password Checkbox */ private Button showVerifyPasswordCheckbox; /** * Creates a new instance of CredentialsDialog. * * @param parentShell the parent shell * @param title the title * @param message the dialog message * @param initialValue the initial value */ public SetupPasswordDialog( Shell parentShell, String title, String message, String initialValue ) { super( parentShell ); this.title = title; this.message = message; if ( initialValue == null ) { value = StringUtils.EMPTY;//$NON-NLS-1$ } else { value = initialValue; } } /** * {@inheritDoc} */ @Override protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( CommonUIUtils.getTextValue( title ) ); } /** * {@inheritDoc} */ @Override protected void createButtonsForButtonBar( Composite parent ) { okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); validate(); } /** * {@inheritDoc} */ @Override protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { value = passwordText.getText(); } else { value = null; } super.buttonPressed( buttonId ); } /** * {@inheritDoc} */ @Override protected Control createDialogArea( Composite parent ) { // Composite Composite composite = new Composite( parent, SWT.NONE ); GridLayout layout = new GridLayout(); layout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN ); layout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN ); layout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING ); layout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING ); composite.setLayout( layout ); GridData compositeGridData = new GridData( SWT.FILL, SWT.FILL, true, true ); compositeGridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( compositeGridData ); // Message if ( message != null ) { Label messageLabel = BaseWidgetUtils.createWrappedLabel( composite, message, 1 ); GridData messageLabelGridData = new GridData( SWT.FILL, SWT.CENTER, true, true ); messageLabelGridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); messageLabel.setLayoutData( messageLabelGridData ); } // Password Group Group passwordGroup = BaseWidgetUtils.createGroup( composite, Messages.getString( "SetupPasswordDialog.Password" ), 1 ); //$NON-NLS-1$ passwordGroup.setLayout( new GridLayout( 2, false ) ); // Password Text BaseWidgetUtils.createLabel( passwordGroup, Messages.getString( "SetupPasswordDialog.PasswordColon" ), 1 ); //$NON-NLS-1$ passwordText = BaseWidgetUtils.createText( passwordGroup, value, 1 ); passwordText.setEchoChar( '\u2022' ); passwordText.addModifyListener( event -> validate() ); // Show Password Checkbox BaseWidgetUtils.createLabel( passwordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ showPasswordCheckbox = BaseWidgetUtils.createCheckbox( passwordGroup, Messages.getString( "SetupPasswordDialog.ShowPassword" ), 1 ); //$NON-NLS-1$ showPasswordCheckbox.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { if ( showPasswordCheckbox.getSelection() ) { passwordText.setEchoChar( '\0' ); } else { passwordText.setEchoChar( '\u2022' ); } } } ); // Verify Text BaseWidgetUtils.createLabel( passwordGroup, Messages.getString( "SetupPasswordDialog.VerifyPasswordColon" ), 1 ); //$NON-NLS-1$ verifyPasswordText = BaseWidgetUtils.createText( passwordGroup, value, 1 ); verifyPasswordText.setEchoChar( '\u2022' ); verifyPasswordText.addModifyListener( event -> validate() ); // Show Verify Password Checkbox BaseWidgetUtils.createLabel( passwordGroup, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ showVerifyPasswordCheckbox = BaseWidgetUtils.createCheckbox( passwordGroup, Messages.getString( "SetupPasswordDialog.ShowPassword" ), 1 ); //$NON-NLS-1$ showVerifyPasswordCheckbox.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { if ( showVerifyPasswordCheckbox.getSelection() ) { verifyPasswordText.setEchoChar( '\0' ); } else { verifyPasswordText.setEchoChar( '\u2022' ); } } } ); // Setting focus passwordText.setFocus(); applyDialogFont( composite ); return composite; } /** * Returns the string typed into this password dialog. * * @return the input string */ public String getPassword() { return value; } /** * Validates the input. */ private void validate() { String password = passwordText.getText(); String verifyPassword = verifyPasswordText.getText(); okButton.setEnabled( ( !Strings.isEmpty( password ) ) && ( password.equals( verifyPassword ) ) ); //$NON-NLS-1$ //$NON-NLS-2$ } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/SelectReferralConnectionDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import java.util.List; import org.apache.directory.api.ldap.model.exception.LdapURLEncodingException; import org.apache.directory.api.ldap.model.url.LdapUrl; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.core.Utils; import org.apache.directory.studio.connection.ui.widgets.ConnectionActionGroup; import org.apache.directory.studio.connection.ui.widgets.ConnectionConfiguration; import org.apache.directory.studio.connection.ui.widgets.ConnectionUniversalListener; import org.apache.directory.studio.connection.ui.widgets.ConnectionWidget; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * Dialog to select the connection of a referral. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class SelectReferralConnectionDialog extends Dialog { /** The dialog title */ private String title; /** The list of available referrals */ private List<String> referralUrls; /** The selected connection */ private Connection selectedConnection; /** The connection configuration */ private ConnectionConfiguration configuration; /** The connection listener */ private ConnectionUniversalListener universalListener; /** The connection action group */ private ConnectionActionGroup actionGroup; /** The connection widget */ private ConnectionWidget mainWidget; /** * Creates a new instance of SelectReferralConnectionDialog. * * @param parentShell the parent shell * @param referralUrl the referral URL */ public SelectReferralConnectionDialog( Shell parentShell, List<String> referralUrls ) { super( parentShell ); super.setShellStyle( super.getShellStyle() | SWT.RESIZE ); this.title = Messages.getString( "SelectReferralConnectionDialog.SelectReferralConenction" ); //$NON-NLS-1$ this.referralUrls = referralUrls; this.selectedConnection = null; } /** * {@inheritDoc} */ @Override protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( title ); } /** * {@inheritDoc} */ @Override public boolean close() { if ( mainWidget != null ) { configuration.dispose(); configuration = null; actionGroup.deactivateGlobalActionHandlers(); actionGroup.dispose(); actionGroup = null; universalListener.dispose(); universalListener = null; mainWidget.dispose(); mainWidget = null; } return super.close(); } /** * {@inheritDoc} */ @Override protected void cancelPressed() { selectedConnection = null; super.cancelPressed(); } /** * {@inheritDoc} */ @Override protected void createButtonsForButtonBar( Composite parent ) { Button okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); okButton.setFocus(); createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); validate(); } private void validate() { if ( getButton( IDialogConstants.OK_ID ) != null ) { getButton( IDialogConstants.OK_ID ).setEnabled( selectedConnection != null ); } } /** * {@inheritDoc} */ @Override protected Control createDialogArea( Composite parent ) { Composite composite = ( Composite ) super.createDialogArea( parent ); GridLayout gridLayout = new GridLayout(); composite.setLayout( gridLayout ); GridData gridData = new GridData( GridData.FILL_BOTH ); gridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); gridData.heightHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2 ); composite.setLayoutData( gridData ); BaseWidgetUtils.createWrappedLabeledText( composite, Messages .getString( "SelectReferralConnectionDialog.SelectConnectionToHandleReferral" ), 1 ); //$NON-NLS-1$ for ( String url : referralUrls ) { BaseWidgetUtils.createWrappedLabeledText( composite, " - " + url, 1 ); //$NON-NLS-1$ } // create configuration configuration = new ConnectionConfiguration(); // create main widget mainWidget = new ConnectionWidget( configuration, null ); mainWidget.createWidget( composite ); mainWidget.setInput( ConnectionCorePlugin.getDefault().getConnectionFolderManager() ); // create actions and context menu (and register global actions) actionGroup = new ConnectionActionGroup( mainWidget, configuration ); actionGroup.fillToolBar( mainWidget.getToolBarManager() ); actionGroup.fillMenu( mainWidget.getMenuManager() ); actionGroup.fillContextMenu( mainWidget.getContextMenuManager() ); actionGroup.activateGlobalActionHandlers(); // create the listener universalListener = new ConnectionUniversalListener( mainWidget.getViewer() ); mainWidget.getViewer().addSelectionChangedListener( event -> { selectedConnection = null; if ( !event.getSelection().isEmpty() ) { Object object = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement(); if ( object instanceof Connection ) { selectedConnection = ( Connection ) object; } } validate(); } ); mainWidget.getViewer().addDoubleClickListener( event -> { selectedConnection = null; if ( !event.getSelection().isEmpty() ) { Object object = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement(); if ( object instanceof Connection ) { selectedConnection = ( Connection ) object; } } validate(); } ); if ( referralUrls != null ) { Connection[] connections = ConnectionCorePlugin.getDefault().getConnectionManager().getConnections(); for ( Connection connection : connections ) { LdapUrl connectionUrl = connection.getUrl(); String normalizedConnectionUrl = Utils.getSimpleNormalizedUrl( connectionUrl ); for ( String url : referralUrls ) { try { if ( ( url != null ) && Utils.getSimpleNormalizedUrl( new LdapUrl( url ) ).equals( normalizedConnectionUrl ) ) { mainWidget.getViewer().reveal( connection ); mainWidget.getViewer().setSelection( new StructuredSelection( connection ), true ); break; } } catch ( LdapURLEncodingException e ) { // Will never occur } } } } applyDialogFont( composite ); validate(); return composite; } /** * Gets the referral connection. * * @return the referral connection */ public Connection getReferralConnection() { return selectedConnection; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/Messages.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * A private constructor : this is an utility class */ private Messages() { } /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/ConnectionFolderDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** * The ConnectionFolderDialog is used to create or rename a connection folder. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionFolderDialog extends InputDialog { /** * Creates a new instance of ConnectionFolderDialog. * * @param parentShell the parent shell * @param dialogTitle the dialog title * @param dialogMessage the dialog message * @param initialValue the initial value * @param validator the validator */ public ConnectionFolderDialog( Shell parentShell, String dialogTitle, String dialogMessage, String initialValue, IInputValidator validator ) { super( parentShell, dialogTitle, dialogMessage, initialValue, validator ); } /** * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ @Override protected Control createDialogArea( Composite parent ) { return super.createDialogArea( parent ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/PasswordDialog.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/dialogs/PasswordDialog.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.dialogs; import org.apache.commons.lang3.StringUtils; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; /** * The PasswordDialog is used to ask the user for password (credentials). * <p> * It has a useful checkbox that can show/hide the typed password. * <pre> * .--------------------------------------------------. * | Enter password for "xxxxx" | * +--------------------------------------------------+ * | Please enter password of user "yyyyyyyyyyyyy" | * | [----------------------------------------------] | * | [ ] Show password | * | | * | (Cancel) ( OK ) | * .__________________________________________________. * </pre> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PasswordDialog extends Dialog { /** The title of the dialog */ private String title; /** The message to display, or <code>null</code> if none */ private String message; /** The input value; the empty string by default */ private String value = StringUtils.EMPTY;//$NON-NLS-1$ // UI Widgets /** The password Text widget */ private Text passwordText; /** The Show Password text widget */ private Button showPasswordCheckbox; /** * Creates a new instance of CredentialsDialog. * * @param parentShell the parent shell * @param title the title * @param message the dialog message * @param initialValue the initial value */ public PasswordDialog( Shell parentShell, String title, String message, String initialValue ) { super( parentShell ); this.title = title; this.message = message; if ( initialValue == null ) { value = StringUtils.EMPTY;//$NON-NLS-1$ } else { value = initialValue; } } /** * {@inheritDoc} */ @Override protected void configureShell( Shell shell ) { super.configureShell( shell ); shell.setText( CommonUIUtils.getTextValue( title ) ); } /** * {@inheritDoc} */ @Override protected void buttonPressed( int buttonId ) { if ( buttonId == IDialogConstants.OK_ID ) { value = passwordText.getText(); } else { value = null; } super.buttonPressed( buttonId ); } /** * The listener for the ShowPassword checkbox */ private SelectionAdapter showPasswordCheckboxListener = new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { if ( showPasswordCheckbox.getSelection() ) { passwordText.setEchoChar( '\0' ); } else { passwordText.setEchoChar( '\u2022' ); } } }; /** * {@inheritDoc} */ @Override protected Control createDialogArea( Composite parent ) { // Composite Composite composite = new Composite( parent, SWT.NONE ); GridLayout layout = new GridLayout(); layout.marginHeight = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_MARGIN ); layout.marginWidth = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_MARGIN ); layout.verticalSpacing = convertVerticalDLUsToPixels( IDialogConstants.VERTICAL_SPACING ); layout.horizontalSpacing = convertHorizontalDLUsToPixels( IDialogConstants.HORIZONTAL_SPACING ); composite.setLayout( layout ); GridData compositeGridData = new GridData( SWT.FILL, SWT.FILL, true, true ); compositeGridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); composite.setLayoutData( compositeGridData ); // Message if ( message != null ) { Label messageLabel = BaseWidgetUtils.createWrappedLabel( composite, message, 1 ); GridData messageLabelGridData = new GridData( SWT.FILL, SWT.CENTER, true, true ); messageLabelGridData.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ); messageLabel.setLayoutData( messageLabelGridData ); } // Password Text passwordText = BaseWidgetUtils.createText( composite, value, 1 ); passwordText.setEchoChar( '\u2022' ); // Show Password Checkbox showPasswordCheckbox = BaseWidgetUtils.createCheckbox( composite, Messages.getString( "PasswordDialog.ShowPassword" ), 1 ); //$NON-NLS-1$ showPasswordCheckbox.addSelectionListener( showPasswordCheckboxListener ); // Setting focus passwordText.setFocus(); applyDialogFont( composite ); return composite; } /** * Returns the string typed into this password dialog. * * @return the input string */ public String getPassword() { return value; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/Messages.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.preferences; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * A private constructor : this is an utility class */ private Messages() { } /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/PasswordsKeystorePreferencePage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/PasswordsKeystorePreferencePage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.preferences; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.security.KeyStoreException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.directory.api.util.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCoreConstants; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.core.ConnectionManager; import org.apache.directory.studio.connection.core.PasswordsKeyStoreManager; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.apache.directory.studio.connection.ui.dialogs.PasswordDialog; import org.apache.directory.studio.connection.ui.dialogs.ResetPasswordDialog; import org.apache.directory.studio.connection.ui.dialogs.SetupPasswordDialog; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** * The passwords keystore preference page contains the settings for keystore * where we store the connections passwords. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class PasswordsKeystorePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** The filename for the temporary keystore */ private static final String TEMPORARY_KEYSTORE_FILENAME = "passwords-prefs-temp.jks"; //$NON-NLS-1$ /** The passwords keystore manager */ private PasswordsKeyStoreManager passwordsKeyStoreManager; /** The map used to backup connections passwords */ private Map<String, String> connectionsPasswordsBackup = new ConcurrentHashMap<>(); /** The connection manager */ private ConnectionManager connectionManager; // UI Widgets private Button enableKeystoreCheckbox; private Button changeMasterPasswordButton; // Listeners private SelectionListener enableKeystoreCheckboxListener = new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { Boolean selected = enableKeystoreCheckbox.getSelection(); try { if ( selected ) { if ( !enablePasswordsKeystore() ) { enableKeystoreCheckbox.setSelection( !selected ); } } else { if ( !disablePasswordsKeystore() ) { enableKeystoreCheckbox.setSelection( !selected ); } } } catch ( KeyStoreException kse ) { CommonUIUtils.openErrorDialog( Messages .getString( "PasswordsKeystorePreferencePage.AnErrorOccurredWhenEnablingDisablingTheKeystore" ) //$NON-NLS-1$ + kse.getMessage() ); enableKeystoreCheckbox.setSelection( !selected ); } updateButtonsEnabledState(); } }; private SelectionListener changeMasterPasswordButtonListener = new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { changeMasterPassword(); } }; /** * Creates a new instance of PasswordsKeyStorePreferencePage. */ public PasswordsKeystorePreferencePage() { super( Messages.getString( "PasswordsKeystorePreferencePage.PasswordsKeystore" ) ); //$NON-NLS-1$ super.setDescription( Messages .getString( "PasswordsKeystorePreferencePage.GeneralSettingsForPasswordsKeystore" ) ); //$NON-NLS-1$ super.noDefaultAndApplyButton(); passwordsKeyStoreManager = new PasswordsKeyStoreManager( TEMPORARY_KEYSTORE_FILENAME ); connectionManager = ConnectionCorePlugin.getDefault().getConnectionManager(); } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { // Getting the keystore file File keystoreFile = ConnectionCorePlugin.getDefault().getPasswordsKeyStoreManager().getKeyStoreFile(); // If the keystore file exists, let's create a copy of it if ( keystoreFile.exists() ) { try { // Copying the file Files.copy( keystoreFile.toPath(), getTemporaryKeystoreFile().toPath() ); } catch ( IOException e ) { ConnectionUIPlugin .getDefault() .getLog() .log( new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR, "Couldn't duplicate the global keystore file.", e ) ); //$NON-NLS-1$ } } } /** * Gets the file for the temporary keystore. * * @return the file for the temporary keystore */ private File getTemporaryKeystoreFile() { return ConnectionCorePlugin.getDefault().getStateLocation().append( TEMPORARY_KEYSTORE_FILENAME ).toFile(); } /** * {@inheritDoc} */ @Override protected void contributeButtons( Composite parent ) { // Increasing the number of columns on the parent layout ( ( GridLayout ) parent.getLayout() ).numColumns++; // Change Master Password Button changeMasterPasswordButton = BaseWidgetUtils.createButton( parent, Messages.getString( "PasswordsKeystorePreferencePage.ChangeMasterPasswordEllipsis" ), 1 ); //$NON-NLS-1$ changeMasterPasswordButton.setLayoutData( new GridData( SWT.BEGINNING, SWT.CENTER, false, false ) ); changeMasterPasswordButton.addSelectionListener( changeMasterPasswordButtonListener ); updateButtonsEnabledState(); } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 ); // Enable Keystore Checkbox enableKeystoreCheckbox = new Button( composite, SWT.CHECK | SWT.WRAP ); enableKeystoreCheckbox .setText( Messages .getString( "PasswordsKeystorePreferencePage.StoreConnectionsPasswordsInPasswordProtectedKeystore" ) ); //$NON-NLS-1$ enableKeystoreCheckbox.setLayoutData( new GridData( SWT.BEGINNING, SWT.CENTER, false, false, 2, 1 ) ); // Warning Label BaseWidgetUtils.createRadioIndent( composite, 1 ); BaseWidgetUtils .createWrappedLabel( composite, Messages.getString( "PasswordsKeystorePreferencePage.WarningPasswordsKeystoreRequiresMasterPassword" ), //$NON-NLS-1$ 1 ); initUI(); addListeners(); return composite; } /** * Initializes the UI. */ private void initUI() { int connectionsPasswordsKeystore = ConnectionCorePlugin.getDefault().getPluginPreferences() .getInt( ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE ); if ( connectionsPasswordsKeystore == ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_OFF ) { enableKeystoreCheckbox.setSelection( false ); } else if ( connectionsPasswordsKeystore == ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_ON ) { enableKeystoreCheckbox.setSelection( true ); } } /** * Adds the listeners. */ private void addListeners() { enableKeystoreCheckbox.addSelectionListener( enableKeystoreCheckboxListener ); } /** * Removes the listeners. */ private void removeListeners() { enableKeystoreCheckbox.removeSelectionListener( enableKeystoreCheckboxListener ); } /** * Updates the buttons enabled state. */ private void updateButtonsEnabledState() { changeMasterPasswordButton.setEnabled( enableKeystoreCheckbox.getSelection() ); } /** * {@inheritDoc} */ @Override protected void performDefaults() { removeListeners(); int enablePasswordsKeystore = ConnectionCorePlugin.getDefault().getPluginPreferences() .getDefaultInt( ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE ); if ( enablePasswordsKeystore == ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_OFF ) { enableKeystoreCheckbox.setSelection( false ); } else if ( enablePasswordsKeystore == ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_ON ) { enableKeystoreCheckbox.setSelection( true ); } updateButtonsEnabledState(); addListeners(); ConnectionCorePlugin.getDefault().savePluginPreferences(); super.performDefaults(); } /** * {@inheritDoc} */ public boolean performOk() { PasswordsKeyStoreManager globalPasswordsKeyStoreManager = ConnectionCorePlugin.getDefault() .getPasswordsKeyStoreManager(); if ( enableKeystoreCheckbox.getSelection() ) { if ( passwordsKeyStoreManager.isLoaded() ) { // First, let's save the temporary keystore manager try { passwordsKeyStoreManager.save(); } catch ( KeyStoreException e ) { ConnectionUIPlugin .getDefault() .getLog() .log( new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR, "Couldn't save the temporary password keystore.", e ) ); //$NON-NLS-1$ } // Now, let's copy the temporary keystore as the global keystore try { Files.copy( getTemporaryKeystoreFile().toPath(), ConnectionCorePlugin.getDefault() .getPasswordsKeyStoreManager().getKeyStoreFile().toPath() ); } catch ( IOException e ) { ConnectionUIPlugin .getDefault() .getLog() .log( new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR, "Couldn't copy the temporary keystore as the global keystore.", e ) ); //$NON-NLS-1$ } // Finally lets reload the global keystore try { globalPasswordsKeyStoreManager.reload( passwordsKeyStoreManager.getMasterPassword() ); } catch ( KeyStoreException e ) { ConnectionUIPlugin .getDefault() .getLog() .log( new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR, "Couldn't reload the global keystore file.", e ) ); //$NON-NLS-1$ } // Clearing each connection password for ( Connection connection : connectionManager.getConnections() ) { connection.getConnectionParameter().setBindPassword( null ); } // Saving the connections ConnectionCorePlugin.getDefault().getConnectionManager().saveConnections(); // Saving the value to the preferences ConnectionCorePlugin.getDefault().getPluginPreferences() .setValue( ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE, ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_ON ); } } else { // Reseting the global passwords keystore globalPasswordsKeyStoreManager.reset(); // Looking for connections passwords in the list if ( !connectionsPasswordsBackup.isEmpty() ) { // Adding them to the keystore for ( Map.Entry<String, String> entry : connectionsPasswordsBackup.entrySet() ) { Connection connection = connectionManager.getConnectionById( entry.getKey() ); if ( connection != null ) { connection.getConnectionParameter().setBindPassword( entry.getValue() ); } } // Saving the connections ConnectionCorePlugin.getDefault().getConnectionManager().saveConnections(); } // Saving the value to the preferences ConnectionCorePlugin.getDefault().getPluginPreferences() .setValue( ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE, ConnectionCoreConstants.PREFERENCE_CONNECTIONS_PASSWORDS_KEYSTORE_OFF ); } ConnectionCorePlugin.getDefault().savePluginPreferences(); deleteTemporaryKeystore(); return true; } /** * {@inheritDoc} */ public boolean performCancel() { deleteTemporaryKeystore(); return true; } /** * Deletes the temporary keystore (if it exists) */ private void deleteTemporaryKeystore() { // Getting the temporary keystore file File temporaryKeystoreFile = getTemporaryKeystoreFile(); // If the temporary keystore file exists, we need to remove it if ( temporaryKeystoreFile.exists() ) { // Deleting the file FileUtils.deleteQuietly( temporaryKeystoreFile ); } } /** * Enables the passwords keystore. * * @return <code>true</code> if the passwords keystore was successfully enabled, * <code>false</code> if not. * @throws KeyStoreException */ private boolean enablePasswordsKeystore() throws KeyStoreException { // Asking the user for a password SetupPasswordDialog setupPasswordDialog = new SetupPasswordDialog( enableKeystoreCheckbox.getShell(), Messages.getString( "PasswordsKeystorePreferencePage.SetupMasterPassword" ), //$NON-NLS-1$ Messages.getString( "PasswordsKeystorePreferencePage.PleaseEnterMasterPasswordToSecurePasswordsKeystore" ), //$NON-NLS-1$ null ); if ( setupPasswordDialog.open() == SetupPasswordDialog.OK ) { // Getting the master password String masterPassword = setupPasswordDialog.getPassword(); // Loading the keystore passwordsKeyStoreManager.load( masterPassword ); // Storing each connection password in the keystore for ( Connection connection : connectionManager.getConnections() ) { String connectionPassword = connection.getBindPassword(); if ( connectionPassword != null ) { passwordsKeyStoreManager.storeConnectionPassword( connection, connectionPassword, false ); } } // Saving the keystore on disk passwordsKeyStoreManager.save(); return true; } return false; } /** * Disables the passwords keystore. * * @return <code>true</code> if the passwords keystore was successfully disabled, * <code>false</code> if not. */ private boolean disablePasswordsKeystore() { // Asking the user if he wants to keep its connections passwords MessageDialog keepConnectionsPasswordsDialog = new MessageDialog( enableKeystoreCheckbox.getShell(), Messages.getString( "PasswordsKeystorePreferencePage.KeepConnectionsPasswords" ), //$NON-NLS-1$ null, Messages.getString( "PasswordsKeystorePreferencePage.DoYouWantToKeepYourConnectionsPasswords" ), //$NON-NLS-1$ MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0 ); int keepConnectionsPasswordsValue = keepConnectionsPasswordsDialog.open(); if ( keepConnectionsPasswordsValue == 1 ) { // The user chose NOT to keep the connections passwords connectionsPasswordsBackup.clear(); passwordsKeyStoreManager.deleteKeystoreFile(); return true; } else if ( keepConnectionsPasswordsValue == 0 ) { // The user chose to keep the connections passwords connectionsPasswordsBackup.clear(); while ( true ) { // We ask the user for the keystore password PasswordDialog passwordDialog = new PasswordDialog( enableKeystoreCheckbox.getShell(), Messages.getString( "PasswordsKeystorePreferencePage.VerifyMasterPassword" ), Messages.getString( "PasswordsKeystorePreferencePage.PleaseEnterYourMasterPassword" ), //$NON-NLS-1$ //$NON-NLS-2$ null ); if ( passwordDialog.open() == PasswordDialog.CANCEL ) { // The user cancelled the action return false; } // Getting the password String password = passwordDialog.getPassword(); // Checking the password Exception checkPasswordException = null; try { if ( passwordsKeyStoreManager.checkMasterPassword( password ) ) { break; } } catch ( KeyStoreException e ) { checkPasswordException = e; } // Creating the message String message = null; if ( checkPasswordException == null ) { message = Messages.getString( "PasswordsKeystorePreferencePage.MasterPasswordVerificationFailed" ); //$NON-NLS-1$ } else { message = Messages .getString( "PasswordsKeystorePreferencePage.MasterPasswordVerificationFailedWithException" ) //$NON-NLS-1$ + checkPasswordException.getMessage(); } // We ask the user if he wants to retry to unlock the passwords keystore MessageDialog errorDialog = new MessageDialog( enableKeystoreCheckbox.getShell(), Messages.getString( "PasswordsKeystorePreferencePage.VerifyMasterPasswordFailed" ), null, message, MessageDialog.ERROR, new String[] //$NON-NLS-1$ { IDialogConstants.RETRY_LABEL, IDialogConstants.CANCEL_LABEL }, 0 ); if ( errorDialog.open() == MessageDialog.CANCEL ) { // The user cancelled the action return false; } } // Getting the connection IDs having their passwords saved in the keystore String[] connectionIds = passwordsKeyStoreManager.getConnectionIds(); if ( connectionIds != null ) { // Adding the passwords to the backup map for ( String connectionId : connectionIds ) { String password = passwordsKeyStoreManager.getConnectionPassword( connectionId ); if ( password != null ) { connectionsPasswordsBackup.put( connectionId, password ); } } } passwordsKeyStoreManager.deleteKeystoreFile(); return true; } else { // The user cancelled the action return false; } } /** * Changes the master password. * * @return <code>true</code> if the master password was successfully changed, * <code>false</code> if not. */ private void changeMasterPassword() { String newMasterPassword = null; while ( true ) { // We ask the user to reset his master password ResetPasswordDialog resetPasswordDialog = new ResetPasswordDialog( changeMasterPasswordButton.getShell(), StringUtils.EMPTY, null, null ); //$NON-NLS-1$ if ( resetPasswordDialog.open() != ResetPasswordDialog.OK ) { // The user cancelled the action return; } // Checking the password Exception checkPasswordException = null; try { if ( passwordsKeyStoreManager.checkMasterPassword( resetPasswordDialog.getCurrentPassword() ) ) { newMasterPassword = resetPasswordDialog.getNewPassword(); break; } } catch ( KeyStoreException e ) { checkPasswordException = e; } // Creating the message String message = null; if ( checkPasswordException == null ) { message = Messages.getString( "PasswordsKeystorePreferencePage.MasterPasswordVerificationFailed" ); //$NON-NLS-1$ } else { message = Messages .getString( "PasswordsKeystorePreferencePage.MasterPasswordVerificationFailedWithException" ) //$NON-NLS-1$ + checkPasswordException.getMessage(); } // We ask the user if he wants to retry to unlock the passwords keystore MessageDialog errorDialog = new MessageDialog( enableKeystoreCheckbox.getShell(), Messages.getString( "PasswordsKeystorePreferencePage.VerifyMasterPasswordFailed" ), null, message, MessageDialog.ERROR, new String[] //$NON-NLS-1$ { IDialogConstants.RETRY_LABEL, IDialogConstants.CANCEL_LABEL }, 0 ); if ( errorDialog.open() == MessageDialog.CANCEL ) { // The user cancelled the action return; } } if ( newMasterPassword != null ) { try { passwordsKeyStoreManager.setMasterPassword( newMasterPassword ); passwordsKeyStoreManager.save(); } catch ( KeyStoreException e ) { ConnectionUIPlugin .getDefault() .getLog() .log( new Status( Status.ERROR, ConnectionUIConstants.PLUGIN_ID, Status.ERROR, "Couldn't save the keystore file.", e ) ); //$NON-NLS-1$ } } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/ConnectionsPreferencePage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/ConnectionsPreferencePage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.preferences; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.ConnectionCoreConstants; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** * The connections preference page contains general settings for LDAP connections. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { private Button useKrb5SystemPropertiesButton; private Label krb5LoginModuleNoteLabel; private Text krb5LoginModuleText; private Label krb5LoginModuleLabel; /** * Creates a new instance of ConnectionsPreferencePage. */ public ConnectionsPreferencePage() { super( Messages.getString( "ConnectionsPreferencePage.Connections" ) ); //$NON-NLS-1$ super.setPreferenceStore( ConnectionUIPlugin.getDefault().getPreferenceStore() ); super.setDescription( Messages.getString( "ConnectionsPreferencePage.GeneralSettings" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { // Nothing to do } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); BaseWidgetUtils.createSpacer( composite, 1 ); BaseWidgetUtils.createSpacer( composite, 1 ); Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences(); Group krb5SettingsGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), Messages .getString( "ConnectionsPreferencePage.Krb5Settings" ), 1 ); //$NON-NLS-1$ boolean useKrb5SystemProperties = preferences .getBoolean( ConnectionCoreConstants.PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES ); useKrb5SystemPropertiesButton = BaseWidgetUtils.createCheckbox( krb5SettingsGroup, Messages .getString( "ConnectionsPreferencePage.UseKrb5SystemProperties" ), 1 ); //$NON-NLS-1$ useKrb5SystemPropertiesButton.setToolTipText( Messages .getString( "ConnectionsPreferencePage.UseKrb5SystemPropertiesTooltip" ) ); //$NON-NLS-1$ useKrb5SystemPropertiesButton.setSelection( useKrb5SystemProperties ); krb5LoginModuleLabel = BaseWidgetUtils.createLabel( krb5SettingsGroup, Messages .getString( "ConnectionsPreferencePage.Krb5LoginModule" ), 1 ); //$NON-NLS-1$ String krb5LoginModule = preferences.getString( ConnectionCoreConstants.PREFERENCE_KRB5_LOGIN_MODULE ); String defaultKrb5LoginModule = preferences .getDefaultString( ConnectionCoreConstants.PREFERENCE_KRB5_LOGIN_MODULE ); String krb5LoginModuleNote = NLS.bind( Messages .getString( "ConnectionsPreferencePage.SystemDetectedContextFactory" ), defaultKrb5LoginModule ); //$NON-NLS-1$ krb5LoginModuleText = BaseWidgetUtils.createText( krb5SettingsGroup, krb5LoginModule, 1 ); krb5LoginModuleNoteLabel = BaseWidgetUtils.createWrappedLabel( krb5SettingsGroup, krb5LoginModuleNote, 1 ); useKrb5SystemPropertiesButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { validate(); } } ); validate(); return composite; } private void validate() { krb5LoginModuleLabel.setEnabled( !useKrb5SystemPropertiesButton.getSelection() ); krb5LoginModuleText.setEnabled( !useKrb5SystemPropertiesButton.getSelection() ); krb5LoginModuleNoteLabel.setEnabled( !useKrb5SystemPropertiesButton.getSelection() ); } /** * {@inheritDoc} */ @Override protected void performDefaults() { krb5LoginModuleText.setText( ConnectionCorePlugin.getDefault().getPluginPreferences().getDefaultString( ConnectionCoreConstants.PREFERENCE_KRB5_LOGIN_MODULE ) ); useKrb5SystemPropertiesButton.setSelection( ConnectionCorePlugin.getDefault().getPluginPreferences() .getDefaultBoolean( ConnectionCoreConstants.PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES ) ); super.performDefaults(); } /** * {@inheritDoc} */ public boolean performOk() { ConnectionCorePlugin.getDefault().getPluginPreferences().setValue( ConnectionCoreConstants.PREFERENCE_KRB5_LOGIN_MODULE, krb5LoginModuleText.getText() ); ConnectionCorePlugin.getDefault().getPluginPreferences() .setValue( ConnectionCoreConstants.PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES, useKrb5SystemPropertiesButton.getSelection() ); ConnectionCorePlugin.getDefault().savePluginPreferences(); return true; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/CertificateValidationPreferencePage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/preferences/CertificateValidationPreferencePage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.preferences; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.core.ConnectionCoreConstants; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.apache.directory.studio.connection.ui.widgets.CertificateListComposite; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** * The certificate validation preference page is used to manage trusted certificates. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class CertificateValidationPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { /** The verify certificates button. */ private Button verifyCertificatesButton; /** The tab folder. */ private TabFolder tabFolder; /** * * Creates a new instance of MainPreferencePage. */ public CertificateValidationPreferencePage() { super( Messages.getString( "CertificateValidationPreferencePage.CertificateValidation" ) ); //$NON-NLS-1$ super.setPreferenceStore( ConnectionUIPlugin.getDefault().getPreferenceStore() ); //super.setDescription( Messages.getString( "SecurityPreferencePage.GeneralSettings" ) ); //$NON-NLS-1$ } /** * {@inheritDoc} */ public void init( IWorkbench workbench ) { // Nothing to do } /** * {@inheritDoc} */ protected Control createContents( Composite parent ) { Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); // enable/disable certificate validation Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences(); boolean validateCertificates = preferences .getBoolean( ConnectionCoreConstants.PREFERENCE_VALIDATE_CERTIFICATES ); verifyCertificatesButton = BaseWidgetUtils.createCheckbox( composite, Messages .getString( "CertificateValidationPreferencePage.ValidateCertificates" ), 1 ); //$NON-NLS-1$ verifyCertificatesButton.setSelection( validateCertificates ); verifyCertificatesButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent event ) { tabFolder.setEnabled( verifyCertificatesButton.getSelection() ); } } ); // certificate list widget tabFolder = new TabFolder( composite, SWT.TOP ); tabFolder.setLayoutData( new GridData( GridData.FILL, GridData.FILL, true, true ) ); CertificateListComposite permanentCLComposite = new CertificateListComposite( tabFolder, SWT.NONE ); permanentCLComposite.setInput( ConnectionCorePlugin.getDefault().getPermanentTrustStoreManager() ); TabItem permanentTab = new TabItem( tabFolder, SWT.NONE, 0 ); permanentTab.setText( Messages.getString( "CertificateValidationPreferencePage.PermanentTrusted" ) ); //$NON-NLS-1$ permanentTab.setControl( permanentCLComposite ); CertificateListComposite sessionCLComposite = new CertificateListComposite( tabFolder, SWT.NONE ); sessionCLComposite.setInput( ConnectionCorePlugin.getDefault().getSessionTrustStoreManager() ); TabItem sessionTab = new TabItem( tabFolder, SWT.NONE, 1 ); sessionTab.setText( Messages.getString( "CertificateValidationPreferencePage.TemporaryTrusted" ) ); //$NON-NLS-1$ sessionTab.setControl( sessionCLComposite ); tabFolder.setEnabled( verifyCertificatesButton.getSelection() ); return composite; } /** * {@inheritDoc} */ @Override protected void performDefaults() { verifyCertificatesButton.setSelection( ConnectionCorePlugin.getDefault().getPluginPreferences() .getDefaultBoolean( ConnectionCoreConstants.PREFERENCE_VALIDATE_CERTIFICATES ) ); ConnectionCorePlugin.getDefault().savePluginPreferences(); super.performDefaults(); } /** * {@inheritDoc} */ public boolean performOk() { ConnectionCorePlugin.getDefault().getPluginPreferences().setValue( ConnectionCoreConstants.PREFERENCE_VALIDATE_CERTIFICATES, verifyCertificatesButton.getSelection() ); ConnectionCorePlugin.getDefault().savePluginPreferences(); return true; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizardPage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizardPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.wizards; import java.io.File; import org.apache.commons.lang3.StringUtils; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.common.ui.CommonUIUtils; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.jface.dialogs.DialogPage; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; /** * This class implements the Export Certificate wizard page. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportCertificateWizardPage extends WizardPage { // UI widgets /** The certificate file name */ private Text fileText; /** The button for overwriting teh file */ private Button overwriteFileButton; /** The combo for the certificate format (DER or PEM) */ private ComboViewer formatComboViewer; /** * Creates a new instance of NewConnectionWizard. * * @param page the page * @param wizard the wizard */ public ExportCertificateWizardPage() { super( "ExportCertificateWizardPage" ); //$NON-NLS-1$ setTitle( Messages.getString( "ExportCertificateWizardPage.ExportCertificate" ) ); //$NON-NLS-1$ setDescription( Messages.getString( "ExportCertificateWizardPage.PleaseSelectFileAndFormat" ) ); //$NON-NLS-1$ setImageDescriptor( ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_CERTIFICATE_EXPORT_WIZARD ) ); } /** * {@inheritDoc} */ public void createControl( Composite parent ) { // Creating the composite Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); composite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Creating the file's group widget Group fileGroup = BaseWidgetUtils.createGroup( composite, Messages.getString( "ExportCertificateWizardPage.File" ), 1 ); //$NON-NLS-1$ fileGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); Composite fileComposite = BaseWidgetUtils.createColumnContainer( fileGroup, 2, 1 ); fileComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Creating the file's text widget fileText = BaseWidgetUtils.createText( fileComposite, StringUtils.EMPTY, 1 ); //$NON-NLS-1$ fileText.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) ); fileText.addModifyListener( event -> validate() ); // Creating the file's 'Browse' button widget Button browseButton = BaseWidgetUtils.createButton( fileComposite, Messages.getString( "ExportCertificateWizardPage.Browse" ), 1 ); //$NON-NLS-1$ browseButton.addSelectionListener( new SelectionAdapter() { /** * {@inheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { chooseExportFile(); validate(); } } ); // Creating the file's 'Overwrite' button widget overwriteFileButton = BaseWidgetUtils.createCheckbox( fileComposite, Messages.getString( "ExportCertificateWizardPage.OverwriteExistingFile" ), 2 ); //$NON-NLS-1$ overwriteFileButton.addSelectionListener( new SelectionAdapter() { /** * {@InheritDoc} */ @Override public void widgetSelected( SelectionEvent event ) { validate(); } } ); // Creating the format's group widget Group formatGroup = BaseWidgetUtils.createGroup( composite, Messages.getString( "ExportCertificateWizardPage.Format" ), 1 ); //$NON-NLS-1$ formatGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // Creating the format's combo viewer widget formatComboViewer = new ComboViewer( formatGroup ); formatComboViewer.setContentProvider( new ArrayContentProvider() ); formatComboViewer.setLabelProvider( new LabelProvider() { /** * {@InheritDoc} */ @Override public String getText( Object element ) { if ( element instanceof CertificateExportFormat ) { CertificateExportFormat format = ( CertificateExportFormat ) element; if ( format == CertificateExportFormat.DER ) { return Messages.getString( "ExportCertificateWizardPage.X509CertificateDER" ); //$NON-NLS-1$ } else { return Messages.getString( "ExportCertificateWizardPage.X509CertificatePEM" ); //$NON-NLS-1$ } } return super.getText( element ); } } ); formatComboViewer.setInput( new CertificateExportFormat[] { CertificateExportFormat.DER, CertificateExportFormat.PEM } ); formatComboViewer.setSelection( new StructuredSelection( CertificateExportFormat.DER ) ); formatComboViewer.getControl().setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); displayErrorMessage( null ); setPageComplete( false ); setControl( composite ); } /** * Validates the page. */ private void validate() { File file = new File( fileText.getText() ); if ( file.isDirectory() ) { displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileNotAFile" ) ); //$NON-NLS-1$ return; } else if ( file.exists() && !overwriteFileButton.getSelection() ) { displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileAlreadyExists" ) ); //$NON-NLS-1$ return; } else if ( file.exists() && !file.canWrite() ) { displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileNotWritable" ) ); //$NON-NLS-1$ return; } else if ( file.getParentFile() == null ) { displayErrorMessage( Messages.getString( "ExportCertificateWizardPage.ErrorFileDirectoryNotWritable" ) ); //$NON-NLS-1$ return; } displayErrorMessage( null ); } /** * Displays an error message and set the page status as incomplete * if the message is not null. * * @param message the message to display */ protected void displayErrorMessage( String message ) { setMessage( null, DialogPage.NONE ); setErrorMessage( message ); setPageComplete( message == null ); } /** * This method is called when the 'browse' button is selected. */ private void chooseExportFile() { FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE ); dialog.setText( Messages.getString( "ExportCertificateWizardPage.ChooseFile" ) ); //$NON-NLS-1$ if ( !Strings.isEmpty( fileText.getText() ) ) //$NON-NLS-1$ { dialog.setFilterPath( fileText.getText() ); } String selectedFile = dialog.open(); fileText.setText( CommonUIUtils.getTextValue( selectedFile ) ); } /** * Returns the export file. * * @return the export file */ public File getExportFile() { return new File( fileText.getText() ); } /** * Gets the certificate export format. * * @return the certificate export format */ public CertificateExportFormat getCertificateExportFormat() { StructuredSelection selection = ( StructuredSelection ) formatComboViewer.getSelection(); if ( !selection.isEmpty() ) { return ( CertificateExportFormat ) selection.getFirstElement(); } // Default format return CertificateExportFormat.DER; } /** * This enum represents the various certificate export formats. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ enum CertificateExportFormat { DER, PEM } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/Messages.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.wizards; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * This class get messages from the resources file. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class Messages { /** The resource name */ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" ); /** * A private constructor : this is an utility class */ private Messages() { } /** * Get back a message from the resource file given a key * * @param key The key associated with the message * @return The found message */ public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizard.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizard.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.wizards; import org.apache.directory.studio.connection.core.Connection; import org.apache.directory.studio.connection.core.ConnectionCorePlugin; import org.apache.directory.studio.connection.core.ConnectionFolder; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.core.jobs.OpenConnectionsRunnable; import org.apache.directory.studio.connection.core.jobs.StudioConnectionJob; import org.apache.directory.studio.connection.ui.ConnectionParameterPage; import org.apache.directory.studio.connection.ui.ConnectionParameterPageManager; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; /** * The NewConnectionWizard is used to create a new connection. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewConnectionWizard extends Wizard implements INewWizard { /** The wizard pages. */ private NewConnectionWizardPage[] wizardPages; /** The connection parameter pages. */ private ConnectionParameterPage[] pages; /** The selected connection folder. */ private ConnectionFolder selectedConnectionFolder; /** * Creates a new instance of NewConnectionWizard. */ public NewConnectionWizard() { super(); setWindowTitle( Messages.getString( "NewConnectionWizard.NewLdapConnection" ) ); //$NON-NLS-1$ setNeedsProgressMonitor( true ); } /** * Gets the id. * * @return the id */ public static String getId() { return ConnectionUIConstants.NEW_WIZARD_NEW_CONNECTION; } /** * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) */ public void init( IWorkbench workbench, IStructuredSelection selection ) { Object firstElement = selection.getFirstElement(); if ( firstElement instanceof ConnectionFolder ) { selectedConnectionFolder = ( ConnectionFolder ) firstElement; } else if ( firstElement instanceof Connection ) { Connection connection = ( Connection ) firstElement; selectedConnectionFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager() .getParentConnectionFolder( connection ); } if ( selectedConnectionFolder == null ) { selectedConnectionFolder = ConnectionCorePlugin.getDefault().getConnectionFolderManager() .getRootConnectionFolder(); } } /** * @see org.eclipse.jface.wizard.Wizard#addPages() */ public void addPages() { pages = ConnectionParameterPageManager.getConnectionParameterPages(); wizardPages = new NewConnectionWizardPage[pages.length]; for ( int i = 0; i < pages.length; i++ ) { wizardPages[i] = new NewConnectionWizardPage( this, pages[i] ); addPage( wizardPages[i] ); pages[i].setRunnableContext( getContainer() ); } } /** * @see org.eclipse.jface.wizard.Wizard#createPageControls(org.eclipse.swt.widgets.Composite) */ public void createPageControls( Composite pageContainer ) { super.createPageControls( pageContainer ); for ( NewConnectionWizardPage wizardPage : wizardPages ) { PlatformUI.getWorkbench().getHelpSystem().setHelp( wizardPage.getControl(), ConnectionUIConstants.PLUGIN_ID + "." + "tools_newconnection_wizard" ); //$NON-NLS-1$ //$NON-NLS-2$ } } /** * @see org.eclipse.jface.wizard.Wizard#canFinish() */ public boolean canFinish() { for ( ConnectionParameterPage page: pages ) { if ( !page.isValid() ) { return false; } } return true; } /** * @see org.eclipse.jface.wizard.Wizard#performFinish() */ public boolean performFinish() { // get connection parameters from pages and save dialog settings ConnectionParameter connectionParameter = new ConnectionParameter(); for ( ConnectionParameterPage page: pages ) { page.saveParameters( connectionParameter ); page.saveDialogSettings(); } // create persistent connection Connection conn = new Connection( connectionParameter ); ConnectionCorePlugin.getDefault().getConnectionManager().addConnection( conn ); // add connection to folder selectedConnectionFolder.addConnectionId( conn.getId() ); // open connection new StudioConnectionJob( new OpenConnectionsRunnable( conn ) ).execute(); return true; } /** * Gets the test connection parameters. * * @return the test connection parameters */ public ConnectionParameter getTestConnectionParameters() { ConnectionParameter connectionParameter = new ConnectionParameter(); for ( ConnectionParameterPage page: pages ) { page.saveParameters( connectionParameter ); } return connectionParameter; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizard.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/ExportCertificateWizard.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.wizards; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import org.apache.commons.codec.binary.Base64; import org.apache.directory.api.util.FileUtils; import org.apache.directory.studio.connection.ui.wizards.ExportCertificateWizardPage.CertificateExportFormat; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.IWorkbench; /** * The ExportCertificateWizard is used to export a certificate. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class ExportCertificateWizard extends Wizard { /** The certificate */ private X509Certificate certificate; /** The wizard page */ private ExportCertificateWizardPage page; /** * Creates a new instance of ExportCertificateWizard. * * @param certificate the certificate */ public ExportCertificateWizard( X509Certificate certificate ) { super(); this.certificate = certificate; setWindowTitle( Messages.getString( "ExportCertificateWizard.ExportCertificate" ) ); //$NON-NLS-1$ setNeedsProgressMonitor( false ); } /** * {@inheritDoc} */ public void init( IWorkbench workbench, IStructuredSelection selection ) { // Nothing to do } /** * {@inheritDoc} */ @Override public void addPages() { page = new ExportCertificateWizardPage(); addPage( page ); } /** * {@inheritDoc} */ public boolean performFinish() { // Getting the export format CertificateExportFormat format = page.getCertificateExportFormat(); try { if ( format == CertificateExportFormat.DER ) { return exportAsDerFormat(); } else { return exportAsPemFormat(); } } catch ( Exception e ) { MessageDialog.openError( getShell(), Messages.getString( "ExportCertificateWizard.ErrorDialogTitle" ), //$NON-NLS-1$ NLS.bind( Messages.getString( "ExportCertificateWizard.ErrorDialogMessage" ), //$NON-NLS-1$ e.getMessage() ) ); return false; } } /** * Exports the certificate as DER format. * * @return <code>true</code> if the export is successful * @throws CertificateEncodingException * @throws IOException */ private boolean exportAsDerFormat() throws CertificateEncodingException, IOException { // Getting the export file File exportFile = page.getExportFile(); // Exporting the certificate FileUtils.writeByteArrayToFile( exportFile, certificate.getEncoded() ); return true; } /** * Exports the certificate as PEM format. * * @return <code>true</code> if the export is successful * @throws CertificateEncodingException * @throws IOException */ private boolean exportAsPemFormat() throws CertificateEncodingException, IOException { // Getting the export file File exportFile = page.getExportFile(); // Exporting the certificate try ( FileOutputStream fos = new FileOutputStream( exportFile ) ) { try ( OutputStreamWriter osw = new OutputStreamWriter( fos, Charset.forName( "UTF-8" ) ) ) //$NON-NLS-1$ { osw.write( "-----BEGIN CERTIFICATE-----\n" ); //$NON-NLS-1$ osw.write( stripLineToNChars( new String( Base64.encodeBase64( certificate.getEncoded() ), Charset.forName( "UTF-8" ) ), 64 ) ); //$NON-NLS-1$ osw.write( "\n-----END CERTIFICATE-----\n" ); //$NON-NLS-1$ osw.flush(); } } return true; } /** * Strips the String every n specified characters * * @param str the string to strip * @param nbChars the number of characters * @return the stripped String */ public static String stripLineToNChars( String str, int nbChars ) { int strLength = str.length(); if ( strLength <= nbChars ) { return str; } // We will first compute the new size of the result // It's at least nbChars chars plus one for \n int charsPerLine = nbChars; int remaining = ( strLength - nbChars ) % charsPerLine; int nbLines = 1 + ( ( strLength - nbChars ) / charsPerLine ) + ( remaining == 0 ? 0 : 1 ); int nbCharsTotal = strLength + nbLines + nbLines - 2; char[] buffer = new char[nbCharsTotal]; char[] orig = str.toCharArray(); int posSrc = 0; int posDst = 0; System.arraycopy( orig, posSrc, buffer, posDst, nbChars ); posSrc += nbChars; posDst += nbChars; for ( int i = 0; i < nbLines - 2; i++ ) { buffer[posDst++] = '\n'; System.arraycopy( orig, posSrc, buffer, posDst, charsPerLine ); posSrc += charsPerLine; posDst += charsPerLine; } buffer[posDst++] = '\n'; System.arraycopy( orig, posSrc, buffer, posDst, remaining == 0 ? charsPerLine : remaining ); return new String( buffer ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizardPage.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/connection/ui/wizards/NewConnectionWizardPage.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.connection.ui.wizards; import org.apache.directory.studio.connection.core.ConnectionParameter; import org.apache.directory.studio.connection.ui.ConnectionParameterPage; import org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener; import org.apache.directory.studio.connection.ui.ConnectionUIConstants; import org.apache.directory.studio.connection.ui.ConnectionUIPlugin; import org.eclipse.jface.wizard.IWizardContainer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; /** * NewConnectionWizard. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class NewConnectionWizardPage extends WizardPage implements ConnectionParameterPageModifyListener { /** The wizard. */ private NewConnectionWizard wizard; /** The page. */ private ConnectionParameterPage page; /** * Creates a new instance of NewConnectionWizard. * * @param page the page * @param wizard the wizard */ public NewConnectionWizardPage( NewConnectionWizard wizard, ConnectionParameterPage page ) { super( page.getPageName() ); setTitle( page.getPageName() ); setDescription( page.getPageDescription() ); setImageDescriptor( ConnectionUIPlugin.getDefault().getImageDescriptor( ConnectionUIConstants.IMG_CONNECTION_WIZARD ) ); setPageComplete( false ); this.wizard = wizard; this.page = page; } /** * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) */ public void setVisible( boolean visible ) { super.setVisible( visible ); if ( visible ) { page.setFocus(); } } /** * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) */ public void createControl( Composite parent ) { Composite composite = new Composite( parent, SWT.NONE ); GridLayout gridLayout = new GridLayout( 1, false ); composite.setLayout( gridLayout ); page.init( composite, this, null ); setControl( composite ); } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#connectionParameterPageModified() */ public void connectionParameterPageModified() { //only one of the messages can be shown //warning messages are more important //than info messages if ( page.getMessage() != null ) { setMessage( page.getMessage() ); } else if ( page.getInfoMessage() != null ) { setMessage( page.getInfoMessage() ); } else { setMessage( null ); } setErrorMessage( page.getErrorMessage() ); setPageComplete( page.isValid() ); IWizardContainer container = getContainer(); if ( ( container != null ) && ( container.getCurrentPage() != null ) ) { container.updateButtons(); } } /** * @see org.apache.directory.studio.connection.ui.ConnectionParameterPageModifyListener#getTestConnectionParameters() */ public ConnectionParameter getTestConnectionParameters() { return wizard.getTestConnectionParameters(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/connection.ui/src/main/java/org/apache/directory/studio/utils/ActionUtils.java
plugins/connection.ui/src/main/java/org/apache/directory/studio/utils/ActionUtils.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.utils; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.IHandler; import org.eclipse.jface.action.IAction; import org.eclipse.jface.commands.ActionHandler; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; /** * Utils for Eclipse IAction objects. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class ActionUtils { /** * A private constructor to make this class an utility class we can't instanciate. **/ private ActionUtils() { } /** * Deactivates the action handler, if the handler's action is equal to * the given action. * * @param action the action */ public static void deactivateActionHandler( IAction action ) { ICommandService commandService = PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { Command command = commandService.getCommand( action.getActionDefinitionId() ); IHandler handler = command.getHandler(); if ( handler instanceof ActionHandler ) { ActionHandler actionHandler = ( ActionHandler ) handler; if ( actionHandler.getAction() == action ) { command.setHandler( null ); } } else if ( handler != null ) { command.setHandler( null ); } } } /** * Activates the action handler * * @param action the action */ public static void activateActionHandler( IAction action ) { ICommandService commandService = PlatformUI.getWorkbench().getAdapter( ICommandService.class ); if ( commandService != null ) { ActionHandler actionHandler = new ActionHandler( action ); commandService.getCommand( action.getActionDefinitionId() ).setHandler( actionHandler ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/test/java/org/apache/directory/studio/openldap/config/acl/model/OpenLdapAclParserTest.java
plugins/openldap.acl.editor/src/test/java/org/apache/directory/studio/openldap/config/acl/model/OpenLdapAclParserTest.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.text.ParseException; import java.util.ArrayList; import java.util.List; import antlr.RecognitionException; import org.apache.directory.studio.openldap.config.acl.model.AclAttribute; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; //assertThrows(ParseException.class, () -> parser.parse( "" )); /** * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclParserTest { @Test public void testEmpty() throws Exception { System.out.println( "\n--> testEmpty" ); OpenLdapAclParser parser = new OpenLdapAclParser(); assertThrows(ParseException.class, () -> parser.parse( "" )); } @Test public void testImpliedWhatStarWithAccess() throws Exception { System.out.println( "\n--> testImpliedWhatStarWithAccess" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseStar ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatStarWithAccess() throws Exception { System.out.println( "\n--> testWhatStarWithAccess" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to * by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseStar ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatStarWithoutAccess() throws Exception { System.out.println( "\n--> testWhatStarWithoutAccess" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( " to * by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseStar ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatStarWithSpaces() throws Exception { System.out.println( "\n--> testWhatStarWithSpaces" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( " access to * by * " ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseStar ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatTwoStars() throws Exception { System.out.println( "\n--> testWhatTwoStars" ); OpenLdapAclParser parser = new OpenLdapAclParser(); assertThrows(ParseException.class, () -> parser.parse( "to * * by *" )); } //----------------------------------------------------------------------------------------- // The WHAT DN rule //----------------------------------------------------------------------------------------- @Test public void testWhatDnValidDnWithQuote() throws Exception { System.out.println( "\n--> testWhatDnValidDnWithQuote" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn)whatClause; assertEquals( dnPattern, whatClauseDn.getPattern() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnStar() throws Exception { System.out.println( "\n--> testWhatDnStar" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn=* by *" )); } @Test public void testWhatDnValidDnNoQuote() throws Exception { System.out.println( "\n--> testWhatDnValidDnNoQuote" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn=" + dnPattern + "\n by *" )); } @Disabled @Test public void testWhatDnBadDn() throws Exception { System.out.println( "\n--> testWhatDnBadDn" ); String dnPattern = "Blah"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn=\"" + dnPattern + "\"\n by *" )); } //----------------------------------------------------------------------------------------- // The basic-dn-style WHAT DN exact //----------------------------------------------------------------------------------------- @Test public void testWhatDnBasicDnExact() throws Exception { System.out.println( "\n--> testWhatDnBasicDnExact" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.exact=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.EXACT, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnBasicDnExactNoQuote() throws Exception { System.out.println( "\n--> testWhatDnBasicDnExactNoQuote" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn.exact=" + dnPattern + " by *" )); } @Test public void testWhatDnBasicDnExactBadDn() throws Exception { System.out.println( "\n--> testWhatDnBasicDnExactBadDn" ); String dnPattern = "example"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn.exact=" + dnPattern + " by *" )); } //----------------------------------------------------------------------------------------- // The basic-dn-style WHAT DN regex //----------------------------------------------------------------------------------------- @Test public void testWhatDnBasicDnRegex() throws Exception { System.out.println( "\n--> testWhatDnBasicDnRegex" ); String dnPattern = "dc=*"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.regex=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.REGEX, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnBasicDnRegexNoQuote() throws Exception { System.out.println( "\n--> testWhatDnBasicDnRegexNoQuote" ); String dnPattern = "dc=*,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn.regex=" + dnPattern + " by *" )); } //----------------------------------------------------------------------------------------- // The scope-dn-clause WHAT DN regex //----------------------------------------------------------------------------------------- @Test public void testWhatDnScopeOneQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeOneQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.one=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.ONE, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeOneLevelQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeOneLevelQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.onelevel=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.ONE_LEVEL, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeBaseQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeBaseQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.base=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.BASE, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeBaseobjectQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeBaseobjectQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.baseobject=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.BASE_OBJECT, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeSubQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeSubQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.sub=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.SUB, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeSubtreeQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeSubtreeQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.subtree=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.SUBTREE, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeChildrenQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeChildrenQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.children=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( dnPattern, whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.CHILDREN, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeOneEmptyDn() throws Exception { System.out.println( "\n--> testWhatDnScopeOneEmptyDn" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn.one=\"\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseDn ); AclWhatClauseDn whatClauseDn = (AclWhatClauseDn) whatClause; // test the content assertEquals( "", whatClauseDn.getPattern() ); assertEquals( AclWhatClauseDnTypeEnum.ONE, whatClauseDn.getType() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatDnScopeOneNoQuotedDn() throws Exception { System.out.println( "\n--> testWhatDnScopeOneNoQuotedDn" ); String dnPattern = "dc=example,dc=com"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn.one=" + dnPattern + " by *" )); } @Test public void testWhatDnScopeOneNoDn() throws Exception { System.out.println( "\n--> testWhatDnScopeOneNoDn" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn.one= by *" )); } @Test public void testWhatDnScopeOneStar() throws Exception { System.out.println( "\n--> testWhatDnScopeOneStar" ); // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to dn.one=* by *" )); } //----------------------------------------------------------------------------------------- // The scope-dn-clause WHAT FILTER //----------------------------------------------------------------------------------------- @Test public void testWhatFilterSimple() throws Exception { System.out.println( "\n--> testWhatFilter" ); String filter = "(objectclass=*)"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to filter=" + filter + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseFilter ); AclWhatClauseFilter whatClauseFilter = (AclWhatClauseFilter) whatClause; // test the content assertEquals( filter, whatClauseFilter.getFilter() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatFilterComplex() throws Exception { System.out.println( "\n--> testWhatFilterComplex" ); String filter = "(&(objectclass=*)(cn=test)(!(sn=test)))"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to filter=" + filter + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); assertTrue( whatClause instanceof AclWhatClauseFilter ); AclWhatClauseFilter whatClauseFilter = (AclWhatClauseFilter) whatClause; // test the content assertEquals( filter, whatClauseFilter.getFilter() ); System.out.println( "<-- ACL:" + aclItem ); } @Test public void testWhatFilterWrongSimple() throws Exception { System.out.println( "\n--> testWhatFilterWrongSimple" ); String filter = "(objectclass=*"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item assertThrows(ParseException.class, () -> parser.parse( "access to filter=" + filter + " by *" )); } @Disabled @Test public void testFail() throws Exception { fail(); } /* @Test public void testWhatDnWithoutAccess() throws Exception { String dnPattern = "dsqdsqdq"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "to dn=\"" + dnPattern + "\" by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseDn whatClauseDn = whatClause.getDnClause(); assertNotNull( whatClauseDn ); assertEquals( dnPattern, whatClauseDn.getPattern() ); } @Test public void testWhatTwoDns() throws Exception { try { OpenLdapAclParser parser = new OpenLdapAclParser(); parser.parse( "to dn=\"dsdsfsd\" dn=\"dsdsfsd\" by *" ); fail(); } catch ( Exception e ) { // Should happen } } @Test public void testWhatAttributes() throws Exception { String attribute = "userPassword"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to attrs=" + attribute + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseAttributes whatClauseAttributes = whatClause.getAttributesClause(); assertNotNull( whatClauseAttributes ); List<AclAttribute> attributesList = whatClauseAttributes.getAttributes(); assertEquals( 1, attributesList.size() ); assertEquals( attribute, attributesList.get( 0 ).getName() ); } @Test public void testWhatAttributesWithoutAccess() throws Exception { String attribute = "userPassword"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "to attrs=" + attribute + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseAttributes whatClauseAttributes = whatClause.getAttributesClause(); assertNotNull( whatClauseAttributes ); List<AclAttribute> attributesList = whatClauseAttributes.getAttributes(); assertEquals( 1, attributesList.size() ); assertEquals( attribute, attributesList.get( 0 ).getName() ); } @Test public void testWhatAttributesWithSpaces() throws Exception { String attribute = "userPassword"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( " access to attrs=" + attribute + " by * " ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseAttributes whatClauseAttributes = whatClause.getAttributesClause(); assertNotNull( whatClauseAttributes ); List<AclAttribute> attributesList = whatClauseAttributes.getAttributes(); assertEquals( 1, attributesList.size() ); assertEquals( attribute, attributesList.get( 0 ).getName() ); } @Test public void testWhatAttributesMultiple() throws Exception { String attribute1 = "userPassword"; String attribute2 = "uid"; String attribute3 = "cn"; String attributes = attribute1 + "," + attribute2 + "," + attribute3; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to attrs=" + attributes + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseAttributes whatClauseAttributes = whatClause.getAttributesClause(); assertNotNull( whatClauseAttributes ); List<AclAttribute> attributesList = whatClauseAttributes.getAttributes(); assertEquals( 3, attributesList.size() ); assertEquals( attribute1, attributesList.get( 0 ).getName() ); assertEquals( attribute2, attributesList.get( 1 ).getName() ); assertEquals( attribute3, attributesList.get( 2 ).getName() ); } @Test public void testWhatAttributesMultipleWithoutAccess() throws Exception { String attribute1 = "userPassword"; String attribute2 = "uid"; String attribute3 = "cn"; String attributes = attribute1 + "," + attribute2 + "," + attribute3; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "to attrs=" + attributes + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseAttributes whatClauseAttributes = whatClause.getAttributesClause(); assertNotNull( whatClauseAttributes ); List<AclAttribute> attributesList = whatClauseAttributes.getAttributes(); assertEquals( 3, attributesList.size() ); assertEquals( attribute1, attributesList.get( 0 ).getName() ); assertEquals( attribute2, attributesList.get( 1 ).getName() ); assertEquals( attribute3, attributesList.get( 2 ).getName() ); } @Test public void testWhatTwoAttributes() throws Exception { try { OpenLdapAclParser parser = new OpenLdapAclParser(); parser.parse( "access to attrs=userPassword attrs=userPassword by *" ); fail(); } catch ( Exception e ) { // Should happen } } @Test public void testWhatFilterWithoutAccess() throws Exception { String filter = "(objectclass=*)"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "to filter=" + filter + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseFilter whatClauseFilter = whatClause.getFilterClause(); assertNotNull( whatClauseFilter ); assertEquals( filter, whatClauseFilter.getFilter() ); } @Test public void testWhatFilterWithSpaces() throws Exception { String filter = "(objectclass=*)"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( " access to filter=" + filter + " by * " ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseFilter whatClauseFilter = whatClause.getFilterClause(); assertNotNull( whatClauseFilter ); assertEquals( filter, whatClauseFilter.getFilter() ); } @Test public void testWhatFilterComplex() throws Exception { String filter = "(&(&(!(cn=jbond))(|(ou=ResearchAndDevelopment)(ou=HumanResources)))(objectclass=Person))"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to filter=" + filter + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseFilter whatClauseFilter = whatClause.getFilterClause(); assertNotNull( whatClauseFilter ); assertEquals( filter, whatClauseFilter.getFilter() ); } @Test public void testWhatFilterComplexWithoutAccess() throws Exception { String filter = "(&(&(!(cn=jbond))(|(ou=ResearchAndDevelopment)(ou=HumanResources)))(objectclass=Person))"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "to filter=" + filter + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseFilter whatClauseFilter = whatClause.getFilterClause(); assertNotNull( whatClauseFilter ); assertEquals( filter, whatClauseFilter.getFilter() ); } @Test public void testWhatTwoFilters() throws Exception { try { OpenLdapAclParser parser = new OpenLdapAclParser(); parser.parse( "access to filter=(objectClass=*) filter=(objectClass=*) by *" ); fail(); } catch ( Exception e ) { // Should happen } } @Test public void testWhatDnAndFilter() throws Exception { String dnPattern = "dsqdsqdq"; String filter = "(objectclass=*)"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn=\"" + dnPattern + "\" filter=" + filter + " by *" ); assertNotNull( aclItem ); // Testing the 'what' clause AclWhatClause whatClause = aclItem.getWhatClause(); assertNotNull( whatClause ); AclWhatClauseDn whatClauseDn = whatClause.getDnClause(); assertNotNull( whatClauseDn ); assertEquals( dnPattern, whatClauseDn.getPattern() ); AclWhatClauseFilter whatClauseFilter = whatClause.getFilterClause(); assertNotNull( whatClauseFilter ); assertEquals( filter, whatClauseFilter.getFilter() ); } @Test public void testWhatDnAndAttributes() throws Exception { String dnPattern = "dsqdsqdq"; String attribute = "userPassword"; // Create parser OpenLdapAclParser parser = new OpenLdapAclParser(); // Testing the ACL item AclItem aclItem = parser.parse( "access to dn=\"" + dnPattern + "\" attrs=" + attribute + " by *" ); assertNotNull( aclItem );
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/Messages.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/Messages.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl; import java.util.MissingResourceException; import java.util.ResourceBundle; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class Messages { private static final String BUNDLE_NAME = "org.apache.directory.studio.openldap.config.acl.messages"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME ); private Messages() { } public static String getString( String key ) { try { return RESOURCE_BUNDLE.getString( key ); } catch ( MissingResourceException e ) { return '!' + key + '!'; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/OpenLdapAclEditorPluginConstants.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/OpenLdapAclEditorPluginConstants.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl; /** * Contains constants for the value editors. * Final reference -> class shouldn't be extended * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public final class OpenLdapAclEditorPluginConstants { /** * Ensures no construction of this class, also ensures there is no need for final keyword above * (Implicit super constructor is not visible for default constructor), * but is still self documenting. */ private OpenLdapAclEditorPluginConstants() { } /** The plug-in ID */ public static final String PLUGIN_ID = OpenLdapAclEditorPluginConstants.class.getPackage().getName(); /** The ID for OpenLDAP ACL Template */ public static String TEMPLATE_ID = OpenLdapAclEditorPlugin.getDefault().getPluginProperties() .getString( "CtxType_Template_id" ); //$NON-NLS-1$ public static String IMG_ADD = "resources/icons/add.gif"; //$NON-NLS-1$ public static String IMG_DELETE = "resources/icons/delete.gif"; //$NON-NLS-1$ public static String IMG_DOWN = "resources/icons/down.png"; //$NON-NLS-1$ public static String IMG_EDITOR = "resources/icons/editor.gif"; //$NON-NLS-1$ public static String IMG_KEYWORD = "resources/icons/keyword.gif"; //$NON-NLS-1$ public static String IMG_UP = "resources/icons/up.png"; //$NON-NLS-1$ public static String DIALOGSETTING_KEY_ATTRIBUTES_HISTORY = "attributesHistory"; //$NON-NLS-1$ }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/OpenLdapAclValueWithContext.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/OpenLdapAclValueWithContext.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl; import java.text.ParseException; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.openldap.config.acl.dialogs.OpenLdapAclDialog; import org.apache.directory.studio.openldap.config.acl.model.AclItem; import org.apache.directory.studio.openldap.config.acl.model.OpenLdapAclParser; /** * The OpenLdapAclValueWithContext is used to pass contextual * information to the opened OpenLdapAclDialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclValueWithContext { /** The connection used to browse the directory */ private IBrowserConnection connection; /** The entry */ private IEntry entry; /** The precedence value, -1 means no precedence */ private int precedence = -1; /** The ACL value */ private String aclValue; /** The ACL instance */ private AclItem aclItem; /** A reference to the ACL dialog */ private OpenLdapAclDialog aclDialog; /** The ACL parser */ private static final OpenLdapAclParser parser = new OpenLdapAclParser(); /** * Creates a new instance of OpenLdapAclValueWithContext. * * @param connection the connection * @param entry the entry * @param precedence the precedence * @param aclValue the ACL value */ public OpenLdapAclValueWithContext( IBrowserConnection connection, IEntry entry, int precedence, String aclValue ) { this.connection = connection; this.entry = entry; this.precedence = precedence; this.aclValue = aclValue; try { aclItem = parser.parse( aclValue ); } catch ( ParseException e ) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Gets the ACL value. * * @return the ACL value */ public String getAclValue() { return aclValue; } /** * @return the connection */ public IBrowserConnection getConnection() { return connection; } /** * @return the entry */ public IEntry getEntry() { return entry; } /** * @return the precedence */ public int getPrecedence() { return precedence; } /** * @return whether precedence is used or not */ public boolean hasPrecedence() { return precedence != -1; } /** * @return The ACL Item being built */ public AclItem getAclItem() { return aclItem; } /** * @return the aclDialog */ public OpenLdapAclDialog getAclDialog() { return aclDialog; } /** * @param aclDialog the aclDialog to set */ public void setAclDialog( OpenLdapAclDialog aclDialog ) { this.aclDialog = aclDialog; } /** * {@inheritDoc} */ public String toString() { if ( aclValue != null ) { if ( precedence != -1 ) { return "{" + precedence + "}" + aclValue; } else { return aclValue; } } return ""; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/OpenLdapAclEditorPlugin.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/OpenLdapAclEditorPlugin.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl; import java.io.IOException; import java.net.URL; import java.util.PropertyResourceBundle; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.templates.GlobalTemplateVariables; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; import org.apache.directory.studio.openldap.config.acl.sourceeditor.OpenLdapAclCodeScanner; import org.apache.directory.studio.openldap.config.acl.sourceeditor.OpenLdapAclTextAttributeProvider; /** * The activator class controls the plug-in life cycle * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclEditorPlugin extends AbstractUIPlugin { /** The shared instance */ private static OpenLdapAclEditorPlugin plugin; /** The shared OpenLDAP ACL Code Scanner */ private OpenLdapAclCodeScanner codeScanner; /** The shared OpenLDAP ACL TextAttribute Provider */ private OpenLdapAclTextAttributeProvider textAttributeProvider; /** The context type registry */ private ContributionContextTypeRegistry templateContextTypeRegistry; /** The template store */ private ContributionTemplateStore templateStore; /** The plugin properties */ private PropertyResourceBundle properties; /** * The constructor */ public OpenLdapAclEditorPlugin() { plugin = this; } /** * {@inheritDoc} */ public void start( BundleContext context ) throws Exception { super.start( context ); // OpenLDAP ACL Template ContextType Registry initialization if ( templateContextTypeRegistry == null ) { templateContextTypeRegistry = new ContributionContextTypeRegistry(); templateContextTypeRegistry.addContextType( OpenLdapAclEditorPluginConstants.TEMPLATE_ID ); templateContextTypeRegistry.getContextType( OpenLdapAclEditorPluginConstants.TEMPLATE_ID ).addResolver( new GlobalTemplateVariables.Cursor() ); } // OpenLDAP ACL Template Store initialization if ( templateStore == null ) { templateStore = new ContributionTemplateStore( getTemplateContextTypeRegistry(), getPreferenceStore(), "templates" ); //$NON-NLS-1$ try { templateStore.load(); } catch ( IOException e ) { e.printStackTrace(); } } } /** * {@inheritDoc} */ public void stop( BundleContext context ) throws Exception { plugin = null; super.stop( context ); } /** * Retuns the the OpenLDAP ACL Code Scanner * * @return the the OpenLDAP ACL Code Scanner */ public OpenLdapAclCodeScanner getCodeScanner() { if ( codeScanner == null ) { codeScanner = new OpenLdapAclCodeScanner( getTextAttributeProvider() ); } return codeScanner; } /** * Returns the TextAttribute Provider * * @return the TextAttribute Provider */ public OpenLdapAclTextAttributeProvider getTextAttributeProvider() { if ( textAttributeProvider == null ) { textAttributeProvider = new OpenLdapAclTextAttributeProvider(); } return textAttributeProvider; } /** * Gets the OpenLDAP ACL Template ContextType Registry * * @return the OpenLDAP ACL Template ContextType Registry */ public ContributionContextTypeRegistry getTemplateContextTypeRegistry() { return templateContextTypeRegistry; } /** * Gets the OpenLDAP ACL Template Store * * @return the OpenLDAP ACL Template Store */ public ContributionTemplateStore getTemplateStore() { return templateStore; } /** * Returns the shared instance * * @return the shared instance */ public static OpenLdapAclEditorPlugin getDefault() { return plugin; } /** * Use this method to get SWT images. Use the IMG_ constants from * ValueEditorConstants for the key. * * @param key The key (relative path to the image im filesystem) * @return The image discriptor or null */ public ImageDescriptor getImageDescriptor( String key ) { if ( key != null ) { URL url = FileLocator.find( getBundle(), new Path( key ), null ); if ( url != null ) { return ImageDescriptor.createFromURL( url ); } } return null; } /** * Use this method to get SWT images. Use the IMG_ constants from * ValueEditorConstants for the key. A ImageRegistry is used to manage the * the key->Image mapping. * <p> * Note: Don't dispose the returned SWT Image. It is disposed * automatically when the plugin is stopped. * * @param key The key (relative path to the image im filesystem) * @return The SWT Image or null * @see OpenLdapAclEditorPluginConstants */ public Image getImage( String key ) { Image image = getImageRegistry().get( key ); if ( image == null ) { ImageDescriptor id = getImageDescriptor( key ); if ( id != null ) { image = id.createImage(); getImageRegistry().put( key, image ); } } return image; } /** * Gets the plugin properties. * * @return the plugin properties */ public PropertyResourceBundle getPluginProperties() { if ( properties == null ) { try { properties = new PropertyResourceBundle( FileLocator.openStream( this.getBundle(), new Path( "plugin.properties" ), false ) ); //$NON-NLS-1$ } catch ( IOException e ) { // We can't use the PLUGIN_ID constant since loading the plugin.properties file has failed, // So we're using a default plugin id. getLog().log( new Status( Status.ERROR, "org.apache.directory.studio.openldap.acl.editor", Status.OK, //$NON-NLS-1$ Messages.getString( "OpenLdapAclEditorPlugin.UnableGetPluginProperties" ), e ) ); //$NON-NLS-1$ } } return properties; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/AbstractRule.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/AbstractRule.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IPredicateRule; import org.eclipse.jface.text.rules.IToken; /** * Rule to detect a "dn[.type[,modifier]]=" clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractRule implements IPredicateRule { /** The token */ protected IToken token; /** * Creates a new instance of AbstractRule. * * @param token the associated token */ public AbstractRule( IToken token ) { this.token = token; } public IToken getSuccessToken() { return token; } /** * Checks if the given char sequence matches the scanner input. * * @param scanner the scanner input * @param sequence the char sequence * @return <code>true</code> if the scanner input matches the char sequence, * <code>false</code> if not. */ boolean matchCharSequence( ICharacterScanner scanner, char[] sequence ) { for ( int i = 0; i < sequence.length; i++ ) { int c = scanner.read(); if ( c != sequence[i] ) { while ( i >= 0 ) { scanner.unread(); i--; } return false; } } return true; } /** * Checks if the given char sequence does not match the scanner input. * * @param scanner the scanner input * @param sequence the char sequence * @return <code>true</code> if the scanner input does not match the char sequence, * <code>false</code> if it does. */ boolean doesNotMatchCharSequence( ICharacterScanner scanner, char[] sequence ) { return !matchCharSequence( scanner, sequence ); } /** * Checks if the char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the char, * <code>false</code> if not. */ boolean matchChar( ICharacterScanner scanner, char character ) { int c = scanner.read(); if ( c == character ) { return true; } else { scanner.unread(); return false; } } /** * Checks if EOF matches the scanner input. * * @return <code>true</code> if the scanner input matches EOF, * <code>false</code> if not. */ boolean matchEOF( ICharacterScanner scanner ) { int c = scanner.read(); if ( c == ICharacterScanner.EOF ) { return true; } else { scanner.unread(); return false; } } /** * Checks if the char does not match the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input does not match the char, * <code>false</code> if it does. */ boolean doesNotMatchChar( ICharacterScanner scanner, char character ) { return !matchChar( scanner, character ); } /** * Checks if the '}' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '}' char, * <code>false</code> if not. */ boolean matchDigit( ICharacterScanner scanner ) { int c = scanner.read(); if ( ( c >= '0' ) && ( c <= '9' ) ) { return true; } else { scanner.unread(); return false; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/GroupRule.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/GroupRule.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.Token; /** * Rule to detect a "group[/objectclass[/attrname]][.type]=" clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class GroupRule extends AbstractRule { /** * The "dn" char sequence. */ private static char[] GROUP_SEQUENCE = new char[] { 'g', 'r', 'o', 'u', 'p' }; /** * The array of the types char sequences */ private static char[][] TYPES_SEQUENCES = new char[][] { new char[] { 'e', 'x', 'p', 'a', 'n', 'd' }, new char[] { 'e', 'x', 'a', 'c', 't' } }; /** * Creates a new instance of GroupRule. * * @param token the associated token */ public GroupRule( IToken token ) { super( token ); } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner, boolean resume ) { // Looking for "group" if ( matchGroup( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } // Looking for '/' else if ( matchSlash( scanner ) ) { // Going forward until we find a '=', '/' or '.' char boolean atLeastFoundOneChar = false; while ( doesNotMatchEqualSlashOrDot( scanner ) ) { atLeastFoundOneChar = true; } // Checking if we found at least one char if ( atLeastFoundOneChar ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } // Looking for '/' else if ( matchSlash( scanner ) ) { // Going forward until we find a '=' or '.' char boolean atLeastFoundOneChar2 = false; while ( doesNotMatchEqualOrDot( scanner ) ) { atLeastFoundOneChar2 = true; } // Checking if we found at least one char if ( atLeastFoundOneChar2 ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } // Looking for '.' else if ( matchDot( scanner ) ) { // Looking for one of the types if ( matchType( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } } } } } // Looking for '.' else if ( matchDot( scanner ) ) { // Looking for one of the types if ( matchType( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } } } } } // Looking for '.' else if ( matchDot( scanner ) ) { // Looking for one of the types if ( matchType( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } } } } return Token.UNDEFINED; } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner ) { return this.evaluate( scanner, false ); } /** * Checks if the "group" char sequence matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the "group" char sequence, * <code>false</code> if not. */ private boolean matchGroup( ICharacterScanner scanner ) { return matchCharSequence( scanner, GROUP_SEQUENCE ); } /** * Checks if one of the types char sequence matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches one of the types char sequence, * <code>false</code> if not. */ private boolean matchType( ICharacterScanner scanner ) { for ( char[] typeSequence : TYPES_SEQUENCES ) { if ( matchCharSequence( scanner, typeSequence ) ) { return true; } } return false; } /** * Checks if the '{' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '{' char, * <code>false</code> if not. */ private boolean matchSlash( ICharacterScanner scanner ) { return matchChar( scanner, '/' ); } /** * Checks if the '.' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '.' char, * <code>false</code> if not. */ private boolean matchDot( ICharacterScanner scanner ) { return matchChar( scanner, '.' ); } /** * Checks if the '=' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '=' char, * <code>false</code> if not. */ private boolean matchEqual( ICharacterScanner scanner ) { return matchChar( scanner, '=' ); } /** * Checks if the '=', '/' or '.' chars don't match the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input don't match the '=', '/' or '.' char, * <code>false</code> if it does. */ private boolean doesNotMatchEqualSlashOrDot( ICharacterScanner scanner ) { if ( matchEOF( scanner ) ) { scanner.unread(); return false; } else if ( matchChar( scanner, '=' ) ) { scanner.unread(); return false; } else if ( matchChar( scanner, '/' ) ) { scanner.unread(); return false; } else if ( matchChar( scanner, '.' ) ) { scanner.unread(); return false; } else { scanner.read(); return true; } } /** * Checks if the '=' or '.' chars don't match the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input don't match the '=' or '.' char, * <code>false</code> if it does. */ private boolean doesNotMatchEqualOrDot( ICharacterScanner scanner ) { if ( matchEOF( scanner ) ) { scanner.unread(); return false; } else if ( matchChar( scanner, '=' ) ) { scanner.unread(); return false; } else if ( matchChar( scanner, '.' ) ) { scanner.unread(); return false; } else { scanner.read(); return true; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclCodeScanner.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclCodeScanner.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import java.util.ArrayList; import java.util.List; import org.eclipse.jface.text.rules.IRule; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.IWhitespaceDetector; import org.eclipse.jface.text.rules.IWordDetector; import org.eclipse.jface.text.rules.RuleBasedScanner; import org.eclipse.jface.text.rules.SingleLineRule; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.rules.WhitespaceRule; import org.eclipse.jface.text.rules.WordRule; /** * Scanner used to analyse ACI code. Allows syntax coloring. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclCodeScanner extends RuleBasedScanner { /** Keywords */ public static final String[] aclKeywords = new String[] { "anonymous", //$NON-NLS-1$ "auth", //$NON-NLS-1$ "break", //$NON-NLS-1$ "by", //$NON-NLS-1$ "c", //$NON-NLS-1$ "compare", //$NON-NLS-1$ "continue", //$NON-NLS-1$ "disclose", //$NON-NLS-1$ "dnattr=", //$NON-NLS-1$ "entry", //$NON-NLS-1$ "m", //$NON-NLS-1$ "manage", //$NON-NLS-1$ "none", //$NON-NLS-1$ "one", //$NON-NLS-1$ "r", //$NON-NLS-1$ "read", //$NON-NLS-1$ "s", //$NON-NLS-1$ "search", //$NON-NLS-1$ "self", //$NON-NLS-1$ "ssf=", //$NON-NLS-1$ "stop", //$NON-NLS-1$ "to", //$NON-NLS-1$ "users", //$NON-NLS-1$ "x", //$NON-NLS-1$ "w", //$NON-NLS-1$ "write" }; //$NON-NLS-1$ /** * Creates a new instance of AciCodeScanner. * * @param provider * the provider */ public OpenLdapAclCodeScanner( OpenLdapAclTextAttributeProvider provider ) { List<IRule> rules = new ArrayList<IRule>(); IToken keyword = new Token( provider.getAttribute( OpenLdapAclTextAttributeProvider.KEYWORD_ATTRIBUTE ) ); IToken string = new Token( provider.getAttribute( OpenLdapAclTextAttributeProvider.STRING_ATTRIBUTE ) ); IToken undefined = new Token( provider.getAttribute( OpenLdapAclTextAttributeProvider.DEFAULT_ATTRIBUTE ) ); // Rules for Strings rules.add( new SingleLineRule( "\"", "\"", string, '\0', true ) ); //$NON-NLS-1$ //$NON-NLS-2$ rules.add( new SingleLineRule( "'", "'", string, '\0', true ) ); //$NON-NLS-1$ //$NON-NLS-2$ // Generic rule for whitespaces rules.add( new WhitespaceRule( new IWhitespaceDetector() { public boolean isWhitespace( char c ) { return Character.isWhitespace( c ); } } ) ); // Rules for specific not simple keywords rules.add( new DnRule( keyword ) ); rules.add( new GroupRule( keyword ) ); rules.add( new KeywordEqualRule( keyword ) ); rules.add( new StarRule( keyword ) ); // If the word isn't in the List, returns undefined WordRule wr = new WordRule( new OpenLdapAclWordDetector(), undefined ); rules.add( wr ); // Adding keywords for ( String aclKeyword : aclKeywords ) { wr.addWord( aclKeyword, keyword ); } IRule[] param = new IRule[rules.size()]; rules.toArray( param ); setRules( param ); } /** * This class implements a word detector for ACI Items * * @author <a href="mailto:$dev@directory.apache.org">Apache Directory Project</a> */ static class OpenLdapAclWordDetector implements IWordDetector { /** * {@inheritDoc} */ public boolean isWordPart( char c ) { return ( Character.isLetterOrDigit( c ) || c == '_' || c == '$' || c == '#' || c == '@' || c == '~' || c == '.' || c == '?' || c == '*' || c == '!' ); } /** * {@inheritDoc} */ public boolean isWordStart( char c ) { return ( Character.isLetter( c ) || c == '.' || c == '_' || c == '?' || c == '$' ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/DnRule.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/DnRule.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.Token; /** * Rule to detect a "dn[.type[,modifier]]=" clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DnRule extends AbstractRule { /** * The "dn" char sequence. */ private static char[] DN_SEQUENCE = new char[] { 'd', 'n' }; /** * The array of the types char sequences */ private static char[][] TYPES_SEQUENCES = new char[][] { new char[] { 'r', 'e', 'g', 'e', 'x' }, new char[] { 'b', 'a', 's', 'e' }, new char[] { 'e', 'x', 'a', 'c', 't' }, new char[] { 'o', 'n', 'e' }, new char[] { 's', 'u', 'b', 't', 'r', 'e', 'e' }, new char[] { 'c', 'h', 'i', 'l', 'd', 'r', 'e', 'n' } }; /** * The "expand" char sequence. */ private static char[] EXPAND_SEQUENCE = new char[] { 'e', 'x', 'p', 'a', 'n', 'd' }; /** * The "level" char sequence. */ private static char[] LEVEL_SEQUENCE = new char[] { 'l', 'e', 'v', 'e', 'l' }; /** * Creates a new instance of DnRule. * * @param token the associated token */ public DnRule( IToken token ) { super( token ); } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner, boolean resume ) { // Looking for "dn" if ( matchDn( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } // Looking for '.' else if ( matchDot( scanner ) ) { // Looking for one of the types if ( matchType( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } // Looking for ',' else if ( matchComma( scanner ) ) { // Looking for "expand" if ( matchExpand( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } } } } // Looking for "level" else if ( matchLevel( scanner ) ) { // Looking for '{' if ( matchOpenCurlyBracket( scanner ) ) { // Looking for digits boolean atLeastFoundOneDigit = false; while ( matchDigit( scanner ) ) { atLeastFoundOneDigit = true; } // Checking if we found at least one digit // and the next char is '}' if ( atLeastFoundOneDigit && ( matchCloseCurlyBracket( scanner ) ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } } } } } } return Token.UNDEFINED; } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner ) { return this.evaluate( scanner, false ); } /** * Checks if the "dn" char sequence matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the "dn" char sequence, * <code>false</code> if not. */ private boolean matchDn( ICharacterScanner scanner ) { return matchCharSequence( scanner, DN_SEQUENCE ); } /** * Checks if one of the types char sequence matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches one of the types char sequence, * <code>false</code> if not. */ private boolean matchType( ICharacterScanner scanner ) { for ( char[] typeSequence : TYPES_SEQUENCES ) { if ( matchCharSequence( scanner, typeSequence ) ) { return true; } } return false; } /** * Checks if the "expand" char sequence matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the "expand" char sequence, * <code>false</code> if not. */ private boolean matchExpand( ICharacterScanner scanner ) { return matchCharSequence( scanner, EXPAND_SEQUENCE ); } /** * Checks if the "level" char sequence matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the "level" char sequence, * <code>false</code> if not. */ private boolean matchLevel( ICharacterScanner scanner ) { return matchCharSequence( scanner, LEVEL_SEQUENCE ); } /** * Checks if the '.' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '.' char, * <code>false</code> if not. */ private boolean matchDot( ICharacterScanner scanner ) { return matchChar( scanner, '.' ); } /** * Checks if the ',' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the ',' char, * <code>false</code> if not. */ private boolean matchComma( ICharacterScanner scanner ) { return matchChar( scanner, ',' ); } /** * Checks if the '=' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '=' char, * <code>false</code> if not. */ private boolean matchEqual( ICharacterScanner scanner ) { return matchChar( scanner, '=' ); } /** * Checks if the '{' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '{' char, * <code>false</code> if not. */ private boolean matchOpenCurlyBracket( ICharacterScanner scanner ) { return matchChar( scanner, '{' ); } /** * Checks if the '}' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '}' char, * <code>false</code> if not. */ private boolean matchCloseCurlyBracket( ICharacterScanner scanner ) { return matchChar( scanner, '}' ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/StarRule.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/StarRule.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.Token; /** * Rule to detect a "dn[.type[,modifier]]=" clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class StarRule extends AbstractRule { /** * Creates a new instance of StarRule. * * @param token the associated token */ public StarRule( IToken token ) { super( token ); } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner, boolean resume ) { // Looking for '*' if ( matchChar( scanner, '*' ) ) { // Token evaluation complete return token; } else { // Not what was expected return Token.UNDEFINED; } } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner ) { return this.evaluate( scanner, false ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/DialogContentAssistant.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/DialogContentAssistant.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; import org.eclipse.jface.contentassist.ComboContentAssistSubjectAdapter; import org.eclipse.jface.contentassist.SubjectControlContentAssistant; import org.eclipse.jface.contentassist.TextContentAssistSubjectAdapter; import org.eclipse.jface.text.ITextViewer; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.IHandlerActivation; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; /** * This class implements the Content Assistant Dialog used in the ACI Item * Source Editor for displaying proposals * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class DialogContentAssistant extends SubjectControlContentAssistant implements FocusListener { private Control control; private IHandlerActivation handlerActivation; private boolean possibleCompletionsVisible; /** * Creates a new instance of DialogContentAssistant. */ public DialogContentAssistant() { super(); this.possibleCompletionsVisible = false; } /** * Installs content assist support on the given subject. * * @param text * the one who requests content assist */ public void install( Text text ) { this.control = text; this.control.addFocusListener( this ); super.install( new TextContentAssistSubjectAdapter( text ) ); } /** * Installs content assist support on the given subject. * * @param combo * the one who requests content assist */ public void install( Combo combo ) { this.control = combo; this.control.addFocusListener( this ); super.install( new ComboContentAssistSubjectAdapter( combo ) ); } /** * {@inheritDoc} */ public void install( ITextViewer viewer ) { this.control = viewer.getTextWidget(); this.control.addFocusListener( this ); // stop traversal (ESC) if popup is shown this.control.addTraverseListener( new TraverseListener() { public void keyTraversed( TraverseEvent e ) { if ( possibleCompletionsVisible ) { e.doit = false; } } } ); super.install( viewer ); } /** * {@inheritDoc} */ public void uninstall() { if ( this.handlerActivation != null ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); handlerService.deactivateHandler( this.handlerActivation ); this.handlerActivation = null; } if ( this.control != null ) { this.control.removeFocusListener( this ); } super.uninstall(); } /** * {@inheritDoc} */ protected Point restoreCompletionProposalPopupSize() { possibleCompletionsVisible = true; return super.restoreCompletionProposalPopupSize(); } /** * {@inheritDoc} */ public String showPossibleCompletions() { possibleCompletionsVisible = true; return super.showPossibleCompletions(); } /** * {@inheritDoc} */ protected void possibleCompletionsClosed() { this.possibleCompletionsVisible = false; super.possibleCompletionsClosed(); } /** * {@inheritDoc} */ public void focusGained( FocusEvent e ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); if ( handlerService != null ) { IHandler handler = new org.eclipse.core.commands.AbstractHandler() { public Object execute( ExecutionEvent event ) throws org.eclipse.core.commands.ExecutionException { showPossibleCompletions(); return null; } }; this.handlerActivation = handlerService.activateHandler( ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler ); } } /** * {@inheritDoc} */ public void focusLost( FocusEvent e ) { if ( this.handlerActivation != null ) { IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter( IHandlerService.class ); handlerService.deactivateHandler( this.handlerActivation ); this.handlerActivation = null; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclFormattingStrategy.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclFormattingStrategy.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; import org.eclipse.jface.text.formatter.IFormattingStrategy; import org.eclipse.jface.text.source.ISourceViewer; /** * This class implements the formatting strategy for the OpenLDAP ACL Editor. * <ul> * <li>New line before the "by" keyword * </ul> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclFormattingStrategy implements IFormattingStrategy { /** The Constant NEWLINE. */ public static final String NEWLINE = BrowserCoreConstants.LINE_SEPARATOR; /** The source viewer. */ private ISourceViewer sourceViewer; /** * Creates a new instance of OpenLdapAclFormattingStrategy. * * @param sourceViewer the source viewer */ public OpenLdapAclFormattingStrategy( ISourceViewer sourceViewer ) { this.sourceViewer = sourceViewer; } /** * {@inheritDoc} */ public String format( String content, boolean isLineStart, String indentation, int[] positions ) { String oldContent = sourceViewer.getDocument().get(); String newContent = internFormat( oldContent ); sourceViewer.getDocument().set( newContent ); return null; } /** * {@inheritDoc} */ public void formatterStarts( String initialIndentation ) { } /** * {@inheritDoc} */ public void formatterStops() { } private String internFormat( String content ) { StringBuffer sb = new StringBuffer(); // Flag to track if we are within a quoted string boolean inQuotedString = false; // Flag to track if a new line was started boolean newLineStarted = true; // Char index int i = 0; int contentLength = content.length(); while ( i < contentLength ) { char currentChar = content.charAt( i ); // Tracking quotes if ( currentChar == '"' ) { inQuotedString = !inQuotedString; } else if ( newLineStarted && ( ( currentChar == '\n' ) || ( currentChar == '\r' ) ) ) { // Compress multiple newlines i++; continue; } // Checking if we're not in a quoted text if ( !inQuotedString ) { // Getting the next char (if available) char nextChar = 0; if ( ( i + 1 ) < contentLength ) { nextChar = content.charAt( i + 1 ); } // Checking if we have the "by" keyword if ( ( !newLineStarted ) && ( currentChar == 'b' ) && ( nextChar == 'y' ) ) { sb.append( NEWLINE ); newLineStarted = true; } else { // Tracking new line newLineStarted = ( ( currentChar == '\n' ) || ( currentChar == '\r' ) ); } } sb.append( currentChar ); i++; } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclSourceViewerConfiguration.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclSourceViewerConfiguration.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.formatter.ContentFormatter; import org.eclipse.jface.text.formatter.IContentFormatter; import org.eclipse.jface.text.formatter.IFormattingStrategy; import org.eclipse.jface.text.presentation.IPresentationReconciler; import org.eclipse.jface.text.presentation.PresentationReconciler; import org.eclipse.jface.text.rules.DefaultDamagerRepairer; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPlugin; /** * This class enables the features of the editor (Syntax coloring, code completion, etc.) * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclSourceViewerConfiguration extends SourceViewerConfiguration { /** * {@inheritDoc} */ public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer ) { PresentationReconciler reconciler = new PresentationReconciler(); reconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) ); // Creating the damager/repairer for code DefaultDamagerRepairer dr = new DefaultDamagerRepairer( OpenLdapAclEditorPlugin.getDefault() .getCodeScanner() ); reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE ); reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE ); return reconciler; } /** * {@inheritDoc} */ public IContentAssistant getContentAssistant( ISourceViewer sourceViewer ) { // ContentAssistant assistant = new ContentAssistant(); ContentAssistant assistant = new DialogContentAssistant(); IContentAssistProcessor aciContentAssistProcessor = new OpenLdapContentAssistProcessor(); assistant.setContentAssistProcessor( aciContentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE ); assistant.enableAutoActivation( true ); assistant.setAutoActivationDelay( 500 ); assistant.setProposalPopupOrientation( IContentAssistant.PROPOSAL_STACKED ); assistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE ); return assistant; } /** * {@inheritDoc} */ public IContentFormatter getContentFormatter( ISourceViewer sourceViewer ) { ContentFormatter formatter = new ContentFormatter(); IFormattingStrategy formattingStrategy = new OpenLdapAclFormattingStrategy( sourceViewer ); formatter.enablePartitionAwareFormatting( false ); formatter.setFormattingStrategy( formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE ); return formatter; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapContentAssistProcessor.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapContentAssistProcessor.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.jface.text.templates.Template; import org.eclipse.jface.text.templates.TemplateCompletionProcessor; import org.eclipse.jface.text.templates.TemplateContextType; import org.eclipse.swt.graphics.Image; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPlugin; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPluginConstants; /** * This class implements the Content Assist Processor for ACI Item * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapContentAssistProcessor extends TemplateCompletionProcessor { /** * {@inheritDoc} */ public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset ) { List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>(); // Add context dependend template proposals ICompletionProposal[] templateProposals = super.computeCompletionProposals( viewer, offset ); if ( templateProposals != null ) { proposalList.addAll( Arrays.asList( templateProposals ) ); } return ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] ); } /** * {@inheritDoc} */ public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset ) { return null; } /** * {@inheritDoc} */ public char[] getCompletionProposalAutoActivationCharacters() { char[] chars = new char[52]; for ( int i = 0; i < 26; i++ ) { chars[i] = ( char ) ( 'a' + i ); } for ( int i = 0; i < 26; i++ ) { chars[i + 26] = ( char ) ( 'A' + i ); } return chars; } /** * {@inheritDoc} */ public char[] getContextInformationAutoActivationCharacters() { return null; } /** * {@inheritDoc} */ public IContextInformationValidator getContextInformationValidator() { return null; } /** * {@inheritDoc} */ public String getErrorMessage() { return null; } /** * {@inheritDoc} */ protected TemplateContextType getContextType( ITextViewer viewer, IRegion region ) { return OpenLdapAclEditorPlugin.getDefault().getTemplateContextTypeRegistry().getContextType( OpenLdapAclEditorPluginConstants.TEMPLATE_ID ); } /** * {@inheritDoc} */ protected Image getImage( Template template ) { return null; } /** * {@inheritDoc} */ protected Template[] getTemplates( String contextTypeId ) { return OpenLdapAclEditorPlugin.getDefault().getTemplateStore().getTemplates( contextTypeId ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclTextAttributeProvider.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclTextAttributeProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import java.util.HashMap; import java.util.Map; import org.apache.directory.studio.common.ui.CommonUIConstants; import org.apache.directory.studio.common.ui.CommonUIPlugin; import org.eclipse.jface.text.TextAttribute; import org.eclipse.swt.SWT; /** * This class provides the TextAttributes elements for each kind of attribute * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclTextAttributeProvider { public static final String DEFAULT_ATTRIBUTE = "__pos_acl_default_attribute"; //$NON-NLS-1$ public static final String KEYWORD_ATTRIBUTE = "__pos_acl_keyword_attribute"; //$NON-NLS-1$ public static final String STRING_ATTRIBUTE = "__pos_acl_string_attribute"; //$NON-NLS-1$ private Map<String, TextAttribute> attributes = new HashMap<String, TextAttribute>(); /** * Creates a new instance of AciTextAttributeProvider. */ public OpenLdapAclTextAttributeProvider() { CommonUIPlugin plugin = CommonUIPlugin.getDefault(); attributes.put( DEFAULT_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.DEFAULT_COLOR ) ) ); attributes.put( KEYWORD_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.ATTRIBUTE_TYPE_COLOR ), null, SWT.BOLD ) ); attributes.put( STRING_ATTRIBUTE, new TextAttribute( plugin.getColor( CommonUIConstants.VALUE_COLOR ) ) ); } /** * Gets the correct TextAttribute for the given type * * @param type * the type of element * @return * the correct TextAttribute for the given type */ public TextAttribute getAttribute( String type ) { TextAttribute attr = ( TextAttribute ) attributes.get( type ); if ( attr == null ) { attr = ( TextAttribute ) attributes.get( DEFAULT_ATTRIBUTE ); } return attr; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/KeywordEqualRule.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/KeywordEqualRule.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.sourceeditor; import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.Token; /** * Rule to detect a "dn[.type[,modifier]]=" clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class KeywordEqualRule extends AbstractRule { /** * The array of the types char sequences */ private static char[][] KEYWORDS_SEQUENCES = new char[][] { new char[] { 'a', 't', 't', 'r', 's' }, new char[] { 'a', 't', 't', 'r' }, new char[] { 'd', 'n', 'a', 't', 't', 'r' }, new char[] { 'f', 'i', 'l', 't', 'e', 'r' }, new char[] { 's', 's', 'f' }, new char[] { 's', 'a', 's', 'l', '_', 's', 's', 'f' }, new char[] { 't', 'l', 's', '_', 's', 's', 'f' }, new char[] { 't', 'r', 'a', 'n', 's', 'p', 'o', 'r', 't', '_', 's', 's', 'f' }, new char[] { 's', 'a', 's', 's', '_', 's', 's', 'f' } }; /** * Creates a new instance of DnRule. * * @param token the associated token */ public KeywordEqualRule( IToken token ) { super( token ); } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner, boolean resume ) { // Looking for any keyword if ( matchKeyword( scanner ) ) { // Looking for '=' if ( matchEqual( scanner ) ) { // Token evaluation complete return token; } } return Token.UNDEFINED; } /** * {@inheritDoc} */ public IToken evaluate( ICharacterScanner scanner ) { return this.evaluate( scanner, false ); } /** * Checks if one of the types char sequence matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches one of the types char sequence, * <code>false</code> if not. */ private boolean matchKeyword( ICharacterScanner scanner ) { for ( char[] typeSequence : KEYWORDS_SEQUENCES ) { if ( matchCharSequence( scanner, typeSequence ) ) { return true; } } return false; } /** * Checks if the '=' char matches the scanner input. * * @param scanner the scanner input * @return <code>true</code> if the scanner input matches the '=' char, * <code>false</code> if not. */ private boolean matchEqual( ICharacterScanner scanner ) { return matchChar( scanner, '=' ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDnTypeEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDnTypeEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * This enum contains all possible values for the type of a DN Who Clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclWhoClauseDnTypeEnum { REGEX, BASE, EXACT, ONE, SUBTREE, CHILDREN, LEVEL; /** The level*/ private int level = -1; /** * Gets the level. * <p> * Only useful for the 'LEVEL' enum type. * * @return the level */ public int getLevel() { return level; } /** * Sets the level. * <p> * Only useful for the 'LEVEL' enum type. * * @param level the level */ public void setLevel( int level ) { this.level = level; } /** * {@inheritDoc} */ public String toString() { switch ( this ) { case REGEX: return "regex"; case BASE: return "base"; case EXACT: return "exact"; case ONE: return "one"; case SUBTREE: return "subtree"; case CHILDREN: return "children"; case LEVEL: return "level{" + level + "}"; } return super.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDn.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDn.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * The Acl * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseDn extends AbstractAclWhoClause { /** The type, default to BASE */ private AclWhoClauseDnTypeEnum type; /** The modifier */ private AclWhoClauseDnModifierEnum modifier; /** The pattern */ private String pattern; /** * Gets the modifier. * * @return the modifier */ public AclWhoClauseDnModifierEnum getModifier() { return modifier; } /** * Gets the pattern. * * @return the pattern */ public String getPattern() { return pattern; } /** * Gets the type. * * @return the type */ public AclWhoClauseDnTypeEnum getType() { return type; } /** * Sets the modifier. * * @param modifier the modifier */ public void setModifier( AclWhoClauseDnModifierEnum modifier ) { this.modifier = modifier; } /** * Sets the pattern * * @param pattern the pattern to set */ public void setPattern( String pattern ) { this.pattern = pattern; } /** * Sets the type. * * @param type the type to set */ public void setType( AclWhoClauseDnTypeEnum type ) { this.type = type; } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); // DN sb.append( "dn" ); // Type if ( type != null ) { sb.append( "." ); sb.append( type ); } // Modifier if ( modifier != null ) { sb.append( "," ); sb.append( modifier ); } // Pattern sb.append( '=' ); sb.append( '"' ); sb.append( pattern ); sb.append( '"' ); return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AbstractAclWhoClauseCryptoStrength.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AbstractAclWhoClauseCryptoStrength.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * An abstract class for all Cryptographic Strength subclasses. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractAclWhoClauseCryptoStrength extends AbstractAclWhoClause { /** The strength */ protected int strength; /** * Sets the cryptographic strength. * * @return the strength. */ public int getStrength() { return strength; } /** * Sets the cryptographic strength. * * @param strength the strength */ public void setStrength( int strength ) { this.strength = strength; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseAnonymous.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseAnonymous.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseAnonymous extends AbstractAclWhoClause { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "anonymous" ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseAttributes.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseAttributes.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * The Acl what-attrs clause. We either have an attribute val clause, or an attribute list clause. * * <pre> * <what-attrs> ::= ( 'attrs' | 'attr' ) SP '=' SP <attrs> * <attrs> ::= IDENT SP 'val' <mr-e> <attr-val-style> SP? '=' SP? REGEX | <what-attr> <what-attr-list> * <attr-val-style> ::= '.' <basic-style> | e * <basic-style> ::= 'exact' | 'base' | 'baseobject' | 'regex' * <mr-e> ::= '/' IDENT | e * <what-attr-list> ::= ',' <what-attr> <what-attr-list> | e * <what-attr> ::= IDENT | '@' IDENT | '!' IDENT | 'entry' | 'children' * </pre> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhatClauseAttributes extends AclWhatClause { /** The attributeVal element */ private AclAttributeVal aclAttributeVal; /** * Creates an instance of AclWhatClauseAttributes */ public AclWhatClauseAttributes() { aclAttributeVal = new AclAttributeVal(); } /** * Gets the attributes list. * * @return the attributes list */ public List<AclAttribute> getAttributes() { List<AclAttribute> copyAttributes = new ArrayList<AclAttribute>( aclAttributeVal.getAclAttributes().size() ); copyAttributes.addAll( aclAttributeVal.getAclAttributes() ); return copyAttributes; } /** * Adds an attribute. * * @param attribute the attribute to add */ public void addAttribute( String attribute ) { aclAttributeVal.getAclAttributes().add( new AclAttribute( attribute, null ) ); } /** * Adds a {@link Collection} of attributes. * * @param attributes the {@link Collection} of attributes */ public void addAllAttributes( Collection<AclAttribute> attributes ) { aclAttributeVal.getAclAttributes().addAll( attributes ); } /** * Clears attributes. */ public void clearAttributes() { aclAttributeVal.getAclAttributes().clear(); } /** * @return true if the AclWhatClauseAttributes has a val flag */ public boolean hasVal() { return aclAttributeVal.hasVal(); } /** * Set the val flag * * @param val The val flag value */ public void setVal( boolean val ) { aclAttributeVal.setVal( val ); } /** * @return true if the AclWhatClauseAttributes has a MatchingRule flag */ public boolean hasMatchingRule() { return aclAttributeVal.hasMatchingRule(); } /** * set the matchingRule flag */ public void setMatchingRule( boolean matchingRule ) { aclAttributeVal.setMatchingRule( matchingRule ); } /** * @return The AclAttribute style */ public AclAttributeStyleEnum getStyle() { return aclAttributeVal.getStyle(); } /** * @param style The AttributeVal style */ public void setStyle( AclAttributeStyleEnum style ) { aclAttributeVal.setStyle( style ); } /** * @return The AclAttribute value */ public String getValue() { return aclAttributeVal.getValue(); } /** * Sets the AclWhatClauseAttributes value * * @param value The AttributeVal value */ public void setValue( String value ) { aclAttributeVal.setValue( value ); } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); // Attrs sb.append( "attrs" ); // Attributes if ( ( aclAttributeVal.getAclAttributes() != null ) && ( aclAttributeVal.getAclAttributes().size() > 0 ) ) { sb.append( '=' ); boolean isFirst = true; for ( AclAttribute attribute : aclAttributeVal.getAclAttributes() ) { if ( isFirst ) { isFirst = false; } else { sb.append( ',' ); } sb.append( attribute ); } } // The val if ( aclAttributeVal.hasVal() ) { sb.append( " val" ); if ( aclAttributeVal.hasMatchingRule() ) { sb.append( "/matchingRule" ); } if ( aclAttributeVal.getStyle() != AclAttributeStyleEnum.NONE ) { sb.append( '.' ); sb.append( aclAttributeVal.getStyle().getName() ); } sb.append( "=\"" ); sb.append( aclAttributeVal.getValue() ); sb.append( '"' ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseTransportSsf.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseTransportSsf.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseTransportSsf extends AbstractAclWhoClauseCryptoStrength { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "transport_ssf=" + strength ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevelLevelEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevelLevelEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * TODO AclAccessLevelLevelEnum. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclAccessLevelLevelEnum { MANAGE, WRITE, READ, SEARCH, COMPARE, AUTH, DISCLOSE, NONE; /** * {@inheritDoc} */ public String toString() { switch ( this ) { case MANAGE: return "manage"; case WRITE: return "write"; case READ: return "read"; case SEARCH: return "search"; case COMPARE: return "compare"; case AUTH: return "auth"; case DISCLOSE: return "disclose"; case NONE: return "none"; } return super.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseGroup.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseGroup.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseGroup extends AbstractAclWhoClause { /** The object class */ private String objectclass; /** The attribute */ private String attribute; /** The type */ private AclWhoClauseGroupTypeEnum type; /** The pattern */ private String pattern; /** * Gets the attribute. * * @return the attribute */ public String getAttribute() { return attribute; } /** * Gets the objectclass. * * @return the objectclass */ public String getObjectclass() { return objectclass; } /** * Gets the pattern. * * @return the pattern */ public String getPattern() { return pattern; } /** * Gets the type. * * @return the type */ public AclWhoClauseGroupTypeEnum getType() { return type; } /** * Sets the attribute. * * @param attribute the attribute */ public void setAttribute( String attribute ) { this.attribute = attribute; } /** * Sets the objectclass. * * @param objectclass the objectclass */ public void setObjectclass( String objectclass ) { this.objectclass = objectclass; } /** * Sets the pattern * * @param pattern the pattern to set */ public void setPattern( String pattern ) { this.pattern = pattern; } /** * Sets the type. * * @param type the type to set */ public void setType( AclWhoClauseGroupTypeEnum type ) { this.type = type; } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); // DN sb.append( "group" ); // Object Class if ( objectclass != null ) { sb.append( "/" ); sb.append( objectclass ); // Attribute Name if ( attribute != null ) { sb.append( "/" ); sb.append( attribute ); } } // Type if ( type != null ) { sb.append( "." ); sb.append( type ); } // Pattern sb.append( '=' ); sb.append( '"' ); sb.append( pattern ); sb.append( '"' ); return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AbstractAclWhoClause.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AbstractAclWhoClause.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AbstractAclWhoClause implements AclWhoClause { /** The access level */ protected AclAccessLevel accessLevel; /** The control */ protected AclControlEnum control; /** * {@inheritDoc} */ public AclAccessLevel getAccessLevel() { return accessLevel; } /** * {@inheritDoc} */ public AclControlEnum getControl() { return control; } /** * {@inheritDoc} */ public void setAccessLevel( AclAccessLevel accessLevel ) { this.accessLevel = accessLevel; } /** * {@inheritDoc} */ public void setControl( AclControlEnum control ) { this.control = control; } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); // Access Level if ( accessLevel != null ) { sb.append( accessLevel ); } // Control if ( control != null ) { if ( sb.length() > 0 ) { sb.append( " " ); } sb.append( control ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeStyleEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeStyleEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclAttributeStyleEnum { EXACT( "exact" ), BASE( "base" ), BASE_OBJECT( "baseobject" ), REGEX( "regex" ), NONE( "---" ); /** The interned name */ private String name; /** * A private constructor */ private AclAttributeStyleEnum( String name ) { this.name = name; } /** * @return the name */ public String getName() { return name; } /** * Return an instance of AclAttributeStyleEnum from a String * * @param name The feature's name * @return The associated AclAttributeStyleEnum */ public static AclAttributeStyleEnum getStyle( String name ) { for ( AclAttributeStyleEnum style : values() ) { if ( style.name.equalsIgnoreCase( name ) ) { return style; } } return NONE; } /** * @return An array with all the Enum value's name */ public static String[] getNames() { String[] names = new String[values().length]; int pos = 0; for ( AclAttributeStyleEnum AclAttributeStyleEnum : values() ) { names[pos] = AclAttributeStyleEnum.name; pos++; } return names; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevel.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevel.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclAccessLevel { /** The 'self' modifier' flag */ private boolean isSelf = false; /** The level */ private AclAccessLevelLevelEnum level; /** The privileges modifier */ private AclAccessLevelPrivModifierEnum privilegesModifier; /** The privileges */ private List<AclAccessLevelPrivilegeEnum> privileges = new ArrayList<AclAccessLevelPrivilegeEnum>(); /** * Adds a privilege. * * @param p the privilege to add */ public void addPrivilege( AclAccessLevelPrivilegeEnum p ) { privileges.add( p ); } /** * Adds a {@link Collection} of privileges. * * @param arg0 the privileges to add */ public void addPrivileges( Collection<? extends AclAccessLevelPrivilegeEnum> c ) { privileges.addAll( c ); } /** * Clears the list of privileges. */ public void clearPrivileges() { privileges.clear(); } /** * Gets the level. * * @return the level */ public AclAccessLevelLevelEnum getLevel() { return level; } /** * Gets the privileges modifier. * * @return the privilegeModifier the privilege modifier */ public AclAccessLevelPrivModifierEnum getPrivilegeModifier() { return privilegesModifier; } /** * Gets the privileges. * * @return the privileges */ public List<AclAccessLevelPrivilegeEnum> getPrivileges() { return privileges; } /** * Gets the 'self' modifier' flag. * * @return the isSelf the 'self' modifier' flag */ public boolean isSelf() { return isSelf; } /** * Sets the level. * * @param level the level to set */ public void setLevel( AclAccessLevelLevelEnum level ) { this.level = level; } /** * Sets the privileges modifier. * * @param privilegeModifier the privilegeModifier to set */ public void setPrivilegeModifier( AclAccessLevelPrivModifierEnum privilegeModifier ) { this.privilegesModifier = privilegeModifier; } /** * Sets the 'self' modifier' flag. * * @param isSelf the 'self' modifier' flag to set */ public void setSelf( boolean isSelf ) { this.isSelf = isSelf; } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); // Self if ( isSelf ) { sb.append( "self " ); } // Level if ( level != null ) { sb.append( level.toString() ); } // Privilege Modifier if ( privilegesModifier != null ) { sb.append( privilegesModifier.toString() ); } // Privileges if ( ( privileges != null ) && ( privileges.size() > 0 ) ) { for ( AclAccessLevelPrivilegeEnum privlege : privileges ) { sb.append( privlege ); } } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseGroupTypeEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseGroupTypeEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * TODO AclWhoClauseGroupTypeEnum. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclWhoClauseGroupTypeEnum { EXACT, EXPAND; /** * {@inheritDoc} */ public String toString() { switch ( this ) { case EXACT: return "exact"; case EXPAND: return "expand"; } return super.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClause.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClause.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * The AclWhoClause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public interface AclWhoClause { /** * Gets the access level. * * @return the access level */ AclAccessLevel getAccessLevel(); /** * Gets the control. * * @return the control */ AclControlEnum getControl(); /** * Sets access level. * * @param accessLevel the access level */ void setAccessLevel( AclAccessLevel accessLevel ); /** * Sets control. * * @param accessLevel the control */ void setControl( AclControlEnum control ); }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseFilter.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseFilter.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * The Acl what-filter clause. It stores a Ldap Filter. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhatClauseFilter extends AclWhatClause { /** The filter */ private String filter; /** * Gets the filter. * * @return the filter */ public String getFilter() { return filter; } /** * Sets the filter. * * @param filter the filter to set */ public void setFilter( String filter ) { this.filter = filter; } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "filter=" ); sb.append( filter ); return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/OpenLdapAclParser.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/OpenLdapAclParser.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; import java.io.StringReader; import java.text.ParseException; import antlr.CharBuffer; import antlr.LexerSharedInputState; import antlr.RecognitionException; import antlr.TokenStreamException; /** * A reusable wrapper around the antlr generated parser for an OpenLDAP ACL. The grammar * to parse is the following : * <pre> * parse ::= SP* aclItem SP* EOF * aclItem ::= ( ID_access SP+ )? ID_to ( SP+ (what_star | what_dn | what_attrs | what_filter | ( ID_by SP+ who ) ) )+ * what_star ::= STAR * what_dn ::= ID_dn ( DOT what_dn_type )? SP+ EQUAL SP+ DOUBLE_QUOTED_STRING * what_dn_type ::= ID_regex | ID_base | ID_exact | ID_one | ID_subtree | ID_children * what_attrs ::= ( ID_attrs | ID_attr ) SP* EQUAL SP* ATTR_IDENT ( SEP ATTR_IDENT )* * ( SP* VAL ( SLASH MATCHING_RULE )? ( DOT what_attrs_style)? ) SP* EQUAL SP* DOUBLE_QUOTED_STRING )? * what_attrs_attr_ident::= ATTR_IDENT * what_attrs_style ::= EXACT | BASE | BASE_OBJECT | REGEX | ONE | ONE_LEVEL | SUB | SUB_TREE | CHILDREN * what_filter ::= ID_filter SP* EQUAL SP* FILTER * who ::= ( who_star | who_anonymous | who_users | who_self | who_dn | who_dnattr | who_group | who_ssf | * who_transport_ssf | who_tls_ssf | who_sasl_ssf ) ( SP+ who_access_level )? ( SP+ who_control )? * who_anonymous ::= ID_anonymous * who_users ::= ID_users * who_self ::= ID_self * who_star ::= STAR * who_dnattr ::= ID_dnattr SP* EQUAL SP* ATTR_IDENT * who_group ::= ID_group ( SLASH ATTR_IDENT ( SLASH ATTR_IDENT )? )? ( DOT who_group_type )? * EQUAL DOUBLE_QUOTED_STRING * who_group_type ::= ID_exact | ID_expand * who_dn ::= ID_dn ( DOT who_dn_type ( SEP who_dn_modifier )? )? SP* EQUAL SP* DOUBLE_QUOTED_STRING * who_dn_type ::= ID_regex | ID_base | ID_exact | ID_one | ID_subtree | ID_children | * ID_level OPEN_CURLY token:INTEGER CLOSE_CURLY * who_dn_modifier ::= ID_expand * who_access_level ::= ID_self SP+ ( who_access_level_level | who_access_level_priv )? | * ( who_access_level_level | who_access_level_priv )? * who_access_level_level ::= ID_manage | ID_write | ID_read | ID_search | ID_compare | ID_auth | ID_disclose | ID_none * who_access_level_priv ::= who_access_level_priv_modifier ( who_access_level_priv_priv )+ * who_access_level_priv_modifier ::= EQUAL | PLUS | MINUS * who_access_level_priv_priv ::= ID_m | ID_w | ID_r | ID_s | ID_c | ID_x * who_control ::= ID_stop | ID_continue | ID_break * who_ssf ::= strength:SSF * who_transport_ssf ::= TRANSPORT_SSF * who_tls_ssf ::= strength:TLS_SSF * who_sasl_ssf ::= strength:SASL_SSF * </pre> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclParser { /** the antlr generated parser being wrapped */ private AntlrAclParser parser; /** the antlr generated lexer being wrapped */ private AntlrAclLexer lexer; /** * Creates an OpenLDAP ACL parser. */ public OpenLdapAclParser() { this.lexer = new AntlrAclLexer( new StringReader( "" ) ); this.parser = new AntlrAclParser( lexer ); } /** * Parses an OpenLDAP ACL. * * @param s the string to be parsed * @return the specification bean * @throws ParseException if there are any recognition errors (bad syntax) */ public synchronized AclItem parse( String s ) throws ParseException { try { LexerSharedInputState state = new LexerSharedInputState( new CharBuffer( new StringReader( s ) ) ); this.lexer.setInputState( state ); this.parser.getInputState().reset(); parser.parse(); return parser.getAclItem(); } catch ( TokenStreamException e ) { throw new ParseException( "Unable to read ACL: " + e.getMessage(), -1 ); } catch ( RecognitionException e ) { throw new ParseException( "Unable to read ACL: " + e.getMessage() + " - [Line:" + e.getLine() + " - Column:" + e.getColumn() + "]", e.getColumn() ); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseSsf.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseSsf.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseSsf extends AbstractAclWhoClauseCryptoStrength { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "ssf=" + strength ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclItem.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclItem.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * This class represents an ACL (Access Control List) Item for OpenLDAP. * * An AclItem contains an AclWhatClause and a list of AclWhoClause * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclItem { /** The {@link AclWhatClause} element */ private AclWhatClause whatClause; /** The {@link AclWhoClause} elements */ private List<AclWhoClause> whoClauses = new ArrayList<AclWhoClause>(); /** * Creates a new instance of AclItem. */ public AclItem() { } /** * Creates a new instance of AclItem. * * @param whatClause the {@link AclWhatClause} element * @param whoClauses the {@link AclWhoClause} elements */ public AclItem( AclWhatClause whatClause, List<AclWhoClause> whoClauses ) { this.whatClause = whatClause; this.whoClauses = whoClauses; } /** * Gets the {@link AclWhatClause} element. * * @return the whatClauses the {@link AclWhatClause} element */ public AclWhatClause getWhatClause() { return whatClause; } /** * Gets the {@link AclWhoClause} elements. * * @return the whoClauses the {@link AclWhoClause} elements */ public List<AclWhoClause> getWhoClauses() { return whoClauses; } /** * Sets the {@link AclWhatClause} element. * * @param whatClause the {@link AclWhatClause} element to set */ public void setWhatClause( AclWhatClause whatClause ) { this.whatClause = whatClause; } /** * Adds an {@link AclWhoClause} element. * * @param c the {@link AclWhoClause} element to add */ public void addWhoClause( AclWhoClause c ) { whoClauses.add( c ); } /** * Adds a {@link Collection} of {@link AclWhoClause} element. * * @param c the {@link Collection} of {@link AclWhoClause} */ public void addAllWhoClause( Collection<? extends AclWhoClause> c ) { whoClauses.addAll( c ); } /** * Clears all {@link AclWhoClause} elements. */ public void clearWhoClause() { whoClauses.clear(); } /** * {@inheritDoc} */ public String toString() { return toString( false ); } public String toString( boolean prependAccess ) { return toString( prependAccess, false ); } public String toString( boolean prependAccess, boolean prettyPrint ) { StringBuilder sb = new StringBuilder(); // Access (if needed) if ( prependAccess ) { sb.append( "access " ); } // To sb.append( "to " ); // What Clause if ( whatClause != null ) { sb.append( whatClause.toString() ); } // Who Clauses if ( ( whoClauses != null ) && ( whoClauses.size() > 0 ) ) { for ( AclWhoClause whoClause : whoClauses ) { if ( prettyPrint ) { sb.append( "\n" ); } else { sb.append( " " ); } sb.append( "by " ); sb.append( whoClause.toString() ); } } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseTlsSsf.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseTlsSsf.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseTlsSsf extends AbstractAclWhoClauseCryptoStrength { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "tls_ssf=" + strength ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseDn.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseDn.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * The Acl what-dn clause. It has a type and a pattern. * The type is one of : * <ul> * <li>base : AclWhatClauseDnTypeEnum.BASE</li> * <li>baseObject : AclWhatClauseDnTypeEnum.BASE_OBJECT</li> * <li>one : AclWhatClauseDnTypeEnum.ONE</li> * <li>oneLevel : AclWhatClauseDnTypeEnum.ONE_LEVEL</li> * <li>sub/subtree : AclWhatClauseDnTypeEnum.SUB</li> * <li>subtree : AclWhatClauseDnTypeEnum.SUBTREE</li> * <li>children : AclWhatClauseDnTypeEnum.CHILDREN</li> * <li>exact : AclWhatClauseDnTypeEnum.EXACT</li> * <li>regex : AclWhatClauseDnTypeEnum.REGEX</li> * </ul> * * The pattern can be a DN or a regexp, depending on the type. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhatClauseDn extends AclWhatClause { /** The type, default to BASE */ private AclWhatClauseDnTypeEnum type; /** The pattern */ private String pattern; /** * Gets the type. * * @return the type */ public AclWhatClauseDnTypeEnum getType() { return type; } /** * Sets the type. * * @param type the type to set */ public void setType( AclWhatClauseDnTypeEnum type ) { this.type = type; } /** * Gets the pattern. * * @return the pattern */ public String getPattern() { return pattern; } /** * Sets the pattern * * @param pattern the pattern to set */ public void setPattern( String pattern ) { this.pattern = pattern; } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); // DN sb.append( "dn" ); // Type if ( type != null ) { sb.append( "." ); sb.append( type ); } // Pattern sb.append( '=' ); sb.append( '"' ); sb.append( pattern ); sb.append( '"' ); return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseSaslSsf.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseSaslSsf.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseSaslSsf extends AbstractAclWhoClauseCryptoStrength { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "sasl_ssf=" + strength ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseStar.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseStar.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * The Acl what-star rule. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhatClauseStar extends AclWhatClause { /** * {@inheritDoc} */ public String toString() { return "*"; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevelPrivModifierEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevelPrivModifierEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * TODO AclAccessLevelPrivModifierEnum. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclAccessLevelPrivModifierEnum { EQUAL, PLUS, MINUS; /** * {@inheritDoc} */ public String toString() { switch ( this ) { case EQUAL: return "="; case PLUS: return "+"; case MINUS: return "-"; } return super.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclControlEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclControlEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * TODO AclControlEnum. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclControlEnum { STOP, CONTINUE, BREAK; /** * {@inheritDoc} */ public String toString() { switch ( this ) { case STOP: return "stop"; case CONTINUE: return "continue"; case BREAK: return "break"; } return super.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseUsers.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseUsers.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseUsers extends AbstractAclWhoClause { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "users" ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttribute.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttribute.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; import org.apache.directory.api.ldap.model.schema.AttributeType; import org.apache.directory.api.ldap.model.schema.ObjectClass; import org.apache.directory.api.ldap.model.schema.SchemaManager; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.openldap.config.OpenLdapConfigurationPlugin; /** * A class used to store the WhatClause attributes with a qualifier (either '!' or '@'). * We store either an AttributeType, or an ObjectClass (prefixed with '@' or '!'), or one * of the two special values : 'entry' and 'children' * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclAttribute { /** The special "entry" constant */ public static final String ENTRY = "entry"; /** The special "children" constant */ public static final String CHILDREN = "children"; /** The special ExtensibleObject constant*/ public static final String EXTENSIBLE_OBJECT = "extensibleObject"; /** The prefix for ObjectClass */ public static final char OC = '@'; /** The prefix for ObjectClass exclusion */ public static final char OC_EX = '!'; /** The AttributeType, if we know about it */ private AttributeType attributeType; /** The ObjectClass, if we know about it */ private ObjectClass objectClass; /** The attributeName */ private String name; /** A flag set when we are storing an AttributeType */ private boolean isAttributeType = false; /** A flag set when we are storing an ObjectClass */ private boolean isObjectClass = false; /** A flag set when we are storing an ObjectClass with control on non allowed attributes */ private boolean isObjectClassNotAllowed = false; /** A flag set when we stored the special 'entry' attribute */ private boolean isEntry = false; /** A flag set when we stored the special 'children' attribute */ private boolean isChildren = false; /** The Connection to the LDAP server */ private IBrowserConnection connection; /** * Create a new AclAttribute with no name * * @param connection The Connection on the LDAP Server */ public AclAttribute( IBrowserConnection connection ) { this.connection = connection; setName( "" ); } /** * Create a new AclAttribute with specific name * * @param name The AlcAttribute name */ public AclAttribute( String name ) { this.connection = null; setName( name ); } /** * Create a new AclAttribute with specific name * * @param name The AlcAttribute name */ public AclAttribute( String name, IBrowserConnection connection ) { this.connection = connection; setName( name ); } /** * @return the attributeType */ public AttributeType getAttributeType() { return attributeType; } /** * @return the objectClass */ public ObjectClass getObjectClass() { return objectClass; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName( String name ) { if ( Strings.isEmpty( name ) ) { //The default is externalObject ObjectClass isObjectClass = true; this.name = EXTENSIBLE_OBJECT; } else { if ( Strings.isCharASCII( name, 0, OC ) ) { isObjectClass = true; this.name = name.substring( 1 ); } else if ( Strings.isCharASCII( name, 0, OC_EX ) ) { isObjectClassNotAllowed = true; this.name = name.substring( 1 ); } else { if ( ENTRY.equalsIgnoreCase( name ) ) { isEntry = true; } else if ( CHILDREN.equalsIgnoreCase( name ) ) { isChildren = true; } else { isAttributeType = true; } this.name = name; } } if ( ( isAttributeType || isObjectClass || isObjectClassNotAllowed ) && ( connection != null ) ) { // Try to find the element in the schema try { SchemaManager schemaManager = OpenLdapConfigurationPlugin.getDefault().getSchemaManager(); if ( schemaManager != null ) { if ( isAttributeType ) { attributeType = schemaManager.lookupAttributeTypeRegistry( this.name ); } else { // It's an ObjectClass objectClass = schemaManager.lookupObjectClassRegistry( this.name ); } } } catch ( Exception e ) { // Nothing to do } } } /** * @return the isAttributeType */ public boolean isAttributeType() { return isAttributeType; } /** * @return the isObjectClass */ public boolean isObjectClass() { return isObjectClass; } /** * @return the isEntry */ public boolean isEntry() { return isEntry; } /** * @return the isChildren */ public boolean isChildren() { return isChildren; } /** * @return the isObjectClassNotAllowed */ public boolean isObjectClassNotAllowed() { return isObjectClassNotAllowed; } /** * @See Object#toString() */ public String toString() { if ( isEntry || isChildren || isAttributeType ) { return name; } StringBuilder buffer = new StringBuilder(); if ( isObjectClass ) { buffer.append( OC ); } else { buffer.append( OC_EX ); } buffer.append( name ); return buffer.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseStar.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseStar.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseStar extends AbstractAclWhoClause { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "*" ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseDnTypeEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClauseDnTypeEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * This enum contains all possible values for the type of a DN What Clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclWhatClauseDnTypeEnum { REGEX( "regex" ), BASE( "base" ), BASE_OBJECT( "baseobject" ), EXACT( "exact" ), ONE( "one" ), ONE_LEVEL( "onelevel" ), SUB( "sub" ), SUBTREE( "subtree" ), CHILDREN( "children" ); /** The interned name */ private String name; private AclWhatClauseDnTypeEnum( String name ) { this.name = name; } /** * @return The interned name */ public String getName() { return name; } /** * {@inheritDoc} */ public String toString() { return name; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClause.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhatClause.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * The ACL what clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhatClause { /** The filter clause */ private AclWhatClauseFilter filterClause; /** The attributes clause */ private AclWhatClauseAttributes attributesClause; public AclWhatClause() { } public AclWhatClause( AclWhatClauseStar starClause, AclWhatClauseDn dnClause, AclWhatClauseFilter filterClause, AclWhatClauseAttributes attributesClause ) { this.filterClause = filterClause; this.attributesClause = attributesClause; } public AclWhatClause( AclWhatClauseFilter filterClause ) { this.filterClause = filterClause; } public AclWhatClause( AclWhatClauseAttributes attributesClause ) { this.attributesClause = attributesClause; } /** * @return the attributesClause */ public AclWhatClauseAttributes getAttributesClause() { return attributesClause; } /** * @return the filterClause */ public AclWhatClauseFilter getFilterClause() { return filterClause; } /** * @param attributesClause the attributesClause to set */ public void setAttributesClause( AclWhatClauseAttributes attributesClause ) { this.attributesClause = attributesClause; } /** * @param filterClause the filterClause to set */ public void setFilterClause( AclWhatClauseFilter filterClause ) { this.filterClause = filterClause; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeVal.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAttributeVal.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; import java.util.ArrayList; import java.util.List; /** * A class used to store the WhatClause attributes with a qualifier (either '!' or '@'). * We store either an AttributeType, or an ObjectClass (prefixed with '@' or '¬'), or one * of the two special values : 'entry' and 'children' * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclAttributeVal { /** The list of AclAttributes */ List<AclAttribute> aclAttributes = new ArrayList<AclAttribute>(); /** The attribute style*/ private AclAttributeStyleEnum style; /** The val flag */ private boolean val; /** The MatchingRule flag */ private boolean matchingRule; /** The regex */ private String regex; private String value; /** * @return the aclAttributes */ public List<AclAttribute> getAclAttributes() { return aclAttributes; } /** * @param aclAttributes the aclAttributes to set */ public void setAclAttributes( List<AclAttribute> aclAttributes ) { this.aclAttributes = aclAttributes; } /** * @return the style */ public AclAttributeStyleEnum getStyle() { return style; } /** * @param style the style to set */ public void setStyle( AclAttributeStyleEnum style ) { this.style = style; } /** * @return the val */ public boolean hasVal() { return val; } /** * @param val the val to set */ public void setVal( boolean val ) { this.val = val; } /** * @return the matchingRule */ public boolean hasMatchingRule() { return matchingRule; } /** * @param matchingRule the matchingRule to set */ public void setMatchingRule( boolean matchingRule ) { this.matchingRule = matchingRule; } /** * @return the value */ public String getValue() { return value; } /** * @param value the value to set */ public void setValue( String value ) { this.value = value; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevelPrivilegeEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclAccessLevelPrivilegeEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * TODO AclAccessLevelPrivilegeEnum. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclAccessLevelPrivilegeEnum { MANAGE, WRITE, READ, SEARCH, DISCLOSE, COMPARE, AUTHENTICATION; /** * {@inheritDoc} */ public String toString() { switch ( this ) { case MANAGE: return "m"; case WRITE: return "w"; case READ: return "r"; case SEARCH: return "s"; case DISCLOSE: return "d"; case COMPARE: return "c"; case AUTHENTICATION: return "x"; } return super.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDnAttr.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDnAttr.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseDnAttr extends AbstractAclWhoClause { /** The attribute */ private String attribute; /** * Gets the attribute. * * @return the attribute */ public String getAttribute() { return attribute; } /** * Sets the attribute. * * @param attribute the attribute */ public void setAttribute( String attribute ) { this.attribute = attribute; } /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "dnattr=" ); sb.append( attribute ); return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclWhoClauseEnum { STAR, ANONYMOUS, USERS, SELF, DN, DNATTR, GROUP, SASL_SSF, SSF, TLS_SSF, TRANSPORT_SSF; /** * Gets the enum value associated with the given clause. * * @param clause the clause * @return the enum value associated with the given clause. */ public static AclWhoClauseEnum get( AclWhoClause clause ) { if ( clause instanceof AclWhoClauseStar ) { return STAR; } else if ( clause instanceof AclWhoClauseAnonymous ) { return ANONYMOUS; } else if ( clause instanceof AclWhoClauseUsers ) { return USERS; } else if ( clause instanceof AclWhoClauseSelf ) { return SELF; } else if ( clause instanceof AclWhoClauseDn ) { return DN; } else if ( clause instanceof AclWhoClauseDnAttr ) { return DNATTR; } else if ( clause instanceof AclWhoClauseGroup ) { return GROUP; } else if ( clause instanceof AclWhoClauseSaslSsf ) { return SASL_SSF; } else if ( clause instanceof AclWhoClauseSsf ) { return SSF; } else if ( clause instanceof AclWhoClauseTlsSsf ) { return TLS_SSF; } else if ( clause instanceof AclWhoClauseSaslSsf ) { return SASL_SSF; } return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseSelf.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseSelf.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AclWhoClauseSelf extends AbstractAclWhoClause { /** * {@inheritDoc} */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "self" ); String whoClauseToString = super.toString(); if ( whoClauseToString.length() > 0 ) { sb.append( " " ); sb.append( whoClauseToString ); } return sb.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDnModifierEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/model/AclWhoClauseDnModifierEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.model; /** * This enum contains all possible values for the modifier of a DN Who Clause. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclWhoClauseDnModifierEnum { EXPAND; /** * {@inheritDoc} */ public String toString() { switch ( this ) { case EXPAND: return "expand"; } return super.toString(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/editor/OpenLdapAclValueEditor.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/editor/OpenLdapAclValueEditor.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.editor; import org.apache.directory.api.util.Strings; import org.apache.directory.studio.ldapbrowser.core.model.AttributeHierarchy; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.IEntry; import org.apache.directory.studio.ldapbrowser.core.model.IValue; import org.apache.directory.studio.valueeditors.AbstractDialogStringValueEditor; import org.eclipse.swt.widgets.Shell; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; import org.apache.directory.studio.openldap.config.acl.dialogs.OpenLdapAclDialog; /** * This class implements a value editor that handle OpenLDAP ACL string values * in a dialog. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclValueEditor extends AbstractDialogStringValueEditor { /** * {@inheritDoc} */ protected boolean openDialog( Shell shell ) { Object value = getValue(); if ( value instanceof OpenLdapAclValueWithContext ) { OpenLdapAclValueWithContext context = ( OpenLdapAclValueWithContext ) value; OpenLdapAclDialog dialog = new OpenLdapAclDialog( shell, context ); if ( ( dialog.open() == OpenLdapAclDialog.OK ) && !"".equals( dialog.getAclValue() ) ) //$NON-NLS-1$ { if ( dialog.hasPrecedence() ) { String aclValue = "{" + dialog.getPrecedence() + "}" + dialog.getAclValue(); setValue( aclValue ); } else { String aclValue = dialog.getAclValue(); setValue( aclValue ); } return true; } } return false; } /** * Returns a ACIItemValueContext with the connection * and entry of the attribute hierarchy and an empty value if there * are no values in attributeHierarchy. * * Returns a ACIItemValueContext with the connection * and entry of the attribute hierarchy and a value if there is * one value in attributeHierarchy. * * @param attributeHierarchy the attribute hierarchy * * @return the raw value */ public Object getRawValue( AttributeHierarchy attributeHierarchy ) { if ( attributeHierarchy == null ) { return null; } if ( ( attributeHierarchy.size() == 1 ) && ( attributeHierarchy.getAttribute().getValueSize() == 0 ) ) { IEntry entry = attributeHierarchy.getAttribute().getEntry(); IBrowserConnection connection = entry.getBrowserConnection(); if ( attributeHierarchy.getAttribute().getValueSize() == 0 ) { return new OpenLdapAclValueWithContext( connection, entry, -1, "" ); //$NON-NLS-1$ } else if ( attributeHierarchy.getAttribute().getValueSize() == 1 ) { String valueStr = getDisplayValue( attributeHierarchy ); int precedence = getPrecedence( valueStr ); String aclValue = valueStr; if ( precedence != -1 ) { aclValue = removePrecedence( valueStr ); } return new OpenLdapAclValueWithContext( connection, entry, precedence, aclValue ); } } return null; } /** * Returns a ACIItemValueContext with the connection, * entry and string value of the given value. * * @param value the value * * @return the raw value */ public Object getRawValue( IValue value ) { Object object = super.getRawValue( value ); if ( object instanceof String ) { IEntry entry = value.getAttribute().getEntry(); IBrowserConnection connection = entry.getBrowserConnection(); String valueStr = ( String ) object; int precedence = getPrecedence( valueStr ); String aclValue = valueStr; if ( precedence != -1 ) { aclValue = removePrecedence( valueStr ); } return new OpenLdapAclValueWithContext( connection, entry, precedence, aclValue ); } return null; } /** * Gets the precedence value (or -1 if none is found). * * @param s the string * @return the precedence value (or -1 if none is found). */ public int getPrecedence( String s ) { // Checking if the acl contains precedence information ("{int}") if ( Strings.isCharASCII( s, 0, '{' ) ) { int precedence = 0; int pos = 1; while ( pos < s.length() ) { char c = s.charAt( pos ); if ( c == '}' ) { if ( pos == 1 ) { return -1; } else { return precedence; } } if ( ( c >= '0' ) && ( c <= '9' ) ) { precedence = precedence*10 + ( c - '0' ); } else { // Not a precedence return -1; } pos++; } return -1; } else { return -1; } } /** * Return the ACII value withoiut the precedence part * * @param str The original ACII, with or without precedence * @return The ACII string minus the precedence part */ public String removePrecedence( String str ) { if ( Strings.isCharASCII( str, 0, '{' ) ) { int pos = 1; while ( pos < str.length() ) { char c = str.charAt( pos ); if ( c == '}' ) { if ( pos == 1 ) { // We just have {}, return the string return str; } else { return str.substring( pos + 1 ); } } if ( ( c < '0' ) && ( c > '9' ) ) { // Not a number, get out return str; } pos++; } return str; } else { return str; } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhatClauseWidget.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhatClauseWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; import org.apache.directory.studio.openldap.config.acl.model.AclWhatClause; import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseAttributes; import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseDn; import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseFilter; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhatClauseAttributesComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhatClauseDnComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhatClauseFilterComposite; /** * The WhatClause widget. It coves all the What possible options : * <ul> * <li>DN</li> * <li>Filter</li> * <li>Attributes</li> * </ul> * The three possible options, when selected, will open new composites dynamically. * * <pre> * </pre> * .---------------------------------------------------------. * | | * | [ ] DN | * | | * | [ ] Filter | * | | * | [ ] Attributes | * | | * `---------------------------------------------------------' * </pre> * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclWhatClauseWidget extends AbstractWidget { /** The visual editor composite */ private OpenLdapAclVisualEditorComposite visualEditorComposite; /** The context */ private OpenLdapAclValueWithContext context; // UI widgets private Composite composite; private Button dnCheckbox; private Composite dnComposite; private Composite dnSubComposite; private Button filterCheckbox; private Composite filterComposite; private Composite filterSubComposite; private Button attributesCheckbox; private Composite attributesComposite; private Composite attributesSubComposite; private WhatClauseAttributesComposite attributesClauseComposite; private WhatClauseFilterComposite filterClauseComposite; private WhatClauseDnComposite dnClauseComposite; // Listeners private SelectionAdapter dnCheckboxListener = new SelectionAdapter() { public void widgetSelected( org.eclipse.swt.events.SelectionEvent e ) { if ( dnCheckbox.getSelection() ) { createDnComposite(); } else { disposeComposite( dnSubComposite ); } // Refreshing the layout of the whole composite visualEditorComposite.layout( true, true ); } }; private SelectionAdapter filterCheckboxListener = new SelectionAdapter() { public void widgetSelected( org.eclipse.swt.events.SelectionEvent e ) { if ( filterCheckbox.getSelection() ) { createFilterComposite(); } else { disposeComposite( filterSubComposite ); } // Refreshing the layout of the whole composite visualEditorComposite.layout( true, true ); } }; /** * The listener on the Attributes Checkbox. It creates the Attributes composite * when selected, dispose it when unchecked. */ private SelectionAdapter attributesCheckboxListener = new SelectionAdapter() { public void widgetSelected( org.eclipse.swt.events.SelectionEvent e ) { if ( attributesCheckbox.getSelection() ) { createAttributesComposite(); } else { disposeComposite( attributesSubComposite ); } // Refreshing the layout of the whole composite visualEditorComposite.layout( true, true ); } }; /** * Creates a new instance of OpenLdapAclWhatClauseWidget. It's just a list of * 3 checkboxes which, when selected, open a new composite dynamically created. * * <pre> * .---------------------------------------------------------. * | | * | [ ] DN | * | | * | [ ] Filter | * | | * | [ ] Attributes | * | | * `---------------------------------------------------------' * </pre> * * @param visualEditorComposite the visual editor composite * @param parent The WhatClause parent's composite * @param context the Acl context */ public OpenLdapAclWhatClauseWidget( OpenLdapAclVisualEditorComposite visualEditorComposite, Composite parent, OpenLdapAclValueWithContext context ) { this.visualEditorComposite = visualEditorComposite; this.context = context; // Creating the widget base composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); // Creating the what group Group whatGroup = BaseWidgetUtils.createGroup( parent, "Acces to \"What\"", 1 ); whatGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); // DN dnCheckbox = BaseWidgetUtils.createCheckbox( whatGroup, "DN", 1 ); dnComposite = BaseWidgetUtils.createColumnContainer( whatGroup, 1, 1 ); dnCheckbox.addSelectionListener( dnCheckboxListener ); // Filter filterCheckbox = BaseWidgetUtils.createCheckbox( whatGroup, "Filter", 1 ); filterComposite = BaseWidgetUtils.createColumnContainer( whatGroup, 1, 1 ); filterCheckbox.addSelectionListener( filterCheckboxListener ); // Attributes attributesCheckbox = BaseWidgetUtils.createCheckbox( whatGroup, "Attributes", 1 ); attributesComposite = BaseWidgetUtils.createColumnContainer( whatGroup, 1, 1 ); attributesCheckbox.addSelectionListener( attributesCheckboxListener ); } /** * Creates the DN composite. */ private void createDnComposite() { Group dnGroup = BaseWidgetUtils.createGroup( dnComposite, "", 1 ); dnGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); dnSubComposite = dnGroup; dnClauseComposite = new WhatClauseDnComposite( context, visualEditorComposite ); dnClauseComposite.createComposite( dnGroup ); /* AclWhatClause whatClause = context.getAclItem().getWhatClause(); if ( whatClause.getDnClause() != null ) { dnClauseComposite.setClause( whatClause.getDnClause() ); } if ( context != null ) { dnClauseComposite.setConnection( context.getConnection() ); } */ } /** * Creates the filter composite. */ private void createFilterComposite() { Group filterGroup = BaseWidgetUtils.createGroup( filterComposite, "", 1 ); filterGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); filterSubComposite = filterGroup; filterClauseComposite = new WhatClauseFilterComposite( context, visualEditorComposite ); filterClauseComposite.createComposite( filterGroup ); /* AclWhatClause whatClause = context.getAclItem().getWhatClause(); if ( whatClause.getFilterClause() != null ) { filterClauseComposite.setClause( whatClause.getFilterClause() ); } if ( context != null ) { filterClauseComposite.setConnection( context.getConnection() ); } */ } /** * Creates the attributes composite. */ private void createAttributesComposite() { attributesSubComposite = BaseWidgetUtils.createGroup( attributesComposite, "", 1 ); attributesSubComposite.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); attributesClauseComposite = new WhatClauseAttributesComposite( visualEditorComposite, attributesSubComposite, context ); /* AclWhatClause whatClause = context.getAclItem().getWhatClause(); if ( whatClause.getAttributesClause() != null ) { attributesClauseComposite.setClause( whatClause.getAttributesClause() ); } if ( context != null ) { attributesClauseComposite.setConnection( context.getConnection() ); } */ } /** * Disposes the given composite. * * @param composite the composite */ private void disposeComposite( Composite composite ) { if ( ( composite != null ) && ( !composite.isDisposed() ) ) { composite.dispose(); } } /** * Refresh the WhatClause GUI */ public void refresh() { AclWhatClause whatClause = context.getAclItem().getWhatClause(); if ( whatClause != null ) { // DN clause if ( whatClause instanceof AclWhatClauseDn ) { dnCheckbox.setSelection( true ); createDnComposite(); } else if ( whatClause instanceof AclWhatClauseFilter ) { // Filter clause filterCheckbox.setSelection( true ); createFilterComposite(); } else if ( whatClause instanceof AclWhatClauseAttributes ) { // Attributes clause attributesCheckbox.setSelection( true ); createAttributesComposite(); } } } /** * Disposes all created SWT widgets. */ public void dispose() { // Composite if ( ( composite != null ) && ( !composite.isDisposed() ) ) { composite.dispose(); } } /** * Saves widget settings. */ public void saveWidgetSettings() { if ( attributesClauseComposite != null ) { attributesClauseComposite.saveWidgetSettings(); } } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclSourceEditorComposite.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclSourceEditorComposite.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; import java.text.ParseException; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; import org.apache.directory.studio.openldap.config.acl.model.AclItem; import org.apache.directory.studio.openldap.config.acl.model.OpenLdapAclParser; import org.apache.directory.studio.openldap.config.acl.sourceeditor.OpenLdapAclSourceViewerConfiguration; /** * This composite contains the source editor. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclSourceEditorComposite extends Composite { /** The source editor */ private SourceViewer sourceEditor; /** The source editor configuration. */ private SourceViewerConfiguration configuration; /** The ACL context */ private OpenLdapAclValueWithContext context; /** The ACL parser */ private OpenLdapAclParser parser = new OpenLdapAclParser(); /** * Creates a new instance of ACIItemSourceEditorComposite. * * @param parent * @param style */ public OpenLdapAclSourceEditorComposite( Composite parent, OpenLdapAclValueWithContext context, int style ) { super( parent, style ); this.context = context; setLayout( new FillLayout() ); createSourceEditor(); } /** * Creates and configures the source editor. * */ private void createSourceEditor() { // create source editor sourceEditor = new SourceViewer( this, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL ); // setup basic configuration configuration = new OpenLdapAclSourceViewerConfiguration(); sourceEditor.configure( configuration ); // set text font Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); sourceEditor.getTextWidget().setFont( font ); // setup document IDocument document = new Document(); sourceEditor.setDocument( document ); } /** * Sets the input to the source editor. * A syntax check is performed before setting the input, an * invalid syntax causes a ParseException. * * @param input the valid string representation of the ACI item * @throws ParseException it the syntax check fails. */ public void refresh() { forceSetInput( context.getAclItem().toString() ); } /** * Set the input to the source editor without a syntax check. * * @param input The string representation of the ACI item, may be invalid */ public void forceSetInput( String input ) { sourceEditor.getDocument().set( input ); // format IRegion region = new Region( 0, sourceEditor.getDocument().getLength() ); configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region ); } /** * Returns the string representation of the ACI item. * A syntax check is performed before returning the input, an * invalid syntax causes a ParseException. * * @return the valid string representation of the ACI item * @throws ParseException it the syntax check fails. */ public String getInput() throws ParseException { String input = forceGetInput(); // strip new lines input = input.replaceAll( "\\n", " " ); //$NON-NLS-1$ //$NON-NLS-2$ input = input.replaceAll( "\\r", " " ); //$NON-NLS-1$ //$NON-NLS-2$ AclItem aclItem = parser.parse( input ); String acl = ""; if ( aclItem != null ) { acl = aclItem.toString(); } return acl; } /** * Returns the string representation of the ACI item without syntax check. * In other words only the text in the source editor is returned. * * @return the string representation of the ACI item, may be invalid */ public String forceGetInput() { return sourceEditor.getDocument().get(); } /** * Sets the context. * * @param context the context */ public void setContext( OpenLdapAclValueWithContext context ) { } /** * Formats the content. */ public void format() { IRegion region = new Region( 0, sourceEditor.getDocument().getLength() ); configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclVisualEditorComposite.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclVisualEditorComposite.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; import java.text.ParseException; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; import org.apache.directory.studio.openldap.config.acl.model.AclItem; /** * This is the main widget of the OpenLDAP ACL visual editor. * <p> * It extends ScrolledComposite. * * <pre> * .----------------(##Visual Editor##| Source )----------------. * | | * | Access to "What" | * | .----------------------------------------------------------. | * | | | | * ... * | | | | * | `----------------------------------------------------------' | * | Access to "Who" | * | .----------------------------------------------------------. | * | | | | * ... * | | | | * | `----------------------------------------------------------' | * | | * | | * `--------------------------------------------------------------' * </pre> * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclVisualEditorComposite extends ScrolledComposite { /** The ACL context */ private OpenLdapAclValueWithContext context; // UI widgets /** The WHAT clause Widget */ private OpenLdapAclWhatClauseWidget whatClauseWidget; /** The WHO clause widget */ private OpenLdapAclWhoClausesBuilderWidget whoClausesBuilderWidget; /** * Creates a new instance of OpenLdapAclVisualEditorComposite. It contains * the WhatClause and WhoClause widgets : * * <pre> * Access to "What" * .----------------------------------------------------------. * | | * ... * | | * `----------------------------------------------------------' * Access to "Who" * .----------------------------------------------------------. * | | * ... * | | * `----------------------------------------------------------' * </pre> * @param parent a widget which will be the parent of the new instance (cannot be null) * @param style the style of widget to construct */ public OpenLdapAclVisualEditorComposite( Composite parent, OpenLdapAclValueWithContext context, int style ) { super( parent, style | SWT.H_SCROLL | SWT.V_SCROLL ); this.context = context; // Creating the composite Composite visualEditorComposite = new Composite( this, SWT.NONE ); visualEditorComposite.setLayout( new GridLayout() ); visualEditorComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); // Creating the WhatClause widget whatClauseWidget = new OpenLdapAclWhatClauseWidget( this, visualEditorComposite, context ); // Creating the WhoClause widget whoClausesBuilderWidget = new OpenLdapAclWhoClausesBuilderWidget( this, context ); whoClausesBuilderWidget.create( visualEditorComposite ); // Configuring the composite setContent( visualEditorComposite ); setExpandHorizontal( true ); setExpandVertical( true ); setMinSize( visualEditorComposite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); } /** * Populate the GUI elements with the Context content. */ public void refresh() { // Setting the input ACL to the widgets whatClauseWidget.refresh(); whoClausesBuilderWidget.refresh(); } /** * Returns the string representation of the ACI item as defined in GUI. * * * @return the string representation of the ACI item * @throws ParseException if the syntax is invalid */ public String getInput() throws ParseException { AclItem aclItem = new AclItem( context.getAclItem().getWhatClause(), context.getAclItem().getWhoClauses() ); return aclItem.toString(); } /** * Saves widget settings. */ public void saveWidgetSettings() { whatClauseWidget.saveWidgetSettings(); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposal.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposal.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; import org.eclipse.jface.fieldassist.ContentProposal; /** * An abstract content proposal for the attributes widget. * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public abstract class AttributesWidgetContentProposal extends ContentProposal { /** The start position */ private int startPosition = 0; /** * Creates a new instance of AttributeWidgetContentProposal. * * @param content the String representing the content. Should not be <code>null</code>. */ public AttributesWidgetContentProposal( String content ) { super( content ); } /** * @return the startPosition */ public int getStartPosition() { return startPosition; } /** * @param startPosition the startPosition to set */ public void setStartPosition( int startPosition ) { this.startPosition = startPosition; } /** * {@inheritDoc} */ public String getContent() { String content = super.getContent(); if ( content != null ) { return content.substring( startPosition ); } return null; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributeTypeContentProposal.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributeTypeContentProposal.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributeTypeContentProposal extends AttributesWidgetContentProposal { public AttributeTypeContentProposal( String content ) { super( content ); } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AclWhoClauseSsfValuesEnum.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AclWhoClauseSsfValuesEnum.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public enum AclWhoClauseSsfValuesEnum { ANY, FORTY, FIFTY_SIX, SIXTY_FOUR, ONE_TWENTY_HEIGHT, ONE_SIXTY_FOUR, TWO_FIFTY_SIX, CUSTOM }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposalProvider.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposalProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; import org.eclipse.jface.fieldassist.ContentProposalAdapter; import org.eclipse.jface.fieldassist.IContentProposal; import org.eclipse.jface.fieldassist.IContentProposalProvider; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class AttributesWidgetContentProposalProvider implements IContentProposalProvider { /** The content proposal adapter */ private ContentProposalAdapter proposalAdapter; /** The browser connection */ private IBrowserConnection browserConnection; /** The proposals */ private List<AttributesWidgetContentProposal> proposals; public AttributesWidgetContentProposalProvider() { // Initializing the proposals list proposals = new ArrayList<AttributesWidgetContentProposal>(); // Building the proposals list buildProposals(); } public IContentProposal[] getProposals( String contents, int position ) { String value = getCurrentValue( contents, position ); List<AttributesWidgetContentProposal> matchingProposals = new ArrayList<AttributesWidgetContentProposal>(); for ( AttributesWidgetContentProposal proposal : proposals ) { if ( proposal.getLabel().toUpperCase().startsWith( value.toUpperCase() ) ) { matchingProposals.add( proposal ); proposal.setStartPosition( value.length() ); } } return matchingProposals.toArray( new AttributesWidgetContentProposal[0] ); } /** * {@inheritDoc} */ public char[] getAutoActivationCharacters() { return new char[0]; } /** * Gets the current value. * * @param contents the contents * @param position the position * @return the current value */ private String getCurrentValue( String contents, int position ) { int start = 0; for ( int i = position - 1; i >= 0; i-- ) { char c = contents.charAt( i ); if ( c == ',' || Character.isWhitespace( c ) ) { start = i + 1; break; } } return contents.substring( start, position ); } /** * Builds the proposals list */ private void buildProposals() { // Reseting previous proposals proposals.clear(); // Adding proposals addKeywordProposals(); addConnectionProposals(); // Sorting the proposals sortProposals(); // Setting auto-activation characters setAutoActivationChars(); } /** * Sets the auto-activation characters */ private void setAutoActivationChars() { if ( proposalAdapter != null ) { Set<Character> characterSet = new HashSet<Character>(); for ( IContentProposal proposal : proposals ) { String string = proposal.getLabel(); for ( int k = 0; k < string.length(); k++ ) { char ch = string.charAt( k ); characterSet.add( Character.toLowerCase( ch ) ); characterSet.add( Character.toUpperCase( ch ) ); } } char[] autoActivationCharacters = new char[characterSet.size() + 1]; autoActivationCharacters[0] = ','; int i = 1; for ( Iterator<Character> it = characterSet.iterator(); it.hasNext(); ) { Character ch = it.next(); autoActivationCharacters[i] = ch.charValue(); i++; } proposalAdapter.setAutoActivationCharacters( autoActivationCharacters ); } } /** * Adding the keyword proposals */ private void addKeywordProposals() { proposals.add( new KeywordContentProposal( "entry" ) ); proposals.add( new KeywordContentProposal( "children" ) ); } /** * Adding the connection proposals (attribute types and object classes). */ private void addConnectionProposals() { if ( browserConnection != null ) { // Attribute types Collection<String> atNames = SchemaUtils.getNames( browserConnection.getSchema().getAttributeTypeDescriptions() ); for ( String atName : atNames ) { proposals.add( new AttributeTypeContentProposal( atName ) ); } // Object classes Collection<String> ocNames = SchemaUtils.getNames( browserConnection.getSchema().getObjectClassDescriptions() ); for ( String ocName : ocNames ) { proposals.add( new ObjectClassContentProposal( "@" + ocName ) ); proposals.add( new ObjectClassContentProposal( "!" + ocName ) ); } } } /** * Sorts the proposals. */ private void sortProposals() { Comparator<? super AttributesWidgetContentProposal> comparator = new Comparator<AttributesWidgetContentProposal>() { public int compare( AttributesWidgetContentProposal o1, AttributesWidgetContentProposal o2 ) { if ( ( o1 instanceof KeywordContentProposal ) && !( o2 instanceof KeywordContentProposal ) ) { return -2; } else if ( !( o1 instanceof KeywordContentProposal ) && ( o2 instanceof KeywordContentProposal ) ) { return 2; } else if ( ( o1 instanceof AttributeTypeContentProposal ) && !( o2 instanceof AttributeTypeContentProposal ) ) { return -3; } else if ( !( o1 instanceof AttributeTypeContentProposal ) && ( o2 instanceof AttributeTypeContentProposal ) ) { return 3; } else if ( ( o1 instanceof ObjectClassContentProposal ) && !( o2 instanceof ObjectClassContentProposal ) ) { return -3; } else if ( !( o1 instanceof ObjectClassContentProposal ) && ( o2 instanceof ObjectClassContentProposal ) ) { return 3; } return o1.getLabel().compareToIgnoreCase( o2.getLabel() ); } }; Collections.sort( proposals, comparator ); } /** * @param browserConnection the browser connection to set */ public void setBrowserConnection( IBrowserConnection browserConnection ) { this.browserConnection = browserConnection; // Re-building proposals buildProposals(); } /** * @param proposalAdapter the proposalAdapter to set */ public void setProposalAdapter( ContentProposalAdapter proposalAdapter ) { this.proposalAdapter = proposalAdapter; } }
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
false
apache/directory-studio
https://github.com/apache/directory-studio/blob/e55b93d729a60c986fc93e52f9519f4bbdf51252/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhoClauseWidget.java
plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhoClauseWidget.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ package org.apache.directory.studio.openldap.config.acl.widgets; import java.text.MessageFormat; import org.apache.directory.studio.common.ui.widgets.AbstractWidget; import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPlugin; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPluginConstants; import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; import org.apache.directory.studio.openldap.config.acl.dialogs.OpenLdapAccessLevelDialog; import org.apache.directory.studio.openldap.config.acl.model.AclAccessLevel; import org.apache.directory.studio.openldap.config.acl.model.AclAccessLevelLevelEnum; import org.apache.directory.studio.openldap.config.acl.model.AclControlEnum; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClause; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseAnonymous; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseDn; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseDnAttr; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseEnum; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseGroup; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseSaslSsf; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseSelf; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseSsf; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseStar; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseTlsSsf; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseTransportSsf; import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseUsers; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhoClauseDnAttributeComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhoClauseDnComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhoClauseGroupComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhoClauseSaslSsfComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhoClauseSsfComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhoClauseTlsSsfComposite; import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhoClauseTransportSsfComposite; /** * * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> */ public class OpenLdapAclWhoClauseWidget extends AbstractWidget implements SelectionListener { /** The ACL context */ private OpenLdapAclValueWithContext context; /** The array of clauses */ private Object[] clauses = new Object[] { new ClauseComboViewerName(), AclWhoClauseEnum.STAR, AclWhoClauseEnum.ANONYMOUS, AclWhoClauseEnum.USERS, AclWhoClauseEnum.SELF, AclWhoClauseEnum.DN, AclWhoClauseEnum.DNATTR, AclWhoClauseEnum.GROUP, AclWhoClauseEnum.SASL_SSF, AclWhoClauseEnum.SSF, AclWhoClauseEnum.TLS_SSF, AclWhoClauseEnum.TRANSPORT_SSF }; /** The array of access levels */ private Object[] accessLevels = new Object[] { new AccessLevelComboViewerName(), AclAccessLevelLevelEnum.MANAGE, AclAccessLevelLevelEnum.WRITE, AclAccessLevelLevelEnum.READ, AclAccessLevelLevelEnum.SEARCH, AclAccessLevelLevelEnum.COMPARE, AclAccessLevelLevelEnum.AUTH, AclAccessLevelLevelEnum.DISCLOSE, AclAccessLevelLevelEnum.NONE, new AccessLevelComboViewerCustom() }; /** The array of controls */ private Object[] controls = new Object[] { new ControlComboViewerName(), AclControlEnum.STOP, AclControlEnum.CONTINUE, AclControlEnum.BREAK }; /** The parent builder widget */ private OpenLdapAclWhoClausesBuilderWidget builderWidget; /** The row index */ private int index; /** The clause */ private AclWhoClause clause; /** The current clause selection */ private Object currentClauseSelection = clauses[0]; /** The current access level selection */ private Object currentAccessLevelSelection = accessLevels[0]; /** The current control selection */ private Object currentControlSelection = controls[0]; /** The current custom access level */ private AclAccessLevel currentCustomAccessLevel; // UI Widgets private Composite composite; private Composite configurationComposite; private ComboViewer clauseComboViewer; private ComboViewer accessLevelComboViewer; private ComboViewer controlComboViewer; private ToolBar toolbar; private ToolItem addButton; private ToolItem deleteButton; private ToolItem moveUpButton; private ToolItem moveDownButton; // Listeners /** The listener for the clause combo viewer */ private ISelectionChangedListener clauseComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { // Getting the selected clause Object selection = ( ( StructuredSelection ) clauseComboViewer .getSelection() ).getFirstElement(); // Only changing the UI when the selection is different if ( currentClauseSelection != selection ) { // Storing the current selection currentClauseSelection = selection; // Disposing the current composite if ( ( configurationComposite != null ) && ( !configurationComposite.isDisposed() ) ) { configurationComposite.dispose(); configurationComposite = null; } // Setting the clause from the current selection setClause(); // Creating the configuration UI createConfigurationUI(); // Notifying listeners notifyListeners(); } } }; /** The listener for the access level combo viewer */ private ISelectionChangedListener accessLevelComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { // Getting the selected access level Object selection = ( ( StructuredSelection ) accessLevelComboViewer .getSelection() ).getFirstElement(); // Special case for the 'custom' item if ( accessLevels[accessLevels.length - 1].equals( selection ) ) { // Getting the current access level AclAccessLevel accessLevel = null; if ( clause != null ) { accessLevel = clause.getAccessLevel(); } // Opening a dialog to edit the access level OpenLdapAccessLevelDialog accessLevelDialog = new OpenLdapAccessLevelDialog( accessLevel ); if ( accessLevelDialog.open() == OpenLdapAccessLevelDialog.OK ) { // Getting the access level from the dialog currentCustomAccessLevel = accessLevelDialog.getAccessLevel(); } else { // The dialog has been canceled // Only changing the UI when the selection is different if ( currentAccessLevelSelection != selection ) { accessLevelComboViewer.removeSelectionChangedListener( accessLevelComboViewerListener ); accessLevelComboViewer .setSelection( new StructuredSelection( currentAccessLevelSelection ) ); accessLevelComboViewer.addSelectionChangedListener( accessLevelComboViewerListener ); } // We exit here return; } } // Only changing the UI when the selection is different or we have a custom access level value to store if ( ( currentAccessLevelSelection != selection ) || ( currentCustomAccessLevel != null ) ) { // Storing the current selection currentAccessLevelSelection = selection; // Setting the access level from the current selection setAccessLevel(); // Is it a simple access level? AclAccessLevel accessLevel = clause.getAccessLevel(); if ( isSimple( accessLevel ) ) { currentAccessLevelSelection = accessLevel.getLevel(); } // Is it a custom access level? else if ( isCustom( accessLevel ) ) { currentAccessLevelSelection = accessLevels[accessLevels.length - 1]; } // Bogus case else { currentAccessLevelSelection = accessLevels[0]; } // Setting the correct selection and refreshing the combo viewer to update the labels accessLevelComboViewer.removeSelectionChangedListener( accessLevelComboViewerListener ); accessLevelComboViewer .setSelection( new StructuredSelection( currentAccessLevelSelection ) ); accessLevelComboViewer.addSelectionChangedListener( accessLevelComboViewerListener ); accessLevelComboViewer.refresh(); // Notifying listeners notifyListeners(); } } }; /** The listener for the control combo viewer */ private ISelectionChangedListener controlComboViewerListener = new ISelectionChangedListener() { public void selectionChanged( SelectionChangedEvent event ) { // Getting the selected control Object selection = ( ( StructuredSelection ) controlComboViewer .getSelection() ).getFirstElement(); // Only changing the UI when the selection is different if ( currentControlSelection != selection ) { // Storing the current selection currentControlSelection = selection; // Setting the control from the current selection setControl(); // Notifying listeners notifyListeners(); } } }; /** * Creates a new instance of OpenLdapAclWhoClauseWidget. * * @param builderWidget the parent builder widget * @param index the row index */ public OpenLdapAclWhoClauseWidget( OpenLdapAclWhoClausesBuilderWidget builderWidget, OpenLdapAclValueWithContext context, AclWhoClause clause, int index ) { this.builderWidget = builderWidget; this.clause = clause; this.index = index; this.context = context; } public void create( Composite parent ) { // Creating the widget base composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); // Creating the top composites Composite topComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); Composite topSubComposite = BaseWidgetUtils.createColumnContainer( topComposite, 3, true, 1 ); // Creating the clause, access level and control combo viewers createClauseComboViewer( topSubComposite ); createAccessLevelComboViewer( topSubComposite ); createControlComboViewer( topSubComposite ); // Creating the toolbar and buttons createToolbarAndButtons( topComposite ); // Initializing the UI with the clause initWithClause(); // Adding the listeners to the UI widgets addListeners(); } /** * Initializes the UI with the clause */ private void initWithClause() { if ( clause != null ) { // Clause currentClauseSelection = AclWhoClauseEnum.get( clause ); // Access Level AclAccessLevel accessLevel = clause.getAccessLevel(); if ( accessLevel == null ) { currentAccessLevelSelection = accessLevels[0]; } else { // Is it a simple access level? if ( isSimple( accessLevel ) ) { currentAccessLevelSelection = accessLevel.getLevel(); } // Is it a custom access level? else if ( isCustom( accessLevel ) ) { currentAccessLevelSelection = accessLevels[accessLevels.length - 1]; } // Bogus case else { currentAccessLevelSelection = accessLevels[0]; } } // Control AclControlEnum control = clause.getControl(); if ( control == null ) { currentControlSelection = controls[0]; } else { currentControlSelection = control; } } else { // Defaulting to the first row of the arrays currentClauseSelection = clauses[0]; currentAccessLevelSelection = accessLevels[0]; currentControlSelection = controls[0]; } // Setting the selection for the combo viewers clauseComboViewer.setSelection( new StructuredSelection( currentClauseSelection ) ); accessLevelComboViewer.setSelection( new StructuredSelection( currentAccessLevelSelection ) ); controlComboViewer.setSelection( new StructuredSelection( currentControlSelection ) ); } /** * Indicates if the given access level is simple or not. * * @param accessLevel the access level * @return <code>true</code> if the access level is simple, * <code>false</code> if not */ private boolean isSimple( AclAccessLevel accessLevel ) { if ( accessLevel != null ) { return ( !accessLevel.isSelf() ) && ( accessLevel.getLevel() != null ); } return false; } /** * Indicates if the given access level is complex or not. * * @param accessLevel the access level * @return <code>true</code> if the access complex is simple, * <code>false</code> if not */ private boolean isCustom( AclAccessLevel accessLevel ) { if ( accessLevel != null ) { return ( accessLevel.isSelf() ) || ( ( accessLevel.getPrivilegeModifier() != null ) && ( accessLevel.getPrivileges().size() > 0 ) ); } return false; } /** * Creates the clause combo viewer. * * @param parent the parent composite */ private void createClauseComboViewer( Composite parent ) { clauseComboViewer = new ComboViewer( BaseWidgetUtils.createReadonlyCombo( parent, new String[0], -1, 1 ) ); clauseComboViewer.setContentProvider( new ArrayContentProvider() ); clauseComboViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof ClauseComboViewerName ) { return "< Clause >"; } else if ( element instanceof AclWhoClauseEnum ) { AclWhoClauseEnum value = ( AclWhoClauseEnum ) element; switch ( value ) { case STAR: return "Anyone (*)"; case ANONYMOUS: return "Anonymous"; case USERS: return "Users"; case SELF: return "Self"; case DN: return "DN"; case DNATTR: return "DN in attribute"; case GROUP: return "Group"; case SASL_SSF: return "SASL SSF"; case SSF: return "SSF"; case TLS_SSF: return "TLS SSF"; case TRANSPORT_SSF: return "Transport SSF"; } } return super.getText( element ); } } ); clauseComboViewer.setInput( clauses ); clauseComboViewer.setSelection( new StructuredSelection( currentClauseSelection ) ); } /** * Creating the access level combo viewer. * * @param parent the parent composite */ private void createAccessLevelComboViewer( Composite parent ) { accessLevelComboViewer = new ComboViewer( BaseWidgetUtils.createReadonlyCombo( parent, new String[0], -1, 1 ) ); accessLevelComboViewer.setContentProvider( new ArrayContentProvider() ); accessLevelComboViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof AccessLevelComboViewerName ) { return "< Access Level >"; } else if ( element instanceof AccessLevelComboViewerCustom ) { if ( ( clause != null ) && ( isCustom( clause.getAccessLevel() ) ) ) { return MessageFormat.format( "Custom... [{0}]", clause.getAccessLevel() ); } return "Custom..."; } else if ( element instanceof AclAccessLevelLevelEnum ) { AclAccessLevelLevelEnum value = ( AclAccessLevelLevelEnum ) element; switch ( value ) { case MANAGE: return "Manage"; case WRITE: return "Write"; case READ: return "Read"; case SEARCH: return "Search"; case COMPARE: return "Compare"; case AUTH: return "Auth"; case DISCLOSE: return "Disclose"; case NONE: return "None"; } } return super.getText( element ); } } ); accessLevelComboViewer.setInput( accessLevels ); accessLevelComboViewer.setSelection( new StructuredSelection( currentAccessLevelSelection ) ); } /** * Creates the control combo viewer. * * @param parent the parent composite */ private void createControlComboViewer( Composite parent ) { controlComboViewer = new ComboViewer( BaseWidgetUtils.createReadonlyCombo( parent, new String[0], -1, 1 ) ); controlComboViewer.setContentProvider( new ArrayContentProvider() ); controlComboViewer.setLabelProvider( new LabelProvider() { public String getText( Object element ) { if ( element instanceof ControlComboViewerName ) { return "< Control >"; } else if ( element instanceof AclControlEnum ) { AclControlEnum value = ( AclControlEnum ) element; switch ( value ) { case STOP: return "Stop"; case CONTINUE: return "Continue"; case BREAK: return "Break"; } } return super.getText( element ); } } ); controlComboViewer.setInput( controls ); controlComboViewer.setSelection( new StructuredSelection( currentControlSelection ) ); } /** * Creates the toolbar and buttons. * * @param parent the parent composite */ private void createToolbarAndButtons( Composite parent ) { // Creating the toolbar toolbar = new ToolBar( parent, SWT.HORIZONTAL ); // Creating the 'Add' button addButton = new ToolItem( toolbar, SWT.PUSH ); addButton.setToolTipText( "Add" ); addButton.setImage( OpenLdapAclEditorPlugin.getDefault().getImage( OpenLdapAclEditorPluginConstants.IMG_ADD ) ); // Creating the 'Delete' button deleteButton = new ToolItem( toolbar, SWT.PUSH ); deleteButton.setToolTipText( "Delete" ); deleteButton.setImage( OpenLdapAclEditorPlugin.getDefault().getImage( OpenLdapAclEditorPluginConstants.IMG_DELETE ) ); // Creating the 'Move Up' button moveUpButton = new ToolItem( toolbar, SWT.PUSH ); moveUpButton.setToolTipText( "Move Up" ); moveUpButton.setImage( OpenLdapAclEditorPlugin.getDefault().getImage( OpenLdapAclEditorPluginConstants.IMG_UP ) ); // Creating the 'Move Down' button moveDownButton = new ToolItem( toolbar, SWT.PUSH ); moveDownButton.setToolTipText( "Move Down" ); moveDownButton.setImage( OpenLdapAclEditorPlugin.getDefault().getImage( OpenLdapAclEditorPluginConstants.IMG_DOWN ) ); } /** * Adds the listeners to the UI widgets. */ private void addListeners() { // Adding the selection listener for the clause combo viewer clauseComboViewer.addSelectionChangedListener( clauseComboViewerListener ); // Adding the selection listener for the access level combo viewer accessLevelComboViewer.addSelectionChangedListener( accessLevelComboViewerListener ); // Adding the selection listener for the control combo viewer controlComboViewer.addSelectionChangedListener( controlComboViewerListener ); // Adding toolbar buttons listeners addButton.addSelectionListener( this ); deleteButton.addSelectionListener( this ); moveUpButton.addSelectionListener( this ); moveDownButton.addSelectionListener( this ); } /** * Create the configuration UI. */ private void createConfigurationUI() { if ( currentClauseSelection instanceof AclWhoClauseEnum ) { AclWhoClauseEnum currentClauseSelectionValue = ( AclWhoClauseEnum ) currentClauseSelection; switch ( currentClauseSelectionValue ) { case STAR: break; // Nothing to configure case ANONYMOUS: break; // Nothing to configure case USERS: break; // Nothing to configure case SELF: break; // Nothing to configure case DN: createUIWhoClauseDn(); break; case DNATTR: createUIWhoClauseDnAttr(); break; case GROUP: createUIWhoClauseGroup(); break; case SASL_SSF: createCompositeWhoClauseSaslSsf(); break; case SSF: createCompositeWhoClauseSsf(); break; case TLS_SSF: createCompositeWhoClauseTlsSsf(); break; case TRANSPORT_SSF: createCompositeWhoClauseTransportSsf(); break; } } } /** * Creates the UI for the DN who clause. */ private void createUIWhoClauseDn() { configurationComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); WhoClauseDnComposite composite = new WhoClauseDnComposite( context, builderWidget.visualEditorComposite ); composite.createComposite( configurationComposite ); } /** * Creates the UI for the DN Attribute who clause. */ private void createUIWhoClauseDnAttr() { configurationComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); WhoClauseDnAttributeComposite composite = new WhoClauseDnAttributeComposite( context, builderWidget.visualEditorComposite ); composite.createComposite( configurationComposite ); } /** * Creates the UI for the Group who clause. */ private void createUIWhoClauseGroup() { configurationComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); WhoClauseGroupComposite composite = new WhoClauseGroupComposite( context, builderWidget.visualEditorComposite ); composite.createComposite( configurationComposite ); } /** * Creates the UI for the SASL SSF who clause. */ private void createCompositeWhoClauseSaslSsf() { configurationComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); WhoClauseSaslSsfComposite composite = new WhoClauseSaslSsfComposite( context, builderWidget.visualEditorComposite ); composite.createComposite( configurationComposite ); } /** * Creates the UI for the SSF who clause. */ private void createCompositeWhoClauseSsf() { configurationComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); WhoClauseSsfComposite composite = new WhoClauseSsfComposite( context, builderWidget.visualEditorComposite ); composite.createComposite( configurationComposite ); } /** * Creates the UI for the TLS SSF who clause. */ private void createCompositeWhoClauseTlsSsf() { configurationComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); WhoClauseTlsSsfComposite composite = new WhoClauseTlsSsfComposite( context, builderWidget.visualEditorComposite ); composite.createComposite( configurationComposite ); } /** * Creates the UI for the Transport SSF who clause. */ private void createCompositeWhoClauseTransportSsf() { configurationComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); WhoClauseTransportSsfComposite composite = new WhoClauseTransportSsfComposite( context, builderWidget.visualEditorComposite ); composite.createComposite( configurationComposite ); } /** * Creates a basic access level. * * @param level the level * @return a basic access level */ private AclAccessLevel createBasicAccessLevel( AclAccessLevelLevelEnum level ) { AclAccessLevel accessLevel = new AclAccessLevel(); accessLevel.setLevel( level ); return accessLevel; } /** * Sets the clause from the current selection. */ private void setClause() { if ( currentClauseSelection instanceof AclWhoClauseEnum ) { AclWhoClauseEnum clauseSelection = ( AclWhoClauseEnum ) currentClauseSelection; // Creating the clause associated with the selection switch ( clauseSelection ) { case STAR: clause = new AclWhoClauseStar(); break; case ANONYMOUS: clause = new AclWhoClauseAnonymous(); break; case USERS: clause = new AclWhoClauseUsers(); break; case SELF: clause = new AclWhoClauseSelf(); break; case DN: clause = new AclWhoClauseDn(); break; case DNATTR: clause = new AclWhoClauseDnAttr(); break; case GROUP: clause = new AclWhoClauseGroup(); break; case SASL_SSF: clause = new AclWhoClauseSaslSsf(); break; case SSF: clause = new AclWhoClauseSsf(); break; case TLS_SSF: clause = new AclWhoClauseTlsSsf(); break; case TRANSPORT_SSF: clause = new AclWhoClauseTransportSsf(); break; } // Also setting access level and control setAccessLevel(); setControl(); } else { clause = null; } } /** * Sets the access level from the current selection. */ private void setAccessLevel() { if ( currentAccessLevelSelection instanceof AclAccessLevelLevelEnum ) { AclAccessLevelLevelEnum accessLevelSelection = ( AclAccessLevelLevelEnum ) currentAccessLevelSelection; // Creating the access level associated with the selection switch ( accessLevelSelection ) { case MANAGE: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.MANAGE ) ); break; case WRITE: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.WRITE ) ); break; case READ: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.READ ) ); break; case SEARCH: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.SEARCH ) ); break; case COMPARE: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.COMPARE ) ); break; case AUTH: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.AUTH ) ); break; case DISCLOSE: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.DISCLOSE ) ); break; case NONE: setAccessLevel( createBasicAccessLevel( AclAccessLevelLevelEnum.NONE ) );
java
Apache-2.0
e55b93d729a60c986fc93e52f9519f4bbdf51252
2026-01-05T02:32:00.866394Z
true