use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class ZookeeperDiscoveryImpl method authenticateNode.
/**
* @param node Node.
* @return Validation result.
*/
private ZkNodeValidateResult authenticateNode(ZookeeperClusterNode node) {
DiscoverySpiNodeAuthenticator nodeAuth = spi.getAuthenticator();
if (nodeAuth == null)
return new ZkNodeValidateResult((byte[]) null);
SecurityCredentials cred;
try {
cred = unmarshalCredentials(node);
} catch (Exception e) {
U.error(log, "Failed to unmarshal node credentials: " + e, e);
return new ZkNodeValidateResult("Failed to unmarshal node credentials");
}
SecurityContext subj = nodeAuth.authenticateNode(node, cred);
if (subj == null) {
U.warn(log, "Authentication failed [nodeId=" + node.id() + ", addrs=" + U.addressesAsString(node) + ']');
// Note: exception message test is checked in tests.
return new ZkNodeValidateResult("Authentication failed");
}
if (!(subj instanceof Serializable)) {
U.warn(log, "Authentication subject is not Serializable [nodeId=" + node.id() + ", addrs=" + U.addressesAsString(node) + ']');
return new ZkNodeValidateResult("Authentication subject is not serializable");
}
byte[] secSubjZipBytes;
try {
secSubjZipBytes = marshalZip(subj);
node.setAttributes(withSecurityContext(subj, node.getAttributes(), marsh));
} catch (Exception e) {
U.error(log, "Failed to marshal node security subject: " + e, e);
return new ZkNodeValidateResult("Failed to marshal node security subject");
}
return new ZkNodeValidateResult(secSubjZipBytes);
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class SqlUserCommandSelfTest method testNotAuthorizedOperation.
/**
* @throws Exception If failed.
*/
@Test
public void testNotAuthorizedOperation() throws Exception {
withSecurityContextOnAllNodes(secCtxDflt);
userSql(0, "CREATE USER user0 WITH PASSWORD 'user0'");
SecurityContext secCtx = authenticate(grid(0), "USER0", "user0");
withSecurityContextOnAllNodes(secCtx);
for (int i = 0; i < NODES_COUNT; ++i) {
final int idx = i;
GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
userSql(idx, "CREATE USER test WITH PASSWORD 'test'");
return null;
}
}, IgniteAccessControlException.class, "User management operations are not allowed for user");
GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
userSql(idx, "ALTER USER test WITH PASSWORD 'test'");
return null;
}
}, IgniteAccessControlException.class, "User management operations are not allowed for user");
GridTestUtils.assertThrowsAnyCause(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
userSql(idx, "DROP USER test");
return null;
}
}, IgniteAccessControlException.class, "User management operations are not allowed for user");
}
}
Aggregations