3535import hudson .security .SecurityRealm ;
3636import hudson .security .UserMayOrMayNotExistException2 ;
3737import hudson .util .FormValidation ;
38- import org .apache .commons .lang3 .StringUtils ;
3938import org .jenkins .ui .symbol .Symbol ;
4039import org .jenkins .ui .symbol .SymbolRequest ;
4140import org .kohsuke .accmod .Restricted ;
@@ -137,17 +136,15 @@ static FormValidation validateGroup(String groupName, SecurityRealm sr, boolean
137136 FormValidation .Kind .WARNING ,
138137 formatUserGroupValidationResponse (
139138 GROUP ,
140- Util .escape (StringUtils . abbreviate (groupDetails .getDisplayName (), 50 )),
139+ Util .escape (abbreviate (groupDetails .getDisplayName ())),
141140 "Group " + escapedSid
142141 + " found; but permissions would also be granted to a user of this name" ,
143142 true ));
144143 } else {
145144 return FormValidation .respond (
146145 FormValidation .Kind .OK ,
147146 formatUserGroupValidationResponse (
148- GROUP ,
149- Util .escape (StringUtils .abbreviate (groupDetails .getDisplayName (), 50 )),
150- "Group " + escapedSid ));
147+ GROUP , Util .escape (abbreviate (groupDetails .getDisplayName ())), "Group " + escapedSid ));
151148 }
152149 } catch (UserMayOrMayNotExistException2 e ) {
153150 // undecidable, meaning the group may exist
@@ -196,15 +193,15 @@ static FormValidation validateUser(String userName, SecurityRealm sr, boolean am
196193 FormValidation .Kind .WARNING ,
197194 formatUserGroupValidationResponse (
198195 USER ,
199- Util .escape (StringUtils . abbreviate (u .getFullName (), 50 )),
196+ Util .escape (abbreviate (u .getFullName ())),
200197 "User " + escapedSid
201198 + " found; but permissions would also be granted to a group of this name" ,
202199 true ));
203200 } else {
204201 return FormValidation .respond (
205202 FormValidation .Kind .OK ,
206203 formatUserGroupValidationResponse (
207- USER , Util .escape (StringUtils . abbreviate (u .getFullName (), 50 )), "User " + escapedSid ));
204+ USER , Util .escape (abbreviate (u .getFullName ())), "User " + escapedSid ));
208205 }
209206 } catch (UserMayOrMayNotExistException2 e ) {
210207 // undecidable, meaning the user may exist
@@ -227,4 +224,15 @@ static FormValidation validateUser(String userName, SecurityRealm sr, boolean am
227224 }
228225 return null ;
229226 }
227+
228+ private static String abbreviate (String str ) {
229+ if (str == null ) {
230+ return null ;
231+ }
232+ final int length = str .length ();
233+ if (length <= 50 ) {
234+ return str ;
235+ }
236+ return str .substring (0 , 47 ) + "..." ;
237+ }
230238}
0 commit comments