@@ -76,13 +76,13 @@ public String encrypt(String str, Map<String, String> attr) throws SecDispatcher
7676 String type = attr .get (DISPATCHER_NAME_ATTR );
7777 Map <String , String > conf = SecUtil .getConfig (sec , type );
7878 Dispatcher dispatcher = dispatchers .get (type );
79- if (dispatcher == null ) throw new SecDispatcherException ("no dispatcher for type " + type );
80- res = dispatcher .encrypt (str , attr , conf );
81- res += ATTR_START
79+ if (dispatcher == null ) throw new SecDispatcherException ("no dispatcher for name " + type );
80+ res = ATTR_START
8281 + attr .entrySet ().stream ()
8382 .map (e -> e .getKey () + "=" + e .getValue ())
8483 .collect (Collectors .joining ("," ))
8584 + ATTR_STOP ;
85+ res += dispatcher .encrypt (str , attr , conf );
8686 }
8787 return cipher .decorate (res );
8888 } catch (PlexusCipherException e ) {
@@ -104,7 +104,7 @@ public String decrypt(String str) throws SecDispatcherException {
104104 String type = attr .get (DISPATCHER_NAME_ATTR );
105105 Map <String , String > conf = SecUtil .getConfig (sec , type );
106106 Dispatcher dispatcher = dispatchers .get (type );
107- if (dispatcher == null ) throw new SecDispatcherException ("no dispatcher for type " + type );
107+ if (dispatcher == null ) throw new SecDispatcherException ("no dispatcher for name " + type );
108108 String pass = strip (bare );
109109 return dispatcher .decrypt (pass , attr , conf );
110110 }
@@ -114,15 +114,19 @@ public String decrypt(String str) throws SecDispatcherException {
114114 }
115115
116116 private String strip (String str ) {
117- int pos = str .indexOf (ATTR_STOP );
118- if (pos != -1 ) return str .substring (pos + 1 );
117+ int start = str .indexOf (ATTR_START );
118+ int stop = str .indexOf (ATTR_STOP );
119+ if (start != -1 && stop != -1 && stop > start ) {
120+ return str .substring (stop + 1 );
121+ }
119122 return str ;
120123 }
121124
122125 private Map <String , String > stripAttributes (String str ) {
123126 int start = str .indexOf (ATTR_START );
124127 int stop = str .indexOf (ATTR_STOP );
125128 if (start != -1 && stop != -1 && stop > start ) {
129+ if (start != 0 ) throw new SecDispatcherException ("Attributes can be prefix only" );
126130 if (stop == start + 1 ) return null ;
127131
128132 String attrs = str .substring (start + 1 , stop ).trim ();
@@ -155,15 +159,11 @@ private Map<String, String> stripAttributes(String str) {
155159 return null ;
156160 }
157161
158- // ----------------------------------------------------------------------------
159-
160162 private boolean isEncryptedString (String str ) {
161163 if (str == null ) return false ;
162164 return cipher .isEncryptedString (str );
163165 }
164166
165- // ----------------------------------------------------------------------------
166-
167167 private SettingsSecurity getSec () throws SecDispatcherException {
168168 String location = System .getProperty (SYSTEM_PROPERTY_CONFIGURATION_LOCATION , getConfigurationFile ());
169169 String realLocation =
0 commit comments