usr/src/java/vpanels/app/usermgr/com/oracle/solaris/vp/panels/usermgr/client/swing/UserManagedObject.java
changeset 847 a8e124b894b8
parent 833 d41a5ad2fa96
--- a/usr/src/java/vpanels/app/usermgr/com/oracle/solaris/vp/panels/usermgr/client/swing/UserManagedObject.java	Thu Apr 26 00:14:30 2012 -0400
+++ b/usr/src/java/vpanels/app/usermgr/com/oracle/solaris/vp/panels/usermgr/client/swing/UserManagedObject.java	Fri Apr 27 00:52:26 2012 -0400
@@ -25,15 +25,18 @@
 
 package com.oracle.solaris.vp.panels.usermgr.client.swing;
 
-import java.util.List;
+import java.util.*;
 import javax.swing.*;
 import com.oracle.solaris.vp.panel.common.model.AbstractManagedObject;
-import com.oracle.solaris.vp.panels.usermgr.*;
+import com.oracle.solaris.rad.usermgr.*;
 import com.oracle.solaris.vp.util.misc.*;
 import com.oracle.solaris.vp.util.misc.finder.Finder;
 import com.oracle.solaris.vp.util.misc.property.*;
 import com.oracle.solaris.vp.util.swing.HasIcon;
 
+/**
+ * User Managed Object represents user object
+ */
 @SuppressWarnings({"serial"})
 public class UserManagedObject
     extends AbstractManagedObject<UserManagedObject> implements HasIcon {
@@ -41,19 +44,16 @@
     //
     // Static data
     //
+    public static final String PASSWORD = "PASSWORD";
+    public static final String NOTACTIVE = "NOTACTIVATED";
+
 
     // Icons - for user, roles
     protected static final List<ImageIcon> userIcons = Finder.getIcons(
-	"images/config-users-16.png",
-	"images/config-users-22.png",
-	"images/config-users-24.png",
-	"images/config-users-32.png");
+	"images/user-24.png");
 
     protected static final List<ImageIcon> roleIcons = Finder.getIcons(
-	"images/config-roles-16.png",
-	"images/config-roles-22.png",
-	"images/config-roles-24.png",
-	"images/config-roles-32.png");
+	"images/role-24.png");
 
     //
     // Instance data
@@ -62,6 +62,7 @@
     private UserMgrPanelDescriptor descriptor;
     private UserType type = UserType.NORMAL;
     private boolean isNewUser = false;
+    private UserChangeFieldsImpl modChanges = null;
 
     private MutableProperty<Long> groupIdProperty =
 	new LongProperty();
@@ -69,8 +70,17 @@
     private MutableProperty<String> homeDirProperty =
 	new StringProperty();
 
-    private MutableProperty<Boolean> isAdminProperty =
-	new BooleanProperty();
+    private MutableProperty<String> rightsProperty =
+	new StringProperty();
+
+    private MutableProperty<String> rolesProperty =
+	new StringProperty();
+
+    private MutableProperty<String> groupsProperty =
+	new StringProperty();
+
+    private MutableProperty<String> authsProperty =
+	new StringProperty();
 
     private MutableProperty<String> shellProperty =
 	new StringProperty();
@@ -84,12 +94,16 @@
     private MutableProperty<String> userNameProperty =
 	new StringProperty();
 
+    private MutableProperty<String> accountStatusProperty =
+	new StringProperty();
+
     private MutableProperty<char[]> passProperty =
 	new BasicMutableProperty<char[]>();
     {
         ChangeableAggregator aggregator = getChangeableAggregator();
 	aggregator.addChangeables(groupIdProperty, homeDirProperty,
-	    isAdminProperty, passProperty, shellProperty,
+	    passProperty, shellProperty,
+	    rolesProperty, rightsProperty, authsProperty, groupsProperty,
 	    userDescProperty, userIdProperty, userNameProperty);
     }
 
