WindowsSSONAuthenticatorADInfo.java

  1. /**
  2.  * Originally contributed by eMation (www.emation.pt)
  3.  */
  4. package org.itracker.services.authentication.adsson;

  5. import org.apache.log4j.Logger;
  6. import org.itracker.model.User;
  7. import org.itracker.services.exceptions.AuthenticatorException;

  8. import javax.security.auth.login.LoginException;
  9. import java.io.IOException;

  10. /**
  11.  * Extends the windows single sign on class, gets user information
  12.  * from active directory
  13.  *
  14.  * @author ricardo
  15.  */
  16. public class WindowsSSONAuthenticatorADInfo extends WindowsSSONAuthenticator {
  17.     private static final Logger logger = Logger.getLogger(WindowsSSONAuthenticatorADInfo.class);

  18.     /**
  19.      * @see com.emation.itracker.authentication.WindowsSSONAuthenticator#getExternalUserInfo(java.lang.String)
  20.      */
  21.     protected User getExternalUserInfo(String login) throws AuthenticatorException {
  22.         try {
  23.             // connect to active directory
  24.             ADIntegration ad = new ADIntegration();
  25.             ad.login();
  26.             // get external user info
  27.             User userModel = (User) ad.getUserInfo(login);
  28.             return userModel;
  29.         } catch (LoginException e) {
  30.             logger.error("getExternalUserInfo: " + e.getMessage() + AuthenticatorException.SYSTEM_ERROR);
  31.             throw new AuthenticatorException("Error accessing Active Directory: " + e.getMessage(), AuthenticatorException.SYSTEM_ERROR, e);
  32.         } catch (IOException e) {
  33.             logger.error(e.getMessage());
  34.             throw new AuthenticatorException(e.getMessage(), AuthenticatorException.SYSTEM_ERROR);
  35.         }
  36.     }

  37. }