diff --git a/pom.xml b/pom.xml index 9803374..16c174c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,14 +1,14 @@ - + 4.0.0 org.codehaus.plexus plexus - 10 + 13 - + plexus-sec-dispatcher 2.0.1-SNAPSHOT @@ -17,8 +17,8 @@ scm:git:git@github.com:codehaus-plexus/plexus-sec-dispatcher.git scm:git:git@github.com:codehaus-plexus/plexus-sec-dispatcher.git - https://github.com/codehaus-plexus/plexus-sec-dispatcher.git HEAD + https://github.com/codehaus-plexus/plexus-sec-dispatcher.git jira diff --git a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/DefaultSecDispatcher.java b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/DefaultSecDispatcher.java index 6ff6387..2421787 100644 --- a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/DefaultSecDispatcher.java +++ b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/DefaultSecDispatcher.java @@ -10,9 +10,12 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ - + package org.sonatype.plexus.components.sec.dispatcher; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -20,10 +23,6 @@ import java.util.Map; import java.util.StringTokenizer; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - import org.sonatype.plexus.components.cipher.DefaultPlexusCipher; import org.sonatype.plexus.components.cipher.PlexusCipher; import org.sonatype.plexus.components.cipher.PlexusCipherException; @@ -34,18 +33,16 @@ */ @Singleton @Named -public class DefaultSecDispatcher - implements SecDispatcher -{ +public class DefaultSecDispatcher implements SecDispatcher { private static final String DEFAULT_CONFIGURATION = "~/.settings-security.xml"; public static final String SYSTEM_PROPERTY_SEC_LOCATION = "settings.security"; - + public static final String TYPE_ATTR = "type"; public static final char ATTR_START = '['; - public static final char ATTR_STOP = ']'; + public static final char ATTR_STOP = ']'; /** * DefaultHandler @@ -63,11 +60,10 @@ public class DefaultSecDispatcher protected String _configurationFile; @Inject - public DefaultSecDispatcher( final PlexusCipher _cipher, - final Map _decryptors, - @Named( "${_configurationFile:-" + DEFAULT_CONFIGURATION + "}" ) - final String _configurationFile ) - { + public DefaultSecDispatcher( + final PlexusCipher _cipher, + final Map _decryptors, + @Named("${_configurationFile:-" + DEFAULT_CONFIGURATION + "}") final String _configurationFile) { this._cipher = _cipher; this._decryptors = _decryptors; this._configurationFile = _configurationFile; @@ -76,271 +72,219 @@ public DefaultSecDispatcher( final PlexusCipher _cipher, /** * Ctor to be used in tests and other simplified cases (no decryptors and config). */ - public DefaultSecDispatcher( final PlexusCipher _cipher ) { - this( _cipher, new HashMap<>(), DEFAULT_CONFIGURATION ); + public DefaultSecDispatcher(final PlexusCipher _cipher) { + this(_cipher, new HashMap<>(), DEFAULT_CONFIGURATION); } // --------------------------------------------------------------- @Override - public String decrypt( String str ) - throws SecDispatcherException - { - if( ! isEncryptedString( str ) ) - return str; - + public String decrypt(String str) throws SecDispatcherException { + if (!isEncryptedString(str)) return str; + String bare; - - try - { - bare = _cipher.unDecorate( str ); - } - catch ( PlexusCipherException e1 ) - { - throw new SecDispatcherException( e1 ); + + try { + bare = _cipher.unDecorate(str); + } catch (PlexusCipherException e1) { + throw new SecDispatcherException(e1); } - - try - { - Map attr = stripAttributes( bare ); - + + try { + Map attr = stripAttributes(bare); + String res; SettingsSecurity sec = getSec(); - - if( attr == null || attr.get( "type" ) == null ) - { - String master = getMaster( sec ); - - res = _cipher.decrypt( bare, master ); - } - else - { - String type = attr.get( TYPE_ATTR ); - - if( _decryptors == null ) - throw new SecDispatcherException( "plexus container did not supply any required dispatchers - cannot lookup "+type ); - - Map conf = SecUtil.getConfig( sec, type ); - - PasswordDecryptor dispatcher = _decryptors.get( type ); - - if( dispatcher == null ) - throw new SecDispatcherException( "no dispatcher for hint "+type ); - - String pass = attr == null ? bare : strip( bare ); - - return dispatcher.decrypt( pass, attr, conf ); + + if (attr == null || attr.get("type") == null) { + String master = getMaster(sec); + + res = _cipher.decrypt(bare, master); + } else { + String type = attr.get(TYPE_ATTR); + + if (_decryptors == null) + throw new SecDispatcherException( + "plexus container did not supply any required dispatchers - cannot lookup " + type); + + Map conf = SecUtil.getConfig(sec, type); + + PasswordDecryptor dispatcher = _decryptors.get(type); + + if (dispatcher == null) throw new SecDispatcherException("no dispatcher for hint " + type); + + String pass = attr == null ? bare : strip(bare); + + return dispatcher.decrypt(pass, attr, conf); } - + return res; - } - catch ( Exception e ) - { + } catch (Exception e) { throw new SecDispatcherException(e); } } - - private String strip( String str ) - { - int pos = str.indexOf( ATTR_STOP ); - - if( pos == str.length() ) - return null; - - if( pos != -1 ) - return str.substring( pos+1 ); - + + private String strip(String str) { + int pos = str.indexOf(ATTR_STOP); + + if (pos == str.length()) return null; + + if (pos != -1) return str.substring(pos + 1); + return str; } - - private Map stripAttributes( String str ) - { - int start = str.indexOf( ATTR_START ); - int stop = str.indexOf( ATTR_STOP ); - if ( start != -1 && stop != -1 && stop > start ) - { - if( stop == start+1 ) - return null; - - String attrs = str.substring( start+1, stop ).trim(); - - if( attrs.length() < 1 ) - return null; - + + private Map stripAttributes(String str) { + int start = str.indexOf(ATTR_START); + int stop = str.indexOf(ATTR_STOP); + if (start != -1 && stop != -1 && stop > start) { + if (stop == start + 1) return null; + + String attrs = str.substring(start + 1, stop).trim(); + + if (attrs.length() < 1) return null; + Map res = null; - - StringTokenizer st = new StringTokenizer( attrs, ", " ); - - while( st.hasMoreTokens() ) - { - if( res == null ) - res = new HashMap<>( st.countTokens() ); - + + StringTokenizer st = new StringTokenizer(attrs, ", "); + + while (st.hasMoreTokens()) { + if (res == null) res = new HashMap<>(st.countTokens()); + String pair = st.nextToken(); - - int pos = pair.indexOf( '=' ); - - if( pos == -1 ) - continue; - - String key = pair.substring( 0, pos ).trim(); - if( pos == pair.length() ) - { - res.put( key, null ); + int pos = pair.indexOf('='); + + if (pos == -1) continue; + + String key = pair.substring(0, pos).trim(); + + if (pos == pair.length()) { + res.put(key, null); continue; } - - String val = pair.substring( pos+1 ); - - res.put( key, val.trim() ); + + String val = pair.substring(pos + 1); + + res.put(key, val.trim()); } - + return res; } - + return null; } - //---------------------------------------------------------------------------- + // ---------------------------------------------------------------------------- - private boolean isEncryptedString( String str ) - { - if( str == null ) - return false; + private boolean isEncryptedString(String str) { + if (str == null) return false; - return _cipher.isEncryptedString( str ); + return _cipher.isEncryptedString(str); } - //---------------------------------------------------------------------------- - - private SettingsSecurity getSec() - throws SecDispatcherException - { - String location = System.getProperty( SYSTEM_PROPERTY_SEC_LOCATION - , getConfigurationFile() - ); - String realLocation = location.charAt( 0 ) == '~' - ? System.getProperty( "user.home" ) + location.substring( 1 ) - : location - ; - - SettingsSecurity sec = SecUtil.read( realLocation, true ); - - if( sec == null ) - throw new SecDispatcherException( "cannot retrieve master password. Please check that "+realLocation+" exists and has data" ); - + // ---------------------------------------------------------------------------- + + private SettingsSecurity getSec() throws SecDispatcherException { + String location = System.getProperty(SYSTEM_PROPERTY_SEC_LOCATION, getConfigurationFile()); + String realLocation = + location.charAt(0) == '~' ? System.getProperty("user.home") + location.substring(1) : location; + + SettingsSecurity sec = SecUtil.read(realLocation, true); + + if (sec == null) + throw new SecDispatcherException( + "cannot retrieve master password. Please check that " + realLocation + " exists and has data"); + return sec; } - //---------------------------------------------------------------------------- + // ---------------------------------------------------------------------------- - private String getMaster( SettingsSecurity sec ) - throws SecDispatcherException - { + private String getMaster(SettingsSecurity sec) throws SecDispatcherException { String master = sec.getMaster(); - - if( master == null ) - throw new SecDispatcherException( "master password is not set" ); - - try - { - return _cipher.decryptDecorated( master, SYSTEM_PROPERTY_SEC_LOCATION ); - } - catch ( PlexusCipherException e ) - { + + if (master == null) throw new SecDispatcherException("master password is not set"); + + try { + return _cipher.decryptDecorated(master, SYSTEM_PROPERTY_SEC_LOCATION); + } catch (PlexusCipherException e) { throw new SecDispatcherException(e); } } - //--------------------------------------------------------------- - public String getConfigurationFile() - { + // --------------------------------------------------------------- + public String getConfigurationFile() { return _configurationFile; } - public void setConfigurationFile( String file ) - { + public void setConfigurationFile(String file) { _configurationFile = file; } - //--------------------------------------------------------------- + // --------------------------------------------------------------- - private static boolean propertyExists( String [] values, String [] av ) - { - if( values != null ) - { - for ( String item : values ) { - String p = System.getProperty( item ); + private static boolean propertyExists(String[] values, String[] av) { + if (values != null) { + for (String item : values) { + String p = System.getProperty(item); - if ( p != null ) { + if (p != null) { return true; } } - - if( av != null ) - for ( String value : values ) - for ( String s : av ) { - if ( ( "--" + value ).equals( s ) ) { + + if (av != null) + for (String value : values) + for (String s : av) { + if (("--" + value).equals(s)) { return true; } } } - + return false; } - - private static void usage() - { - System.out.println( "usage: java -jar ...jar [-m|-p]\n-m: encrypt master password\n-p: encrypt password" ); + + private static void usage() { + System.out.println("usage: java -jar ...jar [-m|-p]\n-m: encrypt master password\n-p: encrypt password"); } - //--------------------------------------------------------------- + // --------------------------------------------------------------- - public static void main( String[] args ) - throws Exception - { - if( args == null || args.length < 1 ) - { + public static void main(String[] args) throws Exception { + if (args == null || args.length < 1) { usage(); return; } - - if( "-m".equals( args[0] ) || propertyExists( SYSTEM_PROPERTY_MASTER_PASSWORD, args ) ) - show( true ); - else if( "-p".equals( args[0] ) || propertyExists( SYSTEM_PROPERTY_SERVER_PASSWORD, args ) ) - show( false ); - else - usage(); + + if ("-m".equals(args[0]) || propertyExists(SYSTEM_PROPERTY_MASTER_PASSWORD, args)) show(true); + else if ("-p".equals(args[0]) || propertyExists(SYSTEM_PROPERTY_SERVER_PASSWORD, args)) show(false); + else usage(); } - //--------------------------------------------------------------- + // --------------------------------------------------------------- + + private static void show(boolean showMaster) throws Exception { + if (showMaster) System.out.print("\nsettings master password\n"); + else System.out.print("\nsettings server password\n"); - private static void show( boolean showMaster ) - throws Exception - { - if( showMaster ) - System.out.print("\nsettings master password\n"); - else - System.out.print("\nsettings server password\n"); - System.out.print("enter password: "); - - BufferedReader r = new BufferedReader( new InputStreamReader( System.in ) ); - + + BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); + String pass = r.readLine(); - + System.out.println("\n"); - + DefaultPlexusCipher dc = new DefaultPlexusCipher(); - DefaultSecDispatcher dd = new DefaultSecDispatcher( dc ); + DefaultSecDispatcher dd = new DefaultSecDispatcher(dc); - if( showMaster ) - System.out.println( dc.encryptAndDecorate( pass, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) ); - else - { + if (showMaster) + System.out.println(dc.encryptAndDecorate(pass, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION)); + else { SettingsSecurity sec = dd.getSec(); - System.out.println( dc.encryptAndDecorate( pass, dd.getMaster(sec) ) ); + System.out.println(dc.encryptAndDecorate(pass, dd.getMaster(sec))); } } } diff --git a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/PasswordDecryptor.java b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/PasswordDecryptor.java index 4491d7f..2d6a434 100644 --- a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/PasswordDecryptor.java +++ b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/PasswordDecryptor.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ - + package org.sonatype.plexus.components.sec.dispatcher; import java.util.Map; @@ -22,17 +22,16 @@ * @version $Id$ * */ -public interface PasswordDecryptor -{ +public interface PasswordDecryptor { /** * decrypt given encrypted string - * + * * @param str - string to decrypt * @param attributes - string attributes * @param config - configuration from settings-security.xml, if any * @return decrypted string - * + * * @throws SecDispatcherException */ - String decrypt( String str, Map attributes, Map config ) throws SecDispatcherException; + String decrypt(String str, Map attributes, Map config) throws SecDispatcherException; } diff --git a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcher.java b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcher.java index 9e5d3ca..1557a69 100644 --- a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcher.java +++ b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcher.java @@ -10,26 +10,25 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ - + package org.sonatype.plexus.components.sec.dispatcher; /** * This component decrypts a string, passed to it - * + * * @author Oleg Gusakov */ -public interface SecDispatcher -{ - String [] SYSTEM_PROPERTY_MASTER_PASSWORD = new String [] {"settings.master.password","settings-master-password"}; - - String [] SYSTEM_PROPERTY_SERVER_PASSWORD = new String [] {"settings.server.password","settings-server-password"}; +public interface SecDispatcher { + String[] SYSTEM_PROPERTY_MASTER_PASSWORD = new String[] {"settings.master.password", "settings-master-password"}; + + String[] SYSTEM_PROPERTY_SERVER_PASSWORD = new String[] {"settings.server.password", "settings-server-password"}; /** * decrypt given encrypted string - * + * * @param str * @return decrypted string * @throws SecDispatcherException */ - String decrypt( String str ) throws SecDispatcherException; + String decrypt(String str) throws SecDispatcherException; } diff --git a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcherException.java b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcherException.java index 1ed35bf..c7b8ad1 100644 --- a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcherException.java +++ b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcherException.java @@ -10,24 +10,19 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ - + package org.sonatype.plexus.components.sec.dispatcher; -public class SecDispatcherException - extends Exception -{ - public SecDispatcherException( String message ) - { - super( message ); +public class SecDispatcherException extends Exception { + public SecDispatcherException(String message) { + super(message); } - public SecDispatcherException( Throwable cause ) - { - super( cause ); + public SecDispatcherException(Throwable cause) { + super(cause); } - public SecDispatcherException( String message, Throwable cause ) - { - super( message, cause ); + public SecDispatcherException(String message, Throwable cause) { + super(message, cause); } } diff --git a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecUtil.java b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecUtil.java index a017e50..ccd32da 100644 --- a/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecUtil.java +++ b/src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecUtil.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ - + package org.sonatype.plexus.components.sec.dispatcher; import java.io.IOException; @@ -34,91 +34,77 @@ * @version $Id$ * */ -public class SecUtil -{ - +public class SecUtil { + public static final String PROTOCOL_DELIM = "://"; - public static final int PROTOCOL_DELIM_LEN = PROTOCOL_DELIM.length(); - public static final String [] URL_PROTOCOLS = new String [] {"http","https","dav","file","davs","webdav","webdavs","dav+http","dav+https"}; + public static final int PROTOCOL_DELIM_LEN = PROTOCOL_DELIM.length(); + public static final String[] URL_PROTOCOLS = + new String[] {"http", "https", "dav", "file", "davs", "webdav", "webdavs", "dav+http", "dav+https"}; - public static SettingsSecurity read( String location, boolean cycle ) - throws SecDispatcherException - { - if( location == null ) - throw new SecDispatcherException("location to read from is null"); + public static SettingsSecurity read(String location, boolean cycle) throws SecDispatcherException { + if (location == null) throw new SecDispatcherException("location to read from is null"); SettingsSecurity sec; - - try - { - try (InputStream in = toStream( location )) { + + try { + try (InputStream in = toStream(location)) { sec = new SecurityConfigurationXpp3Reader().read(in); } - if( cycle && sec.getRelocation() != null ) - return read( sec.getRelocation(), true ); - + if (cycle && sec.getRelocation() != null) return read(sec.getRelocation(), true); + return sec; - } - catch ( Exception e ) - { + } catch (Exception e) { throw new SecDispatcherException(e); } } - //--------------------------------------------------------------------------------------------------------------- - private static InputStream toStream( String resource ) - throws IOException - { - if( resource == null ) - return null; - - int ind = resource.indexOf( PROTOCOL_DELIM ); - - if( ind > 1 ) - { - String protocol = resource.substring( 0, ind ); - resource = resource.substring( ind + PROTOCOL_DELIM_LEN ); - - for ( String p : URL_PROTOCOLS ) { - if ( protocol.regionMatches( true, 0, p, 0, p.length() ) ) { - return new URL( p + PROTOCOL_DELIM + resource ).openStream(); - } - } - } - - return Files.newInputStream(Paths.get(resource)); + // --------------------------------------------------------------------------------------------------------------- + private static InputStream toStream(String resource) throws IOException { + if (resource == null) return null; + + int ind = resource.indexOf(PROTOCOL_DELIM); + + if (ind > 1) { + String protocol = resource.substring(0, ind); + resource = resource.substring(ind + PROTOCOL_DELIM_LEN); + + for (String p : URL_PROTOCOLS) { + if (protocol.regionMatches(true, 0, p, 0, p.length())) { + return new URL(p + PROTOCOL_DELIM + resource).openStream(); + } + } + } + + return Files.newInputStream(Paths.get(resource)); } - //--------------------------------------------------------------------------------------------------------------- - public static Map getConfig( SettingsSecurity sec, String name ) - { - if( name == null ) - return null; - + // --------------------------------------------------------------------------------------------------------------- + public static Map getConfig(SettingsSecurity sec, String name) { + if (name == null) return null; + List cl = sec.getConfigurations(); - - if( cl == null || cl.isEmpty() ) - return null; - for ( Config cf : cl ) { - if ( !name.equals( cf.getName() ) ) { + if (cl == null || cl.isEmpty()) return null; + + for (Config cf : cl) { + if (!name.equals(cf.getName())) { continue; } List pl = cf.getProperties(); - if ( pl == null || pl.isEmpty() ) { + if (pl == null || pl.isEmpty()) { return null; } - Map res = new HashMap<>( pl.size() ); + Map res = new HashMap<>(pl.size()); - for ( ConfigProperty p : pl ) { - res.put( p.getName(), p.getValue() ); + for (ConfigProperty p : pl) { + res.put(p.getName(), p.getValue()); } return res; } - + return null; } } diff --git a/src/test/java/org/sonatype/plexus/components/sec/dispatcher/SecUtilTest.java b/src/test/java/org/sonatype/plexus/components/sec/dispatcher/SecUtilTest.java index 578b904..3b387c0 100644 --- a/src/test/java/org/sonatype/plexus/components/sec/dispatcher/SecUtilTest.java +++ b/src/test/java/org/sonatype/plexus/components/sec/dispatcher/SecUtilTest.java @@ -10,8 +10,6 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ - - package org.sonatype.plexus.components.sec.dispatcher; @@ -20,7 +18,6 @@ import org.junit.Before; import org.junit.Test; - import org.sonatype.plexus.components.cipher.DefaultPlexusCipher; import org.sonatype.plexus.components.sec.dispatcher.model.Config; import org.sonatype.plexus.components.sec.dispatcher.model.ConfigProperty; @@ -37,80 +34,72 @@ * @version $Id$ * */ -public class SecUtilTest -{ +public class SecUtilTest { String _pw = "{1wQaa6S/o8MH7FnaTNL53XmhT5O0SEGXQi3gC49o6OY=}"; - + String _clear = "testtest"; - + String _encrypted = "{BteqUEnqHecHM7MZfnj9FwLcYbdInWxou1C929Txa0A=}"; - + String _confName = "cname"; - + String _propName = "pname"; - + String _propVal = "pval"; @Before - public void prepare() - throws Exception - { - System.setProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, "./target/sec.xml" ); - -//DefaultPlexusCipher c = new DefaultPlexusCipher(); -//System.out.println(_clear+" -> "+c.encrypt( _clear, "testtest" )); - - + public void prepare() throws Exception { + System.setProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, "./target/sec.xml"); + + // DefaultPlexusCipher c = new DefaultPlexusCipher(); + // System.out.println(_clear+" -> "+c.encrypt( _clear, "testtest" )); + SettingsSecurity sec = new SettingsSecurity(); - - sec.setRelocation( "./target/sec1.xml" ); - new SecurityConfigurationXpp3Writer().write( new FileWriter("./target/sec.xml"), sec ); - - sec.setRelocation( null ); - sec.setMaster( _pw ); - + + sec.setRelocation("./target/sec1.xml"); + new SecurityConfigurationXpp3Writer().write(new FileWriter("./target/sec.xml"), sec); + + sec.setRelocation(null); + sec.setMaster(_pw); + ConfigProperty cp = new ConfigProperty(); - cp.setName( _propName ); - cp.setValue( _propVal ); - + cp.setName(_propName); + cp.setValue(_propVal); + Config conf = new Config(); - conf.setName( _confName ); - conf.addProperty( cp ); - - sec.addConfiguration( conf ); - - new SecurityConfigurationXpp3Writer().write( new FileWriter("./target/sec1.xml"), sec ); + conf.setName(_confName); + conf.addProperty(cp); + + sec.addConfiguration(conf); + + new SecurityConfigurationXpp3Writer().write(new FileWriter("./target/sec1.xml"), sec); } @Test - public void testRead() - throws Exception - { - SettingsSecurity sec = SecUtil.read( "./target/sec.xml", true ); - - assertNotNull( sec ); - - assertEquals( _pw, sec.getMaster() ); - - Map conf = SecUtil.getConfig( sec, _confName ); - - assertNotNull( conf ); - - assertNotNull( conf.get( _propName ) ); - - assertEquals( _propVal, conf.get( _propName ) ); + public void testRead() throws Exception { + SettingsSecurity sec = SecUtil.read("./target/sec.xml", true); + + assertNotNull(sec); + + assertEquals(_pw, sec.getMaster()); + + Map conf = SecUtil.getConfig(sec, _confName); + + assertNotNull(conf); + + assertNotNull(conf.get(_propName)); + + assertEquals(_propVal, conf.get(_propName)); } @Test - public void testDecrypt() - throws Exception - { + public void testDecrypt() throws Exception { DefaultSecDispatcher sd = new DefaultSecDispatcher(new DefaultPlexusCipher()); - String pass = sd.decrypt( _encrypted ); - - assertNotNull( pass ); - - assertEquals( _clear, pass ); + String pass = sd.decrypt(_encrypted); + + assertNotNull(pass); + + assertEquals(_clear, pass); } }