@@ -98,7 +112,7 @@
     //
 
     UserManagedObject(UserMgrPanelDescriptor descriptor,
-	User user, UserType type, boolean isAdministrator,
+	User user, UserType type,
 	char[] password, boolean bNewUser) {
 
 	this.descriptor = descriptor;
@@ -111,13 +125,22 @@
 	groupIdProperty.update(user.getGroupID(), true);
 	homeDirProperty.update(user.getHomeDirectory(), true);
 	shellProperty.update(user.getDefaultShell(), true);
-	passProperty.update(password, true);
-	isAdminProperty.update(isAdministrator, true);
+
+	rolesProperty.update(listToString(user.getRoles()), true);
+	rightsProperty.update(listToString(user.getProfiles()), true);
+	authsProperty.update(listToString(user.getAuths()), true);
+	groupsProperty.update(listToString(user.getGroups()), true);
+	accountStatusProperty.update(user.getAccountStatus() == null ? ""
+		: user.getAccountStatus(), true);
+
+	if (password != null) {
+	    passProperty.update(password, true);
+        }
     }
 
     UserManagedObject(UserMgrPanelDescriptor descriptor,
 	User user, char[] password) {
-	this(descriptor, user, UserType.NORMAL, false, password, true);
+	this(descriptor, user, UserType.NORMAL, password, true);
     }
 
     //
@@ -148,19 +171,34 @@
     @Override
     public String toString() {
 	StringBuilder sb = new StringBuilder();
-	sb.append("\n\tuser name: ").append(getUsername())
-	    .append("\n\tuserID: ").append(getUserId())
-	    .append("\n\tgroupID: ").append(getGroupId())
+	sb.append("\n\tname: ").append(getUsername())
+	    .append("\n\tuid: ").append(getUserId())
+	    .append("\n\tgid: ").append(getGroupId())
 	    .append("\n\tdescription: ").append(getUserDescription())
 	    .append("\n\thome dir: ").append(getHomedir())
-	    .append("\n\tdefault shell: ").append(getShell())
-	    .append("\n\tuser type: ")
-	    .append(type == UserType.NORMAL ? "normal" : "role")
-	    .append("\n\tadmin: ")
-	    .append(isAdministrator() ? "true" : "false");
+	    .append("\n\tshell: ").append(getShell())
+	    .append("\n\ttype: ")
+	    .append(type == UserType.NORMAL ? "user" : "role")
+	    .append("\n\trights: ").append(getRights())
+	    .append("\n\tauths: ").append(getAuths())
+	    .append("\n\tgroups: ").append(getGroups())
+	    .append("\n\troles: ").append(getRoles())
+	    .append("\n\tstatus: ").append(getAccountStatus());
 	return sb.toString();
     }
 
+    public void setUser(User user, char[] password) {
+
+	userNameProperty.update(user.getUsername(), true);
+	userDescProperty.update(user.getDescription(), true);
+	userIdProperty.update(user.getUserID(), true);
+	groupIdProperty.update(user.getGroupID(), true);
+	homeDirProperty.update(user.getHomeDirectory(), true);
+	shellProperty.update(user.getDefaultShell(), true);
+
+	passProperty.update(password, true);
+    }
+
     //
     // UserManagedObject methods
     //
@@ -173,8 +211,21 @@
 	return homeDirProperty;
     }
 
-    public MutableProperty<Boolean> getIsAdminProperty() {
-	return isAdminProperty;
+
+    public MutableProperty<String> getRightsProperty() {
+	return rightsProperty;
+    }
+
+    public MutableProperty<String> getRolesProperty() {
+	return rolesProperty;
+    }
+
+    public MutableProperty<String> getGroupsProperty() {
+	return groupsProperty;
+    }
+
+    public MutableProperty<String> getAuthsProperty() {
+	return authsProperty;
     }
 
     public MutableProperty<String> getUserDescProperty() {
@@ -209,10 +260,6 @@
 	return userDescProperty.getValue();
     }
 
-    public boolean isAdministrator() {
-	return isAdminProperty.getValue();
-    }
-
     public long getUserId() {
 	return userIdProperty.getValue();
     }
@@ -237,11 +284,31 @@
 	return type;
     }
 
+    public String getRights() {
+	return rightsProperty.getValue();
+    }
+
+    public String getRoles() {
+	return rolesProperty.getValue();
+    }
+
+    public String getGroups() {
+	return groupsProperty.getValue();
+    }
+
+    public String getAuths() {
+	return authsProperty.getValue();
+    }
+
+    public String getAccountStatus() {
+	return accountStatusProperty.getValue();
+    }
+
     public boolean isUserNormal() {
 	return type == UserType.NORMAL;
     }
 
