You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by jbertram <gi...@git.apache.org> on 2016/11/02 18:13:06 UTC

[GitHub] activemq-artemis pull request #835: ARTEMIS-786 Store user's password in has...

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

    https://github.com/apache/activemq-artemis/pull/835#discussion_r86208017
  
    --- Diff: artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/user/UserAction.java ---
    @@ -0,0 +1,107 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements. See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License. You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.activemq.artemis.cli.commands.user;
    +
    +import io.airlift.airline.Option;
    +import org.apache.activemq.artemis.cli.commands.InputAbstract;
    +import org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule;
    +import org.apache.activemq.artemis.util.FileBasedSecStoreConfig;
    +
    +import javax.security.auth.login.AppConfigurationEntry;
    +import javax.security.auth.login.Configuration;
    +import java.io.File;
    +import java.util.List;
    +
    +import static org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule.ROLE_FILE_PROP_NAME;
    +import static org.apache.activemq.artemis.spi.core.security.jaas.PropertiesLoginModule.USER_FILE_PROP_NAME;
    +
    +public abstract class UserAction extends InputAbstract {
    +
    +   @Option(name = "--user", description = "The user name")
    +   String username = null;
    +
    +   /**
    +    * Adding a new user
    +    * @param hash the password
    +    * @param role the role
    +    * @throws IllegalArgumentException if user exists
    +    */
    +   protected void add(String hash, String... role) throws Exception {
    +      FileBasedSecStoreConfig config = getConfiguration();
    +      config.addNewUser(username, hash, role);
    +      config.save();
    +      context.out.println("User added successfully.");
    +   }
    +
    +   /**
    +    * list a single user or all users
    +    * if username is not specified
    +    */
    +   protected void list() throws Exception {
    +      FileBasedSecStoreConfig config = getConfiguration();
    +      List<String> result = config.listUser(username);
    +      for (String str : result) {
    +         context.out.println(str);
    +      }
    +   }
    +
    +   protected void remove() throws Exception {
    +      FileBasedSecStoreConfig config = getConfiguration();
    +      config.removeUser(username);
    +      config.save();
    +      context.out.println("User removed.");
    +   }
    +
    +   protected void reset(String password, String[] roles) throws Exception {
    +      if (password == null && roles == null) {
    +         context.err.println("Nothing to update.");
    +         return;
    +      }
    +      FileBasedSecStoreConfig config = getConfiguration();
    +      config.updateUser(username, password, roles);
    +      config.save();
    +      context.out.println("User updated");
    +   }
    +
    +   private FileBasedSecStoreConfig getConfiguration() throws Exception {
    +
    +      Configuration securityConfig = Configuration.getConfiguration();
    +      AppConfigurationEntry[] entries = securityConfig.getAppConfigurationEntry("activemq");
    --- End diff --
    
    This should be configurable or if not it should be documented as only working for app config entries named "activemq".  The app config entry in login.config is completely arbitrary.  It doesn't have to be named "activemq".


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---