PWCallbackSend.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */



  20. package org.openspcoop2.security.utils;

  21. import java.io.IOException;
  22. import javax.security.auth.callback.Callback;
  23. import javax.security.auth.callback.CallbackHandler;
  24. import javax.security.auth.callback.UnsupportedCallbackException;

  25. import org.apache.wss4j.common.ext.WSPasswordCallback;

  26. /**
  27.  * Gestore delle password dei certificati scambiati con wssecurity, gestore di esempio.
  28.  *  
  29.  * @author Montebove Luciano (L.Montebove@finsiel.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */

  33. public class PWCallbackSend implements CallbackHandler {

  34.     @Override
  35.     public void handle(Callback[] callbacks) throws IOException,
  36.             UnsupportedCallbackException {
  37.         for (int i = 0; i < callbacks.length; i++) {
  38.             if (callbacks[i] instanceof WSPasswordCallback) {
  39.                 WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
  40.         //System.out.println("Alias ["+pc.getIdentifer()+"]");
  41.                 // setta la password per l'alias della chiave
  42. //                if ("erogatore".equals(pc.getIdentifer())) {
  43. //                    pc.setPassword("foobar");
  44. //                }
  45.                
  46.                // System.out.println("Alias ["+pc.getIdentifier()+"]");
  47.                 if ("pd".equals(pc.getIdentifier())) {
  48.                     pc.setPassword("certpd");
  49.                 }else if ("pa".equals(pc.getIdentifier())) {
  50.                     pc.setPassword("certpa");
  51.                 }
  52.                 else if ("pdP12".equalsIgnoreCase(pc.getIdentifier())) {
  53.                     pc.setPassword("keypd");
  54.                 }else if ("paP12".equalsIgnoreCase(pc.getIdentifier())) {
  55.                     pc.setPassword("keypa");
  56.                 }
  57.                
  58.                
  59.               //pc.setPassword("foobar");
  60.             } else {
  61.                 throw new UnsupportedCallbackException(callbacks[i],
  62.                         "Unrecognized Callback");
  63.             }
  64.         }
  65.     }
  66. }