-    public boolean isUserRole() {
+    public boolean isRole() {
 	return type == UserType.ROLE;
     }
 
@@ -249,6 +316,14 @@
 	return isNewUser;
     }
 
+    public boolean hasPassword() {
+        if (getAccountStatus().equals(PASSWORD)) {
+	    return (true);
+	}
+
+	return (false);
+    }
+
     // Update the "auto-generated" properties for the newly created user
     public void updateUser(User user) {
 	userIdProperty.update(user.getUserID(), true);
@@ -258,6 +333,7 @@
 
     // Construct a new User object from the defined properties
     public User getNewUser() {
+
 	UserImpl newUser = new UserImpl();
 	newUser.setUsername(getUsername());
 	newUser.setUserID(getUserId());
@@ -267,7 +343,27 @@
 	    newUser.setHomeDirectory(getHomedir());
 	else // must be null
 	    newUser.setHomeDirectory(null);
+
 	newUser.setDefaultShell(getShell());
+
+	if (getRights() != null) {
+	    // System.out.println("new user rights:" + getRights());
+	    newUser.setProfiles(stringToList(getRights()));
+	}
+
+	if (getRoles() != null) {
+	    // System.out.println("new user roles:" + getRoles());
+	    newUser.setRoles(stringToList(getRoles()));
+	}
+
+	if (getAuths() != null) {
+	    newUser.setAuths(stringToList(getAuths()));
+	}
+
+	if (getGroups() != null) {
+	    newUser.setGroups(stringToList(getGroups()));
+	}
+
 	return newUser;
     }
 
@@ -275,6 +371,8 @@
     public User getModifiedUser() {
 	boolean bChanged = false;
 	UserImpl modUser = new UserImpl();
+	modChanges = new UserChangeFieldsImpl();
+
 	// check each property for changes
 	if (userDescProperty.isChanged()) {
 	    modUser.setDescription(getUserDescription());
@@ -291,7 +389,35 @@
 	if (passProperty.isChanged()) {
 	    bChanged = true;
 	}
-	// If *only* the admin property is changed, the User object is not used.
+
+	if (rightsProperty.isChanged()) {
+	    // System.out.println("mod user rights " + getRights());
+	    modUser.setProfiles(stringToList(getRights()));
+	    modChanges.setProfilesChanged(true);
+	    bChanged = true;
+	}
+
+	if (rolesProperty.isChanged()) {
+	    // System.out.println("mod user roles " + getRoles());
+	    modUser.setRoles(stringToList(getRoles()));
+	    modChanges.setRolesChanged(true);
+	    bChanged = true;
+	}
+
+	if (authsProperty.isChanged()) {
+	    // System.out.println("mod user auths " + getAuths());
+	    modUser.setAuths(stringToList(getAuths()));
+	    modChanges.setAuthsChanged(true);
+	    bChanged = true;
+	}
+
+	if (groupsProperty.isChanged()) {
+	    // System.out.println("mod user groups " + getGroups());
+	    modUser.setGroups(stringToList(getGroups()));
+	    modChanges.setGroupsChanged(true);
+	    bChanged = true;
+	}
+
 	if (bChanged) {
 	    modUser.setUsername(getUsername());
 	} else {
@@ -300,4 +426,40 @@
 
 	return modUser;
     }
+
+    public String listToString(List<String> list) {
+	String str;
+
+	if (list == null) {
+	    return ("");
+	}
+
+	if (list.size() > 0) {
+		str = list.get(0);
+	} else {
+		str = "";
+	}
+
+	for (int i = 1; i < list.size(); i++) {
+	    str = str.concat(",");
+	    str = str.concat(list.get(i));
+        }
+
+	return (str);
+    }
+
+    public List<String> stringToList(String str) {
+	List<String> list = new ArrayList<String>();
+	String[] strings = str.split(",");
+
+	for (String s : strings) {
+	    list.add(s);
+        }
+
+	return (list);
+    }
+
+    public UserChangeFieldsImpl getModifiedChanges() {
+        return (modChanges);
+    }
 }