Search in sources :

Example 1 with PermissionManager

use of net.sf.kraken.permissions.PermissionManager in project Openfire by igniterealtime.

the class BaseTransport method setup.

/**
     * Set up the transport instance.
     *
     * @param type Type of the transport.
     * @param description Description of the transport (for Disco).
     * @param sessionRouter The session router.
     */
public void setup(TransportType type, String description, TransportSessionRouter sessionRouter) {
    // TODO: Make this more generic.
    if (type.equals(TransportType.xmpp) && JiveGlobals.getProperty("plugin.gateway.xmpp.overridename") != null) {
        description = JiveGlobals.getProperty("plugin.gateway.xmpp.overridename");
    }
    this.description = description;
    this.transportType = type;
    this.sessionRouter = sessionRouter;
    permissionManager = new PermissionManager(transportType);
}
Also used : PermissionManager(net.sf.kraken.permissions.PermissionManager)

Example 2 with PermissionManager

use of net.sf.kraken.permissions.PermissionManager in project Openfire by igniterealtime.

the class ConfigManager method savePermissions.

/**
     * Saves permissions settings from web interface.
     *
     * We validate all of the groups before actually adding them.
     *
     * @param transportName Name of the transport to have it's options saved (type of transport)
     * @param overallSetting The general "all(1), some(2), or none(3)" setting for the permissions.
     * @param users List of specific users that have access.
     * @param groups List of specific groups that have access.
     * @param strict Strict permissions associted with setting.
     * @return List of usernames and groups (@ preceded) that were rejected.
     */
public List<String> savePermissions(String transportName, Integer overallSetting, List<String> users, List<String> groups, Boolean strict) {
    JiveGlobals.setProperty("plugin.gateway." + transportName + ".registration", overallSetting.toString());
    JiveGlobals.setProperty("plugin.gateway." + transportName + ".registrationstrict", strict ? "true" : "false");
    PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName));
    List<String> errorList = new ArrayList<String>();
    ArrayList<User> userList = new ArrayList<User>();
    UserManager userManager = UserManager.getInstance();
    for (String username : users) {
        if (username.matches("\\s*")) {
            continue;
        }
        try {
            if (username.contains("@")) {
                JID jid = new JID(username);
                if (!jid.getDomain().equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
                    throw new UserNotFoundException();
                }
                username = username.substring(0, username.indexOf("@"));
            }
            User user = userManager.getUser(username);
            if (user == null || user.getUsername() == null) {
                throw new UserNotFoundException();
            }
            userList.add(user);
        } catch (UserNotFoundException e) {
            Log.warn("User " + username + " not found while adding access rules.");
            errorList.add(username);
        }
    }
    permissionManager.storeUserList(userList);
    ArrayList<Group> groupList = new ArrayList<Group>();
    GroupManager groupManager = GroupManager.getInstance();
    for (String grpname : groups) {
        if (grpname.matches("\\s*")) {
            continue;
        }
        try {
            Group group = groupManager.getGroup(grpname);
            if (group == null || group.getName() == null) {
                throw new GroupNotFoundException();
            }
            groupList.add(group);
        } catch (GroupNotFoundException e) {
            Log.warn("Group " + grpname + " not found while adding access rules.");
            errorList.add("@" + grpname);
        }
    }
    permissionManager.storeGroupList(groupList);
    return errorList;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) PermissionManager(net.sf.kraken.permissions.PermissionManager) ArrayList(java.util.ArrayList) GroupManager(org.jivesoftware.openfire.group.GroupManager) UserManager(org.jivesoftware.openfire.user.UserManager) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

PermissionManager (net.sf.kraken.permissions.PermissionManager)2 ArrayList (java.util.ArrayList)1 Group (org.jivesoftware.openfire.group.Group)1 GroupManager (org.jivesoftware.openfire.group.GroupManager)1 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)1 User (org.jivesoftware.openfire.user.User)1 UserManager (org.jivesoftware.openfire.user.UserManager)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 JID (org.xmpp.packet.JID)1