Commons Lang
  1. Commons Lang
  2. LANG-226

[lang] Using ReflectionToStringBuilder and excluding secure fields

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Other

      Issue Links

        Activity

        ggregory@seagullsw.com created issue -
        Hide
        ggregory@seagullsw.com added a comment -

        ----Original Message----
        From: Gary Gregory ggregory@seagullsoftware.com
        Sent: Thursday, August 04, 2005 11:33 AM
        To: Jakarta Commons Developers List
        Subject: [lang] Using ReflectionToStringBuilder and excluding secure fields

        Hello:

        Right now, I use the code below to exclude password fields from output.

        /**

        • Builds a String for a toString method excluding the given field
          name.
        • @param obj
        • The object to "toString".
        • @param excludeFieldName
        • The field name to exclude
        • @return The toString String.
          */
          public static String toStringExcluding(Object obj, final String
          excludeFieldName) {
          return (new ReflectionToStringBuilder(obj)
          Unknown macro: { protected boolean accept(Field f) { return super.accept(f) && !f.getName().equals(excludeFieldName); } }

          ).toString();
          }

        I could imagine writing my call sites like this instead:

        new ReflectionToStringBuilder(obj).setExcludeFields(new
        String[]

        {"password"}

        ).toString();

        Which means adding the set/getExcludeFields() feature.

        Any thoughts?

        Gary

        Show
        ggregory@seagullsw.com added a comment - ---- Original Message ---- From: Gary Gregory ggregory@seagullsoftware.com Sent: Thursday, August 04, 2005 11:33 AM To: Jakarta Commons Developers List Subject: [lang] Using ReflectionToStringBuilder and excluding secure fields Hello: Right now, I use the code below to exclude password fields from output. /** Builds a String for a toString method excluding the given field name. @param obj The object to "toString". @param excludeFieldName The field name to exclude @return The toString String. */ public static String toStringExcluding(Object obj, final String excludeFieldName) { return (new ReflectionToStringBuilder(obj) Unknown macro: { protected boolean accept(Field f) { return super.accept(f) && !f.getName().equals(excludeFieldName); } } ).toString(); } I could imagine writing my call sites like this instead: new ReflectionToStringBuilder(obj).setExcludeFields(new String[] {"password"} ).toString(); Which means adding the set/getExcludeFields() feature. Any thoughts? Gary
        Hide
        ggregory@seagullsw.com added a comment -

        ----Original Message----
        From: Steven Caswell steven.caswell@gmail.com
        Sent: Saturday, August 06, 2005 3:28 PM
        To: Jakarta Commons Developers List
        Subject: Re: [lang] Using ReflectionToStringBuilder and excluding secure fields

        +1

        I've thought about something similar, just never did anything about
        it. I like the idea of being able to exclude some fields from the
        string build.

        <SNIP>

        Show
        ggregory@seagullsw.com added a comment - ---- Original Message ---- From: Steven Caswell steven.caswell@gmail.com Sent: Saturday, August 06, 2005 3:28 PM To: Jakarta Commons Developers List Subject: Re: [lang] Using ReflectionToStringBuilder and excluding secure fields +1 I've thought about something similar, just never did anything about it. I like the idea of being able to exclude some fields from the string build. <SNIP>
        Hide
        ggregory@seagullsw.com added a comment -

        Experimented version checked into SVN with unit tests.

        Show
        ggregory@seagullsw.com added a comment - Experimented version checked into SVN with unit tests.
        Hide
        ggregory@seagullsw.com added a comment -

        ----Original Message----
        From: Stephen Colebourne scolebourne@btopenworld.com
        Sent: Sunday, April 16, 2006 7:23 AM
        To: Jakarta Commons Developers List
        Subject: Re: [lang] next version etc

        <snip>

        >>36925: Status Gary?
        >
        > I like the feature and it is done and it tested. The only thing I can
        > think of is trying to make the API names better (they seem fine now to
        > me).

        I would like to see method override taking in a Collection of Strings,
        otherwise its done.

        Show
        ggregory@seagullsw.com added a comment - ---- Original Message ---- From: Stephen Colebourne scolebourne@btopenworld.com Sent: Sunday, April 16, 2006 7:23 AM To: Jakarta Commons Developers List Subject: Re: [lang] next version etc <snip> >>36925: Status Gary? > > I like the feature and it is done and it tested. The only thing I can > think of is trying to make the API names better (they seem fine now to > me). I would like to see method override taking in a Collection of Strings, otherwise its done.
        Hide
        ggregory@seagullsw.com added a comment -

        Stephen Colebourne: "I would like to see method override taking in a Collection
        of Strings, otherwise its done."

        Now in SVN.

        Show
        ggregory@seagullsw.com added a comment - Stephen Colebourne: "I would like to see method override taking in a Collection of Strings, otherwise its done." Now in SVN.
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 36925 12342600
        Henri Yandell made changes -
        Component/s Lang [ 12311121 ]
        Affects Version/s Nightly Builds [ 12311648 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Fix Version/s 2.2 [ 12311686 ]
        Project Commons [ 12310458 ] Commons Lang [ 12310481 ]
        Key COM-2448 LANG-226
        Henri Yandell made changes -
        Affects Version/s Nightly Builds [ 12311718 ]
        Henri Yandell made changes -
        Fix Version/s 2.2 [ 12311702 ]
        Hide
        Henri Yandell added a comment -

        Biggest problem here is that we have two exclusion mechanisms in there with different styles (my fault for committing a contributor patch for the other style).

        Do you have any time to look at unifying those Gary?

        Show
        Henri Yandell added a comment - Biggest problem here is that we have two exclusion mechanisms in there with different styles (my fault for committing a contributor patch for the other style). Do you have any time to look at unifying those Gary?
        Hide
        ggregory@seagullsw.com added a comment -

        "Do you have any time to look at unifying those Gary?"

        I've just come back from my honeymoon and I will not be able to take the time to look at this for a week or so.

        Show
        ggregory@seagullsw.com added a comment - "Do you have any time to look at unifying those Gary?" I've just come back from my honeymoon and I will not be able to take the time to look at this for a week or so.
        Hide
        Henri Yandell added a comment -

        I've added Collection variants for the other exclude APIs.

        svn ci -m "Added Collection APIs for the excludeFieldNames as sugge
        sted at the end of LANG-226"
        Sending builder/CompareToBuilder.java
        Sending builder/EqualsBuilder.java
        Sending builder/HashCodeBuilder.java
        Sending builder/ReflectionToStringBuilder.java
        Transmitting file data ....
        Committed revision 416487.

        Show
        Henri Yandell added a comment - I've added Collection variants for the other exclude APIs. svn ci -m "Added Collection APIs for the excludeFieldNames as sugge sted at the end of LANG-226 " Sending builder/CompareToBuilder.java Sending builder/EqualsBuilder.java Sending builder/HashCodeBuilder.java Sending builder/ReflectionToStringBuilder.java Transmitting file data .... Committed revision 416487.
        Henri Yandell made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Workflow jira [ 12371505 ] Default workflow, editable Closed status [ 12601990 ]
        Mark Thomas made changes -
        Reporter Gary Gregory [ ggregory@seagullsw.com ] Gary D. Gregory [ garydgregory ]
        Henri Yandell made changes -
        Affects Version/s Nightly Builds [ 12311718 ]
        Matt Benson made changes -
        Link This issue is duplicated by LANG-945 [ LANG-945 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        260d 20h 19m 1 Henri Yandell 23/Jun/06 06:20
        Resolved Resolved Closed Closed
        228d 18h 26m 1 Henri Yandell 06/Feb/07 23:47

          People

          • Assignee:
            Unassigned
            Reporter:
            Gary Gregory
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development