Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public static ConfigPhysicalPlan create(ByteBuffer buffer) throws IOException {
case RevokeRole:
case RevokeRoleFromUser:
case UpdateUser:
case CreateUserWithRawPassword:
plan = new AuthorPlan(configPhysicalPlanType);
break;
case ApplyConfigNode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public enum ConfigPhysicalPlanType {
ListUserRoles((short) 636),
@Deprecated
ListRoleUsers((short) 637),
CreateUserWithRawPassword((short) 638),

/** Function. */
CreateFunction((short) 700),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ public TSStatus authorNonQuery(AuthorPlan authorPlan) {
case CreateUser:
authorizer.createUser(userName, password);
break;
case CreateUserWithRawPassword:
authorizer.createUserWithRawPassword(userName, password);
break;
case CreateRoleDep:
AuthUtils.validateRolenamePre(roleName);
authorizer.createRole(roleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.iotdb.confignode.consensus.request.auth.AuthorPlan;
import org.apache.iotdb.confignode.consensus.response.auth.PermissionInfoResp;
import org.apache.iotdb.confignode.rpc.thrift.TCheckUserPrivilegesReq;
import org.apache.iotdb.confignode.rpc.thrift.TPermissionInfoResp;
import org.apache.iotdb.rpc.TSStatusCode;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -1020,4 +1021,24 @@ public void testDepAuthorPlan() throws TException, AuthException, IllegalPathExc
}
}
}

@Test
public void createUserWithRawPassword() throws AuthException {
TSStatus status;
AuthorPlan authorPlan;
authorPlan =
new AuthorPlan(
ConfigPhysicalPlanType.CreateUserWithRawPassword,
"testuser",
"",
AuthUtils.encryptPassword("password"),
"",
new HashSet<>(),
false,
new ArrayList<>());
status = authorInfo.authorNonQuery(authorPlan);
Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
TPermissionInfoResp result = authorInfo.login("testuser", "password");
Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), result.getStatus().getCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,30 @@ public Statement visitMeasurementMNode(
final CreateLogicalViewStatement stmt = new CreateLogicalViewStatement();
final LogicalViewSchema viewSchema =
(LogicalViewSchema) node.getAsMeasurementMNode().getSchema();
stmt.setTargetFullPaths(Collections.singletonList(path));
stmt.setViewExpressions(Collections.singletonList(viewSchema.getExpression()));
if (viewSchema != null) {
stmt.setTargetFullPaths(Collections.singletonList(path));
stmt.setViewExpressions(Collections.singletonList(viewSchema.getExpression()));
return stmt;
}
// if (node.getOffset() >= 0) {
// final AlterTimeSeriesStatement alterTimeSeriesStatement = new
// AlterTimeSeriesStatement();
// alterTimeSeriesStatement.setPath(path);
// try {
// Pair<Map<String, String>, Map<String, String>> tagsAndAttribute =
// getTagsAndAttributes(node.getOffset());
// if (tagsAndAttribute != null) {
// alterTimeSeriesStatement.setTagsMap(tagsAndAttribute.left);
// alterTimeSeriesStatement.setAttributesMap(tagsAndAttribute.right);
// }
// } catch (IOException ioException) {
// lastExcept = ioException;
// LOGGER.warn(
// "Error when parse tag and attributes file of node path {}", path,
// ioException);
// }
// node.setOffset(0);
// }
return stmt;
} else {
final CreateTimeSeriesStatement stmt = new CreateTimeSeriesStatement();
Expand All @@ -291,24 +313,18 @@ public Statement visitMeasurementMNode(
stmt.setDataType(node.getDataType());
stmt.setEncoding(node.getAsMeasurementMNode().getSchema().getEncodingType());
if (node.getOffset() >= 0) {
if (tagFileChannel != null) {
try {
final ByteBuffer byteBuffer =
ByteBuffer.allocate(COMMON_CONFIG.getTagAttributeTotalSize());
tagFileChannel.read(byteBuffer, node.getOffset());
byteBuffer.flip();
final Pair<Map<String, String>, Map<String, String>> tagsAndAttributes =
new Pair<>(
ReadWriteIOUtils.readMap(byteBuffer), ReadWriteIOUtils.readMap(byteBuffer));
try {
final Pair<Map<String, String>, Map<String, String>> tagsAndAttributes =
getTagsAndAttributes(node.getOffset());
if (tagsAndAttributes != null) {
stmt.setTags(tagsAndAttributes.left);
stmt.setAttributes(tagsAndAttributes.right);
} catch (IOException exception) {
lastExcept = exception;
LOGGER.warn("Error when parser tag and attributes files", exception);
}
} else {
LOGGER.warn("Timeseries has attributes and tags but don't find tag file");
} catch (IOException ioException) {
lastExcept = ioException;
LOGGER.warn("Error when parser tag and attributes files", ioException);
}
node.setOffset(0);
}
return stmt;
}
Expand Down Expand Up @@ -338,30 +354,41 @@ private Statement genAlignedTimeseriesStatement(IMNode node, PartialPath path) {
stmt.addEncoding(measurement.getAsMeasurementMNode().getSchema().getEncodingType());
stmt.addCompressor(measurement.getAsMeasurementMNode().getSchema().getCompressor());
if (measurement.getAsMeasurementMNode().getOffset() >= 0) {
if (tagFileChannel != null) {
try {
ByteBuffer byteBuffer = ByteBuffer.allocate(COMMON_CONFIG.getTagAttributeTotalSize());
tagFileChannel.read(byteBuffer, measurement.getAsMeasurementMNode().getOffset());
byteBuffer.flip();
Pair<Map<String, String>, Map<String, String>> tagsAndAttributes =
new Pair<>(
ReadWriteIOUtils.readMap(byteBuffer), ReadWriteIOUtils.readMap(byteBuffer));
try {
Pair<Map<String, String>, Map<String, String>> tagsAndAttributes =
getTagsAndAttributes(measurement.getAsMeasurementMNode().getOffset());
if (tagsAndAttributes != null) {
stmt.addAttributesList(tagsAndAttributes.right);
stmt.addTagsList(tagsAndAttributes.left);
} catch (IOException exception) {
lastExcept = exception;
LOGGER.warn(
"Error when parse tag and attributes file of node path {}",
measurement.getPartialPath(),
exception);
}
} else {
LOGGER.warn("Measurement has set attributes or tags, but not find snapshot files");
} catch (IOException ioException) {
lastExcept = ioException;
LOGGER.warn(
"Error when parse tag and attributes file of node path {}", path, ioException);
}
measurement.getAsMeasurementMNode().setOffset(0);
} else {
stmt.addAttributesList(null);
stmt.addTagsList(null);
}
}
return stmt;
}
return null;
}

private Pair<Map<String, String>, Map<String, String>> getTagsAndAttributes(long offset)
throws IOException {
if (tagFileChannel != null) {
ByteBuffer byteBuffer = ByteBuffer.allocate(COMMON_CONFIG.getTagAttributeTotalSize());
tagFileChannel.read(byteBuffer, offset);
byteBuffer.flip();
Pair<Map<String, String>, Map<String, String>> tagsAndAttributes =
new Pair<>(ReadWriteIOUtils.readMap(byteBuffer), ReadWriteIOUtils.readMap(byteBuffer));
return tagsAndAttributes;
} else {
LOGGER.warn("Measurement has set attributes or tags, but not find snapshot files");
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,12 @@ public void test() throws AuthException, IllegalPathException {
assertEquals(users[i].getName(), usernames.get(i + 1));
}
}

@Test
public void testCreateUserRawPassword() throws AuthException {
Assert.assertTrue(
manager.createUser("testRaw", AuthUtils.encryptPassword("password1"), true, false));
User user = manager.getUser("testRaw");
Assert.assertEquals(user.getPassword(), AuthUtils.encryptPassword("password1"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,32 +254,43 @@ public void testAlignedTimeseriesTranslateSnapshot() throws Exception {
ICreateAlignedTimeSeriesPlan plan =
SchemaRegionWritePlanFactory.getCreateAlignedTimeSeriesPlan(
new PartialPath("root.sg.t1.t2"),
Arrays.asList("s1", "s2"),
Arrays.asList(TSDataType.INT32, TSDataType.INT64),
Arrays.asList(TSEncoding.PLAIN, TSEncoding.RLE),
Arrays.asList(CompressionType.SNAPPY, CompressionType.LZ4),
Arrays.asList("alias1", "alias2"),
Arrays.asList("s1", "s2", "s3"),
Arrays.asList(TSDataType.INT32, TSDataType.INT64, TSDataType.BOOLEAN),
Arrays.asList(TSEncoding.PLAIN, TSEncoding.RLE, TSEncoding.PLAIN),
Arrays.asList(
CompressionType.SNAPPY, CompressionType.LZ4, CompressionType.UNCOMPRESSED),
Arrays.asList("alias1", "alias2", null),
Arrays.asList(
new HashMap<String, String>() {
{
put("tag1", "t1");
put("tag_1", "value2");
}
},
new HashMap<String, String>() {
{
put("tag2", "t2");
put("tag_2", "t_2");
}
}),
},
new HashMap<>()), // not all measurements have tag
Arrays.asList(
new HashMap<String, String>() {
{
put("attr1", "a1");
put("attr_1", "a_1");
}
},
new HashMap<String, String>() {
{
put("attr2", "a2");
}
},
new HashMap<String, String>() {
{
put("tag2", "t2");
put("tag_2", "t_2");
}
}));
schemaRegion.createAlignedTimeSeries(plan);
File snapshotDir = new File(config.getSchemaDir() + File.separator + "snapshot");
Expand All @@ -305,6 +316,69 @@ public void testAlignedTimeseriesTranslateSnapshot() throws Exception {
CreateAlignedTimeSeriesStatement createAlignedTimeSeriesStatement =
(CreateAlignedTimeSeriesStatement) stmt;
Assert.assertEquals(plan.getDevicePath(), createAlignedTimeSeriesStatement.getDevicePath());

Assert.assertEquals(
plan.getTagsList().size(), createAlignedTimeSeriesStatement.getTagsList().size());
Assert.assertEquals(
plan.getAliasList().size(), createAlignedTimeSeriesStatement.getAliasList().size());
Assert.assertEquals(
plan.getAttributesList().size(),
createAlignedTimeSeriesStatement.getAttributesList().size());
Assert.assertEquals(
createAlignedTimeSeriesStatement.getMeasurements().size(),
createAlignedTimeSeriesStatement.getAttributesList().size());
Assert.assertEquals(
createAlignedTimeSeriesStatement.getMeasurements().size(),
createAlignedTimeSeriesStatement.getTagsList().size());

Comparator<Map<String, String>> comp =
new Comparator<Map<String, String>>() {
@Override
public int compare(Map<String, String> o1, Map<String, String> o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null) {
return -1;
}
if (o2 == null) {
return 1;
}
return Integer.compare(o1.hashCode(), o2.hashCode());
}
};

Comparator<String> comp_str =
new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null) {
return -1;
}
if (o2 == null) {
return 1;
}
return Integer.compare(o1.hashCode(), o2.hashCode());
}
};

Collections.sort(plan.getAliasList(), comp_str);
Collections.sort(createAlignedTimeSeriesStatement.getAliasList(), comp_str);
Collections.sort(plan.getAttributesList(), comp);
Collections.sort(createAlignedTimeSeriesStatement.getAttributesList(), comp);
Collections.sort(plan.getMeasurements(), comp_str);
Collections.sort(createAlignedTimeSeriesStatement.getMeasurements(), comp_str);
Collections.sort(plan.getTagsList(), comp);
Collections.sort(createAlignedTimeSeriesStatement.getTagsList(), comp);
Collections.sort(plan.getEncodings());
Collections.sort(createAlignedTimeSeriesStatement.getEncodings());
Collections.sort(plan.getCompressors());
Collections.sort(createAlignedTimeSeriesStatement.getCompressors());
Collections.sort(plan.getDataTypes());
Collections.sort(createAlignedTimeSeriesStatement.getDataTypes());
Assert.assertEquals(
plan.getMeasurements(), createAlignedTimeSeriesStatement.getMeasurements());
Assert.assertEquals(plan.getAliasList(), createAlignedTimeSeriesStatement.getAliasList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,23 @@ public boolean login(String username, String password) throws AuthException {

@Override
public void createUser(String username, String password) throws AuthException {
if (!userManager.createUser(username, password, true)) {
if (!userManager.createUser(username, password, true, true)) {
throw new AuthException(
TSStatusCode.USER_ALREADY_EXIST, String.format("User %s already exists", username));
}
}

@Override
public void createUserWithoutCheck(String username, String password) throws AuthException {
if (!userManager.createUser(username, password, false)) {
if (!userManager.createUser(username, password, false, true)) {
throw new AuthException(
TSStatusCode.USER_ALREADY_EXIST, String.format("User %s already exists", username));
}
}

@Override
public void createUserWithRawPassword(String username, String password) throws AuthException {
if (!userManager.createUser(username, password, true, false)) {
throw new AuthException(
TSStatusCode.USER_ALREADY_EXIST, String.format("User %s already exists", username));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,7 @@ boolean checkUserPrivileges(String username, PartialPath path, int privilegeId)
*/
void createUserWithoutCheck(String username, String password) throws AuthException;

void createUserWithRawPassword(String username, String password) throws AuthException;

void checkUserPathPrivilege();
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void initAdmin() throws AuthException {
createUser(
CommonDescriptor.getInstance().getConfig().getAdminName(),
CommonDescriptor.getInstance().getConfig().getAdminPassword(),
true,
true);
setUserUseWaterMark(CommonDescriptor.getInstance().getConfig().getAdminName(), false);
}
Expand Down Expand Up @@ -138,11 +139,14 @@ public User getUser(String username) throws AuthException {
}

@Override
public boolean createUser(String username, String password, boolean validCheck)
public boolean createUser(
String username, String password, boolean validCheck, boolean enableEncrypt)
throws AuthException {
if (validCheck) {
AuthUtils.validateUsername(username);
AuthUtils.validatePassword(password);
if (enableEncrypt) {
AuthUtils.validatePassword(password);
}
}

User user = getUser(username);
Expand All @@ -151,7 +155,7 @@ public boolean createUser(String username, String password, boolean validCheck)
}
lock.writeLock(username);
try {
user = new User(username, AuthUtils.encryptPassword(password));
user = new User(username, enableEncrypt ? AuthUtils.encryptPassword(password) : password);
userMap.put(username, user);
return true;
} finally {
Expand Down Expand Up @@ -389,4 +393,10 @@ public void checkAndRefreshPathPri() {
AuthUtils.checkAndRefreshPri(user);
});
}

@TestOnly
public boolean createUser(String username, String password, boolean validCheck)
throws AuthException {
return createUser(username, password, validCheck, true);
}
}
Loading