How to add Authentication correctly in Windows 7?

asked 2015-02-09 04:29:54 -0800

almcalle gravatar image

I'm trying to use the config interface using Java and Windows 7. Inside the code I call:

languageTag="en"
Map<String, Object> configMap = configClient.getConfig(languageTag);

The config client has been configured and a AuthListener has been registered:

authListener = new SrpAnonymousKeyListener();


        logger.info("Registering an AuthListener");





        Status status = bus.registerAuthListener("ALLJOYN_ECDHE_PSK", authListener,"KeyStore");

        logger.debug(TAG, "BusAttachment.registerAuthListener status = " + status);
        if (status ==Status.OK){

            logger.info("AuthListener is OK");



    }


final ConfigStore configStore = getConfigStore();


        serviceHelper.startAboutServer((short) 1080, configStore);


        ConfigService configService = ConfigServiceImpl.getInstance();













    ConfigChangeListener configChangeListener = new ConfigChangeListener()
    {

        @Override
        public void onConfigChanged(Map<String, Variant> arg0,
                String arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onResetConfiguration(String arg0, String[] arg1) {
            // TODO Auto-generated method stub

        }

    };

    RestartHandler restartHandler = new RestartHandler()
    {
        @Override
        public void restart()
        {
            // Restart application disconnecting and reconnecting to the
            //AllJoyn network.




        }
    };

    FactoryResetHandler factoryResetHandler = new FactoryResetHandler()
    {
        public void doFactoryReset()
        {
            try {
                configStore.resetAll();
            } catch (PropertyStoreException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // Reset the ConfigStore restoring default factory values.
            // Perform any other reset logic related to the AllJoyn services
            //platform.
        }
    };
    PassphraseChangedListener passphraseChangeListener = new
            PassphraseChangedListener()
    {
        public void onPassphraseChanged(byte[] passphrase)
        {
            // Perform any other passphrase change logic related to the application.

            logger.debug("CHANGE PASS");
        }
    };




    configService.startConfigServer(configStore, configChangeListener, 
            restartHandler, factoryResetHandler, passphraseChangeListener, bus);



    SetPasswordHandler setPasswordHandler = new SetPasswordHandler() {
           @Override
           public void setPassword(String peerName, char[] password)
           {
              // Store new credentials
              // Clear all current encryption keys that were generated from the current passphrase.

               logger.debug("SETTING PASS:"
                    + password);
               bus.clearKeyStore();
              authListener.setPSK(password);

           }
        };
        configService.setSetPasswordHandler(setPasswordHandler);

This is my implemented AuthListener

 public class SrpAnonymousKeyListener implements AuthListener



   {



  public static String KEY_STORE_FINE_NAME;

private  String[] auth_mechanisms={"ALLJOYN_ECDHE_PSK"};

char[] PSK = new char[]{'0','0','0','0','0','0'};

private Logger m_logger= LoggerFactory.getLogger(TAG);


 public String getMechanisms() {
      return "ALLJOYN_ECDHE_PSK";
   }

public void setPSK(char[] password) {

    System.out.println("Changing password from "+PSK+" to "+password);


    PSK=password;

}


@Override
public boolean requested(String authMechanism, String authPeer, int count, 
 String userName, AuthRequest[] requests) {

    m_logger.info(" ** " + "requested, mechanism = " + authMechanism + " peer = " + authPeer);

    try {
                if (!authMechanism.equals("ALLJOYN_ECDHE_PSK")) {
                   return false;
                }

                for (AuthRequest rqst: requests) {
                   if (rqst instanceof PasswordRequest) {
                      /*
                       * The ECDHE_PSK key exchange requests for the pre shared secret. 
                       * Based on the pre shared secret id given the username input variable,
                       * the application can retrieve the pre shared secret
                       * from storage or from the end user.
                       * In this example, the pre shared secret is a hard coded string
                       */

                       PasswordRequest pskRqst = (PasswordRequest) rqst; 

                       pskRqst.setPassword(PSK);
                   }
                }

                return true;

             } catch (Exception ex) {
                ex.printStackTrace();
             }
             return false;
          }

@Override
public void completed(String authMechanism, String authPeer, 
        boolean authenticated) {
      if (!authenticated) { 
         System.out.println("Authentication failed "+authMechanism);
      } else {
         System.out.println("Authentication successful "+authMechanism);
      }

   } 
}

But the problem is that the method requested(String authMechanism, String authPeer, int count, String userName, AuthRequest[] requests) is never called inside the ConfigServer, but it is called in the other side of the comunication

Do you know how I can solve this problem? What am I doing wrong? Thanks in advance.

edit retag flag offensive close merge delete

Comments

you might try on the core mailing list. https://lists.allseenalliance.org/mailman/listinfo/allseen-core

ry.jones ( 2015-10-04 19:26:59 -0800 )edit