浏览代码

SEC-2559: Added missing givenName attribute to Person

Chris Bonham 11 年之前
父节点
当前提交
d579d00892

+ 12 - 0
ldap/src/main/java/org/springframework/security/ldap/userdetails/Person.java

@@ -37,6 +37,7 @@ public class Person extends LdapUserDetailsImpl {
 
     private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
 
+    private String givenName;
     private String sn;
     private String description;
     private String telephoneNumber;
@@ -45,6 +46,10 @@ public class Person extends LdapUserDetailsImpl {
     protected Person() {
     }
 
+    public String getGivenName() {
+        return givenName;
+    }
+
     public String getSn() {
         return sn;
     }
@@ -62,6 +67,7 @@ public class Person extends LdapUserDetailsImpl {
     }
 
     protected void populateContext(DirContextAdapter adapter) {
+        adapter.setAttributeValue("givenName", givenName);
         adapter.setAttributeValue("sn", sn);
         adapter.setAttributeValues("cn", getCn());
         adapter.setAttributeValue("description", getDescription());
@@ -81,6 +87,7 @@ public class Person extends LdapUserDetailsImpl {
         public Essence(DirContextOperations ctx) {
             super(ctx);
             setCn(ctx.getStringAttributes("cn"));
+            setGivenName(ctx.getStringAttribute("givenName"));
             setSn(ctx.getStringAttribute("sn"));
             setDescription(ctx.getStringAttribute("description"));
             setTelephoneNumber(ctx.getStringAttribute("telephoneNumber"));
@@ -94,6 +101,7 @@ public class Person extends LdapUserDetailsImpl {
 
         public Essence(Person copyMe) {
             super(copyMe);
+            setGivenName(copyMe.givenName);
             setSn(copyMe.sn);
             setDescription(copyMe.getDescription());
             setTelephoneNumber(copyMe.getTelephoneNumber());
@@ -104,6 +112,10 @@ public class Person extends LdapUserDetailsImpl {
             return new Person();
         }
 
+        public void setGivenName(String givenName) {
+            ((Person) instance).givenName = givenName;
+        }
+
         public void setSn(String sn) {
             ((Person) instance).sn = sn;
         }

+ 2 - 0
ldap/src/test/java/org/springframework/security/ldap/userdetails/InetOrgPersonTests.java

@@ -50,6 +50,7 @@ public class InetOrgPersonTests {
 
         assertEquals("HORS1", p.getCarLicense());
         assertEquals("ghengis@mongolia", p.getMail());
+        assertEquals("Ghengis", p.getGivenName());
         assertEquals("Khan", p.getSn());
         assertEquals("Ghengis Khan", p.getCn()[0]);
         assertEquals("00001", p.getEmployeeNumber());
@@ -111,6 +112,7 @@ public class InetOrgPersonTests {
         ctx.setAttributeValue("description", "Scary");
         ctx.setAttributeValue("destinationIndicator", "West");
         ctx.setAttributeValue("displayName", "Ghengis McCann");
+        ctx.setAttributeValue("givenName", "Ghengis");
         ctx.setAttributeValue("homePhone", "+467575436521");
         ctx.setAttributeValue("initials", "G");
         ctx.setAttributeValue("employeeNumber", "00001");