brikar-server/src/main/java/com/truward/brikar/server/auth/SimpleAuthenticatorUtil.java
public static SecurityHandler newSecurityHandler(List<SimpleServiceUser> users) {
    final HashLoginService loginService = new HashLoginService();
    final Set<String> roles = new HashSet<>();
    for (final SimpleServiceUser user : users) {
      final List<String> authorities = user.getAuthorities();
      loginService.putUser(user.getUsername(), Credential.getCredential(user.getPassword()),
          authorities.toArray(new String[authorities.size()]));
      roles.addAll(authorities);

    }
    loginService.setName(DEFAULT_REALM);

    final Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(roles.toArray(new String[roles.size()]));
    constraint.setAuthenticate(true);

    final ConstraintMapping constraintMapping = new ConstraintMapping();
    constraintMapping.setConstraint(constraint);
    constraintMapping.setPathSpec("/*");

    final ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
    csh.setAuthenticator(new BasicAuthenticator());
    csh.setRealmName(DEFAULT_REALM_NAME);
    csh.addConstraintMapping(constraintMapping);
    csh.setLoginService(loginService);

    return csh;
  }
public static SecurityHandler newSecurityHandler(List<SimpleServiceUser> users) {
    final HashLoginService loginService = new HashLoginService();
    final Set<String> roles = new HashSet<>();
    for (final SimpleServiceUser user : users) {
      final List<String> authorities = user.getAuthorities();
      loginService.putUser(user.getUsername(), Credential.getCredential(user.getPassword()),
          authorities.toArray(new String[authorities.size()]));
      roles.addAll(authorities);

    }
    loginService.setName(DEFAULT_REALM);

    final Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(roles.toArray(new String[roles.size()]));
    constraint.setAuthenticate(true);

    final ConstraintMapping constraintMapping = new ConstraintMapping();
    constraintMapping.setConstraint(constraint);
    constraintMapping.setPathSpec("/*");

    final ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
    csh.setAuthenticator(new BasicAuthenticator());
    csh.setRealmName(DEFAULT_REALM_NAME);
    csh.addConstraintMapping(constraintMapping);
    csh.setLoginService(loginService);

    return csh;
  }
public static SecurityHandler newSecurityHandler ( List < SimpleServiceUser > users ) { final HashLoginService loginService = new HashLoginService ( ) ; final Set < String > roles = new HashSet <> ( ) ; for ( final SimpleServiceUser user : users ) { final List < String > authorities = user . getAuthorities ( ) ; loginService . putUser ( user . getUsername ( ) , Credential . getCredential ( user . getPassword ( ) ) , authorities . toArray ( new String [ authorities . size ( ) ] ) ) ; roles . addAll ( authorities ) ; } loginService . setName ( DEFAULT_REALM ) ; final Constraint constraint = new Constraint ( ) ; constraint . setName ( Constraint . __BASIC_AUTH ) ; constraint . setRoles ( roles . toArray ( new String [ roles . size ( ) ] ) ) ; constraint . setAuthenticate ( true ) ; final ConstraintMapping constraintMapping = new ConstraintMapping ( ) ; constraintMapping . setConstraint ( constraint ) ; constraintMapping . setPathSpec ( "/*" ) ; final ConstraintSecurityHandler csh = new ConstraintSecurityHandler ( ) ; csh . setAuthenticator ( new BasicAuthenticator ( ) ) ; csh . setRealmName ( DEFAULT_REALM_NAME ) ; csh . addConstraintMapping ( constraintMapping ) ; csh . setLoginService ( loginService ) ; return csh ; }
Creates a handler for jetty server with the given list of users.
The list of users can be conveniently loaded by using the other method in
this utility class: {@link #loadUsers(PropertySource, String)}.

@param users List of user entries
@return Jetty security handler
Creates a handler for jetty server with the given list of users . The list of users can be conveniently loaded by using the other method in this utility class : { @link #loadUsers ( PropertySource String ) } .