Repository: jenkinsci/jenkins
File: test/src/test/java/test/security/realm/InMemorySecurityRealm.java (Java)

Code before:
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package test.security.realm;

import hudson.security.AbstractPasswordBasedSecurityRealm;
import hudson.security.GroupDetails;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 *  This class provides an in-memory implementation of Jenkin's SecurityRealm for
 *  testing.
 *  <p>
 *  It allows the creation and removal of users, and accepts any password for authentication.
 *  It maintains an in-memory storage of user accounts in a HashMap {@link #userStorage} and
 *  allows for creation and deletion of users by modifying this hashmap.
 *  <p>
 *  The user also gets authenticated with any password as the only thing validated is presence
 *  of username entry in the hashmap.
 *  It implements the {@link #loadUserByUsername2(String)} method which simply returns the user from the
 *  in memory storage based on username passed.
 *  <p>
 *  A dummy implementation for {@link InMemorySecurityRealm} is provided in class {@link InMemorySecurityRealm}
 *  which contains no roles and only username is returned.
 *
 */
public class InMemorySecurityRealm extends AbstractPasswordBasedSecurityRealm {
    private Map<String, UserDetails> userStorage = new HashMap<>();

    public synchronized void createAccount(String username) {
        if (userStorage.containsKey(username)) {
            return;
        }
        UserDetails details = new InMemoryUserDetails(username);
        userStorage.put(username, details);
    }

    public synchronized void deleteAccount(String username) {
        if (!userStorage.containsKey(username)) {
            return;
        }

Review comment (suggestion):
This is unnecessary implementation detail for a class-level Javadoc, given the field is `private`.
```suggestion
 *  It maintains an in-memory storage of user accounts.
```

(Or remove entirely, it's kinda obvious from the name.)

Code after:
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package test.security.realm;

import hudson.security.AbstractPasswordBasedSecurityRealm;
import hudson.security.GroupDetails;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 *  This class provides an in-memory implementation of Jenkins's {@link hudson.security.SecurityRealm} for
 *  testing.
 *  <p>
 *  It allows the creation and removal of users, and accepts any password for authentication.
 *  It maintains an in-memory storage of user accounts.
 *  <p>
 *  The user also gets authenticated with any password as the only thing validated is presence
 *  of username entry in the hashmap.
 *  The {@link #createAccount(String)} is used to populate the in-memory storage.
 *  It implements the {@link #loadUserByUsername2(String)} method which simply returns the user from the
 *  in memory storage based on username passed.
 *  <p>
 *  A dummy implementation for {@link InMemorySecurityRealm} is provided in class {@link InMemorySecurityRealm}
 *  which contains no roles and only username is returned.
 *
 */
public class InMemorySecurityRealm extends AbstractPasswordBasedSecurityRealm {
    private Map<String, UserDetails> userStorage = new HashMap<>();

    public synchronized void createAccount(String username) {
        if (userStorage.containsKey(username)) {
            return;
        }
        UserDetails details = new InMemoryUserDetails(username);
        userStorage.put(username, details);
    }

    public synchronized void deleteAccount(String username) {
        if (!userStorage.containsKey(username)) {
            return;
        }