本文整理汇总了Java中com.sun.net.httpserver.Authenticator类的典型用法代码示例。如果您正苦于以下问题:Java Authenticator类的具体用法?Java Authenticator怎么用?Java Authenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Authenticator类属于com.sun.net.httpserver包,在下文中一共展示了Authenticator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServer
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
public void startServer() throws Exception
{
executeUpgrader();
Authenticator auth = new MyAuthenticator(config);
server = HttpServerProvider.provider().createHttpServer(
new InetSocketAddress(config.getManagerDetails().getManagerPort()), 50);
AjaxState ajaxState = new AjaxStateImpl();
createContext(server, "/", new WebRootHandler()); //$NON-NLS-1$
createContext(server, "/pages/", new PagesHandler(config), auth); //$NON-NLS-1$
createContext(server, "/server/", new ServerHandler(config), auth); //$NON-NLS-1$
createContext(server, "/deploy/", new DeployHandler(config, ajaxState), auth); //$NON-NLS-1$
createContext(server, "/ajax/", new AjaxProgressHandler(ajaxState)); //$NON-NLS-1$
createContext(server, "/upload/", new UploadHandler(config)); //$NON-NLS-1$
server.start();
}
示例2: createContext
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
private void createContext(HttpServer server, String path, HttpHandler handler, Authenticator auth)
{
final HttpContext context = server.createContext(path, handler);
if( auth != null )
{
context.setAuthenticator(auth);
}
context.getFilters().addAll(filters);
}
示例3: setAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
@Override
public Authenticator setAuthenticator(Authenticator auth)
{
Authenticator previous = _authenticator;
_authenticator = auth;
return previous;
}
示例4: getAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
private Authenticator getAuthenticator() {
Authenticator authenticator = new BasicAuthenticator(REALM) {
public boolean checkCredentials(String username, String password) {
return USERNAME.equals(username) && PASSWORD.equals(password);
}
};
return authenticator;
}
示例5: createContexts
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
protected Collection<HttpContext> createContexts() {
final Filter[] filtersArray = createFilters();
final Collection<Filter> filtersList;
if (filtersArray != null && filtersArray.length != 0) {
filtersList = Arrays.asList(filtersArray);
}
else {
filtersList = Collections.emptyList();
}
final Collection<HttpContext> httpContexts = new ArrayList<HttpContext>();
final Authenticator authenticator = httpServerConfiguration.getAuthenticator();
final HttpPathHandler[] handlersArray = createHandlers();
if (handlersArray != null && handlersArray.length > 0) {
for (final HttpPathHandler handler : handlersArray) {
final HttpContext httpContext = server.createContext(handler.getPath(), handler);
if (filtersArray != null && filtersArray.length != 0) {
httpContext.getFilters().addAll(filtersList);
}
if (authenticator != null) {
httpContext.setAuthenticator(authenticator);
}
httpContexts.add(httpContext);
}
}
else {
logger.log(Level.WARNING, JFaceMessages.get("msg.httpserver.configuration.handlers.none"));
}
return httpContexts;
}
示例6: shouldSetFiltersAndAuthenticatorsOnHttpContext
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
@Test
public void shouldSetFiltersAndAuthenticatorsOnHttpContext() throws Exception {
// setup
Map<String, HttpHandler> contexts = new HashMap<String, HttpHandler>();
HttpHandler httpHandler = mock(HttpHandler.class);
contexts.put("test1", httpHandler);
Filter filter = mock(Filter.class);
List<Filter> filters = new ArrayList<Filter>();
filters.add(filter);
Authenticator authenticator = mock(Authenticator.class);
simpleHttpServerFactoryBean.setContexts(contexts);
simpleHttpServerFactoryBean.setFilters(filters);
simpleHttpServerFactoryBean.setAuthenticator(authenticator);
List<Filter> httpContextFilters = new ArrayList<Filter>();
HttpContext httpContext = mock(HttpContext.class);
when(httpContext.getFilters()).thenReturn(httpContextFilters);
when(httpServer.createContext("test1", httpHandler)).thenReturn(httpContext);
// act
simpleHttpServerFactoryBean.afterPropertiesSet();
// assert
verify(httpContext).setAuthenticator(authenticator);
assertThat(httpContextFilters.contains(filter), is(true));
}
示例7: handle
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
@Override
public void handle(String target, HttpServletRequest req,
HttpServletResponse resp, int dispatch) throws IOException,
ServletException
{
if (!target.startsWith(getContextPath())) return;
JettyHttpExchange jettyHttpExchange = new JettyHttpExchange(_context, req, resp);
// TODO: add filters processing
Authenticator auth = _context.getAuthenticator();
try
{
if (auth != null)
handleAuthentication(resp, jettyHttpExchange, auth);
else
_handler.handle(jettyHttpExchange);
}
catch(Exception ex)
{
PrintWriter writer = new PrintWriter(jettyHttpExchange.getResponseBody());
resp.setStatus(500);
writer.println("<h2>HTTP ERROR: 500</h2>");
writer.println("<pre>INTERNAL_SERVER_ERROR</pre>");
writer.println("<p>RequestURI=" + req.getRequestURI() + "</p>");
writer.println("<pre>");
ex.printStackTrace(writer);
writer.println("</pre>");
writer.println("<p><i><small><a href=\"http://jetty.mortbay.org\">Powered by jetty://</a></small></i></p>");
writer.close();
}
finally
{
Request base_request = (req instanceof Request) ? (Request)req:HttpConnection.getCurrentConnection().getRequest();
base_request.setHandled(true);
}
}
示例8: getAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
@Override
public Authenticator getAuthenticator()
{
return _authenticator;
}
示例9: setHttpServerAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
public ODataJerseyServer setHttpServerAuthenticator(Authenticator authenticator) {
httpServerAuthenticator = authenticator;
return this;
}
示例10: getAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
@Nullable
Authenticator getAuthenticator();
示例11: getAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
@Override
public Authenticator getAuthenticator() {
return null; // no authentication
}
示例12: init
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
@BeforeClass
public static void init() throws InterruptedException, IOException {
LoggingSupport.setRootLevel(Level.FINE);
certificate = File.createTempFile("cert-", ".jks");
logger.info(certificate.toString());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(certificate);
fos.write(DatatypeConverter.parseBase64Binary(JKS));
}
finally {
IOUtils.closeQuietly(fos);
}
final IHttpServerConfig configuration = new HttpServerDefaultConfig() {
@Override
public Authenticator getAuthenticator() {
return authenticator;
}
@Override
public BaseHttpHandler[] getHandlers() {
final BaseHttpHandler h1 = new BaseHttpHandler(this) {
@Override
protected void doGet(final HttpExchange exchange) throws IOException, HttpException {
sendResponse(exchange, loremSmallTxt.getBytes());
}
};
h1.setPath(HANDLER_PATH_TXT);
final BaseHttpHandler h2 = new DisabledHandler(this);
h2.setEnabled(false);
final BaseHttpHandler h3 = new RequestParameterHandler(this);
final FilesHandler h4 = new FilesHandler(this, certificate.getParentFile().getPath(), "/files/");
h4.setAttachment(true);
final ResourcesHandler h5 = new ResourcesHandler(this, getClass().getPackage(), "/resources/");
h5.setAttachment(true);
h5.setCacheControl("max-age=86400");
final ResourcesHandler h6 = new ResourcesHandler(this, (Package) null, "/root/");
final FilesHandler h7 = new FilesHandler(this, certificate.getParentFile().getPath() + "/backtracking", "/backtracking/");
return new BaseHttpHandler[] { h1, h2, h3, h4, h5, h6, h7 };
}
@Override
public char[] getKeyPass() {
return "keypass".toCharArray();
}
@Override
public String getKeyStoreFileName() {
return certificate.getPath();
}
@Override
public int getPort() {
return port;
}
@Override
public char[] getStorePass() {
return "storepass".toCharArray();
}
@Override
public boolean isSslEnabled() {
return sslEnabled;
}
@Override
public boolean isTraceMethodEnabled() {
return true;
}
};
server = new LightweightHttpServer(configuration);
}
示例13: setAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
/**
* Register a common {@link com.sun.net.httpserver.Authenticator} to be
* applied to all locally registered {@link #setContexts contexts}.
*/
public void setAuthenticator(Authenticator authenticator) {
this.authenticator = authenticator;
}
示例14: setAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
/**
* Register a common {@link com.sun.net.httpserver.Authenticator} to be
* applied to all detected {@link javax.jws.WebService} annotated beans.
*/
public void setAuthenticator(Authenticator authenticator) {
this.authenticator = authenticator;
}
示例15: setAuthenticator
import com.sun.net.httpserver.Authenticator; //导入依赖的package包/类
/**
* Register a common {@link com.sun.net.httpserver.Authenticator} to be applied to all locally registered
* {@link #setContexts contexts}.
*/
public void setAuthenticator(Authenticator anAuthenticator) {
this.authenticator = anAuthenticator;
}