8 Replies Latest reply on Mar 21, 2019 3:26 AM by boa-ig

    AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)

    boa-ig

      Good day!

       

      Can you please tell me how to access the EJB inside public void paint (Graphics g, ....?

       

      public class olTabbedPaneUI extends BasicTabbedPaneUI {
      ...
      
      AuthenticationConfiguration common = AuthenticationConfiguration.empty();
      AuthenticationConfiguration igAuthUser = common.useName("ig").usePassword("xxxx");
      final AuthenticationContext authCtx1 = AuthenticationContext.empty().with(MatchRule.ALL, igAuthUser);
      
      authCtx1.   ?????
      
              public void paint(Graphics g, JComponent JTabbedPane) {
                   try {
      
      
                       Context context33 = getInitialContext();
           
                       EJBAccessRemote ejb332222 = (EJBAccessRemote) context33
                            .lookup("ejb:/ejb-security-jaas/EJBAccess!org.jboss.as.quickstarts.ejb_security_jaas.EJBAccessRemote?stateful");
                       
                       System.out.println("Version = "+ejb332222.getVersion());
                    } catch (NamingException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
               }

      ....

       

      I get an error if the AuthenticationContext is out public class olTabbedPaneUI extends BasicTabbedPaneUI { :

       

      Caused by: org.wildfly.security.auth.AuthenticationException: JBREM000308: Authentication failed (no mechanisms left), tried: (none)
        • 1. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
          dlofthouse

          Maybe take my question with a large pinch of salt as I am not a UI developer, however is this really the best place for adding remote network calls?

           

          Over the years I have used a number of UIs that end up offering a bad experience when they become unresponsive as they make remote calls, I have always had the impression they would be better if the UI handling was independent from the network calls so at least it could be responsive even if the network call is slow.

           

          For the example code you have pasted have you tried running the code in a stand alone client without a UI to verify the low level calls work?

          • 2. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
            boa-ig

            In the process of drawing a map(geographic information system (GIS)) on the screen, I have to go to the database for information, uploading data to the intermediate storage requires large resources.

            • 3. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
              boa-ig

              I try various connection options

               

              public class RemoteClientPrg2 {
              
              
              public static void main(String[] args) throws Exception {
              /*
              JFrame f = new JFrame("panel");
              JLabel l = new JLabel("panel label");
              olTabbedPaneUI Заставка = new olTabbedPaneUI();
              JTabbedPane tabbedPane = new JTabbedPane();
              tabbedPane.setUI(Заставка);
              JPanel p = new JPanel();
              p.add(tabbedPane);
              f.add(p); 
                      f.setSize(700, 700); 
                      f.show(); */
              
              EJBAccessRemote eJB_OlUtilRemote = getEJB_OlUtil("ig", "XXXX");
              
              
              try {
              System.out.println("Внешний callable = "+eJB_OlUtilRemote.getVersion());
              } catch (Exception e) {
              System.out.println("Уровень 0  -  Внешний callable ОШИБКА кол-во строк = "+e.getStackTrace().length);
              // TODO Auto-generated catch block
              // e.printStackTrace();
              }
              System.out.println("\n\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
              }
              
              
              public static EJBAccessRemote getEJB_OlUtil(String uName, String uPass) {
              
              
              AuthenticationConfiguration common = AuthenticationConfiguration.empty();
              AuthenticationConfiguration igAuthUser = common.useName(uName).usePassword(uPass);
              final AuthenticationContext authCtx1 = AuthenticationContext.empty().with(MatchRule.ALL, igAuthUser);
              
              
              // create a callable that invokes an EJB
              Callable<EJBAccessRemote> callable = () -> {
              //final Hashtable<String, String> jndiProperties = new Hashtable<>();
              Context context = getInitialContext();
              //System.out.println("\n\n\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n");
              //System.out.println("ejb:/IGEJB/EJBAccess!  Start=" + EJBAccessRemote.class.getName());
              EJBAccessRemote ejb33 = (EJBAccessRemote) context
              .lookup("ejb:/ejb-security-jaas/EJBAccess!org.jboss.as.quickstarts.ejb_security_jaas.EJBAccessRemote?stateful");
              System.out.println("Уровень 1  -  Внутренний callable = "+ejb33.getVersion());
              
              
              
              
              SimpClass simpClass =  new SimpClass();
              
              JFrame f = new JFrame("panel");
              JLabel l = new JLabel("panel label");
              olTabbedPaneUI Заставка = new olTabbedPaneUI(ejb33);
              JTabbedPane tabbedPane = new JTabbedPane();
              tabbedPane.setUI(Заставка);
              JPanel p = new JPanel();
              p.add(l);
              p.add(tabbedPane);
              f.add(p); 
                      f.setSize(700, 700); 
                      f.show(true);; 
              
              AuthenticationConfiguration common22 = AuthenticationConfiguration.empty();
              AuthenticationConfiguration igAuthUser22 = common22.useName(uName).usePassword(uPass);
              final AuthenticationContext authCtx122 = AuthenticationContext.empty().with(MatchRule.ALL, igAuthUser22);
              
              Callable<String> callable2 = () -> {
              //final Hashtable<String, String> jndiProperties2 = new Hashtable<>();
              Context context22 = getInitialContext();
              //System.out.println("\n\n\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n");
              System.out.println("\nCallable может возвращать параметр, а также встроенный exception\n");
              EJBAccessRemote ejb332222 = (EJBAccessRemote) context22
              .lookup("ejb:/ejb-security-jaas/EJBAccess!org.jboss.as.quickstarts.ejb_security_jaas.EJBAccessRemote?stateful");
              System.out.println("Уровень 2  -  Внутренний callable = "+ejb332222.getVersion());
              return "ejb332222";
              };
              authCtx1.runCallable(callable2);
              
              Runnable runnable = () -> {
              try {
              //final Hashtable<String, String> jndiProperties2 = new Hashtable<>();
              Context context33 = getInitialContext();
              System.out.println("\nRunnable параметр не возвращает, нет встроенного exception\n");
              EJBAccessRemote ejb332222 = (EJBAccessRemote) context33
              .lookup("ejb:/ejb-security-jaas/EJBAccess!org.jboss.as.quickstarts.ejb_security_jaas.EJBAccessRemote?stateful");
              System.out.println("Уровень 2  -  Внутренний runnable = "+ejb332222.getVersion());
              } catch (NamingException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              }
              
              };
              
              authCtx1.run(runnable);
              
              
              
              
              
              return ejb33;
              
              };
              
              
              try {
              return authCtx1.runCallable(callable);
              } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              return null;
              }
              };
              
              
              static final Context getInitialContext()
              // в этом случае не нужен файл jndi.properties
              throws javax.naming.NamingException {
              Hashtable environment = new Hashtable();
              environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
              // environment.put(Context.URL_PKG_PREFIXES,
              // "org.jboss.naming:org.jnp.interfaces");
              // if (IGConstants.PROVIDER_URL != null)// если Java 7,8 то некоторые системные
              // параметры блокируются в JNLP
              // поэтому передаем как параметры программы
              environment.put(Context.PROVIDER_URL, "remote+http://localhost:8080");
              // IG.IGClient.IGMessage.showMessage(null,"jnp://localhost:1099");
              // environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");
              
              
              //System.out.println("InitialContext : PROVIDER_URL=" + "remote+http://localhost:8080");
              return new InitialContext(environment);
              }
              
              
              }
              
              • 4. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
                boa-ig

                translate the running system from JBoss AS 6.1 to WildFly 15

                • 5. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
                  boa-ig

                  How to work with classes (objects) that automatically create a thread?

                   

                  sorry for my English 

                  • 6. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
                    dlofthouse

                    In general the AuthenticationContext.run() call is correct, you just need to make sure this is called in the running thread and not just an initiating Thread.

                    • 7. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
                      boa-ig

                      Tell me please.

                      Can I do authorization inside the thread?

                       

                       

                      public void paint(Graphics g, JComponent JTabbedPane) {
                      
                      AuthenticationConfiguration common22 = AuthenticationConfiguration.empty();
                      AuthenticationConfiguration igAuthUser22 = common22.useName("IG").usePassword("XXXX");
                      final AuthenticationContext authCtx122 = AuthenticationContext.empty().with(MatchRule.ALL, igAuthUser22);
                      ?????????
                              try {
                      Context context22 = getInitialContext();
                      EJBAccessRemote ejb332222 = (EJBAccessRemote) context22
                      .lookup("ejb:/ejb-security-jaas/EJBAccess!org.jboss.as.quickstarts.ejb_security_jaas.EJBAccessRemote?stateful");
                      System.out.println("Level 2  -  = "+ejb332222.getVersion());
                      } catch (NamingException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                      }
                             
                                      Graphics2D g2 = (Graphics2D) g;
                      • 8. Re: AuthenticationContext...  paint(Graphics g... .lookup("ejb:/ ?  (JBREM000308)
                        boa-ig
                        AuthenticationConfiguration common = AuthenticationConfiguration.empty();
                              AuthenticationConfiguration igAuthUser =
                              common.useName(edUserName.getText()).usePassword(String.valueOf(edPassword.getPassword()));
                              final AuthenticationContext authCtx1 = AuthenticationContext.empty().with(MatchRule.ALL, igAuthUser);
                              AuthenticationContext.getContextManager().setThreadDefault(authCtx1);
                              AuthenticationContext.getContextManager().setGlobalDefault(authCtx1);