Source:
public NutchServer() { configManager = new RAMConfManager(); BlockingQueue<Runnable> runnables = Queues .newArrayBlockingQueue(JOB_CAPACITY); NutchServerPoolExecutor executor = new NutchServerPoolExecutor(10, JOB_CAPACITY, 1, TimeUnit.HOURS, runnables); jobMgr = new RAMJobManager(new JobFactory(), executor, configManager); component = new Component(); component.getLogger().setLevel(Level.parse(logLevel)); component.getServers().add(Protocol.HTTP, port); Context childContext = component.getContext().createChildContext(); JaxRsApplication application = new JaxRsApplication(childContext); application.add(this); application.setStatusService(new ErrorStatusService()); childContext.getAttributes().put(NUTCH_SERVER, this); AuthenticationTypeEnum authenticationType = configManager.get(ConfigResource.DEFAULT) .getEnum("restapi.auth", AuthenticationTypeEnum.NONE); if (authenticationType == AuthenticationTypeEnum.NONE) { component.getDefaultHost().attach(application); return; } MapVerifier mapVerifier = new MapVerifier(); String username = configManager.get(ConfigResource.DEFAULT).get("restapi.auth.username", "admin"); String password = configManager.get(ConfigResource.DEFAULT).get("restapi.auth.password", "nutch"); mapVerifier.getLocalSecrets().put(username, password.toCharArray()); if (authenticationType == AuthenticationTypeEnum.BASIC) { ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm"); guard.setVerifier(mapVerifier); guard.setNext(application); component.getDefaultHost().attach(guard); return; } if (authenticationType == AuthenticationTypeEnum.DIGEST) { DigestAuthenticator guard = new DigestAuthenticator(null, "Nutch REST API Realm", "NutchSecretKey"); guard.setWrappedVerifier(mapVerifier); guard.setNext(application); component.getDefaultHost().attachDefault(guard); } }

Target:
public NutchServer() { configManager = new RAMConfManager(); BlockingQueue<Runnable> runnables = Queues .newArrayBlockingQueue(JOB_CAPACITY); NutchServerPoolExecutor executor = new NutchServerPoolExecutor(10, JOB_CAPACITY, 1, TimeUnit.HOURS, runnables); jobMgr = new RAMJobManager(new JobFactory(), executor, configManager); component = new Component(); component.getLogger().setLevel(Level.parse(logLevel)); component.getServers().add(Protocol.HTTP, port); Context childContext = component.getContext().createChildContext(); JaxRsApplication application = new JaxRsApplication(childContext); application.add(this); application.setStatusService(new ErrorStatusService()); childContext.getAttributes().put(NUTCH_SERVER, this); AuthenticationTypeEnum authenticationType = configManager.get(ConfigResource.DEFAULT).getEnum("restapi.auth", AuthenticationTypeEnum.NONE); switch (authenticationType) { case NONE: component.getDefaultHost().attach(application); break; case BASIC: ChallengeAuthenticator challengeGuard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm"); challengeGuard.setVerifier(retrieveServerCredentials()); challengeGuard.setNext(application); component.getDefaultHost().attach(challengeGuard); break; case DIGEST: DigestAuthenticator digestGuard = new DigestAuthenticator(null, "Nutch REST API Realm", "NutchSecretKey"); digestGuard.setWrappedVerifier(retrieveServerCredentials()); digestGuard.setNext(application); component.getDefaultHost().attachDefault(digestGuard); break; default: throw new IllegalStateException("Unsupported Server Security Type!"); } }