title: how to configure a shiro Realm to connect to an oracle database within a struts2 application
body: <p>I have been working with shiro (ki, jsecurity) now for a few days and have been able to create a test application.  I am working with struts2, off JBoss.  I have been able create a shiro.ini file with a few hard-coded users, and i have gotten that to work. It seems like the API within JAVA is extremely easy to get a grasp of, so integrating shiro to my application and making it functional hasnt been the real problem.  My real issue is that i have not been able to find any form of documentation on how to create/tie a REALM to an oracle database using this set up.  I have found several examples and tried aimlessly to adapt it to my situation.  but i have been unable. </p>
  
  <p>I have an oracle database with a USERS table, it simply holds a username, password, and role.  If i am able to make the connection, it seems as though it should simply fit right into my current login/logoff app.</p>
  
  <p>I added the following lines to my web.xml</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;ShiroFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.apache.shiro.web.servlet.ShiroFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
          &lt;filter-mapping&gt;
      &lt;filter-name&gt;ShiroFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt; 
      &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt; 
      &lt;dispatcher&gt;INCLUDE&lt;/dispatcher&gt; 
      &lt;dispatcher&gt;ERROR&lt;/dispatcher&gt;
  &lt;/filter-mapping&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.apache.shiro.web.env.EnvironmentLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>I then added shiro.ini to my WEB-INF:</p>
  
  <pre><code>[main]
  
  [users]
  bruins = boston, admin, super, worker
  rangers = newyork, super, worker
  leafs = toronto, worker
  
  [urls]
  /authoring/logout = logout
  /authoring/** = authc
  </code></pre>
  
  <p>after that it was simply calling the java code from within my loginAction.java:</p>
  
  <pre><code>Factory&lt;SecurityManager&gt; factory = new IniSecurityManagerFactory("classpath:shiro.ini");
  SecurityManager securityManager = factory.getInstance();   
  SecurityUtils.setSecurityManager(securityManager);   
  Subject currentUser = SecurityUtils.getSubject();   
  UsernamePasswordToken token = new UsernamePasswordToken(this.username, this.password);
  try {   
      currentUser.login(token);   
      Session session = currentUser.getSession();   
      session.setAttribute("user", this.username);   
  } catch (UnknownAccountException uae) {   
    ... 
  } catch (IncorrectCredentialsException iae) {   
   ...
  } catch (LockedAccountException lae) {   
   ... 
  } catch (AuthenticationException ae) {   
    ...         
  } catch (Exception e) {   
   ...
  }   
  ActionMessages messages = new ActionMessages();
  if (currentUser.isAuthenticated()) {   
      System.out.println("user is authenticated!!!!!");
  
      if (currentUser.hasRole("admin")){
          System.out.println(this.username + " can access admin functions");
      }
      if(currentUser.hasRole("super")){
          System.out.println(this.username + " can access supervisor functions");
      }
      if(currentUser.hasRole("worker")){
          System.out.println(this.username + " can only perform worker functions");
      }
      addActionMessage(getText("success.valid.user", this.username));
      return SUCCESS;
  } else {   
      System.out.println("user was not authenticated!!!!!!");
      addActionError(getText("error.login"));
      return ERROR;
  }
  </code></pre>
  
  <p>so all in all, i have the application working with hard-coded users:  my question is what is the best way for me to set up the REALM to connect to my oracle database?  I have seen it online done in several different ways, and i have been unable to adapt any of them to my set up, and i would love to get this going to that i can continue to familiarize myself with the API.</p>
  
  <p>thanks - John</p>