Search in sources :

Example 6 with Group

use of com.ramussoft.net.common.Group in project ramus by Vitaliy-Yakovchuk.

the class EditUsersDialog method createModels.

private void createModels() {
    userModel = new AbstractTableModel() {

        /**
         */
        private static final long serialVersionUID = -5788741544620802246L;

        private String[] columnNames = new String[] { plugin.getString("Column.User.Login"), plugin.getString("Column.User.Name") };

        public int getColumnCount() {
            return 2;
        }

        public int getRowCount() {
            return users.size();
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            User user = users.get(rowIndex);
            return (columnIndex == 0) ? user.getLogin() : user.getName();
        }

        public String getColumnName(int column) {
            return columnNames[column];
        }
    };
    groupModel = new AbstractTableModel() {

        /**
         */
        private static final long serialVersionUID = 2848439255843446217L;

        private String[] columnNames = new String[] { plugin.getString("Column.Selected"), plugin.getString("Column.Group.Name") };

        public int getColumnCount() {
            return 2;
        }

        public int getRowCount() {
            return groups.size();
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 0) {
                if (getActiveUser() != null) {
                    return getActiveUser().getGroups().indexOf(groups.get(rowIndex)) >= 0;
                } else
                    return false;
            }
            return groups.get(rowIndex).getName();
        }

        public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 0)
                return Boolean.class;
            return super.getColumnClass(columnIndex);
        }

        public String getColumnName(int column) {
            return columnNames[column];
        }

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (columnIndex == 0) && (getActiveUser() != null);
        }

        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            User user = getActiveUser();
            if (user != null) {
                updateUser(user);
                Group group = groups.get(rowIndex);
                if ((Boolean) value)
                    user.getGroups().add(group);
                else
                    user.getGroups().remove(group);
            }
        }
    };
    qualifierModel = new AbstractTableModel() {

        /**
         */
        private static final long serialVersionUID = -8072350565904373494L;

        private String[] columnNames = new String[] { plugin.getString("Column.Selected"), plugin.getString("Column.Qualifier.Name") };

        public int getColumnCount() {
            return 2;
        }

        public int getRowCount() {
            return qualifiers.size();
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 0) {
                if (getActiveGroup() != null) {
                    return getActiveGroup().getQualifierIds().indexOf(qualifiers.get(rowIndex).getId()) >= 0;
                } else
                    return Boolean.FALSE;
            }
            return qualifiers.get(rowIndex).getName();
        }

        public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 0)
                return Boolean.class;
            return super.getColumnClass(columnIndex);
        }

        public String getColumnName(int column) {
            return columnNames[column];
        }

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (columnIndex == 0) && (getActiveGroup() != null);
        }

        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            Group group = getActiveGroup();
            if (group != null) {
                updateGroup(group);
                long qualifierId = qualifiers.get(rowIndex).getId();
                if ((Boolean) value)
                    group.getQualifierIds().add(qualifierId);
                else
                    group.getQualifierIds().remove(qualifierId);
            }
        }
    };
}
Also used : Group(com.ramussoft.net.common.Group) User(com.ramussoft.net.common.User) AbstractTableModel(javax.swing.table.AbstractTableModel)

Example 7 with Group

use of com.ramussoft.net.common.Group in project ramus by Vitaliy-Yakovchuk.

the class EditUsersDialog method createActions.

