Package org.nemesis.forum.proxy

Source Code of org.nemesis.forum.proxy.ProfileManagerProxy

/*
* NEMESIS-FORUM.
* Copyright (C) 2002  David Laurent(lithium2@free.fr). All rights reserved.
*
* Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
*
* Copyright (C) 2001 Yasna.com. All rights reserved.
*
* Copyright (C) 2000 CoolServlets.com. All rights reserved.
*
* NEMESIS-FORUM. is free software; you can redistribute it and/or
* modify it under the terms of the Apache Software License, Version 1.1,
* or (at your option) any later version.
*
* NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
* application are parts of NEMESIS-FORUM and are distributed under
* same terms of licence.
*
*
* NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
* and software developed by CoolServlets.com (http://www.coolservlets.com).
* and software developed by Yasna.com (http://www.yasna.com).
*
*/
package org.nemesis.forum.proxy;

import java.util.Iterator;

import org.nemesis.forum.Authorization;
import org.nemesis.forum.Forum;
import org.nemesis.forum.ForumPermissions;
import org.nemesis.forum.Group;
import org.nemesis.forum.ProfileManager;
import org.nemesis.forum.User;
import org.nemesis.forum.config.Constants;
import org.nemesis.forum.exception.GroupAlreadyExistsException;
import org.nemesis.forum.exception.GroupNotFoundException;
import org.nemesis.forum.exception.UnauthorizedException;
import org.nemesis.forum.exception.UserAlreadyExistsException;
import org.nemesis.forum.exception.UserNotFoundException;
/**
* Protection proxy for the ProfileManager class. It restricts access to
* protected methods by throwing UnauthorizedExceptions when necessary.
*
* @see ProfileManager
*/
public class ProfileManagerProxy implements ProfileManager {

  private ProfileManager profileManager;
  private Authorization authorization;
  private ForumPermissions permissions;

  /**
   * Creates a new ProfileManagerProxy.
   */
  public ProfileManagerProxy(
    ProfileManager profileManager,
    Authorization authorization,
    ForumPermissions permissions) {
    this.profileManager = profileManager;
    this.authorization = authorization;
    this.permissions = permissions;
  }

  public User createUser(String username, String password, String email)
    throws UserAlreadyExistsException {
    return profileManager.createUser(username, password, email);
  }

  public Group createGroup(String name)
    throws UnauthorizedException, GroupAlreadyExistsException {
    if (permissions.get(Constants.SYSTEM_ADMIN)) {
      Group group = profileManager.createGroup(name);
      return new GroupProxy(group, authorization, permissions);
    } else {
      throw new UnauthorizedException();
    }
  }

  public User getUser(int userID) throws UserNotFoundException {
    User user = profileManager.getUser(userID);
    ForumPermissions userPermissions = user.getPermissions(authorization);
    ForumPermissions newPermissions =
      new ForumPermissions(permissions, userPermissions);
    return new UserProxy(user, authorization, newPermissions);
  }

  public User getUser(String username) throws UserNotFoundException {
    User user = profileManager.getUser(username);
    ForumPermissions userPermissions = user.getPermissions(authorization);
    ForumPermissions newPermissions =
      new ForumPermissions(permissions, userPermissions);
    return new UserProxy(user, authorization, newPermissions);
  }

  public User getAnonymousUser() {
    return profileManager.getAnonymousUser();
  }

  public User getSpecialUser() {
    return profileManager.getSpecialUser();
  }

  public Group getGroup(int groupID) throws GroupNotFoundException {
    Group group = profileManager.getGroup(groupID);
    ForumPermissions groupPermissions = group.getPermissions(authorization);
    ForumPermissions newPermissions =
      new ForumPermissions(permissions, groupPermissions);
    return new GroupProxy(group, authorization, newPermissions);
  }

  public Group getGroup(String name) throws GroupNotFoundException {
    Group group = profileManager.getGroup(name);
    ForumPermissions groupPermissions = group.getPermissions(authorization);
    ForumPermissions newPermissions =
      new ForumPermissions(permissions, groupPermissions);
    return new GroupProxy(group, authorization, newPermissions);
  }

  public void deleteUser(User user) throws UnauthorizedException {
    if (permissions.get(Constants.SYSTEM_ADMIN)) {
      profileManager.deleteUser(user);
    } else {
      throw new UnauthorizedException();
    }
  }

  public void deleteGroup(Group group) throws UnauthorizedException {
    if (permissions.get(Constants.SYSTEM_ADMIN)) {
      profileManager.deleteGroup(group);
    } else {
      throw new UnauthorizedException();
    }
  }

  public int getUserCount() {
    return profileManager.getUserCount();
  }

  public int getGroupCount() {
    return profileManager.getGroupCount();
  }

  public Iterator users() {
    Iterator iterator = profileManager.users();
    return new UserIteratorProxy(iterator, authorization, permissions);
  }

  public Iterator users(int startIndex, int numResults) {
    Iterator iterator = profileManager.users(startIndex, numResults);
    return new UserIteratorProxy(iterator, authorization, permissions);
  }

  public Iterator groups() {
    Iterator iterator = profileManager.groups();
    return new GroupIteratorProxy(iterator, authorization, permissions);
  }

  public Iterator groups(int startIndex, int numResults) {
    Iterator iterator = profileManager.groups(startIndex, numResults);
    return new GroupIteratorProxy(iterator, authorization, permissions);
  }

  public int userMessageCount(User user, Forum forum) {
    return profileManager.userMessageCount(user, forum);
  }

  public Iterator userMessages(User user, Forum forum) {
    Iterator iterator = profileManager.userMessages(user, forum);
    return new MessageIteratorProxy(iterator, authorization, permissions);
  }
}
TOP

Related Classes of org.nemesis.forum.proxy.ProfileManagerProxy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.