Search in sources :

Example 11 with User

use of com.ramussoft.net.common.User 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 12 with User

use of com.ramussoft.net.common.User 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 13 with User

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

the class EngineConnection method getAccessRules.

public AccessRules getAccessRules(final User finalUser) {
    if (finalUser == null)
        return rules;
    IntegrityAccessorSuit suit = new IntegrityAccessorSuit();
    suit.addAccessRules(rules);
    suit.addAccessRules(new ServerAccessRules(engine, userFactory) {

        @Override
        public User getUser() {
            return finalUser;
        }
    });
    return suit;
}
Also used : IntegrityAccessorSuit(com.ramussoft.core.impl.IntegrityAccessorSuit) User(com.ramussoft.net.common.User) ServerAccessRules(com.ramussoft.server.ServerAccessRules)

Example 14 with User

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

the class ServerAccessRules method getUser.

public User getUser() {
    synchronized (lock) {
        String login = getLogin();
        User user = users.get(login);
        if (user != null)
            return user;
        user = userFactory.getUser(login);
        if (user != null)
            users.put(login, user);
        return user;
    }
}
Also used : User(com.ramussoft.net.common.User)

Example 15 with User

use of com.ramussoft.net.common.User 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

User (com.ramussoft.net.common.User)17 Group (com.ramussoft.net.common.Group)7 ResultSet (java.sql.ResultSet)3 JDBCCallback (com.ramussoft.jdbc.JDBCCallback)2 ActionEvent (java.awt.event.ActionEvent)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractAction (javax.swing.AbstractAction)2 AccessRules (com.ramussoft.common.AccessRules)1 Engine (com.ramussoft.common.Engine)1 PluginFactory (com.ramussoft.common.PluginFactory)1 PluginProvider (com.ramussoft.common.PluginProvider)1 Qualifier (com.ramussoft.common.Qualifier)1 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)1 IntegrityAccessorSuit (com.ramussoft.core.impl.IntegrityAccessorSuit)1 PersistentFactory (com.ramussoft.core.persistent.PersistentFactory)1 AbstractGUIPluginFactory (com.ramussoft.gui.common.AbstractGUIPluginFactory)1 ActionDescriptor (com.ramussoft.gui.common.ActionDescriptor)1