private void createActions() {
    editUser = new AbstractAction() {

        {
            putValue(SHORT_DESCRIPTION, plugin.getString("Action.EditUser"));
            putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/client/edit_user.png")));
        }

        /**
         */
        private static final long serialVersionUID = 3903478872742330272L;

        public void actionPerformed(ActionEvent e) {
            User user = getActiveUser();
            if (user == null)
                return;
            EditUserDialog dialog = new EditUserDialog(EditUsersDialog.this, user, plugin);
            dialog.setVisible(true);
            updateUser(user);
            userModel.fireTableDataChanged();
        }
    };
    createUser = new AbstractAction() {

        {
            putValue(SHORT_DESCRIPTION, plugin.getString("Action.CreateUser"));
            putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/client/add_user.png")));
        }

        /**
         */
        private static final long serialVersionUID = -1876218590535351065L;

        public void actionPerformed(ActionEvent e) {
            EditUserDialog dialog = new EditUserDialog(EditUsersDialog.this, null, plugin);
            dialog.setVisible(true);
            User user = dialog.getUser();
            if (user != null) {
                User u = findUser(user.getLogin());
                if (u != null) {
                    JOptionPane.showMessageDialog(EditUsersDialog.this, MessageFormat.format(plugin.getString("User.Exists"), u.getLogin()));
                    return;
                }
                usersToUpdate.add(user);
                Group group = findGroup(user.getLogin());
                if (group == null) {
                    group = new Group(user.getLogin());
                    groups.add(group);
                    groupsToUpdate.add(group);
                    user.getGroups().add(group);
                    groupModel.fireTableDataChanged();
                }
                users.add(user);
                userModel.fireTableDataChanged();
                u = findUser(user.getLogin());
                if (u != null) {
                    usersToDelete.remove(u);
                }
            }
        }
    };
    createGroup = new AbstractAction() {

        /**
         */
        private static final long serialVersionUID = 7889274557650997117L;

        {
            putValue(SHORT_DESCRIPTION, plugin.getString("Action.CreateGroup"));
            putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/client/add_group.png")));
        }

        public void actionPerformed(ActionEvent e) {
            String string = JOptionPane.showInputDialog(plugin.getString("Action.CreateGroup"));
            if (string != null) {
                if (findGroup(string) != null) {
                    JOptionPane.showMessageDialog(EditUsersDialog.this, MessageFormat.format(plugin.getString("Group.Exists"), string));
                    return;
                }
                Group g = findGroup(string);
                if (g != null)
                    groupsToDelete.remove(g);
                Group group = new Group(string);
                groups.add(group);
                groupsToUpdate.add(group);
                groupModel.fireTableDataChanged();
            }
        }
    };
    deleteGroup = new AbstractAction() {

        /**
         */
        private static final long serialVersionUID = 7889274557650997117L;

        {
            putValue(SHORT_DESCRIPTION, plugin.getString("Action.DeleteGroup"));
            putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/client/delete_group.png")));
        }

        public void actionPerformed(ActionEvent e) {
            Group group = getActiveGroup();
            if (group != null) {
                if ((groupsToDelete.indexOf(group.getName())) < 0)
                    groupsToDelete.add(group.getName());
                groups.remove(group);
                groupModel.fireTableDataChanged();
                groupsToUpdate.remove(group);
            }
        }
    };
    deleteUser = new AbstractAction() {

        /**
         */
        private static final long serialVersionUID = 7889274557650997117L;

        {
            putValue(SHORT_DESCRIPTION, plugin.getString("Action.DeleteUser"));
            putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/com/ramussoft/client/delete_user.png")));
        }

        public void actionPerformed(ActionEvent e) {
            User user = getActiveUser();
            if (user != null) {
                if ((usersToDelete.indexOf(user.getLogin())) < 0)
                    usersToDelete.add(user.getLogin());
                users.remove(user);
                usersToUpdate.remove(user);
                userModel.fireTableDataChanged();
            }
        }
    };
}
Also used : ImageIcon(javax.swing.ImageIcon) Group(com.ramussoft.net.common.Group) User(com.ramussoft.net.common.User) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 8 with Group

use of com.ramussoft.net.common.Group in project ramus by Vitaliy-Yakovchuk.

the class TcpLightClient method start.

