sourcecode

Java 프로그램에서 MariaDB에 액세스하려고 하면 암호가 올바르는데도 'access denied' 예외가 발생하는 이유는 무엇입니까?

codebag 2023. 8. 21. 21:15
반응형

Java 프로그램에서 MariaDB에 액세스하려고 하면 암호가 올바르는데도 'access denied' 예외가 발생하는 이유는 무엇입니까?

SQL 데이터베이스에 사용자 이름과 암호가 있는지 확인하기 위해 쿼리를 꺼내는 Java 프로그램을 작성하고 있습니다.내 코드는:

내 코드는:

public UserInfo getUserExists(final String userEmail) throws SQLException, ClassNotFoundException {

    if (!isBlank(userEmail)) {
        Connection conn;
        Statement stmt;

        try{
            Class.forName("org.mariadb.jdbc.Driver");
            System.out.println("Connecting to DB...");

            conn = DriverManager.getConnection("jdbc:mariadb://10.0.0.0:3306/mydb","myusername", "mypassword");

            System.out.println("Connected to DB successfully");
            System.out.println("querying if user is valid");

            stmt = conn.createStatement();

            ResultSet rs;
            rs = stmt.executeQuery("SELECT IF (EXISTS(select user_email, user_pass, meta_value from myorg_users left join myorg_usermeta on ( myorg_users.id = myorg_usermeta.user_id) where meta_value LIKE '%\"administrator\"%' and meta_key=\"myorg_capabilities\" AND user_email="+userEmail+"),1,0) AS result;");
            int result = 0;
            System.out.println(rs);

            while(rs.next()){
                result = Integer.parseInt(rs.getString("result"));
                System.out.println("result is " + result);
            }
            conn.close();
            if(result == 1){
                UserInfo SYSTEM_USER = new UserInfo.Builder(UserInfo.Username.valueOf("SYSTEM_USER")).withFirstName("System").withLastName("User").withEmail(userEmail).withUserId("sample").build();
                System.out.println(SYSTEM_USER);
                return SYSTEM_USER;
            }

        }
        catch(SQLException se){
            se.printStackTrace();
        }
        catch(Exception e){
            e.printStackTrace();
        }

    } else {
        throw new AuthenticationException("user does not exists in system");
    }
    System.out.println("executed new user exists");
    return null;
}

하지만 API를 실행하면 이 메시지가 표시되고 비밀번호/사용자 이름이 정확하다는 것을 알고 있습니다.

java.sql.SQLSyntaxErrorException: Access denied for user 'myusername'@'10.%' to database 'mydb'
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:163)
    at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:106)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1036)
    at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:490)
    at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:144)
    at org.mariadb.jdbc.Driver.connect(Driver.java:90)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at com.intuit.wasabi.authentication.impl.DefaultAuthentication.getUserExists(DefaultAuthentication.java:168)
    at com.intuit.wasabi.api.AuthenticationResource.getUserExists(AuthenticationResource.java:214)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:287)
    at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:277)
    at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:182)
    at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
    at com.intuit.autumn.web.WebFilter.doFilter(WebFilter.java:65)
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
    at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:119)
    at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:133)
    at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:130)
    at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:203)
    at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:130)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1676)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
    at org.eclipse.jetty.server.Server.handle(Server.java:518)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
    at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:246)
    at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: Access denied for user 'myusername'@'10.%' to database 'mydb'
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.authentication(AbstractConnectProtocol.java:787)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.handleConnectionPhases(AbstractConnectProtocol.java:713)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connect(AbstractConnectProtocol.java:402)
    at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1032)
    ... 59 more

무슨 일입니까?저는 이 쿼리를 DB에서 실행했고 MariaDB에서 작동합니다.Java에서 필요한 것을 수행할 수 없는 이유는 무엇입니까?

음, java는 제쳐두고, 당신은 당신의 db에 10.0.0.0에 접속할 것이 확실합니까? 저는 당신의 MariaDB가 루프백 인터페이스(127.0.0.1)에서 수신하도록 구성되어 있다고 추측할 수 있습니다. 그래서 만약 당신의 MariaDB가 다른 인터페이스를 수신하도록 구성되어 있지 않다면 당신은 연결 거부된 경우와 같은 경우를 얻을 수 있습니다.그래서 만약 당신이 phpmyadmin에서 그것을 할 수 있다고 확신한다면 나는 이것을 확인하기 시작할 것입니다(당신이 그것을 사용하고 있고 그것은 localhost를 통해 액세스될 수도 있다고 생각합니다).및 10.0.0.0은 가능한 IP가 아닙니다.

언급URL : https://stackoverflow.com/questions/59130477/why-does-my-attempt-to-access-a-mariadb-in-my-java-program-get-give-me-an-acces

반응형