使用 Jdbc 领域的 Zeppelin 身份验证

Zeppelin authentication with Jdbc realm

我一直在尝试使用 Shiro JDBC 领域的身份验证设置飞艇。经过我所有的尝试,我无法让它工作。基本身份验证有效,但使用 JDBC 领域失败。

zeppelin 服务器是根据文档创建的:http://zeppelin.apache.org/docs/0.9.0/quickstart/kubernetes.html

POD 正在工作。

我通过扩展 docker 图像启用了 Shiro。我的 Dockerfile:


ARG ZEPPELIN_IMAGE=apache/zeppelin:0.9.0
FROM ${ZEPPELIN_IMAGE}
#https://hub.docker.com/r/apache/zeppelin/dockerfile


WORKDIR ${Z_HOME}

ADD /zeppelin/shiro.ini ${Z_HOME}/conf/

ADD https://repo1.maven.org/maven2/mysql/mysql-connector-java/6.0.4/mysql-connector-java-6.0.4.jar ${Z_HOME}/lib/
ENV CLASSPATH=${Z_HOME}/lib/mysql-connector-java-6.0.4.jar:${CLASSPATH}

ENTRYPOINT [ "/usr/bin/tini", "--" ]
WORKDIR ${Z_HOME}
CMD ["bin/zeppelin.sh"]

我的 shiro.ini 来自 https://gist.github.com/adamjshook/6c42b03fdb09b60cd519174d0aec1af5

[main]
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName = localhost
ds.databaseName = zeppelin
ds.user = zeppelin
ds.password = zeppelin
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealmCredentialsMatcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
jdbcRealm.credentialsMatcher = $jdbcRealmCredentialsMatcher
ps = org.apache.shiro.authc.credential.DefaultPasswordService
pm = org.apache.shiro.authc.credential.PasswordMatcher
pm.passwordService = $ps
jdbcRealm.dataSource = $ds
jdbcRealm.credentialsMatcher = $pm
shiro.loginUrl = /api/login
[urls]/** = authc

现在,当我部署 zeppelin 服务器时,我得到:

rg.apache.shiro.config.ConfigurationException: Unable to instantiate class [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] for object named 'ds'.  Please ensure you've specified the fully qualified class name correctly.
    at org.apache.shiro.config.ReflectionBuilder.createNewInstance(ReflectionBuilder.java:327)
    at org.apache.shiro.config.ReflectionBuilder$InstantiationStatement.doExecute(ReflectionBuilder.java:961)
    at org.apache.shiro.config.ReflectionBuilder$Statement.execute(ReflectionBuilder.java:921)
    at org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:799)
    at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:278)
    at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:181)
    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:139)
    at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:107)
    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:98)
    at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:47)
    at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:150)
    at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)


Caused by: org.apache.shiro.util.UnknownClassException: Unable to load class named [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] from the thread context, current, or system/application ClassLoaders.  All heuristics have been exhausted.  Class could not be found.
    at org.apache.shiro.util.ClassUtils.forName(ClassUtils.java:152)
    at org.apache.shiro.util.ClassUtils.newInstance(ClassUtils.java:168)
    at org.apache.shiro.config.ReflectionBuilder.createNewInstance(ReflectionBuilder.java:320)
    ... 40 more

即使我在类路径上定义了 jar 文件,也不确定为什么会失败。

jar 的问题是没有正确的权限。用下面的 Dockerfile

修复了它
ARG ZEPPELIN_IMAGE=apache/zeppelin:0.9.0
FROM ${ZEPPELIN_IMAGE}
#https://hub.docker.com/r/apache/zeppelin/dockerfile


WORKDIR ${Z_HOME}

USER root
ADD /zeppelin/shiro.ini ${Z_HOME}/conf/

ADD https://repo1.maven.org/maven2/mysql/mysql-connector-java/6.0.4/mysql-connector-java-6.0.4.jar ${Z_HOME}/lib/
ENV CLASSPATH=${Z_HOME}/lib/mysql-connector-java-6.0.4.jar:${CLASSPATH}

RUN chmod 777 ${Z_HOME}/lib/mysql-connector-java-6.0.4.jar

USER 1000


ENTRYPOINT [ "/usr/bin/tini", "--" ]
WORKDIR ${Z_HOME}
CMD ["bin/zeppelin.sh"]