protected void start(final String[] args) throws Exception {
    if (args.length < 2) {
        System.err.println("Usage java -jar ... url ..., for example: java -jar my.jar localhost 38617 ");
        return;
    }
    try {
        String lookAndFeel = Options.getString("LookAndFeel");
        if (lookAndFeel != null)
            UIManager.setLookAndFeel(lookAndFeel);
        else {
            if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(UIManager.getSystemLookAndFeelClassName()))
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            else
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        UIManager.put("swing.boldMetal", Boolean.FALSE);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    StandardAttributesPlugin.setDefaultDisableAutoupdate(true);
    this.host = args[0];
    this.port = args[1];
    try {
        final PrintStream old = System.err;
        System.setErr(new PrintStream(new OutputStream() {

            FileOutputStream fos = null;

            private boolean err = false;

            @Override
            public void write(final int b) throws IOException {
                getFos();
                if (!err)
                    fos.write(b);
                old.write(b);
            }

            private FileOutputStream getFos() throws IOException {
                if (fos == null) {
                    try {
                        System.out.println("Getting calendar");
                        final Calendar c = Calendar.getInstance();
                        System.out.println("Getting options path");
                        String name = System.getProperty("user.home");
                        if (!name.equals(File.separator))
                            name += File.separator;
                        name += ".ramus" + File.separator + "log";
                        System.out.println("Creating dir: " + name);
                        new File(name).mkdirs();
                        name += File.separator + c.get(Calendar.YEAR) + "_" + c.get(Calendar.MONTH) + "_" + c.get(Calendar.DAY_OF_MONTH) + "_" + c.get(Calendar.HOUR_OF_DAY) + "_" + c.get(Calendar.MINUTE) + "_" + c.get(Calendar.SECOND) + "_" + c.get(Calendar.MILLISECOND) + "-client.log";
                        fos = new FileOutputStream(name);
                    } catch (final Exception e) {
                        err = true;
                        e.printStackTrace(System.out);
                    // throw e;
                    }
                }
                return fos;
            }
        }));
        connection = new TcpClientConnection(args[0], Integer.parseInt(args[1])) {

            private boolean exitShown = false;

            @Override
            protected void objectReaded(Object object) {
                if (tcpClientEngine != null)
                    tcpClientEngine.call((EvenstHolder) object);
            }

            @Override
            protected void showDialogEndExit(String message) {
                if (exitShown)
                    return;
                exitShown = true;
                System.err.println("Connection lost");
                // JOptionPane.showMessageDialog(framework.getMainFrame(),
                // message);
                System.exit(1);
            }
        };
        connection.start();
        Boolean canLogin = (Boolean) connection.invoke("canLogin", new Object[] {});
        if (!canLogin) {
            ResourceBundle bundle = ResourceBundle.getBundle("com.ramussoft.client.client");
            JOptionPane.showMessageDialog(null, bundle.getString("Message.ServerBusy"));
            System.exit(1);
            return;
        }
        final JXLoginFrame frame = JXLoginPane.showLoginFrame(new LoginService() {

            @Override
            public boolean authenticate(String name, char[] passwordChars, String server) throws Exception {
                String password = new String(passwordChars);
                try {
                    sessionId = (Long) connection.invoke("login", new Object[] { name, password });
                    if ((sessionId == null) || (sessionId.longValue() < 0l)) {
                        return false;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw e;
                }
                return sessionId != null;
            }

            @Override
            public void cancelAuthentication() {
                System.exit(0);
            }
        });
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/ramussoft/gui/application.png")));
        frame.setVisible(true);
        frame.addPropertyChangeListener("status", new PropertyChangeListener() {

            private boolean run = false;

            {
                Thread t = new Thread() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(120000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        if (!run)
                            System.exit(0);
                    }
                };
                t.start();
            }

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                Status status = frame.getStatus();
                if ((status.equals(Status.CANCELLED)) || (status.equals(Status.NOT_STARTED)) || (status.equals(Status.FAILED)) || (status.equals(Status.IN_PROGRESS))) {
                    return;
                }
                if (run)
                    return;
                run = true;
                userProvider = (UserProvider) createDeligate(UserProvider.class);
                if (season) {
                    boolean exit = true;
                    for (Group g : getMe().getGroups()) {
                        if (("admin".equals(g.getName())) || ("season".equals(g.getName()))) {
                            exit = false;
                        }
                    }
                    if (exit) {
                        JOptionPane.showMessageDialog(null, "Тільки користувач групи season або admin може працювати з системою планування");
                        System.exit(5);
                        return;
                    }
                }
                rules = (AccessRules) createDeligate(AccessRules.class);
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        TcpLightClient.this.run(args);
                    }
                });
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, "Неможливо з’єднатись з сервером, дивіться log-файл для деталей " + e.getLocalizedMessage());
        System.exit(1);
    }
}
Also used : Group(com.ramussoft.net.common.Group) PropertyChangeListener(java.beans.PropertyChangeListener) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) JXLoginFrame(org.jdesktop.swingx.JXLoginPane.JXLoginFrame) UserProvider(com.ramussoft.net.common.UserProvider) Status(org.jdesktop.swingx.JXLoginPane.Status) PrintStream(java.io.PrintStream) PropertyChangeEvent(java.beans.PropertyChangeEvent) Calendar(java.util.Calendar) IOException(java.io.IOException) LoginService(org.jdesktop.swingx.auth.LoginService) FileOutputStream(java.io.FileOutputStream) AccessRules(com.ramussoft.common.AccessRules) ResourceBundle(java.util.ResourceBundle) File(java.io.File)

