You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/06/05 10:59:31 UTC
svn commit: r1683681 - in /directory/studio/trunk/plugins:
openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/
openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/
openldap.confi...
Author: elecharny
Date: Fri Jun 5 08:59:31 2015
New Revision: 1683681
URL: http://svn.apache.org/r1683681
Log:
Added the Ssf wrapper, enum and test
Added:
directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/SsfEnum.java
directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SsfWrapper.java
directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SsfWrapperTest.java
Added: directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/SsfEnum.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/SsfEnum.java?rev=1683681&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/SsfEnum.java (added)
+++ directory/studio/trunk/plugins/openldap.common.ui/src/main/java/org/apache/directory/studio/openldap/common/ui/SsfEnum.java Fri Jun 5 08:59:31 2015
@@ -0,0 +1,120 @@
+/*
+ * 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.common.ui;
+
+import org.apache.directory.api.util.Strings;
+
+/**
+ * An enumeratuon of all the possible SSF freatures.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum SsfEnum
+{
+ SSF( "ssf" ),
+ TRANSPORT( "transport" ),
+ TLS( "tls" ),
+ SASL( "sasl" ),
+ UPDATE_SSF( "update_ssf" ),
+ UPDATE_TRANSPORT( "update_transport" ),
+ UPDATE_TLS( "update_tls" ),
+ UPDATE_SASL( "update_sasl" ),
+ SIMPLE_BIND( "simple_bind" ),
+ NONE( "" );
+
+ /** The associated Text */
+ private String text;
+
+ /**
+ * Creates an SsfEnum instance
+ */
+ private SsfEnum( String text )
+ {
+ this.text = text;
+ }
+
+ /**
+ * @return the text
+ */
+ public String getText()
+ {
+ return text;
+ }
+
+
+ /**
+ * Retrieve the instance associated to a String. Return NONE if not found.
+ *
+ * @param feature The feature to retrieve
+ * @return The SsfEnum instance found, or NONE.
+ */
+ public static SsfEnum getSsf( String feature )
+ {
+ String ssfText = Strings.toLowerCase( feature );
+
+ if ( SSF.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( TRANSPORT.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( TLS.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( SASL.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( SIMPLE_BIND.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( UPDATE_SASL.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( UPDATE_SSF.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( UPDATE_TLS.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ if ( UPDATE_TRANSPORT.text.equals( ssfText ) )
+ {
+ return SSF;
+ }
+
+ // Default...
+ return NONE;
+ }
+}
Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SsfWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SsfWrapper.java?rev=1683681&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SsfWrapper.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SsfWrapper.java Fri Jun 5 08:59:31 2015
@@ -0,0 +1,195 @@
+/*
+ * 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.editor.wrappers;
+
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.studio.openldap.common.ui.SsfEnum;
+
+/**
+ * This class wraps the olcSecurity parameter :
+ * <pre>
+ * olcSecurity ::= (<feature>=<size>)*
+ * <feature> ::= 'ssf' | 'transport' | 'tls' | 'sasl' | 'simple_bind' |
+ * 'updates_ssf' | 'updates_transport' | 'updates_rls' | 'updates_sasl'
+ * </pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SsfWrapper
+{
+ /** The feature */
+ private SsfEnum feature;
+
+ /** The number of bits for this feature */
+ private int nbBits;
+
+ /**
+ * Creates an instance using a name of a feature and its size
+ *
+ * @param feature The feature to use
+ * @param nbBits The number of bits
+ */
+ public SsfWrapper( String feature, int nbBits )
+ {
+ this.feature = SsfEnum.getSsf( feature );
+
+ if ( this.feature == SsfEnum.NONE )
+ {
+ this.nbBits = 0;
+ }
+ else
+ {
+ this.nbBits = nbBits;
+ }
+
+ if ( nbBits < 0 )
+ {
+ this.nbBits = 0;
+ }
+
+ }
+
+
+ /**
+ * Creates an instance using a String representation, which format is
+ * feature = <nbBits>
+ *
+ * @param feature The feature to use
+ */
+ public SsfWrapper( String feature )
+ {
+ if ( Strings.isEmpty( feature ) )
+ {
+ this.feature = SsfEnum.NONE;
+ this.nbBits = 0;
+ }
+ else
+ {
+ int pos = feature.indexOf( '=' );
+
+ if ( pos < 0 )
+ {
+ this.feature = SsfEnum.NONE;
+ this.nbBits = 0;
+ }
+
+ String name = Strings.trim( feature.substring( 0, pos ) );
+ this.feature = SsfEnum.getSsf( name );
+
+ if ( this.feature == SsfEnum.NONE )
+ {
+ this.nbBits = 0;
+ }
+ else
+ {
+ String value = Strings.trim( feature.substring( pos + 1 ) );
+
+ try
+ {
+ this.nbBits = Integer.parseInt( value );
+ }
+ catch ( NumberFormatException nfe )
+ {
+ this.nbBits = 0;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Tells if the String is a valid SSF. The format is :
+ * feature = <nbBits>
+ *
+ * @param feature The feature to check
+ * @return true if valid
+ */
+ public static boolean isValid(String feature )
+ {
+ if ( Strings.isEmpty( feature ) )
+ {
+ return false;
+ }
+ else
+ {
+ int pos = feature.indexOf( '=' );
+
+ if ( pos < 0 )
+ {
+ return false;
+ }
+
+ String name = Strings.trim( feature.substring( 0, pos ) );
+ SsfEnum ssf = SsfEnum.getSsf( name );
+
+ if ( ssf == SsfEnum.NONE )
+ {
+ return false;
+ }
+ else
+ {
+ String value = Strings.trim( feature.substring( pos + 1 ) );
+
+ try
+ {
+ return Integer.parseInt( value ) >= 0 ;
+ }
+ catch ( NumberFormatException nfe )
+ {
+ return false;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * @return the feature
+ */
+ public SsfEnum getFeature()
+ {
+ return feature;
+ }
+
+
+ /**
+ * @return the nbBits
+ */
+ public int getNbBits()
+ {
+ return nbBits;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ if ( feature != SsfEnum.NONE )
+ {
+ return feature.getText() + '=' + nbBits;
+ }
+ else
+ {
+ return "";
+ }
+ }
+}
Added: directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SsfWrapperTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SsfWrapperTest.java?rev=1683681&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SsfWrapperTest.java (added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SsfWrapperTest.java Fri Jun 5 08:59:31 2015
@@ -0,0 +1,85 @@
+/*
+ * 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.wrappers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.directory.studio.openldap.common.ui.SsfEnum;
+import org.apache.directory.studio.openldap.config.editor.wrappers.SsfWrapper;
+import org.junit.Test;
+
+/**
+ * A test for the SsfWrapper class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SsfWrapperTest
+{
+ @Test
+ public void testToString()
+ {
+ SsfWrapper ssfWrapper = new SsfWrapper( "ssf", 128 );
+
+ assertEquals( "ssf=128", ssfWrapper.toString() );
+
+ ssfWrapper = new SsfWrapper( "SSF", 128 );
+
+ assertEquals( "ssf=128", ssfWrapper.toString() );
+
+ ssfWrapper = new SsfWrapper( "ABC", 128 );
+
+ assertEquals( "", ssfWrapper.toString() );
+ }
+
+
+ @Test
+ public void testIsValid()
+ {
+ assertFalse( SsfWrapper.isValid( null ) );
+ assertFalse( SsfWrapper.isValid( "" ) );
+ assertFalse( SsfWrapper.isValid( " " ) );
+
+ assertTrue( SsfWrapper.isValid( "ssf=0" ) );
+ assertTrue( SsfWrapper.isValid( "ssf=256" ) );
+ assertTrue( SsfWrapper.isValid( "update_transport=64" ) );
+ assertTrue( SsfWrapper.isValid( " SSF = 128" ) );
+ assertFalse( SsfWrapper.isValid( " ssf = 5 = 7 " ) );
+ assertFalse( SsfWrapper.isValid( "ssf=-2 " ) );
+ }
+
+
+ @Test
+ public void testCreateSsf()
+ {
+ SsfWrapper ssfWrapper = new SsfWrapper( "ssf", 128 );
+ assertEquals( SsfEnum.SSF, ssfWrapper.getFeature() );
+ assertEquals( 128, ssfWrapper.getNbBits() );
+
+ ssfWrapper = new SsfWrapper( "ssf", -128 );
+ assertEquals( SsfEnum.SSF, ssfWrapper.getFeature() );
+ assertEquals( 0, ssfWrapper.getNbBits() );
+
+ ssfWrapper = new SsfWrapper( "SSF", 128 );
+ assertEquals( SsfEnum.SSF, ssfWrapper.getFeature() );
+ assertEquals( 128, ssfWrapper.getNbBits() );
+ }
+}