org.eclipse.jetty.security.authentication.BasicAuthenticator Java Examples
The following examples show how to use
org.eclipse.jetty.security.authentication.BasicAuthenticator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GatewayMicroService.java From apiman with Apache License 2.0 | 6 votes |
/** * Creates a basic auth security handler. */ protected SecurityHandler createSecurityHandler() throws Exception { HashLoginService l = new HashLoginService(); UserStore userStore = new UserStore(); l.setUserStore(userStore); for (User user : Users.getUsers()) { userStore.addUser(user.getId(), Credential.getCredential(user.getPassword()), user.getRolesAsArray()); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
Example #2
Source File: ManagerApiMicroService.java From apiman with Apache License 2.0 | 6 votes |
/** * Creates a basic auth security handler. * @throws Exception */ protected SecurityHandler createSecurityHandler() throws Exception { HashLoginService l = new HashLoginService(); // UserStore is now separate store entity and must be added to HashLoginService UserStore userStore = new UserStore(); l.setUserStore(userStore); for (User user : Users.getUsers()) { userStore.addUser(user.getId(), Credential.getCredential(user.getPassword()), user.getRolesAsArray()); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
Example #3
Source File: CustomInitTest.java From rest-utils with Apache License 2.0 | 6 votes |
@Override public void accept(final ServletContextHandler context) { final List<String> roles = config.getList(RestConfig.AUTHENTICATION_ROLES_CONFIG); final Constraint constraint = new Constraint(); constraint.setAuthenticate(true); constraint.setRoles(roles.toArray(new String[0])); final ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setMethod("*"); constraintMapping.setPathSpec("/*"); final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.addConstraintMapping(constraintMapping); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(new TestLoginService()); securityHandler.setRealmName("TestRealm"); context.setSecurityHandler(securityHandler); }
Example #4
Source File: GerritRestClientTest.java From gerrit-rest-java-client with Apache License 2.0 | 6 votes |
private static SecurityHandler basicAuth(String username, String password, String realm) { HashLoginService loginService = new HashLoginService(); loginService.putUser(username, Credential.getCredential(password), new String[]{"user"}); loginService.setName(realm); Constraint constraint = new Constraint(); constraint.setName(Constraint.__DIGEST_AUTH); constraint.setRoles(new String[]{"user"}); constraint.setAuthenticate(true); ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setPathSpec("/*"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("realm"); csh.addConstraintMapping(constraintMapping); csh.setLoginService(loginService); return csh; }
Example #5
Source File: HttpService.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** * Enables basic HTTP authentication on the server. */ public HttpService basicAuthentication(String username, String password) { HashLoginService l = new HashLoginService(); UserStore userStore = new UserStore(); userStore.addUser(username, Credential.getCredential(password), new String[]{"user"}); l.setUserStore(userStore); l.setName("test-realm"); Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); constraint.setAuthenticate(true); ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setPathSpec("/*"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("test-realm"); csh.addConstraintMapping(constraintMapping); csh.setLoginService(l); this.securityHandler = Optional.of(csh); return this; }
Example #6
Source File: JettySecurity.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Produces @Named("securityHandler") public static ConstraintSecurityHandler createSecurityHandler() { Constraint constraint = new Constraint("BASIC", "customer"); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); mapping.setConstraint(constraint); mapping.setPathSpec("/*"); ConstraintSecurityHandler handler = new ConstraintSecurityHandler(); handler.addConstraintMapping(mapping); handler.setAuthenticator(new BasicAuthenticator()); handler.setLoginService(new HashLoginService("RiderAutoParts", "src/main/resources/users.properties")); return handler; }
Example #7
Source File: HttpProtocolServer.java From gitflow-incremental-builder with MIT License | 6 votes |
private void addBasicAuth(Server server) { ConstraintSecurityHandler security = new ConstraintSecurityHandler(); security.setAuthenticator(new BasicAuthenticator()); Constraint constraint = new Constraint(); constraint.setAuthenticate(true); constraint.setRoles(ROLES); ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec("/*"); mapping.setConstraint(constraint); security.setConstraintMappings(Collections.singletonList(mapping)); HashLoginService loginService = new HashLoginService(); loginService.setUserStore(buildUserStore()); server.addBean(loginService); security.setLoginService(loginService); security.setHandler(server.getHandler()); server.setHandler(security); }
Example #8
Source File: InMemoryIdentityManager.java From crnk-framework with Apache License 2.0 | 6 votes |
public InMemoryIdentityManager() { loginService = new HashLoginService(); loginService.setName(realm); securityHandler = new ConstraintSecurityHandler(); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setRealmName(realm); securityHandler.setLoginService(loginService); Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); // constraint.setRoles(new String[] { "getRole", "postRole", "allRole" }); constraint.setRoles(new String[]{Constraint.ANY_AUTH, "getRole", "postRole", "allRole"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); securityHandler.addConstraintMapping(cm); }
Example #9
Source File: ManagerApiTestServer.java From apiman with Apache License 2.0 | 6 votes |
/** * Creates a basic auth security handler. */ private SecurityHandler createSecurityHandler() { HashLoginService l = new HashLoginService(); UserStore userStore = new UserStore(); l.setUserStore(userStore); for (String [] userInfo : TestUsers.USERS) { String user = userInfo[0]; String pwd = userInfo[1]; String[] roles = new String[] { "apiuser" }; if (user.startsWith("admin")) { roles = new String[] { "apiuser", "apiadmin"}; } userStore.addUser(user, Credential.getCredential(pwd), roles); } l.setName("apimanrealm"); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
Example #10
Source File: BasicAuthTest.java From apiman with Apache License 2.0 | 6 votes |
/** * Creates a basic auth security handler. */ private static SecurityHandler createSecurityHandler() { UserStore userStore = new UserStore(); String user = "user"; String pwd = "user123!"; String[] roles = new String[] { "user" }; userStore.addUser(user, Credential.getCredential(pwd), roles); HashLoginService l = new HashLoginService(); l.setName("apimanrealm"); l.setUserStore(userStore); ConstraintSecurityHandler csh = new ConstraintSecurityHandler(); csh.setAuthenticator(new BasicAuthenticator()); csh.setRealmName("apimanrealm"); csh.setLoginService(l); return csh; }
Example #11
Source File: JavaxServletSyncServerITest.java From hawkular-apm with Apache License 2.0 | 5 votes |
@BeforeClass public static void initClass() throws Exception { server = new Server(8180); LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); server.addBean(loginService); ConstraintSecurityHandler security = new ConstraintSecurityHandler(); server.setHandler(security); Constraint constraint = new Constraint(); constraint.setName("auth"); constraint.setAuthenticate(true); constraint.setRoles(new String[] { "user", "admin" }); ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec("/*"); mapping.setConstraint(constraint); security.setConstraintMappings(Collections.singletonList(mapping)); security.setAuthenticator(new BasicAuthenticator()); security.setLoginService(loginService); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(EmbeddedServlet.class, "/hello"); security.setHandler(context); server.start(); }
Example #12
Source File: ClientJettyStreamITest.java From hawkular-apm with Apache License 2.0 | 5 votes |
@BeforeClass public static void initClass() { server = new Server(8180); LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); server.addBean(loginService); ConstraintSecurityHandler security = new ConstraintSecurityHandler(); server.setHandler(security); Constraint constraint = new Constraint(); constraint.setName("auth"); constraint.setAuthenticate(true); constraint.setRoles(new String[] { "user", "admin" }); ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec("/*"); mapping.setConstraint(constraint); security.setConstraintMappings(Collections.singletonList(mapping)); security.setAuthenticator(new BasicAuthenticator()); security.setLoginService(loginService); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); context.addServlet(EmbeddedServlet.class, "/hello"); security.setHandler(context); try { server.start(); } catch (Exception e) { fail("Failed to start server: " + e); } }
Example #13
Source File: HttpServer.java From calcite-avatica with Apache License 2.0 | 5 votes |
protected ConstraintSecurityHandler configureBasicAuthentication(Server server, AvaticaServerConfiguration config) { final String[] allowedRoles = config.getAllowedRoles(); final String realm = config.getHashLoginServiceRealm(); final String loginServiceProperties = config.getHashLoginServiceProperties(); HashLoginService loginService = new HashLoginService(realm, loginServiceProperties); server.addBean(loginService); return configureCommonAuthentication(Constraint.__BASIC_AUTH, allowedRoles, new BasicAuthenticator(), null, loginService); }
Example #14
Source File: JettySecurity.java From camelinaction2 with Apache License 2.0 | 5 votes |
public static ConstraintSecurityHandler createSecurityHandler() { Constraint constraint = new Constraint("BASIC", "customer"); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); mapping.setConstraint(constraint); mapping.setPathSpec("/*"); ConstraintSecurityHandler handler = new ConstraintSecurityHandler(); handler.addConstraintMapping(mapping); handler.setAuthenticator(new BasicAuthenticator()); handler.setLoginService(new HashLoginService("RiderAutoParts", "etc/rest-users.properties")); return handler; }
Example #15
Source File: JettySecurity.java From camelinaction2 with Apache License 2.0 | 5 votes |
public static ConstraintSecurityHandler createSecurityHandler() { Constraint constraint = new Constraint("BASIC", "customer"); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); mapping.setConstraint(constraint); mapping.setPathSpec("/*"); ConstraintSecurityHandler handler = new ConstraintSecurityHandler(); handler.addConstraintMapping(mapping); handler.setAuthenticator(new BasicAuthenticator()); handler.setLoginService(new HashLoginService("RiderAutoParts", "src/main/resources/users.properties")); return handler; }
Example #16
Source File: BaleenWebApi.java From baleen with Apache License 2.0 | 5 votes |
private void configureServer(Server server, WebAuthConfig authConfig, Handler servletHandler) throws BaleenException { Handler serverHandler; if (authConfig == null || authConfig.getType() == AuthType.NONE) { LOGGER.warn("No security applied to API"); // No security serverHandler = servletHandler; } else if (authConfig.getType() == AuthType.BASIC) { // Basic authentication LOGGER.info("Using Basic HTTP authentication for API"); HashLoginService loginService = new HashLoginService(authConfig.getName()); UserStore userStore = new UserStore(); for (WebUser user : authConfig.getUsers()) { Credential credential = Credential.getCredential(user.getPassword()); userStore.addUser(user.getUsername(), credential, user.getRolesAsArray()); } loginService.setUserStore(userStore); server.addBean(loginService); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.setHandler(servletHandler); securityHandler.setConstraintMappings(constraintMappings); securityHandler.setAuthenticator(new BasicAuthenticator()); securityHandler.setLoginService(loginService); serverHandler = securityHandler; } else { throw new InvalidParameterException("Configuration of authentication failed"); } server.setHandler(serverHandler); }
Example #17
Source File: HttpServerExtension.java From kareldb with Apache License 2.0 | 5 votes |
@Override protected ConstraintSecurityHandler configureBasicAuthentication(Server server, AvaticaServerConfiguration config) { LOG.info("Configuring basic auth"); final String[] allowedRoles = config.getAllowedRoles(); final String realm = config.getHashLoginServiceRealm(); JAASLoginService loginService = new JAASLoginService(realm); server.addBean(loginService); return configureCommonAuthentication(Constraint.__BASIC_AUTH, allowedRoles, new BasicAuthenticator(), null, loginService); }
Example #18
Source File: HttpReceiverServerPush.java From datacollector with Apache License 2.0 | 5 votes |
public static SecurityHandler getBasicAuthHandler(HttpSourceConfigs httpCourceConf) { List<CredentialValueUserPassBean> basicAuthUsers = httpCourceConf.getBasicAuthUsers(); HashLoginService loginService = new HashLoginService(); UserStore userStore = new UserStore(); boolean empty = true; for (CredentialValueUserPassBean userPassBean : basicAuthUsers) { String username = userPassBean.getUsername(); String password = userPassBean.get(); if(StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { userStore.addUser(username, new Password(password), new String[]{"sdc"}); empty = false; } } if(empty) { return null; } loginService.setUserStore(userStore); Constraint constraint = new Constraint(Constraint.__BASIC_AUTH,"sdc"); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); mapping.setConstraint(constraint); mapping.setPathSpec("/*"); ConstraintSecurityHandler handler = new ConstraintSecurityHandler(); handler.setAuthenticator(new BasicAuthenticator()); handler.addConstraintMapping(mapping); handler.setLoginService(loginService); return handler; }
Example #19
Source File: WebServerTask.java From datacollector with Apache License 2.0 | 5 votes |
private ConstraintSecurityHandler configureDigestBasic(Configuration conf, Server server, String mode) { LoginService loginService = getLoginService(conf, mode); server.addBean(loginService); ConstraintSecurityHandler security = new ConstraintSecurityHandler(); switch (mode) { case "digest": security.setAuthenticator(injectActivationCheck(new ProxyAuthenticator( new DigestAuthenticator(), runtimeInfo, conf ))); break; case "basic": security.setAuthenticator(injectActivationCheck(new ProxyAuthenticator( new BasicAuthenticator(), runtimeInfo, conf ))); break; default: // no action break; } security.setLoginService(loginService); return security; }
Example #20
Source File: Application.java From rest-utils with Apache License 2.0 | 5 votes |
protected LoginAuthenticator createAuthenticator() { final String method = config.getString(RestConfig.AUTHENTICATION_METHOD_CONFIG); if (enableBasicAuth(method)) { return new BasicAuthenticator(); } else if (enableBearerAuth(method)) { throw new UnsupportedOperationException( "Must implement Application.createAuthenticator() when using '" + RestConfig.AUTHENTICATION_METHOD_CONFIG + "=" + RestConfig.AUTHENTICATION_METHOD_BEARER + "'." ); } return null; }
Example #21
Source File: ApplicationTest.java From rest-utils with Apache License 2.0 | 5 votes |
@Test(expected = UnsupportedOperationException.class) public void testBearerNoLoginService() { final Map<String, Object> config = ImmutableMap.of( RestConfig.AUTHENTICATION_METHOD_CONFIG, RestConfig.AUTHENTICATION_METHOD_BEARER); Application app = new TestApp(config) { @Override protected LoginAuthenticator createAuthenticator() { return new BasicAuthenticator(); } }; app.createBearerSecurityHandler(); }
Example #22
Source File: TestWebServicesFetcher.java From datacollector with Apache License 2.0 | 4 votes |
protected void runServer(int port, boolean serverSsl, boolean clientSsl, String httpAuth, Callable<Void> test) throws Exception { Server server = createServer(port, serverSsl, clientSsl); ServletContextHandler contextHandler = new ServletContextHandler(); if (!httpAuth.equals("none")) { File realmFile = new File(getConfDir(), httpAuth + ".properties"); LoginService loginService = new HashLoginService(httpAuth, realmFile.getAbsolutePath()); server.addBean(loginService); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); switch (httpAuth) { case "basic": securityHandler.setAuthenticator(new BasicAuthenticator()); break; case "digest": securityHandler.setAuthenticator(new DigestAuthenticator()); break; } securityHandler.setLoginService(loginService); Constraint constraint = new Constraint(); constraint.setName("auth"); constraint.setAuthenticate(true); constraint.setRoles(new String[]{"user"}); ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec("/*"); mapping.setConstraint(constraint); securityHandler.addConstraintMapping(mapping); contextHandler.setSecurityHandler(securityHandler); } MockCyberArkServlet servlet = new MockCyberArkServlet(); contextHandler.addServlet(new ServletHolder(servlet), "/AIMWebService/api/Accounts"); contextHandler.setContextPath("/"); server.setHandler(contextHandler); try { server.start(); test.call(); } finally { server.stop(); } }
Example #23
Source File: JettyHttpServer.java From everrest with Eclipse Public License 2.0 | 4 votes |
public void start() throws Exception { RequestLogHandler handler = new RequestLogHandler(); if (context == null) { context = new ServletContextHandler(handler, "/", ServletContextHandler.SESSIONS); } context.setEventListeners(new EventListener[]{new EverrestInitializedListener()}); ServletHolder servletHolder = new ServletHolder(new EverrestServlet()); context.addServlet(servletHolder, UNSECURE_PATH_SPEC); context.addServlet(servletHolder, SECURE_PATH_SPEC); //set up security Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); constraint.setRoles(new String[]{"cloud-admin", "users", "user", "temp_user"}); constraint.setAuthenticate(true); ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); constraintMapping.setPathSpec(SECURE_PATH_SPEC); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.addConstraintMapping(constraintMapping); HashLoginService loginService = new HashLoginService(); UserStore userStore = new UserStore(); userStore.addUser(ADMIN_USER_NAME, new Password(ADMIN_USER_PASSWORD), new String[]{"cloud-admin", "users", "user", "temp_user", "developer", "admin", "workspace/developer", "workspace/admin", "account/owner", "account/member", "system/admin", "system/manager" }); userStore.addUser(MANAGER_USER_NAME, new Password(MANAGER_USER_PASSWORD), new String[]{"cloud-admin", "user", "temp_user", "users"}); loginService.setUserStore(userStore); securityHandler.setLoginService(loginService); securityHandler.setAuthenticator(new BasicAuthenticator()); context.setSecurityHandler(securityHandler); server.setHandler(handler); server.start(); ResourceBinder binder = (ResourceBinder)context.getServletContext().getAttribute(ResourceBinder.class.getName()); DependencySupplier dependencies = (DependencySupplier)context.getServletContext().getAttribute(DependencySupplier.class.getName()); GroovyResourcePublisher groovyPublisher = new GroovyResourcePublisher(binder, dependencies); context.getServletContext().setAttribute(GroovyResourcePublisher.class.getName(), groovyPublisher); }
Example #24
Source File: ODataTestServer.java From syndesis with Apache License 2.0 | 4 votes |
@SuppressWarnings( "deprecation" ) private void initServer(SSLContext sslContext, String userName) throws UnknownHostException { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(FORWARD_SLASH); this.setHandler(context); ServletHandler productsHandler = new ServletHandler(); productsHandler.addServletWithMapping( ProductsServlet.class, FORWARD_SLASH + PRODUCTS_SVC + FORWARD_SLASH + STAR); productsHandler.addFilterWithMapping(ODataPathFilter.class, FORWARD_SLASH + STAR, FilterMapping.REQUEST); context.insertHandler(productsHandler); if (userName != null) { LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); this.addBean(loginService); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); Constraint constraint = new Constraint(); constraint.setName("auth"); constraint.setAuthenticate(true); constraint.setRoles(new String[] { USER, "admin" }); ConstraintMapping mapping = new ConstraintMapping(); mapping.setPathSpec(FORWARD_SLASH + PRODUCTS_SVC + FORWARD_SLASH + STAR); mapping.setConstraint(constraint); securityHandler.setConstraintMappings(Collections.singletonList(mapping)); securityHandler.setAuthenticator(new BasicAuthenticator()); context.setSecurityHandler(securityHandler); } httpConnector = new ServerConnector(this); httpConnector.setPort(httpPort); // Finds next available port if still 0 this.addConnector(httpConnector); if (sslContext != null) { // HTTPS HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setSecureScheme("https"); httpConfiguration.setSecurePort(httpsPort); // Finds next available port if still 0 httpConfiguration.addCustomizer(new SecureRequestCustomizer()); final SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setSslContext(sslContext); httpsConnector = new ServerConnector(this, sslContextFactory, new HttpConnectionFactory(httpConfiguration)); httpsConnector.setPort(httpsPort); // Finds next available port if still 0 this.addConnector(httpsConnector); } }
Example #25
Source File: AuthenticationIntegrationTest.java From cruise-control with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Authenticator authenticator() { return new BasicAuthenticator(); }
Example #26
Source File: BasicSecurityProvider.java From cruise-control with BSD 2-Clause "Simplified" License | 4 votes |
@Override public Authenticator authenticator() { return new BasicAuthenticator(); }