Example 9 with Group

use of com.ramussoft.net.common.Group in project ramus by Vitaliy-Yakovchuk.

the class RamusService method login.

@Override
public long login(String login, String password) {
    if (!Metadata.CORPORATE) {
        if (server.getConnectionsCount() >= 3)
            return -1l;
    } else {
        int cc = ServerConnection.getConnectionCount(EngineFactory.getPropeties());
        if (cc >= 0) {
            if (server.getConnectionsCount() >= cc)
                return -1l;
        }
    }
    User user = userFactory.getUser(login);
    if (user == null)
        return -1l;
    if (!user.getPassword().equals(password))
        user = null;
    if (user == null)
        return -1l;
    this.user = user;
    setLogin(login);
    for (Group group : user.getGroups()) {
        if (group.getName().equals("admin")) {
            userFactoryClient.setAdmin(true);
            break;
        }
    }
    return 1l;
}
Also used : Group(com.ramussoft.net.common.Group) User(com.ramussoft.net.common.User)

Example 10 with Group

use of com.ramussoft.net.common.Group in project ramus by Vitaliy-Yakovchuk.

the class ServerAccessRules method isHasAccess.

private boolean isHasAccess(long qualifierId) {
    boolean admin = isAdmin();
    if (admin)
        return true;
    if (qualifierId == -1)
        return false;
    User user = getUser();
    for (Group group : user.getGroups()) if (group.getName().equals("admin"))
        return true;
    else {
        for (Long long1 : group.getQualifierIds()) if (long1.longValue() == qualifierId)
            return true;
    }
    Qualifier qualifier = engine.getQualifier(qualifierId);
    if (qualifier == null)
        return admin;
    if (qualifier.isSystem()) {
        if (qualifier.getName().equals(StandardAttributesPlugin.QUALIFIERS_QUALIFIER))
            return admin;
        return true;
    }
    return false;
}
Also used : Group(com.ramussoft.net.common.Group) User(com.ramussoft.net.common.User) Qualifier(com.ramussoft.common.Qualifier)

Aggregations

Group (com.ramussoft.net.common.Group)11 User (com.ramussoft.net.common.User)7 AccessRules (com.ramussoft.common.AccessRules)1 Qualifier (com.ramussoft.common.Qualifier)1 UserProvider (com.ramussoft.net.common.UserProvider)1 ActionEvent (java.awt.event.ActionEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 ResultSet (java.sql.ResultSet)1 Calendar (java.util.Calendar)1 ResourceBundle (java.util.ResourceBundle)1 AbstractAction (javax.swing.AbstractAction)1 ImageIcon (javax.swing.ImageIcon)1 AbstractTableModel (javax.swing.table.AbstractTableModel)1 GrantedAuthority (org.acegisecurity.GrantedAuthority)1