components/visual-panels/usermgr/src/java/vpanels/app/usermgr/com/oracle/solaris/vp/panels/usermgr/client/swing/AddUserAction.java
branchs11-update
changeset 2805 4888f6212f94
parent 843 190d2b5889a8
equal deleted inserted replaced
2804:7546c836fd87 2805:4888f6212f94
    18  *
    18  *
    19  * CDDL HEADER END
    19  * CDDL HEADER END
    20  */
    20  */
    21 
    21 
    22 /*
    22 /*
    23  * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
    23  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
    24  */
    24  */
    25 
    25 
    26 package com.oracle.solaris.vp.panels.usermgr.client.swing;
    26 package com.oracle.solaris.vp.panels.usermgr.client.swing;
    27 
    27 
    28 import java.awt.*;
    28 import java.awt.*;
    29 import java.awt.event.*;
    29 import java.awt.event.*;
    30 import java.util.List;
    30 import java.util.List;
    31 import javax.swing.*;
    31 import javax.swing.*;
    32 import javax.swing.text.JTextComponent;
    32 import javax.swing.text.JTextComponent;
       
    33 import com.oracle.solaris.rad.client.ADRUinteger;
    33 import com.oracle.solaris.vp.panel.common.action.*;
    34 import com.oracle.solaris.vp.panel.common.action.*;
    34 import com.oracle.solaris.vp.panel.common.control.*;
    35 import com.oracle.solaris.vp.panel.common.control.*;
    35 import com.oracle.solaris.vp.panel.swing.action.AddManagedObjectAction;
    36 import com.oracle.solaris.vp.panel.swing.action.AddManagedObjectAction;
    36 import com.oracle.solaris.vp.panel.swing.view.ChangeIndicator;
    37 import com.oracle.solaris.vp.panel.swing.view.ChangeIndicator;
    37 import com.oracle.solaris.rad.usermgr.*;
    38 import com.oracle.solaris.rad.usermgr.*;
    50 @SuppressWarnings({"serial"})
    51 @SuppressWarnings({"serial"})
    51 public class AddUserAction extends AddManagedObjectAction
    52 public class AddUserAction extends AddManagedObjectAction
    52     <UserManagedObject, AddUserAction.Data, UserManagedObject> {
    53     <UserManagedObject, AddUserAction.Data, UserManagedObject> {
    53 
    54 
    54     private UserManagedObject umo = null;
    55     private UserManagedObject umo = null;
    55     private UserImpl user = null;
    56     private User user = null;
    56 
    57 
    57     //
    58     //
    58     // Inner classes
    59     // Inner classes
    59     //
    60     //
    60 
    61 
    74 	public LongProperty uidProperty = new LongProperty();
    75 	public LongProperty uidProperty = new LongProperty();
    75 	public MutableProperty<String> descProperty = new StringProperty();
    76 	public MutableProperty<String> descProperty = new StringProperty();
    76 	public MutableProperty<String> groupProperty = new StringProperty();
    77 	public MutableProperty<String> groupProperty = new StringProperty();
    77 	public MutableProperty<String> homeProperty = new StringProperty();
    78 	public MutableProperty<String> homeProperty = new StringProperty();
    78 	public MutableProperty<String> shellProperty = new StringProperty();
    79 	public MutableProperty<String> shellProperty = new StringProperty();
    79 	public MutableProperty<char[]> passProperty =
    80 	public MutableProperty<String> passProperty =
    80 	    new BasicMutableProperty<char[]>();
    81 	    new BasicMutableProperty<String>();
    81 	public MutableProperty<char[]> passConfirmProperty =
    82 	public MutableProperty<String> passConfirmProperty =
    82 	    new BasicMutableProperty<char[]>();
    83 	    new BasicMutableProperty<String>();
    83 
    84 
    84 	private JOptionPane pane;
    85 	private JOptionPane pane;
    85 	private JDialog dialog;
    86 	private JDialog dialog;
    86         private static final String ACTION_ADV_SETTINGS = "settings";
    87         private static final String ACTION_ADV_SETTINGS = "settings";
    87 	private UserMgrPanelDescriptor descriptor = null;
    88 	private UserMgrPanelDescriptor descriptor = null;
   100 		descriptor.getTypeString());
   101 		descriptor.getTypeString());
   101 	    dialog = pane.createDialog(getHasComponent().getComponent(),
   102 	    dialog = pane.createDialog(getHasComponent().getComponent(),
   102 		title);
   103 		title);
   103 	}
   104 	}
   104 
   105 
   105     private JPanel createForm() {
   106         private JPanel createForm() {
   106 	    ActionListener listener =
   107 	    ActionListener listener =
   107 		new ActionListener() {
   108 		new ActionListener() {
   108 		    @Override
   109 		    @Override
   109 		    public void actionPerformed(ActionEvent e) {
   110 		    public void actionPerformed(ActionEvent e) {
   110 			pane.setValue(JOptionPane.OK_OPTION);
   111 			pane.setValue(JOptionPane.OK_OPTION);
   208 	groupCombo = new JComboBox();
   209 	groupCombo = new JComboBox();
   209 	new ComboBoxPropertySynchronizer<String>(groupProperty, groupCombo);
   210 	new ComboBoxPropertySynchronizer<String>(groupProperty, groupCombo);
   210 
   211 
   211 	for (Group g : descriptor.getGroups()) {
   212 	for (Group g : descriptor.getGroups()) {
   212 	    groupCombo.addItem(g.getGroupName());
   213 	    groupCombo.addItem(g.getGroupName());
   213 	    if (user.getGroupID() == g.getGroupID()) {
   214 	    if (user.getGroupID().equals(g.getGroupID())) {
   214 		groupCombo.setSelectedItem(g.getGroupName());
   215 		groupCombo.setSelectedItem(g.getGroupName());
   215 	    }
   216 	    }
   216 	}
   217 	}
   217 
   218 
   218 	// Connect the label to the field
   219 	// Connect the label to the field
   263 	gbc.gridy++; // next row
   264 	gbc.gridy++; // next row
   264         form.add(shellLabel, gbc);
   265         form.add(shellLabel, gbc);
   265 	gbc.gridx = GridBagConstraints.RELATIVE;
   266 	gbc.gridx = GridBagConstraints.RELATIVE;
   266         form.add(shellCombo, gbc);
   267         form.add(shellCombo, gbc);
   267 
   268 
   268 	    // Password
   269 	// Password
   269 	actString = new ActionString("usermgr.basic.label.pass");
   270 	actString = new ActionString("usermgr.basic.label.pass");
   270         JLabel passLabel = new JLabel(actString.getString());
   271         JLabel passLabel = new JLabel(actString.getString());
   271         passLabel.setDisplayedMnemonic(actString.getMnemonic());
   272         passLabel.setDisplayedMnemonic(actString.getMnemonic());
   272 
   273 
   273 	    JPasswordField passField = new JPasswordField(width);
   274 	JPasswordField passField = new JPasswordField(width);
   274 	    passField.addActionListener(listener);
   275 	passField.addActionListener(listener);
   275 	new PasswordFieldPropertySynchronizer(passProperty, passField, false);
   276 	new PasswordFieldPropertySynchronizer(passProperty, passField, false);
   276 
   277 
   277 	// Connect the label to the field
   278 	// Connect the label to the field
   278 	passLabel.setLabelFor(passField);
   279 	passLabel.setLabelFor(passField);
   279 
   280 
   375     // DefaultStructuredAction methods
   376     // DefaultStructuredAction methods
   376     //
   377     //
   377 
   378 
   378     @Override
   379     @Override
   379     public UserManagedObject workBusy(List<UserManagedObject> selection,
   380     public UserManagedObject workBusy(List<UserManagedObject> selection,
   380 	Data uData) throws ActionFailedException,
   381 	Data uData) throws ActionFailedException, ActionAbortedException,
   381 		ActionAbortedException,
       
   382 	ActionUnauthorizedException {
   382 	ActionUnauthorizedException {
   383 
       
   384 
   383 
   385 	UserMgrPanelDescriptor descriptor = control.getPanelDescriptor();
   384 	UserMgrPanelDescriptor descriptor = control.getPanelDescriptor();
   386 
   385 
   387 	String username = uData.nameProperty.getValue();
   386 	String username = uData.nameProperty.getValue();
   388 	UserMgrUtils.validateUsername(descriptor, username);
   387 	UserMgrUtils.validateUsername(descriptor, username);
   392 
   391 
   393 	String group = uData.groupProperty.getValue();
   392 	String group = uData.groupProperty.getValue();
   394 	String shell = uData.shellProperty.getValue();
   393 	String shell = uData.shellProperty.getValue();
   395 	String homedir = uData.homeProperty.getValue();
   394 	String homedir = uData.homeProperty.getValue();
   396 
   395 
   397 	char[] password = uData.passProperty.getValue();
   396 	String password = uData.passProperty.getValue();
   398 	char[] password2 = uData.passConfirmProperty.getValue();
   397 	String password2 = uData.passConfirmProperty.getValue();
   399 	UserMgrUtils.validatePassword(true, password, password2);
   398 	UserMgrUtils.validatePassword(true, password, password2);
   400 
   399 
   401 	UserMgrUtils.clearPassword(password2);
   400 	UserMgrUtils.clearPassword(password2);
   402 
   401 
   403 	user.setUsername(username);
   402 	user.setUsername(username);
   404 	if (uData.uidProperty.isChanged()) {
   403 	if (uData.uidProperty.isChanged()) {
   405 	    long uid = uData.uidProperty.getValue();
   404 	    long uid = uData.uidProperty.getValue();
   406 	    user.setUserID(uid);
   405 	    user.setUserID(new ADRUinteger(uid));
   407 	}
   406 	}
   408 
   407 
   409 	user.setDescription(description);
   408 	user.setDescription(description);
   410 	user.setDefaultShell(shell);
   409 	user.setDefaultShell(shell);
   411 	user.setHomeDirectory(homedir);
   410 	user.setHomeDirectory(homedir);