use of org.eclipse.jetty.security.UserStore in project cayenne by apache.
the class Http2Server method basicAuth.
private static SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService loginService = new HashLoginService();
UserStore userStore = new UserStore();
userStore.addUser(username, Credential.getCredential(password), new String[] { "cayenne-service-user" });
loginService.setUserStore(userStore);
loginService.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "cayenne-service-user" });
constraint.setAuthenticate(true);
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec("/*");
ConstraintSecurityHandler constraintSecurityHandler = new ConstraintSecurityHandler();
constraintSecurityHandler.setAuthenticator(new BasicAuthenticator());
constraintSecurityHandler.setRealmName(realm);
constraintSecurityHandler.addConstraintMapping(constraintMapping);
constraintSecurityHandler.setLoginService(loginService);
return constraintSecurityHandler;
}
Aggregations