2016-11-30 12 views
0

Apache Shiroを使用してユーザーを認証するためにデータベースに接続しようとしています。このタスクを実行するためにサーブレットがJavaクラスを呼び出しています。今すぐ正常に認証された場合、単に文字列を変更しています。私は、多くの異なる接続方法を試みてきた:データプール、JTDS、Microsoft SQL ServerのJDBCを、そしてすべては私にエラーを与える:Apache Shiroユーザーの認証中にSQLエラーが発生しました

SQL error while authenticating user [user1]

私のログファイルにも、このエラーが表示さ:

Warning: RAR5058: Error while Resizing pool SQLS1-TestBilling. Exception : Connection could not be allocated because: The TCP/IP connection to the host SQLS1, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

私ができる午前サーブレットのTestBilling接続プールをうまく使ってプールに問題はないと思っていますが、iniファイル宣言を使用してSQLを使用できないようです。私が行方不明、忘れていること、間違っていることがありますか?

GetAuthServlet.java:

package com.phmc.shiro5web; 

import java.io.IOException; 
import java.io.PrintWriter; 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

public class GetAuthServlet extends HttpServlet { 
@Override 
protected void doGet(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException { 
     response.setContentType("text/html;charset=UTF-8"); 
     PrintWriter out = response.getWriter(); 
     out.println("<!DOCTYPE html>"); 
     out.println("<html>"); 
     out.println("<head>"); 
     out.println("<title>Auth</title>");    
     out.println("</head>"); 
     out.println("<body>"); 
     AuthenticationClass au = new AuthenticationClass(); 

     String b = ""; 
     b = au.isAuthenticated("mmarino", "test"); 
     out.println(b); 
     out.println("</body>"); 
     out.println("</html>"); 
} 

AuthenticationClass.java:

package com.phmc.shiro5web; 
import org.apache.shiro.SecurityUtils; 
import org.apache.shiro.authc.*; 
import org.apache.shiro.config.IniSecurityManagerFactory; 
import org.apache.shiro.mgt.SecurityManager; 
import org.apache.shiro.subject.Subject; 
import org.apache.shiro.util.Factory; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

public class AuthenticationClass { 
    private static final transient Logger log = LoggerFactory.getLogger(Authentication.class); 



    String isAuthenticated(String username, String password){ 
     Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); 
     SecurityManager securityManager = factory.getInstance(); 
     SecurityUtils.setSecurityManager(securityManager); 
     Subject currentUser = SecurityUtils.getSubject(); 
     String b = "fail"; 
     log.info("Test"); 
     try{ 
      if (!currentUser.isAuthenticated()) { 

       UsernamePasswordToken token = new UsernamePasswordToken("mmarino", "test") ; 
       token.setRememberMe(true); 
       try { 
        currentUser.login(token); 
        b = "Success"; 
       }catch (UnknownAccountException uae) { 
        log.info("There is no user with username of " + token.getPrincipal()); 
       } 
      } 
     }catch(Exception e){ 
      b = e.toString(); 
     } 
     ) 
     return b; 
    } 

} 

Shiro.ini:

ここ

は、関連するファイルがあります

[main] 
ds = org.apache.shiro.jndi.JndiObjectFactory 
ds.resourceName = jdbc/TestBilling 


jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm 
jdbcRealm.dataSource = $ds 
jdbcRealm.permissionsLookupEnabled = true 
jdbcRealm.authenticationQuery = SELECT theuser FROM UserList 
securityManager.realm = $jdbcRealm 

私も試してみました: jdbcRealm.authenticationQuery = userからFROM UserListを選択してくださいpasswordList =?

最後の2行目のShiro.iniファイル。

+0

接続プールの大きさはどれくらいですか? –

+0

@BrianDemers「どのくらいの大きさ」を意味しますか?今はまだテストモードに入っていますので、多くのトラフィックは得られません。 –

+0

右ですが、プールが本当に小さく、複数の接続がある場合(1つはShiroから、もう1つはサーブレットから)、それほど多くはかかりません。また、リクエストごとに新しいSecurityManagerを作成しています。 私はShiro [web sample](https://github.com/apache/shiro/tree/master/samples/web)を見てみるか、[私たちのapp doc ](http://shiro.apache.org/web.html)。私は出発点として、Shiroサーブレットフィルタの設定と作業を済ませたら、カスタムロジックを追加するほうがはるかに簡単になることをお勧めします。 –

答えて

0

を試してみてください。

0

は、基本的なSQLエラーを示したことが見られることから、他のエラーを保っていたのlog4jが破損する原因と私はキャッチしていない追加のエラーがあったようです

# DataSource config 
ds = org.apache.shiro.jndi.JndiObjectFactory 
ds.requiredType = javax.sql.DataSource 
ds.resourceName = jdbc/TestBilling 
+0

私は大きな期待を持っていましたが、この変更でも同じエラーが発生しています。 :-( –

関連する問題