[ 
https://issues.apache.org/jira/browse/NUTCH-2289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15351553#comment-15351553
 ] 

ASF GitHub Bot commented on NUTCH-2289:
---------------------------------------

Github user lewismc commented on a diff in the pull request:

    https://github.com/apache/nutch/pull/128#discussion_r68630587
  
    --- Diff: src/java/org/apache/nutch/api/NutchServer.java ---
    @@ -99,17 +114,70 @@ public NutchServer() {
         component = new Component();
         component.getLogger().setLevel(Level.parse(logLevel));
     
    -    // Add a new HTTP server listening on defined port.
    -    component.getServers().add(Protocol.HTTP, port);
    +    AuthenticationTypeEnum authenticationType = 
configManager.get(ConfigResource.DEFAULT)
    +            .getEnum("restapi.auth", AuthenticationTypeEnum.NONE);
    +
    +    if (authenticationType == AuthenticationTypeEnum.SSL) {
    +      // Add a new HTTPS server listening on defined port.
    +      Server server = component.getServers().add(Protocol.HTTPS, port);
    +
    +      Series parameters = server.getContext().getParameters();
    +      parameters.add("sslContextFactory", 
"org.restlet.engine.ssl.DefaultSslContextFactory");
    +
    +      String keyStorePath = configManager.get(ConfigResource.DEFAULT)
    +              .get("restapi.auth.ssl.storepath", 
"etc/nutch-ssl.keystore.jks");
    +      parameters.add("keyStorePath", keyStorePath);
    +
    +      String keyStorePassword = configManager.get(ConfigResource.DEFAULT)
    +              .get("restapi.auth.ssl.storepass", "password");
    +      parameters.add("keyStorePassword", keyStorePassword);
    +
    +      String keyPassword = configManager.get(ConfigResource.DEFAULT)
    +              .get("restapi.auth.ssl.keypass", "password");
    +      parameters.add("keyPassword", keyPassword);
    +
    +      parameters.add("keyStoreType", "JKS");
    +      LOG.info("SSL Authentication is set for NutchServer");
    +    } else {
    +      // Add a new HTTP server listening on defined port.
    +      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);
     
    -    // Attach the application.
    -    component.getDefaultHost().attach(application);
    +    if (authenticationType == AuthenticationTypeEnum.NONE || 
authenticationType == AuthenticationTypeEnum.SSL ) {
    +      component.getDefaultHost().attach(application);
    +      return;
    +    }
    +
    +    String username = 
configManager.get(ConfigResource.DEFAULT).get("restapi.auth.username", "admin");
    +    String password = 
configManager.get(ConfigResource.DEFAULT).get("restapi.auth.password", "nutch");
    +
    +    MapVerifier mapVerifier = new MapVerifier();
    +    mapVerifier.getLocalSecrets().put(username, password.toCharArray());
    +
    +    if (authenticationType == AuthenticationTypeEnum.BASIC) {
    --- End diff --
    
    Please see comment on other issue for use of switch block.


> SSL Support for REST API
> ------------------------
>
>                 Key: NUTCH-2289
>                 URL: https://issues.apache.org/jira/browse/NUTCH-2289
>             Project: Nutch
>          Issue Type: Sub-task
>          Components: REST_api, web gui
>            Reporter: Furkan KAMACI
>            Assignee: Furkan KAMACI
>             Fix For: 2.5
>
>
> Add SSL Authentication for Nutch REST API.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to