HBASE-2257 [stargate] multiuser mode
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@915996 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1e6ce3e242
commit
4ca0a97783
|
@ -402,6 +402,7 @@ Release 0.21.0 - Unreleased
|
|||
HBASE-2129 Simple Master/Slave replication
|
||||
HBASE-2070 Collect HLogs and delete them after a period of time
|
||||
HBASE-2221 MR to copy a table
|
||||
HBASE-2257 [stargate] multiuser mode
|
||||
|
||||
OPTIMIZATIONS
|
||||
HBASE-410 [testing] Speed up the test suite
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -24,14 +24,17 @@ package org.apache.hadoop.hbase.stargate;
|
|||
* Common constants for org.apache.hadoop.hbase.stargate
|
||||
*/
|
||||
public interface Constants {
|
||||
public static final String VERSION_STRING = "0.0.2";
|
||||
|
||||
public static final String AUTHENTICATOR_KEY = "stargate.authenticator";
|
||||
public static final String MULTIUSER_KEY = "stargate.multiuser";
|
||||
|
||||
public static final int DEFAULT_MAX_AGE = 60 * 60 * 4; // 4 hours
|
||||
|
||||
public static final String MIMETYPE_TEXT = "text/plain";
|
||||
public static final String MIMETYPE_HTML = "text/html";
|
||||
public static final String MIMETYPE_XML = "text/xml";
|
||||
public static final String MIMETYPE_BINARY = "application/octet-stream";
|
||||
public static final String MIMETYPE_PROTOBUF = "application/x-protobuf";
|
||||
public static final String MIMETYPE_JSON = "application/json";
|
||||
public static final String MIMETYPE_JAVASCRIPT = "application/x-javascript";
|
||||
|
||||
public static final String PATH_STATUS_CLUSTER = "/status/cluster";
|
||||
public static final String PATH_VERSION = "/version";
|
||||
public static final String PATH_VERSION_CLUSTER = "/version/cluster";
|
||||
}
|
||||
|
|
|
@ -39,12 +39,14 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
|
|||
* <li>-p: service port</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class Main {
|
||||
public class Main implements Constants {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// process command line
|
||||
|
||||
Options options = new Options();
|
||||
options.addOption("p", "port", true, "service port");
|
||||
options.addOption("m", "multiuser", false, "enable multiuser mode");
|
||||
CommandLineParser parser = new PosixParser();
|
||||
CommandLine cmd = parser.parse(options, args);
|
||||
int port = 8080;
|
||||
|
@ -52,7 +54,13 @@ public class Main {
|
|||
port = Integer.valueOf(cmd.getOptionValue("p"));
|
||||
}
|
||||
|
||||
// configure the Stargate singleton
|
||||
|
||||
RESTServlet servlet = RESTServlet.getInstance();
|
||||
servlet.setMultiUser(cmd.hasOption("m"));
|
||||
|
||||
// set up the Jersey servlet container for Jetty
|
||||
|
||||
ServletHolder sh = new ServletHolder(ServletContainer.class);
|
||||
sh.setInitParameter(
|
||||
"com.sun.jersey.config.property.resourceConfigClass",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -69,7 +69,6 @@ public class RESTServlet extends ServletAdaptor {
|
|||
this.pool = new HTablePool(conf, 10);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a table pool for the given table.
|
||||
* @return the table pool
|
||||
|
@ -124,4 +123,45 @@ public class RESTServlet extends ServletAdaptor {
|
|||
public void invalidateMaxAge(String tableName) {
|
||||
maxAgeMap.remove(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the servlet should operate in multiuser mode
|
||||
*/
|
||||
public boolean isMultiUser() {
|
||||
return multiuser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param flag true if the servlet should operate in multiuser mode
|
||||
*/
|
||||
public void setMultiUser(boolean multiuser) {
|
||||
this.multiuser = multiuser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an authenticator
|
||||
*/
|
||||
public Authenticator getAuthenticator() {
|
||||
if (authenticator == null) {
|
||||
String className = conf.get("stargate.auth.authenticator");
|
||||
if (className != null) try {
|
||||
Class<?> c = getClass().getClassLoader().loadClass(className);
|
||||
authenticator = (Authenticator)c.newInstance();
|
||||
} catch (Exception e) {
|
||||
LOG.error(StringUtils.stringifyException(e));
|
||||
}
|
||||
if (authenticator == null) {
|
||||
authenticator = new HBCAuthenticator(conf);
|
||||
}
|
||||
}
|
||||
return authenticator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticator
|
||||
*/
|
||||
public void setAuthenticator(Authenticator authenticator) {
|
||||
this.authenticator = authenticator;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.hbase.stargate;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.stargate.auth.User;
|
||||
import org.apache.hadoop.hbase.stargate.model.TableListModel;
|
||||
import org.apache.hadoop.hbase.stargate.model.TableModel;
|
||||
|
||||
@Path("/")
|
||||
public class RootResource implements Constants {
|
||||
private static final Log LOG = LogFactory.getLog(RootResource.class);
|
||||
|
||||
RESTServlet servlet;
|
||||
CacheControl cacheControl;
|
||||
|
||||
public RootResource() throws IOException {
|
||||
servlet = RESTServlet.getInstance();
|
||||
cacheControl = new CacheControl();
|
||||
cacheControl.setNoCache(true);
|
||||
cacheControl.setNoTransform(false);
|
||||
}
|
||||
|
||||
TableListModel getTableList() throws IOException {
|
||||
TableListModel tableList = new TableListModel();
|
||||
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
|
||||
HTableDescriptor[] list = admin.listTables();
|
||||
for (HTableDescriptor htd: list) {
|
||||
tableList.add(new TableModel(htd.getNameAsString()));
|
||||
}
|
||||
return tableList;
|
||||
}
|
||||
|
||||
TableListModel getTableListForUser(User user) throws IOException {
|
||||
TableListModel tableList;
|
||||
if (user.isAdmin()) {
|
||||
tableList = getTableList();
|
||||
} else {
|
||||
tableList = new TableListModel();
|
||||
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
|
||||
HTableDescriptor[] list = admin.listTables();
|
||||
String prefix = user.getName() + ".";
|
||||
for (HTableDescriptor htd: list) {
|
||||
String name = htd.getNameAsString();
|
||||
if (!name.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
tableList.add(new TableModel(name.substring(prefix.length())));
|
||||
}
|
||||
}
|
||||
return tableList;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response get(@Context UriInfo uriInfo) throws IOException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("GET " + uriInfo.getAbsolutePath());
|
||||
}
|
||||
if (servlet.isMultiUser()) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
ResponseBuilder response = Response.ok(getTableList());
|
||||
response.cacheControl(cacheControl);
|
||||
return response.build();
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Path("status/cluster")
|
||||
public StorageClusterStatusResource getClusterStatusResource()
|
||||
throws IOException {
|
||||
if (servlet.isMultiUser()) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
return new StorageClusterStatusResource();
|
||||
}
|
||||
|
||||
@Path("version")
|
||||
public VersionResource getVersionResource() {
|
||||
return new VersionResource();
|
||||
}
|
||||
|
||||
@Path("{token: [0-9a-fA-F]{32} }") // 128 bit md5 sums
|
||||
public Response getTableRootResource(
|
||||
@PathParam("token") String token) throws IOException {
|
||||
if (servlet.isMultiUser()) {
|
||||
User user = servlet.getAuthenticator().getUserForToken(token);
|
||||
if (user == null || user.isDisabled()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
}
|
||||
try {
|
||||
ResponseBuilder response = Response.ok(getTableListForUser(user));
|
||||
response.cacheControl(cacheControl);
|
||||
return response.build();
|
||||
} catch (IOException e) {
|
||||
throw new WebApplicationException(e,
|
||||
Response.Status.SERVICE_UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@Path("{token: [0-9a-fA-F]{32} }/status/cluster") // 128 bit md5 sums
|
||||
public StorageClusterStatusResource getClusterStatusResourceAuthorized(
|
||||
@PathParam("token") String token) throws IOException {
|
||||
if (servlet.isMultiUser()) {
|
||||
User user = servlet.getAuthenticator().getUserForToken(token);
|
||||
if (user != null && user.isAdmin() && !user.isDisabled()) {
|
||||
return new StorageClusterStatusResource();
|
||||
}
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
}
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@Path("{token: [0-9a-fA-F]{32} }/{table}")
|
||||
public TableResource getTableResource(@PathParam("token") String token,
|
||||
@PathParam("table") String table) throws IOException {
|
||||
if (servlet.isMultiUser()) {
|
||||
User user = servlet.getAuthenticator().getUserForToken(token);
|
||||
if (user == null || user.isDisabled()) {
|
||||
throw new WebApplicationException(Response.Status.FORBIDDEN);
|
||||
}
|
||||
return new TableResource(user, table);
|
||||
}
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@Path("{table}")
|
||||
public TableResource getTableResource(@PathParam("table") String table)
|
||||
throws IOException {
|
||||
if (servlet.isMultiUser()) {
|
||||
throw new WebApplicationException(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
return new TableResource(null, table);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -63,8 +63,7 @@ public class ScannerInstanceResource implements Constants {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
@Produces({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response get(@Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("GET " + uriInfo.getAbsolutePath());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -41,18 +41,29 @@ import javax.ws.rs.core.UriInfo;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.apache.hadoop.hbase.stargate.auth.User;
|
||||
import org.apache.hadoop.hbase.stargate.model.ScannerModel;
|
||||
|
||||
public class ScannerResource implements Constants {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(ScannerResource.class);
|
||||
protected static final Map<String,ScannerInstanceResource> scanners =
|
||||
|
||||
static final Map<String,ScannerInstanceResource> scanners =
|
||||
new HashMap<String,ScannerInstanceResource>();
|
||||
|
||||
private String table;
|
||||
User user;
|
||||
String tableName;
|
||||
String actualTableName;
|
||||
|
||||
public ScannerResource(String table) {
|
||||
this.table = table;
|
||||
public ScannerResource(User user, String table) {
|
||||
if (user != null) {
|
||||
this.user = user;
|
||||
this.actualTableName =
|
||||
!user.isAdmin() ? user.getName() + "." + table : table;
|
||||
} else {
|
||||
this.actualTableName = table;
|
||||
}
|
||||
this.tableName = table;
|
||||
}
|
||||
|
||||
private Response update(ScannerModel model, boolean replace,
|
||||
|
@ -61,10 +72,10 @@ public class ScannerResource implements Constants {
|
|||
byte[] endRow = model.hasEndRow() ? model.getEndRow() : null;
|
||||
RowSpec spec = new RowSpec(model.getStartRow(), endRow,
|
||||
model.getColumns(), model.getStartTime(), model.getEndTime(), 1);
|
||||
ScannerResultGenerator gen = new ScannerResultGenerator(table, spec);
|
||||
ScannerResultGenerator gen = new ScannerResultGenerator(actualTableName, spec);
|
||||
String id = gen.getID();
|
||||
ScannerInstanceResource instance =
|
||||
new ScannerInstanceResource(table, id, gen, model.getBatch());
|
||||
new ScannerInstanceResource(actualTableName, id, gen, model.getBatch());
|
||||
synchronized (scanners) {
|
||||
scanners.put(id, instance);
|
||||
}
|
||||
|
@ -83,8 +94,7 @@ public class ScannerResource implements Constants {
|
|||
}
|
||||
|
||||
@PUT
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response put(ScannerModel model, @Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("PUT " + uriInfo.getAbsolutePath());
|
||||
|
@ -93,8 +103,7 @@ public class ScannerResource implements Constants {
|
|||
}
|
||||
|
||||
@POST
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response post(ScannerModel model, @Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("POST " + uriInfo.getAbsolutePath());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -47,6 +47,7 @@ import org.apache.hadoop.hbase.client.HBaseAdmin;
|
|||
import org.apache.hadoop.hbase.client.HTableInterface;
|
||||
import org.apache.hadoop.hbase.client.HTablePool;
|
||||
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
||||
import org.apache.hadoop.hbase.stargate.auth.User;
|
||||
import org.apache.hadoop.hbase.stargate.model.ColumnSchemaModel;
|
||||
import org.apache.hadoop.hbase.stargate.model.TableSchemaModel;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
@ -76,8 +77,7 @@ public class SchemaResource implements Constants {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response get(@Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("GET " + uriInfo.getAbsolutePath());
|
||||
|
@ -85,7 +85,7 @@ public class SchemaResource implements Constants {
|
|||
try {
|
||||
HTableDescriptor htd = getTableSchema();
|
||||
TableSchemaModel model = new TableSchemaModel();
|
||||
model.setName(htd.getNameAsString());
|
||||
model.setName(tableName);
|
||||
for (Map.Entry<ImmutableBytesWritable, ImmutableBytesWritable> e:
|
||||
htd.getValues().entrySet()) {
|
||||
model.addAttribute(Bytes.toString(e.getKey().get()),
|
||||
|
@ -176,10 +176,9 @@ public class SchemaResource implements Constants {
|
|||
private Response update(TableSchemaModel model, boolean replace,
|
||||
UriInfo uriInfo) {
|
||||
try {
|
||||
RESTServlet server = RESTServlet.getInstance();
|
||||
server.invalidateMaxAge(model.getName());
|
||||
HBaseAdmin admin = new HBaseAdmin(server.getConfiguration());
|
||||
byte[] tableName = Bytes.toBytes(model.getName());
|
||||
servlet.invalidateMaxAge(tableName);
|
||||
byte[] tableName = Bytes.toBytes(actualTableName);
|
||||
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
|
||||
if (replace || !admin.tableExists(tableName)) {
|
||||
return replace(tableName, model, uriInfo, admin);
|
||||
} else {
|
||||
|
@ -192,22 +191,32 @@ public class SchemaResource implements Constants {
|
|||
}
|
||||
|
||||
@PUT
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response put(TableSchemaModel model, @Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("PUT " + uriInfo.getAbsolutePath());
|
||||
}
|
||||
// use the name given in the path, but warn if the name on the path and
|
||||
// the name in the schema are different
|
||||
if (model.getName() != tableName) {
|
||||
LOG.warn("table name mismatch: path='" + tableName + "', schema='" +
|
||||
model.getName() + "'");
|
||||
}
|
||||
return update(model, true, uriInfo);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
@Consumes({MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response post(TableSchemaModel model, @Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("PUT " + uriInfo.getAbsolutePath());
|
||||
}
|
||||
// use the name given in the path, but warn if the name on the path and
|
||||
// the name in the schema are different
|
||||
if (model.getName() != tableName) {
|
||||
LOG.warn("table name mismatch: path='" + tableName + "', schema='" +
|
||||
model.getName() + "'");
|
||||
}
|
||||
return update(model, false, uriInfo);
|
||||
}
|
||||
|
||||
|
@ -217,10 +226,9 @@ public class SchemaResource implements Constants {
|
|||
LOG.debug("DELETE " + uriInfo.getAbsolutePath());
|
||||
}
|
||||
try {
|
||||
HBaseAdmin admin =
|
||||
new HBaseAdmin(RESTServlet.getInstance().getConfiguration());
|
||||
admin.disableTable(table);
|
||||
admin.deleteTable(table);
|
||||
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
|
||||
admin.disableTable(actualTableName);
|
||||
admin.deleteTable(actualTableName);
|
||||
return Response.ok().build();
|
||||
} catch (TableNotFoundException e) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -23,7 +23,6 @@ package org.apache.hadoop.hbase.stargate;
|
|||
import java.io.IOException;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
|
@ -41,29 +40,28 @@ import org.apache.hadoop.hbase.HServerLoad;
|
|||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.stargate.model.StorageClusterStatusModel;
|
||||
|
||||
@Path(Constants.PATH_STATUS_CLUSTER)
|
||||
public class StorageClusterStatusResource implements Constants {
|
||||
private static final Log LOG =
|
||||
LogFactory.getLog(StorageClusterStatusResource.class);
|
||||
|
||||
private CacheControl cacheControl;
|
||||
private RESTServlet servlet;
|
||||
|
||||
public StorageClusterStatusResource() {
|
||||
public StorageClusterStatusResource() throws IOException {
|
||||
cacheControl = new CacheControl();
|
||||
cacheControl.setNoCache(true);
|
||||
cacheControl.setNoTransform(false);
|
||||
servlet = RESTServlet.getInstance();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response get(@Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("GET " + uriInfo.getAbsolutePath());
|
||||
}
|
||||
try {
|
||||
RESTServlet server = RESTServlet.getInstance();
|
||||
HBaseAdmin admin = new HBaseAdmin(server.getConfiguration());
|
||||
HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
|
||||
ClusterStatus status = admin.getClusterStatus();
|
||||
StorageClusterStatusModel model = new StorageClusterStatusModel();
|
||||
model.setRegions(status.getRegionsCount());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -23,7 +23,6 @@ package org.apache.hadoop.hbase.stargate;
|
|||
import java.io.IOException;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
|
@ -39,7 +38,6 @@ import org.apache.hadoop.hbase.HBaseConfiguration;
|
|||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.stargate.model.StorageClusterVersionModel;
|
||||
|
||||
@Path(Constants.PATH_VERSION_CLUSTER)
|
||||
public class StorageClusterVersionResource implements Constants {
|
||||
private static final Log LOG =
|
||||
LogFactory.getLog(StorageClusterVersionResource.class);
|
||||
|
@ -53,7 +51,7 @@ public class StorageClusterVersionResource implements Constants {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT})
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON})
|
||||
public Response get(@Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("GET " + uriInfo.getAbsolutePath());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -41,7 +41,6 @@ import org.apache.hadoop.hbase.stargate.model.VersionModel;
|
|||
* <p>
|
||||
* <tt>/version</tt> (alias for <tt>/version/stargate</tt>)
|
||||
*/
|
||||
@Path(Constants.PATH_VERSION)
|
||||
public class VersionResource implements Constants {
|
||||
private static final Log LOG = LogFactory.getLog(VersionResource.class);
|
||||
|
||||
|
@ -60,9 +59,9 @@ public class VersionResource implements Constants {
|
|||
* @return a response for a version request
|
||||
*/
|
||||
@GET
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_JAVASCRIPT,
|
||||
MIMETYPE_PROTOBUF})
|
||||
public Response get(@Context ServletContext context, @Context UriInfo uriInfo) {
|
||||
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF})
|
||||
public Response get(@Context ServletContext context,
|
||||
@Context UriInfo uriInfo) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("GET " + uriInfo.getAbsolutePath());
|
||||
}
|
||||
|
@ -71,10 +70,17 @@ public class VersionResource implements Constants {
|
|||
return response.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch to StorageClusterVersionResource
|
||||
*/
|
||||
@Path("cluster")
|
||||
public StorageClusterVersionResource getClusterVersionResource() {
|
||||
return new StorageClusterVersionResource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch <tt>/version/stargate</tt> to self.
|
||||
*/
|
||||
// "/version/stargate" is an alias for "/version"
|
||||
@Path("stargate")
|
||||
public VersionResource getVersionResource() {
|
||||
return this;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class Authenticator {
|
||||
|
||||
public abstract User getUserForToken(String token) throws IOException;
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
|
||||
public class HBCAuthenticator extends Authenticator {
|
||||
|
||||
HBaseConfiguration conf;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public HBCAuthenticator() {
|
||||
this(new HBaseConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param conf
|
||||
*/
|
||||
public HBCAuthenticator(HBaseConfiguration conf) {
|
||||
this.conf = conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserForToken(String token) {
|
||||
String name = conf.get("stargate.auth.token." + token);
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
boolean admin = conf.getBoolean("stargate.auth.user." + name + ".admin",
|
||||
false);
|
||||
boolean disabled = conf.getBoolean("stargate.auth.user." + name + ".disabled",
|
||||
false);
|
||||
return new User(name, token, admin, disabled);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
import org.apache.hadoop.hbase.client.Get;
|
||||
import org.apache.hadoop.hbase.client.HTable;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class HTableAuthenticator extends Authenticator {
|
||||
|
||||
static final byte[] USER = Bytes.toBytes("user");
|
||||
static final byte[] NAME = Bytes.toBytes("name");
|
||||
static final byte[] ADMIN = Bytes.toBytes("admin");
|
||||
static final byte[] DISABLED = Bytes.toBytes("disabled");
|
||||
|
||||
HBaseConfiguration conf;
|
||||
String tableName;
|
||||
HTable table;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public HTableAuthenticator() {
|
||||
this(new HBaseConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param conf
|
||||
*/
|
||||
public HTableAuthenticator(HBaseConfiguration conf) {
|
||||
this.conf = conf;
|
||||
this.tableName = conf.get("stargate.auth.htable.name",
|
||||
"stargate.users");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param conf
|
||||
* @param tableName
|
||||
*/
|
||||
public HTableAuthenticator(HBaseConfiguration conf, String tableName) {
|
||||
this.conf = conf;
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param conf
|
||||
* @param table
|
||||
*/
|
||||
public HTableAuthenticator(HBaseConfiguration conf, HTable table) {
|
||||
this.conf = conf;
|
||||
this.table = table;
|
||||
this.tableName = Bytes.toString(table.getTableName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserForToken(String token) throws IOException {
|
||||
if (table == null) {
|
||||
this.table = new HTable(conf, tableName);
|
||||
}
|
||||
Get get = new Get(Bytes.toBytes(token));
|
||||
get.addColumn(USER, NAME);
|
||||
get.addColumn(USER, ADMIN);
|
||||
get.addColumn(USER, DISABLED);
|
||||
Result result = table.get(get);
|
||||
byte[] value = result.getValue(USER, NAME);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String name = Bytes.toString(value);
|
||||
boolean admin = false;
|
||||
value = result.getValue(USER, ADMIN);
|
||||
if (value != null) {
|
||||
admin = Bytes.toBoolean(value);
|
||||
}
|
||||
boolean disabled = false;
|
||||
value = result.getValue(USER, DISABLED);
|
||||
if (value != null) {
|
||||
disabled = Bytes.toBoolean(value);
|
||||
}
|
||||
return new User(name, token, admin, disabled);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
import org.mortbay.log.Log;
|
||||
|
||||
public class JDBCAuthenticator extends Authenticator {
|
||||
|
||||
static final int MAX_RETRIES = 5;
|
||||
static final long RETRY_SLEEP_TIME = 1000 * 2;
|
||||
|
||||
String url;
|
||||
String table;
|
||||
String user;
|
||||
String password;
|
||||
Connection connection;
|
||||
PreparedStatement userFetchStmt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param url
|
||||
* @param user
|
||||
* @param password
|
||||
*/
|
||||
public JDBCAuthenticator(String url, String user, String password) {
|
||||
this(url, "users", user, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param url
|
||||
* @param table
|
||||
* @param user
|
||||
* @param password
|
||||
*/
|
||||
public JDBCAuthenticator(String url, String table, String user,
|
||||
String password) {
|
||||
this.url = url;
|
||||
this.table = table;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserForToken(String token) throws IOException {
|
||||
int retries = 0;
|
||||
while (true) try {
|
||||
if (connection == null) {
|
||||
connection = DriverManager.getConnection(url, user, password);
|
||||
userFetchStmt = connection.prepareStatement(
|
||||
"SELECT name, admin, disabled FROM " + table + " WHERE token = ?");
|
||||
}
|
||||
ResultSet results;
|
||||
synchronized (userFetchStmt) {
|
||||
userFetchStmt.setString(1, token);
|
||||
results = userFetchStmt.executeQuery();
|
||||
}
|
||||
if (!results.next()) {
|
||||
return null;
|
||||
}
|
||||
return new User(results.getString(1), token, results.getBoolean(2),
|
||||
results.getBoolean(3));
|
||||
} catch (SQLException e) {
|
||||
connection = null;
|
||||
if (++retries > MAX_RETRIES) {
|
||||
throw new IOException(e);
|
||||
} else try {
|
||||
Log.warn(StringUtils.stringifyException(e));
|
||||
Thread.sleep(RETRY_SLEEP_TIME);
|
||||
} catch (InterruptedException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
/** Representation of an authorized user */
|
||||
public class User {
|
||||
|
||||
public static final User DEFAULT_USER = new User("default",
|
||||
"00000000000000000000000000000000", false, true);
|
||||
|
||||
private String name;
|
||||
private String token;
|
||||
private boolean admin;
|
||||
private boolean disabled = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* <p>
|
||||
* Creates an access token. (Normally, you don't want this.)
|
||||
* @param name user name
|
||||
* @param admin true if user has administrator privilege
|
||||
* @throws Exception
|
||||
*/
|
||||
public User(String name, boolean admin) throws Exception {
|
||||
this.name = name;
|
||||
this.admin = admin;
|
||||
byte[] digest = MessageDigest.getInstance("MD5")
|
||||
.digest(Bytes.toBytes(name));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < digest.length; i++) {
|
||||
sb.append(Integer.toHexString(0xff & digest[i]));
|
||||
}
|
||||
this.token = sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name user name
|
||||
* @param token access token, a 16 char hex string
|
||||
* @param admin true if user has administrator privilege
|
||||
*/
|
||||
public User(String name, String token, boolean admin) {
|
||||
this(name, token, admin, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name user name
|
||||
* @param token access token, a 16 char hex string
|
||||
* @param admin true if user has administrator privilege
|
||||
* @param disabled true if user is disabled
|
||||
*/
|
||||
public User(String name, String token, boolean admin, boolean disabled) {
|
||||
this.name = name;
|
||||
this.token = token;
|
||||
this.admin = admin;
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return user name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name user name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return access token, a 16 char hex string
|
||||
*/
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param token access token, a 16 char hex string
|
||||
*/
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if user has administrator privilege
|
||||
*/
|
||||
public boolean isAdmin() {
|
||||
return admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param admin true if user has administrator privilege
|
||||
*/
|
||||
public void setAdmin(boolean admin) {
|
||||
this.admin = admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if user is disabled
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param admin true if user is disabled
|
||||
*/
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2009 The Apache Software Foundation
|
||||
// Copyright 2010 The Apache Software Foundation
|
||||
//
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -85,7 +85,7 @@ public class TestStatusResource extends MiniClusterTestCase {
|
|||
}
|
||||
|
||||
public void testGetClusterStatusXML() throws IOException, JAXBException {
|
||||
Response response = client.get(Constants.PATH_STATUS_CLUSTER, MIMETYPE_XML);
|
||||
Response response = client.get("/status/cluster", MIMETYPE_XML);
|
||||
assertEquals(response.getCode(), 200);
|
||||
StorageClusterStatusModel model = (StorageClusterStatusModel)
|
||||
context.createUnmarshaller().unmarshal(
|
||||
|
@ -94,8 +94,7 @@ public class TestStatusResource extends MiniClusterTestCase {
|
|||
}
|
||||
|
||||
public void testGetClusterStatusPB() throws IOException {
|
||||
Response response =
|
||||
client.get(Constants.PATH_STATUS_CLUSTER, MIMETYPE_PROTOBUF);
|
||||
Response response = client.get("/status/cluster", MIMETYPE_PROTOBUF);
|
||||
assertEquals(response.getCode(), 200);
|
||||
StorageClusterStatusModel model = new StorageClusterStatusModel();
|
||||
model.getObjectFromMessage(response.getBody());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2009 The Apache Software Foundation
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
|
@ -85,7 +85,7 @@ public class TestVersionResource extends MiniClusterTestCase {
|
|||
}
|
||||
|
||||
public void testGetStargateVersionText() throws IOException {
|
||||
Response response = client.get(Constants.PATH_VERSION, MIMETYPE_PLAIN);
|
||||
Response response = client.get("/version", MIMETYPE_PLAIN);
|
||||
assertTrue(response.getCode() == 200);
|
||||
String body = Bytes.toString(response.getBody());
|
||||
assertTrue(body.length() > 0);
|
||||
|
@ -101,7 +101,7 @@ public class TestVersionResource extends MiniClusterTestCase {
|
|||
}
|
||||
|
||||
public void testGetStargateVersionXML() throws IOException, JAXBException {
|
||||
Response response = client.get(Constants.PATH_VERSION, MIMETYPE_XML);
|
||||
Response response = client.get("/version", MIMETYPE_XML);
|
||||
assertTrue(response.getCode() == 200);
|
||||
VersionModel model = (VersionModel)
|
||||
context.createUnmarshaller().unmarshal(
|
||||
|
@ -111,12 +111,12 @@ public class TestVersionResource extends MiniClusterTestCase {
|
|||
}
|
||||
|
||||
public void testGetStargateVersionJSON() throws IOException {
|
||||
Response response = client.get(Constants.PATH_VERSION, MIMETYPE_JSON);
|
||||
Response response = client.get("/version", MIMETYPE_JSON);
|
||||
assertTrue(response.getCode() == 200);
|
||||
}
|
||||
|
||||
public void testGetStargateVersionPB() throws IOException {
|
||||
Response response = client.get(Constants.PATH_VERSION, MIMETYPE_PROTOBUF);
|
||||
Response response = client.get("/version", MIMETYPE_PROTOBUF);
|
||||
assertTrue(response.getCode() == 200);
|
||||
VersionModel model = new VersionModel();
|
||||
model.getObjectFromMessage(response.getBody());
|
||||
|
@ -125,15 +125,13 @@ public class TestVersionResource extends MiniClusterTestCase {
|
|||
}
|
||||
|
||||
public void testGetStorageClusterVersionText() throws IOException {
|
||||
Response response =
|
||||
client.get(Constants.PATH_VERSION_CLUSTER, MIMETYPE_PLAIN);
|
||||
Response response = client.get("/version/cluster", MIMETYPE_PLAIN);
|
||||
assertTrue(response.getCode() == 200);
|
||||
}
|
||||
|
||||
public void testGetStorageClusterVersionXML() throws IOException,
|
||||
JAXBException {
|
||||
Response response =
|
||||
client.get(Constants.PATH_VERSION_CLUSTER, MIMETYPE_XML);
|
||||
Response response = client.get("/version/cluster", MIMETYPE_XML);
|
||||
assertTrue(response.getCode() == 200);
|
||||
StorageClusterVersionModel clusterVersionModel =
|
||||
(StorageClusterVersionModel)
|
||||
|
@ -145,8 +143,7 @@ public class TestVersionResource extends MiniClusterTestCase {
|
|||
}
|
||||
|
||||
public void testGetStorageClusterVersionJSON() throws IOException {
|
||||
Response response =
|
||||
client.get(Constants.PATH_VERSION_CLUSTER, MIMETYPE_JSON);
|
||||
Response response = client.get("/version/cluster", MIMETYPE_JSON);
|
||||
assertTrue(response.getCode() == 200);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestHBCAuthenticator extends TestCase {
|
||||
|
||||
static final String UNKNOWN_TOKEN = "00000000000000000000000000000000";
|
||||
static final String ADMIN_TOKEN = "e998efffc67c49c6e14921229a51b7b3";
|
||||
static final String ADMIN_USERNAME = "testAdmin";
|
||||
static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
|
||||
static final String USER_USERNAME = "testUser";
|
||||
static final String DISABLED_TOKEN = "17de5b5db0fd3de0847bd95396f36d92";
|
||||
static final String DISABLED_USERNAME = "disabledUser";
|
||||
|
||||
static HBCAuthenticator authenticator;
|
||||
static HBaseConfiguration conf;
|
||||
static {
|
||||
conf = new HBaseConfiguration();
|
||||
conf.set("stargate.auth.token." + USER_TOKEN, USER_USERNAME);
|
||||
conf.set("stargate.auth.user." + USER_USERNAME + ".admin", "false");
|
||||
conf.set("stargate.auth.user." + USER_USERNAME + ".disabled", "false");
|
||||
conf.set("stargate.auth.token." + ADMIN_TOKEN, ADMIN_USERNAME);
|
||||
conf.set("stargate.auth.user." + ADMIN_USERNAME + ".admin", "true");
|
||||
conf.set("stargate.auth.user." + ADMIN_USERNAME + ".disabled", "false");
|
||||
conf.set("stargate.auth.token." + DISABLED_TOKEN, DISABLED_USERNAME);
|
||||
conf.set("stargate.auth.user." + DISABLED_USERNAME + ".admin", "false");
|
||||
conf.set("stargate.auth.user." + DISABLED_USERNAME + ".disabled", "true");
|
||||
authenticator = new HBCAuthenticator(conf);
|
||||
}
|
||||
|
||||
public void testGetUserUnknown() throws Exception {
|
||||
User user = authenticator.getUserForToken(UNKNOWN_TOKEN);
|
||||
assertNull(user);
|
||||
}
|
||||
|
||||
public void testGetAdminUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(ADMIN_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), ADMIN_USERNAME);
|
||||
assertTrue(user.isAdmin());
|
||||
assertFalse(user.isDisabled());
|
||||
}
|
||||
|
||||
public void testGetPlainUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(USER_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), USER_USERNAME);
|
||||
assertFalse(user.isAdmin());
|
||||
assertFalse(user.isDisabled());
|
||||
}
|
||||
|
||||
public void testGetDisabledUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(DISABLED_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), DISABLED_USERNAME);
|
||||
assertFalse(user.isAdmin());
|
||||
assertTrue(user.isDisabled());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||
import org.apache.hadoop.hbase.client.HTable;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.hadoop.hbase.stargate.MiniClusterTestCase;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
|
||||
public class TestHTableAuthenticator extends MiniClusterTestCase {
|
||||
|
||||
static final String UNKNOWN_TOKEN = "00000000000000000000000000000000";
|
||||
static final String ADMIN_TOKEN = "e998efffc67c49c6e14921229a51b7b3";
|
||||
static final String ADMIN_USERNAME = "testAdmin";
|
||||
static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
|
||||
static final String USER_USERNAME = "testUser";
|
||||
static final String DISABLED_TOKEN = "17de5b5db0fd3de0847bd95396f36d92";
|
||||
static final String DISABLED_USERNAME = "disabledUser";
|
||||
|
||||
static final String TABLE = "TestHTableAuthenticator";
|
||||
static final byte[] USER = Bytes.toBytes("user");
|
||||
static final byte[] NAME = Bytes.toBytes("name");
|
||||
static final byte[] ADMIN = Bytes.toBytes("admin");
|
||||
static final byte[] DISABLED = Bytes.toBytes("disabled");
|
||||
|
||||
HTableAuthenticator authenticator;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
if (!admin.tableExists(TABLE)) {
|
||||
HTableDescriptor htd = new HTableDescriptor(TABLE);
|
||||
htd.addFamily(new HColumnDescriptor(USER));
|
||||
admin.createTable(htd);
|
||||
HTable table = new HTable(conf, TABLE);
|
||||
Put put = new Put(Bytes.toBytes(ADMIN_TOKEN));
|
||||
put.add(USER, NAME, Bytes.toBytes(ADMIN_USERNAME));
|
||||
put.add(USER, ADMIN, Bytes.toBytes(true));
|
||||
table.put(put);
|
||||
put = new Put(Bytes.toBytes(USER_TOKEN));
|
||||
put.add(USER, NAME, Bytes.toBytes(USER_USERNAME));
|
||||
put.add(USER, ADMIN, Bytes.toBytes(false));
|
||||
table.put(put);
|
||||
put = new Put(Bytes.toBytes(DISABLED_TOKEN));
|
||||
put.add(USER, NAME, Bytes.toBytes(DISABLED_USERNAME));
|
||||
put.add(USER, DISABLED, Bytes.toBytes(true));
|
||||
table.put(put);
|
||||
table.flushCommits();
|
||||
}
|
||||
authenticator = new HTableAuthenticator(conf, TABLE);
|
||||
}
|
||||
|
||||
public void testGetUserUnknown() throws Exception {
|
||||
User user = authenticator.getUserForToken(UNKNOWN_TOKEN);
|
||||
assertNull(user);
|
||||
}
|
||||
|
||||
public void testGetAdminUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(ADMIN_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), ADMIN_USERNAME);
|
||||
assertTrue(user.isAdmin());
|
||||
assertFalse(user.isDisabled());
|
||||
}
|
||||
|
||||
public void testGetPlainUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(USER_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), USER_USERNAME);
|
||||
assertFalse(user.isAdmin());
|
||||
assertFalse(user.isDisabled());
|
||||
}
|
||||
|
||||
public void testGetDisabledUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(DISABLED_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), DISABLED_USERNAME);
|
||||
assertFalse(user.isAdmin());
|
||||
assertTrue(user.isDisabled());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright 2010 The Apache Software Foundation
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.hbase.stargate.auth;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestJDBCAuthenticator extends TestCase {
|
||||
|
||||
static final Log LOG = LogFactory.getLog(TestJDBCAuthenticator.class);
|
||||
|
||||
static final String TABLE = "users";
|
||||
static final String JDBC_URL = "jdbc:hsqldb:mem:test";
|
||||
|
||||
static final String UNKNOWN_TOKEN = "00000000000000000000000000000000";
|
||||
static final String ADMIN_TOKEN = "e998efffc67c49c6e14921229a51b7b3";
|
||||
static final String ADMIN_USERNAME = "testAdmin";
|
||||
static final String USER_TOKEN = "da4829144e3a2febd909a6e1b4ed7cfa";
|
||||
static final String USER_USERNAME = "testUser";
|
||||
static final String DISABLED_TOKEN = "17de5b5db0fd3de0847bd95396f36d92";
|
||||
static final String DISABLED_USERNAME = "disabledUser";
|
||||
|
||||
static JDBCAuthenticator authenticator;
|
||||
static {
|
||||
try {
|
||||
Class.forName("org.hsqldb.jdbcDriver");
|
||||
Connection c = DriverManager.getConnection(JDBC_URL, "SA", "");
|
||||
c.createStatement().execute(
|
||||
"CREATE TABLE " + TABLE + " ( " +
|
||||
"token CHAR(32) PRIMARY KEY, " +
|
||||
"name VARCHAR(32), " +
|
||||
"admin BOOLEAN, " +
|
||||
"disabled BOOLEAN " +
|
||||
")");
|
||||
c.createStatement().execute(
|
||||
"INSERT INTO " + TABLE + " ( token,name,admin,disabled ) " +
|
||||
"VALUES ( '" + ADMIN_TOKEN + "','" + ADMIN_USERNAME +
|
||||
"',TRUE,FALSE )");
|
||||
c.createStatement().execute(
|
||||
"INSERT INTO " + TABLE + " ( token,name,admin,disabled ) " +
|
||||
"VALUES ( '" + USER_TOKEN + "','" + USER_USERNAME +
|
||||
"',FALSE,FALSE )");
|
||||
c.createStatement().execute(
|
||||
"INSERT INTO " + TABLE + " ( token,name,admin,disabled ) " +
|
||||
"VALUES ( '" + DISABLED_TOKEN + "','" + DISABLED_USERNAME +
|
||||
"',FALSE,TRUE )");
|
||||
c.createStatement().execute("CREATE USER test PASSWORD access");
|
||||
c.createStatement().execute("GRANT ALL ON " + TABLE + " TO test");
|
||||
c.close();
|
||||
authenticator = new JDBCAuthenticator(JDBC_URL, TABLE, "test",
|
||||
"access");
|
||||
} catch (Exception e) {
|
||||
LOG.warn(StringUtils.stringifyException(e));
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetUserUnknown() throws Exception {
|
||||
User user = authenticator.getUserForToken(UNKNOWN_TOKEN);
|
||||
assertNull(user);
|
||||
}
|
||||
|
||||
public void testGetAdminUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(ADMIN_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), ADMIN_USERNAME);
|
||||
assertTrue(user.isAdmin());
|
||||
assertFalse(user.isDisabled());
|
||||
}
|
||||
|
||||
public void testGetPlainUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(USER_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), USER_USERNAME);
|
||||
assertFalse(user.isAdmin());
|
||||
assertFalse(user.isDisabled());
|
||||
}
|
||||
|
||||
public void testGetDisabledUser() throws Exception {
|
||||
User user = authenticator.getUserForToken(DISABLED_TOKEN);
|
||||
assertNotNull(user);
|
||||
assertEquals(user.getName(), DISABLED_USERNAME);
|
||||
assertFalse(user.isAdmin());
|
||||
assertTrue(user.isDisabled());
|
||||
}
|
||||
|
||||
}
|
|
@ -268,7 +268,7 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
|
|||
}
|
||||
if (b[0] == '.' || b[0] == '-') {
|
||||
throw new IllegalArgumentException("Illegal first character <" + b[0] +
|
||||
">. " + "User-space table names can only start with 'word " +
|
||||
"> at 0. User-space table names can only start with 'word " +
|
||||
"characters': i.e. [a-zA-Z_0-9]: " + Bytes.toString(b));
|
||||
}
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
|
@ -276,9 +276,9 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
|
|||
b[i] == '.') {
|
||||
continue;
|
||||
}
|
||||
throw new IllegalArgumentException("Illegal character <" + b[i] + ">. " +
|
||||
"User-space table names can only contain 'word characters':" +
|
||||
"i.e. [a-zA-Z_0-9-.]: " + Bytes.toString(b));
|
||||
throw new IllegalArgumentException("Illegal character <" + b[i] +
|
||||
"> at " + i + ". User-space table names can only contain " +
|
||||
"'word characters': i.e. [a-zA-Z_0-9-.]: " + Bytes.toString(b));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
@ -409,6 +409,11 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
|
|||
return HConstants.DEFAULT_MAX_FILE_SIZE;
|
||||
}
|
||||
|
||||
/** @param name name of table */
|
||||
public void setName(byte[] name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxFileSize The maximum file size that a store file can grow to
|
||||
* before a split is triggered.
|
||||
|
|
Loading…
Reference in New Issue