@Test private void testAuthenticate(ConnectorFacade facade) { String user = "TESTUSER"; GuardedString password = new GuardedString("TEST".toCharArray()); try { facade.delete(ObjectClass.ACCOUNT, new Uid(user), null); } catch (UnknownUidException e) { } Attribute authentication = AttributeBuilder.build(OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_LOCAL); Attribute name = new Name(user); Attribute passwordAttribute = AttributeBuilder.buildPassword(password); Attribute privileges = AttributeBuilder.build(OracleConstants.ORACLE_PRIVS_ATTR_NAME, "CREATE SESSION"); Uid uid = facade.create(ObjectClass.ACCOUNT, CollectionUtil.newSet(authentication, name, passwordAttribute, privileges), null); Uid aUid = facade.authenticate(ObjectClass.ACCOUNT, user, password, null); AssertJUnit.assertEquals( "Uid returned from authenticate must be same as returned from create ", uid, aUid); try { facade.authenticate(ObjectClass.ACCOUNT, user, new GuardedString("wrongPassword" .toCharArray()), null); Assert.fail("Authenticate must fail for invalid user/password"); } catch (PasswordExpiredException e) { Assert.fail("Invalid password cannot throw PasswordExpiredException"); } catch (InvalidCredentialException e) { } try { facade.authenticate(ObjectClass.GROUP, user, password, null); Assert.fail("Authenticate must fail for invalid object class"); } catch (IllegalArgumentException e) { } try { facade.authenticate(ObjectClass.ACCOUNT, null, password, null); Assert.fail("Must fail for null user"); } catch (Exception e) { } facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(AttributeBuilder .buildPasswordExpired(true)), null); try { uid = facade.authenticate(ObjectClass.ACCOUNT, user, password, null); Assert.fail("Should not Authenticate with expired password"); } catch (PasswordExpiredException e) { } catch (RuntimeException e) { Assert.fail("Authenticate with expired accoun must throw PasswordExpiredException only :" + e); } facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(AttributeBuilder .buildPassword(password)), null); facade.authenticate(ObjectClass.ACCOUNT, user, password, null); facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(AttributeBuilder .buildEnabled(false)), null); try { facade.authenticate(ObjectClass.ACCOUNT, user, password, null); } catch (PasswordExpiredException e) { Assert.fail("Must not throw PasswordExpiredException on locked account"); } catch (ConnectorSecurityException e) { assertThat(e.getMessage()).contains("account is locked"); } facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(AttributeBuilder .buildEnabled(true)), null); facade.authenticate(ObjectClass.ACCOUNT, user, password, null); facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(AttributeBuilder.build( OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_EXTERNAL)), null); try { facade.authenticate(ObjectClass.ACCOUNT, user, password, null); Assert.fail("Cannot authenticate with external authentication"); } catch (ConnectorException e) { } boolean tryGlobal = false; try { facade.update(ObjectClass.ACCOUNT, uid, CollectionUtil.newSet(AttributeBuilder.build( OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_GLOBAL), AttributeBuilder.build( OracleConstants.ORACLE_GLOBAL_ATTR_NAME, "anyGlobalName")), null); tryGlobal = true; } catch (ConnectorException e) { if (e.getCause() instanceof SQLException) { if ("67000".equals(((SQLException) e.getCause()).getSQLState()) && 439 == ((SQLException) e.getCause()).getErrorCode()) { } else { Assert.fail(e.getMessage()); } } else { Assert.fail(e.getMessage()); } } if (tryGlobal) { try { facade.authenticate(ObjectClass.ACCOUNT, user, password, null); Assert.fail("Cannot authenticate with global authentication"); } catch (ConnectorException e) { } } facade.delete(ObjectClass.ACCOUNT, uid, null); }
public Uid authenticate(ObjectClass objectClass, String username, GuardedString password, OperationOptions options) { OracleConnectorHelper.checkObjectClass(objectClass, cfg.getConnectorMessages()); new LocalizedAssert(cfg.getConnectorMessages()).assertNotBlank(username, "username"); new LocalizedAssert(cfg.getConnectorMessages()).assertNotNull(password, "password"); if (options != null && Boolean.TRUE.equals(options.getOptions().get("returnUidOnly"))) { return findUserByName(username); } LOG.info("Authenticate user: [{0}]", username); if (cfg.isUseDriverForAuthentication()) { doDriverAuthenticate(username, password); } else { doCfgAuthenticate(username, password); } LOG.info("User authenticated : [{0}]", username); return new Uid(username); }
OracleOperationAuthenticate extends AbstractOracleOperation implements AuthenticateOp { public Uid authenticate(ObjectClass objectClass, String username, GuardedString password, OperationOptions options) { OracleConnectorHelper.checkObjectClass(objectClass, cfg.getConnectorMessages()); new LocalizedAssert(cfg.getConnectorMessages()).assertNotBlank(username, "username"); new LocalizedAssert(cfg.getConnectorMessages()).assertNotNull(password, "password"); if (options != null && Boolean.TRUE.equals(options.getOptions().get("returnUidOnly"))) { return findUserByName(username); } LOG.info("Authenticate user: [{0}]", username); if (cfg.isUseDriverForAuthentication()) { doDriverAuthenticate(username, password); } else { doCfgAuthenticate(username, password); } LOG.info("User authenticated : [{0}]", username); return new Uid(username); } }
OracleOperationAuthenticate extends AbstractOracleOperation implements AuthenticateOp { public Uid authenticate(ObjectClass objectClass, String username, GuardedString password, OperationOptions options) { OracleConnectorHelper.checkObjectClass(objectClass, cfg.getConnectorMessages()); new LocalizedAssert(cfg.getConnectorMessages()).assertNotBlank(username, "username"); new LocalizedAssert(cfg.getConnectorMessages()).assertNotNull(password, "password"); if (options != null && Boolean.TRUE.equals(options.getOptions().get("returnUidOnly"))) { return findUserByName(username); } LOG.info("Authenticate user: [{0}]", username); if (cfg.isUseDriverForAuthentication()) { doDriverAuthenticate(username, password); } else { doCfgAuthenticate(username, password); } LOG.info("User authenticated : [{0}]", username); return new Uid(username); } OracleOperationAuthenticate(OracleConfiguration cfg, Connection adminConn); }
OracleOperationAuthenticate extends AbstractOracleOperation implements AuthenticateOp { public Uid authenticate(ObjectClass objectClass, String username, GuardedString password, OperationOptions options) { OracleConnectorHelper.checkObjectClass(objectClass, cfg.getConnectorMessages()); new LocalizedAssert(cfg.getConnectorMessages()).assertNotBlank(username, "username"); new LocalizedAssert(cfg.getConnectorMessages()).assertNotNull(password, "password"); if (options != null && Boolean.TRUE.equals(options.getOptions().get("returnUidOnly"))) { return findUserByName(username); } LOG.info("Authenticate user: [{0}]", username); if (cfg.isUseDriverForAuthentication()) { doDriverAuthenticate(username, password); } else { doCfgAuthenticate(username, password); } LOG.info("User authenticated : [{0}]", username); return new Uid(username); } OracleOperationAuthenticate(OracleConfiguration cfg, Connection adminConn); Uid authenticate(ObjectClass objectClass, String username, GuardedString password,
            OperationOptions options); }
OracleOperationAuthenticate extends AbstractOracleOperation implements AuthenticateOp { public Uid authenticate(ObjectClass objectClass, String username, GuardedString password, OperationOptions options) { OracleConnectorHelper.checkObjectClass(objectClass, cfg.getConnectorMessages()); new LocalizedAssert(cfg.getConnectorMessages()).assertNotBlank(username, "username"); new LocalizedAssert(cfg.getConnectorMessages()).assertNotNull(password, "password"); if (options != null && Boolean.TRUE.equals(options.getOptions().get("returnUidOnly"))) { return findUserByName(username); } LOG.info("Authenticate user: [{0}]", username); if (cfg.isUseDriverForAuthentication()) { doDriverAuthenticate(username, password); } else { doCfgAuthenticate(username, password); } LOG.info("User authenticated : [{0}]", username); return new Uid(username); } OracleOperationAuthenticate(OracleConfiguration cfg, Connection adminConn); Uid authenticate(ObjectClass objectClass, String username, GuardedString password,
            OperationOptions options);  }