private void authenticateToKDC( GSSAPICallbackHandler callbackHandler, UserDomainInfo userDomainInfo) throws EngineDirectoryServiceException { try { loginContext = new LoginContext(LOGIN_MODULE_POLICY_NAME, callbackHandler); loginContext.login(); userDomainInfo.setLoginContext(loginContext); if (log.isDebugEnabled()) { log.debug("Successful login for user " + userName); } } catch (LoginException ex) { // JAAS throws login exception due to various reasons. // We check if the login exception matches a case where the user // provided wrong authentication details, or // if there was another error - in case the user provided wrong // authentication details, we will abort the kdc search loginContext = null; KerberosReturnCodeParser parser = new KerberosReturnCodeParser(); AuthenticationResult result = parser.parse(ex.getMessage()); if (result == AuthenticationResult.OTHER || result == null) { // An error our error parser does not recognize log.error("Error from Kerberos: " + ex.getMessage()); } else { StringBuilder error = new StringBuilder(); error.append(result.getDetailedMessage()); log.error(error.toString()); } throw new EngineDirectoryServiceException(result); } }
protected void setUpLogExpectations(boolean debug) { mockStatic(LogFactoryCompat.class); LogCompat log = createMock(LogCompat.class); expect(LogFactoryCompat.getLog(AbstractBackendResource.class)).andReturn(log); expect(log.isDebugEnabled()).andReturn(debug).anyTimes(); replayAll(); }
/** @pre called with class-level mutex held */ private static DatatypeFactory getDatatypeFactory() { if (datatypeFactory == null) { try { datatypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException dce) { LOG.warn(DATATYPE_FACTORY_CREATION_FAILED, dce); } } return datatypeFactory; }
public LdapTestsSetup() { String confFile = System.getenv("LDAP_TESTER_PROPERTIES_FILE"); if (confFile == null) { confFile = "ldap.integ/ldap-test.properties"; } try { testProperties = new PropertiesConfiguration(confFile); Configuration usersSubset = testProperties.subset("users"); HierarchicalConfiguration usersConfig = ConfigurationUtils.convertToHierarchical(usersSubset); List<ConfigurationNode> childrens = usersConfig.getRootNode().getChildren(); for (ConfigurationNode node : childrens) { String name = node.getName(); users.put(name, new Person(usersSubset.subset(name))); } Configuration groupsSubset = testProperties.subset("groups"); HierarchicalConfiguration groupsConfig = ConfigurationUtils.convertToHierarchical(groupsSubset); childrens = groupsConfig.getRootNode().getChildren(); for (ConfigurationNode node : childrens) { String name = node.getName(); groups.put(name, new Group(groupsSubset.subset(name))); } Configuration ldapConfigurationSubset = testProperties.subset("configuration"); HierarchicalConfiguration ldapConfig = ConfigurationUtils.convertToHierarchical(ldapConfigurationSubset); childrens = ldapConfig.getRootNode().getChildren(); for (ConfigurationNode node : childrens) { String key = node.getName(); String value = (String) node.getValue(); ldapConfiguration.put(key, value); } } catch (ConfigurationException ex) { String message = "Problem loading configuration: " + ex.getMessage(); log.error(message); throw new IllegalStateException(message); } }