Saiku登录源码追踪.(十三)
Saiku登录源码追踪呀~
>>首先我们需要debug跟踪saiku登录执行的源码信息
saiku源码的debug方式上一篇博客已有说明,这里简单介绍一下
在saiku启动脚本中添加如下命令: (windows下: start-saiku.bat)
set CATALINA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n (后面可能还会有一些JVM参数信息)
使用Eclipse打开saiku源码 -- > Eclipse工具栏中的 Run --> Debug configurations --> Remote Java Application --> 选中对应的源码项目(saiku-web),远程访问saiku的ip,以及脚本中指定监听的端口 (address) 8787 --> Debug
在浏览器中根据saiku地址信息访问saiku,输入用户名以及密码信息登录,Eclipse则会进入对应的debug阶段。
>>源码追踪
1.首先会调用 saiku-web项目 org.saiku.web.rest.resources 包下的 SessionResource中的登录方法
sessionService.login(res,username,password)
/**
* Saiku Session Endpoints
*/
@Component
@Path("/saiku/session")
public class SessionResource { /*此处省略其他代码信息*/ private ISessionService sessionService; /**
* Login to Saiku
* @summary Login
* @param req Servlet request
* @param username Username
* @param password Password
* @return A 200 response
*/
@POST
@Consumes("application/x-www-form-urlencoded")
public Response login(
@Context HttpServletRequest req,
@FormParam("username") String username,
@FormParam("password") String password)
{
try {
sessionService.login(req, username, password);
return Response.ok().build();
}
catch (Exception e) {
log.debug("Error logging in:" + username, e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getLocalizedMessage()).build();
}
}
}
2.进入org.saiku.web.service 包下的 SessionService类中的 sessionService.login(res,username,password)方法
进行认证的方法主要是: authenticate(req, username, password);
package org.saiku.web.service;
/*此处省略了导入相关包信息*/
public class SessionService implements ISessionService { /**此处省略其他代码*/ /* (non-Javadoc)
* @see org.saiku.web.service.ISessionService#login(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)
*/
public Map<String, Object> login(HttpServletRequest req, String username, String password ) throws LicenseException {
Object sl = null;
String notice = null;
HttpSession session = ((HttpServletRequest)req).getSession(true);
session.getId();
sessionRepo.setSession(session);
try {
sl = l.getLicense();
} catch (Exception e) {
log.debug("Could not process license", e);
throw new LicenseException("Error fetching license. Get a free license from http://licensing.meteorite.bi. You can upload it at /upload.html");
} if (sl != null) { try {
l.validateLicense();
} catch (RepositoryException | IOException | ClassNotFoundException e) {
log.debug("Repository Exception, couldn't get license", e);
throw new LicenseException("Error fetching license. Please check your logs.");
} try {
if (l.getLicense() instanceof SaikuLicense2) { if (authenticationManager != null) {
authenticate(req, username, password);
}
if (SecurityContextHolder.getContext() != null
&& SecurityContextHolder.getContext().getAuthentication() != null) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (authorisationPredicate.isAuthorised(auth)) {
Object p = auth.getPrincipal();
createSession(auth, username, password);
return sessionHolder.get(p);
} else {
log.info(username + " failed authorisation. Rejecting login");
throw new RuntimeException("Authorisation failed for: " + username);
}
}
return new HashMap<>();
}
} catch (IOException | ClassNotFoundException | RepositoryException e) {
log.debug("Repository Exception, couldn't get license", e);
throw new LicenseException("Error fetching license. Please check your logs.");
}
}
return null;
}
}
3.继续进入SessionService的 authenticate (req,username,password)方法进行认证
主要认证: Authentication authentication = this.authenticationManager.authenticate(token);
/* (non-Javadoc)
* @see org.saiku.web.service.ISessionService#authenticate(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)
*/
public void authenticate(HttpServletRequest req, String username, String password) {
try {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
token.setDetails(new WebAuthenticationDetails(req));
Authentication authentication = this.authenticationManager.authenticate(token);
log.debug("Logging in with [{}]", authentication.getPrincipal());
SecurityContextHolder.getContext().setAuthentication(authentication);
}
catch (BadCredentialsException bd) {
throw new RuntimeException("Authentication failed for: " + username, bd);
} }
4.转入spring-security认证框架中的 org.springframework.security.authentication包下的ProviderManager类中的 this.authenticationManager.authenticate(token)方法
主要认证: result = provider.authenticate(authentication);
/**
* Attempts to authenticate the passed {@link Authentication} object.
* <p>
* The list of {@link AuthenticationProvider}s will be successively tried until an
* <code>AuthenticationProvider</code> indicates it is capable of authenticating the
* type of <code>Authentication</code> object passed. Authentication will then be
* attempted with that <code>AuthenticationProvider</code>.
* <p>
* If more than one <code>AuthenticationProvider</code> supports the passed
* <code>Authentication</code> object, only the first
* <code>AuthenticationProvider</code> tried will determine the result. No subsequent
* <code>AuthenticationProvider</code>s will be tried.
*
* @param authentication the authentication request object.
*
* @return a fully authenticated object including credentials.
*
* @throws AuthenticationException if authentication fails.
*/
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
Class<? extends Authentication> toTest = authentication.getClass();
AuthenticationException lastException = null;
Authentication result = null;
boolean debug = logger.isDebugEnabled(); for (AuthenticationProvider provider : getProviders()) {
if (!provider.supports(toTest)) {
continue;
} if (debug) {
logger.debug("Authentication attempt using "
+ provider.getClass().getName());
} try {
result = provider.authenticate(authentication); if (result != null) {
copyDetails(authentication, result);
break;
}
}
catch (AccountStatusException e) {
prepareException(e, authentication);
// SEC-546: Avoid polling additional providers if auth failure is due to
// invalid account status
throw e;
}
catch (InternalAuthenticationServiceException e) {
prepareException(e, authentication);
throw e;
}
catch (AuthenticationException e) {
lastException = e;
}
} if (result == null && parent != null) {
// Allow the parent to try.
try {
result = parent.authenticate(authentication);
}
catch (ProviderNotFoundException e) {
// ignore as we will throw below if no other exception occurred prior to
// calling parent and the parent
// may throw ProviderNotFound even though a provider in the child already
// handled the request
}
catch (AuthenticationException e) {
lastException = e;
}
} if (result != null) {
if (eraseCredentialsAfterAuthentication
&& (result instanceof CredentialsContainer)) {
// Authentication is complete. Remove credentials and other secret data
// from authentication
((CredentialsContainer) result).eraseCredentials();
} eventPublisher.publishAuthenticationSuccess(result);
return result;
} // Parent was null, or didn't authenticate (or throw an exception). if (lastException == null) {
lastException = new ProviderNotFoundException(messages.getMessage(
"ProviderManager.providerNotFound",
new Object[] { toTest.getName() },
"No AuthenticationProvider found for {0}"));
} prepareException(lastException, authentication); throw lastException;
}
5.转入 org.springframework.security.authentication.dao包下的 AbstractUserDetailsAuthenticationProvider类中的 result = provider.authenticate(authentication);
关于密码的校验主要是:additionalAuthenticationChecks(user,(UsernamePasswordAuthenticationToken) authentication);
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication,
messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.onlySupports",
"Only UsernamePasswordAuthenticationToken is supported")); // Determine username
String username = (authentication.getPrincipal() == null) ? "NONE_PROVIDED"
: authentication.getName(); boolean cacheWasUsed = true;
UserDetails user = this.userCache.getUserFromCache(username); if (user == null) {
cacheWasUsed = false; try {
user = retrieveUser(username,
(UsernamePasswordAuthenticationToken) authentication);
}
catch (UsernameNotFoundException notFound) {
logger.debug("User '" + username + "' not found"); if (hideUserNotFoundExceptions) {
throw new BadCredentialsException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.badCredentials",
"Bad credentials"));
}
else {
throw notFound;
}
} Assert.notNull(user,
"retrieveUser returned null - a violation of the interface contract");
} try {
preAuthenticationChecks.check(user);
additionalAuthenticationChecks(user,
(UsernamePasswordAuthenticationToken) authentication);
}
catch (AuthenticationException exception) {
if (cacheWasUsed) {
// There was a problem, so try again after checking
// we're using latest data (i.e. not from the cache)
cacheWasUsed = false;
user = retrieveUser(username,
(UsernamePasswordAuthenticationToken) authentication);
preAuthenticationChecks.check(user);
additionalAuthenticationChecks(user,
(UsernamePasswordAuthenticationToken) authentication);
}
else {
throw exception;
}
}
6.org.springframework.security.authentication.dao包下的 DaoAuthenticationProvider 类中 additionalAuthenticationChecks(user,(UsernamePasswordAuthenticationToken) authentication)方法如下
校验密码的主要方法: passwordEncoder.isPasswordValid(userDetails.getPassword(), presentedPassword,salt)
@SuppressWarnings("deprecation")
protected void additionalAuthenticationChecks(UserDetails userDetails,
UsernamePasswordAuthenticationToken authentication)
throws AuthenticationException {
Object salt = null;
if (this.saltSource != null) {
salt = this.saltSource.getSalt(userDetails);
}
if (authentication.getCredentials() == null) {
logger.debug("Authentication failed: no credentials provided");
throw new BadCredentialsException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.badCredentials",
"Bad credentials"));
}
if (!passwordEncoder.isPasswordValid(userDetails.getPassword(),
presentedPassword, salt)) {
logger.debug("Authentication failed: password does not match stored value");
throw new BadCredentialsException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.badCredentials",
"Bad credentials"));
}
}
好了,关于saiku登录源码就追踪到这里啦~ ,到这里我们就知道怎么更改saiku对密码校验的逻辑信息啦~
Saiku登录源码追踪.(十三)的更多相关文章
- saiku的源码包Bulid常见问题和jar包
最近在做kylin+mondrian+saiku的二次开发的时候,Bulid saiku的源码出现了很多问题,基本上一大部分问题jar找不到问题,很多jar国内网站都找不到.这时候只有手动下载然后注册 ...
- Yii2 使用 QQ 和 Weibo 第三方登录源码
我们社区在 yii2-authclient 多次升级后,登录异常.一直想寻求一种通用的方法,尽量不重写 OAuth2, BaseOAuth 以及 OAuthToken 类, 所以本次直接在 initU ...
- 源码追踪,解决Could not locate executable null\bin\winutils.exe in the Hadoop binaries.问题
在windows系统本地运行spark的wordcount程序,会出现一个异常,但不影响现有程序运行. >>提君博客原创 http://www.cnblogs.com/tijun/ & ...
- [大数据可视化]-saiku的源码包Bulid常见问题和jar包
最近在做kylin+mondrian+saiku的二次开发的时候,Bulid saiku的源码出现了很多问题,基本上一大部分问题jar找不到问题,很多jar国内网站都找不到.这时候只有手动下载然后注册 ...
- OpenJDK源码研究笔记(十三):Javac编译过程中的上下文容器(Context)、单例(Singleton)和延迟创建(LazyCreation)3种模式
在阅读Javac源码的过程中,发现一个上下文对象Context. 这个对象用来确保一次编译过程中的用到的类都只有一个实例,即实现我们经常提到的"单例模式". 今天,特意对这个上下文 ...
- CAS Server集成QQ登录、新浪微博登录源码及配置文件
转载自素文宅博客:https://blog.yoodb.com/yoodb/article/detail/1446 CAS Server集成QQ第三方登录,CAS Server集成新浪微博第三方登录以 ...
- Spring Boot 注解之ObjectProvider源码追踪
最近依旧在学习阅读Spring Boot的源代码,在此过程中涉及到很多在日常项目中比较少见的功能特性,对此深入研究一下,也挺有意思,这也是阅读源码的魅力之一.这里写成文章,分享给大家. 自动配置中的O ...
- [大数据可视化]-saiku的源码打包运行/二次开发构建
Saiku构建好之后,会将项目的各个模块达成jar包,整个项目也会打成war包 saiku目录结构: 我们选中saiku-server/target/ 下面的zip压缩包.这是个打包后的文件,进行 ...
- 类似818tu.co微信小说分销系统设计之多公众号网页授权自动登录源码
/** 转载请保留原地址以及版权声明,请勿恶意修改 * 作者:杨浩瑞 QQ:1420213383 独立博客:http://www.yxxrui.cn * [后台]http://xiaoshuo. ...
随机推荐
- 【Checkio Exercise】Three Point Circle
计算三角形外接圆的函数: Three Point Circle If we want to build new silos, then we need to make more formal and ...
- PHP提交表单失败后如何保留填写的信息
index.html模板文件大内容: <html> <head> <title>jQuery Ajax 实例演示</title> </head&g ...
- 使用freemarker和itext把html转pdf
1.把html转pdf,首先必须要解决中文显示问题,CSS样式问题以及可能的JS问题,先上例子,自己去体会. 2.先去下载simsun.ttc字体: 2.demo.html <!DOCTYPE ...
- hdu5029 Relief grain
题目链接 树剖+线段树 将区间修改转化为单点修改,因为如果按DFS序进行修改,那么一定会对DFS序更大的点造成影响 #include<iostream> #include<vecto ...
- GoldenGate使用SQLEXEC和GETVAL实现码表关联
使用OGG中的SQLEXEC参数,可以执行SQL语句或存储过程,再加上@GETVAL函数,可以在目标端获取源表没有的字段值.比如,源端有一个事实表和一个代码表COUNTRY_CODES,代码表中有两个 ...
- 怎样从外网访问内网Memcached数据库
外网访问内网Memcached数据库 本地安装了Memcached数据库,只能在局域网内访问,怎样从外网也能访问本地Memcached数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装 ...
- 第六节 DOM操作应用
创建.插入和删除元素 创建DOM元素: createElement(标签名); //创建一个节点 appendChild(节点); //追加一个节点 例如:document.body.appendCh ...
- Linux 系统日志
查看日志服务 大部分Linux发行版默认的日志守护进程为 syslog,位于 /etc/syslog 或 /etc/syslogd 或/etc/rsyslog.d,默认配置文件为 /etc/syslo ...
- 复旦大学2017--2018学年第一学期高等代数I期末考试情况分析
一.期末考试成绩班级前十名 郭宇城(100).魏一鸣(93).乔嘉玮(92).刘宇其(90).朱柏青(90).王成文健(90).方博越(88).熊子恺(88).张君格(88).崔镇涛(87).史书珣( ...
- Cmd Markdown 编辑阅读器
我们理解您需要更便捷更高效的工具记录思想,整理笔记.知识,并将其中承载的价值传播给他人,Cmd Markdown 是我们给出的答案 -- 我们为记录思想和分享知识提供更专业的工具. 您可以使用 Cmd ...