⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oc4jjaasmanager.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
字号:
/*
* @author                        : Neelesh
* @Version                       : 1.0
*
* Development Environment        : Oracle9i JDeveloper
* Name of the File               : OC4JJAASManager.java
* Creation/Modification History  :
*
* Neelesh   10-Dec-2002      Created
*
*/

package oracle.otnsamples.vsm;
import com.evermind.security.User;
import com.evermind.security.Group;
import java.util.*;
import oracle.security.jazn.oc4j.JAZNUserManager;
import javax.servlet.ServletContext;
/**
 * This class implements the JAASManager interface, which has methods for
 * adding/removing users with roles to the JAAS provider system.
 * The implementation for these methods adds user and role data to
 * jazn-data.xml, the repository for user name, password and roles.
 * The implementation can be changed depending on the repository.eg LDAP,RDBMS etc
 * 
 */

public class OC4JJAASManager implements JAASManager {

  // user manager instance
  private JAZNUserManager userMgr;
  // servlet context, the user manager is stored in the context by OC4J
  private ServletContext ctx;
  /**
   * This method casts the initParam to ServletContext and extracts 
   * the JAZNUserManager instance from this context
   * @param initParam
   */
  public synchronized void init(Object initParam){
    ctx=(ServletContext)initParam;
    userMgr=(JAZNUserManager)ctx.getAttribute("user.manager");
  }

  /**
   * Adds a user with userName password to jazn-data.xml, simultaneously adding
   * the user to the specified role.
   * @param userName
   * @param password
   * @param role
   * @throws UserException if the user cannot be added to XML file
   */
  public synchronized void addUser(String userName,String password,String role) throws UserException{
    try {
        User user=userMgr.createUser(userName,password);
        Group group= userMgr.getGroup(role);
        if(group!=null){
          user.addToGroup(group);
        }
    } catch (Exception ex){
      throw new UserException(ex.getMessage());
    } 
  }
  /**
   * Removes the user information from jazn-data.xml file
   * @param userName
   * @throws UserException if the data could not be removed from the xml file
   */
  public synchronized void  dropUser(String userName) throws UserException{
    try {
      if(userMgr.getUser(userName)!=null){
        User usr =userMgr.getUser(userName);
        Set grps =usr.getGroups();
        for(Iterator i=grps.iterator();i.hasNext();){
          Group grp = (Group)i.next();
          usr.removeFromGroup(grp);
        }
        userMgr.remove(usr);
      }
    } catch (Exception ex){
      throw new UserException(ex.getMessage());
    }    
  }
  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -