best365(中文版)官网登录-Official Platform

best365官网中文版登录Logo best365官网中文版登录Logo

Saiku去掉License验证信息以及数据备份

2020-03-17

Saiku去掉License验证信息

终于还是走到了这一步,老早就在说要去掉这个License验证了,一直没做因为忙着别的。但是因为这个License还和可定义的用户数相关,限制了我们的使用,所以这里从saiku源码中做更改,去掉License验证。

 

需要更改的代码文件如下:

saiku-core\\saiku-web\\src\\main\\java\\org\\saiku\\web\\rest\\resources\\License.java saiku-core\\saiku-web\\src\\main\\java\\org\\saiku\\web\\service\\SessionService.java saiku-ui\\js\\saiku\\models\\Session.js saiku-ui\\js\\saiku\\views\\Upgrade.js

 

>>>后台代码更改  

1.更改SesseionService.java类中的 login方法,将有关于Licence验证的代码注释掉即可。改完后的login方法如下:

* @see org.saiku.web.service.ISessionService#login(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)  */ /**modify the login for getting rid of license validate 2019-03-29*/ public Map 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."); // } 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<>(); }

  

2.更改License.java类中的getLicense方法,将License校验直接返回正确的结果。 改动后的代码getLicense方法如下:

@GET   @Produces({ "application/json" })   public Response getLicense() { //    try { //      return Response.ok().entity(licenseUtils.getLicense()).build(); //    } catch (IOException | RepositoryException | ClassNotFoundException e) { //      e.printStackTrace(); //    }     return Response.serverError().build();   }

  

 >>>前端代码更改

3. 去掉Saiku升级相关提示,Upgrade.js文件中将render方法内容注释掉,详情如下:

render: function() { /* var self = this; var license = new License(); if(Settings.BIPLUGIN5){ if(Saiku.session.get("notice") != undefined && Saiku.session.get("notice")!=null && Saiku.session.get("notice")!=""){ $(this.el).append("
Notice:"+Saiku.session.get("notice")+"
"); } if (Settings.LICENSE.licenseType != undefined && (Settings.LICENSE.licenseType != "trial" && Settings.LICENSE.licenseType != "Open Source License")) { return this; } if (Settings.LICENSE != undefined && Settings.LICENSE.licenseType === "trial") { var yourEpoch = parseFloat(Settings.LICENSE.expiration); var yourDate = new Date(yourEpoch); self.remainingdays = self.daydiff(new Date(), yourDate); $(this.el).append("
You are using a Saiku Enterprise" + " Trial license, you have "+ self.remainingdays+" days remaining. Buy licenses online.
"); return self; } else { $(this.el).append("
You are using Saiku Community" + " Edition, please consider upgrading to Saiku Enterprise, or entering a sponsorship agreement with us to support development. " + "Or contribute by joining our community and helping other users!
"); return self; } } else { if(Saiku.session.get("notice") != undefined && Saiku.session.get("notice")!=null && Saiku.session.get("notice")!=""){ $(this.el).append("
Notice:"+Saiku.session.get("notice")+"
"); } if (Settings.LICENSE.licenseType != undefined && (Settings.LICENSE.licenseType != "trial" && Settings.LICENSE.licenseType != "Open Source License")) { return this; } if (Settings.LICENSE.licenseType === "trial") { var yourEpoch = parseFloat(Settings.LICENSE.expiration); var yourDate = new Date(yourEpoch); self.remainingdays = self.daydiff(new Date(), yourDate); $(this.el).append("
You are using a Saiku Enterprise" + " Trial license, you have "+ self.remainingdays+" days remaining. Buy licenses online.
"); return self; } else { $(this.el).append("
You are using Saiku Community" + " Edition, please consider upgrading to Saiku Enterprise, or entering a sponsorship agreement with us to support development. " + "Or contribute by joining our community and helping other users!
"); return self; } } */ },

  

4.为了防止前台console中出现调用License接口404错误,我们还需要更改一下 Session.js的process_session与check_session方法,使其不调用License

check_session: function() { // This authentication cookie is used only by Orbis authentication strategy var authCookie = this.getCookie(Settings.ORBIS_AUTH.cookieName); if (Settings.ORBIS_AUTH.hazelcast_enabled && authCookie && !this.atemptedToLoginByCookie) {             this.sessionid               = 1;             this.username                = authCookie;             this.password                = authCookie;             this.atemptedToLoginByCookie = true;             // In this case we inject the proper license attributes             var ONE_YEAR = 31556952000;                          /**             Settings.LICENSE = {               licenseType: 'Orbis',               expiration: Date.now() + ONE_YEAR             }             */             this.login(authCookie, authCookie); } else { if (this.sessionid === null || this.username === null || this.password === null) { var that = this; this.clear(); this.fetch({ success: this.process_session, error: this.brute_force }); } else {                 if (!this.atemptedToLoginByCookie) {                     this.username = encodeURIComponent(options.username);                 } this.load_session(); } }     },  process_session: function(model, response) {         if ((response === null || response.sessionid == null)) {             // Open form and retrieve credentials             Saiku.ui.unblock();             if (Settings.DEMO) {                 this.form = new DemoLoginForm({ session: this });             } else {                 this.form = new LoginForm({ session: this });             }             this.form.render().open();         } else {             this.sessionid = response.sessionid;             this.roles = response.roles;             this.isAdmin = Settings.ORBIS_AUTH.hazelcast_enabled || response.isadmin;             this.username = encodeURIComponent(response.username);             this.language = response.language;             if (typeof this.language != "undefined" && this.language != Saiku.i18n.locale) {                 Saiku.i18n.locale = this.language;                 Saiku.i18n.automatic_i18n();             }             /**                 var license =new License();                 license.fetch_license('api/license/', function(opt) {                     if (opt.status === 'success') {                         Settings.LICENSE = opt.data.toJSON();                     }                     if(Saiku.session.isAdmin) {                         var quota = new LicenseQuota();                         quota.fetch_quota('api/license/quota', function (opt) {                             if (opt.status === 'success') {                                 Settings.LICENSEQUOTA = opt.data.toJSON();                             }                         });                     }                 }); */             this.load_session();         }         return this;     },

  

做出以上更改后,重新打包编译源码即可。

再次启动编译好的saiku,就会发现不需要上传License文件啦!可直接登录saiku进行使用~

而且还有个地方可以验证你是否已经成功取得License相关信息,使用admin登录控制管理台,看不到license就表示成功了!!

Saiku 控制台中无 License 信息

 

 

>>> Saiku数据备份

 关于saiku的数据备份,今日份尝试了一下,只需要将saiku-server目录下的 data,repository目录备份即可。(如果对saiku的源码有改动,重新编译了saiku ,建议将正在使用的saiku相关数据保存下来,免得自己再去配置。)

可直接去替换重新编译好的data , repository目录,在启动saiku,就会发现之前配置好的数据以及用户角色信息、文件信息都完好的保存了啦!!! 这就很赞啦嘻嘻嘻

需要备份的 saiku 数据目录截图

 

 

 最后提供一下被更改过的完整的文件信息:(可直接用来替换本地的这个四个文件哦)

saiku-core\\saiku-web\\src\\main\\java\\org\\saiku\\web\\rest\\resources\\License.java

/* Copyright (C) OSBI Ltd - All Rights Reserved  * Unauthorized copying of this file, via any medium is strictly prohibited  * Proprietary and confidential  * Written by OSBI LTD, 2014  */ package org.saiku.web.rest.resources; import org.saiku.service.license.ILicenseUtils; import org.saiku.database.Database; import org.saiku.service.license.Base64Coder; import org.saiku.service.user.UserService; import org.saiku.web.rest.objects.UserList; import com.qmino.miredot.annotations.ReturnType; import org.springframework.stereotype.Component; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import javax.jcr.RepositoryException; import javax.ws.rs.*; import javax.ws.rs.core.Response; /**  * Saiku license information resource.  *  * @since 3.0  * @author tbarber  */ @Component @Path("/saiku/api/license") public class License {   private ILicenseUtils licenseUtils;   private UserService userService;   public ILicenseUtils getLicenseUtils() {     return licenseUtils;   }   public void setLicenseUtils(ILicenseUtils licenseUtils) {     this.licenseUtils = licenseUtils;   }   private Database databaseManager;   public Database getDatabaseManager() {     return databaseManager;   }   public void setDatabaseManager(Database databaseManager) {     this.databaseManager = databaseManager;   }   public void setUserService(UserService us) {     userService = us;   }   /**    * Get the saiku    * @summary Get the Saiku License installed on the current server    * @return A response containing a license object.    */   @GET   @Produces({ "application/json" })   public Response getLicense() { //    try { //      return Response.ok().entity(licenseUtils.getLicense()).build(); //    } catch (IOException | RepositoryException | ClassNotFoundException e) { //      e.printStackTrace(); //    }     return Response.serverError().build();   }   private static final int SIZE = 2048;   /**    * Upload a new license to the Saiku server.    * @summary Upload a new license    * @param is A license encapsulated in an input stream    * @return An acknowledgement as to whether the server installation was successful.    */   @POST   @Consumes("application/x-java-serialized-object")   @Produces("text/plain")   @ReturnType("java.lang.String")   public Response saveLicense(InputStream is) {     ObjectInputStream si = null;     byte[] sig;     byte[] data = null;     try {       si = new ObjectInputStream(is);     } catch (IOException e) {       e.printStackTrace();     }     try {       int sigLength = si.readInt();       sig = new byte[sigLength];       si.read(sig);       ByteArrayOutputStream dataStream = new ByteArrayOutputStream();       byte[] buf = new byte[SIZE];       int len;       while ((len = si.read(buf)) != -1) {         dataStream.write(buf, 0, len);       }       dataStream.flush();       data = dataStream.toByteArray();       dataStream.close();     } catch (IOException e) {       e.printStackTrace();     } finally {       try {         si.close();       } catch (IOException e) {         e.printStackTrace();       }     }     getLicenseUtils().setLicense(new String(Base64Coder.encode(data)));     return Response.ok("License Upload Successful").build();   }   /**    * Validate the license installed on the server.    * @summary License validation    * @return A response indicating whether the operation was successful.    */   @GET   @Path("/validate")   @Produces({ "text/plain" })   @ReturnType("java.lang.String")   public Response validateLicense() { //    if(!userService.isAdmin()){ //      return Response.status(Response.Status.FORBIDDEN).build(); //    } //    try { //      licenseUtils.validateLicense(); //    } catch (IOException e) { //      e.printStackTrace(); //      return Response.status(Response.Status.INTERNAL_SERVER_ERROR) //                     .entity(e.getLocalizedMessage()).build(); //    } catch (ClassNotFoundException e) { //      e.printStackTrace(); //      return Response.status(Response.Status.INTERNAL_SERVER_ERROR) //                     .entity(e.getLocalizedMessage()).build(); //    } catch (LicenseException e) { //      return Response.status(Response.Status.INTERNAL_SERVER_ERROR) //                     .entity(e.getLocalizedMessage()).build(); //    } catch (RepositoryException e) { //      return Response.status(Response.Status.INTERNAL_SERVER_ERROR) //                     .entity("Could not find license file").build(); //    } catch (Exception e) { //      e.printStackTrace(); //    }     return Response.ok().entity("Valid License").build();   }   /**    * Get the current user list from the server.    * @summary Get the user list    * @return A list of users.    */   @GET   @Path("/usercount")   @Produces({"application/json"})   @ReturnType("java.util.ArrayList")   public Response getUserCount(){     if(!userService.isAdmin()){       return Response.status(Response.Status.FORBIDDEN).build();     }     try {       List l = getAuthUsers();       if(l!=null) {         List ul = new ArrayList();         int i = 0;         for (String l2 : l) {           ul.add(new UserList(l2, i));           i++;         }         return Response.ok().entity(ul.size()).build();       }     } catch (SQLException e) {       e.printStackTrace();       return Response.ok().entity(0).build();     }     return Response.ok().entity(0).build();   }   /**    * Get the current user list from the server.    * @summary Get the user list    * @return A list of users.    */   @GET   @Path("/users")   @Produces({"application/json"})   @ReturnType("java.util.ArrayList")   public Response getUserlist(){     if(!userService.isAdmin()){       return Response.status(Response.Status.FORBIDDEN).build();     }     try {       List l = getAuthUsers();       if(l!=null) {         List ul = new ArrayList();         int i = 0;         for (String l2 : l) {           ul.add(new UserList(l2, i));           i++;         }         return Response.ok().entity(ul).build();       }     } catch (SQLException e) {       e.printStackTrace();     }     return null;   }   /**    * Upload a user list to the server.    * @summary Upload user list    * @param l A List of UserList objects    * @return A response indicating whether the operation was successful.    */   @POST   @Path("/users")   @Produces({"text/plain"})   @Consumes({"application/json"})   @ReturnType("java.lang.String")   public Response createUserList(List l){     try {       List l3 = new ArrayList<>();       for(UserList l2 : l){         l3.add(l2.getName());       }       addUsers(l3);     } catch (SQLException e) {       e.printStackTrace();     }     return Response.ok().entity("List created").build();   }   /**    * Update the list of users with new users.    * @summary Update user list    * @param l A list of UserList objects    * @return A response indicating whether the operation was successful.    */   @PUT   @Path("/users")   @Produces({"text/plain"})   @Consumes({"application/json"})   @ReturnType("java.lang.String")   public Response updateUserList(List l){     try {       List l3 = new ArrayList<>();       for(UserList l2 : l){         l3.add(l2.getName());       }       updateUsers(l3);     } catch (SQLException e) {       e.printStackTrace();     }     return Response.ok().entity("List updated").build();   }   /**    * Delete the user list from the server.    * @summary Delete user list.    * @return A response indicating whether the operation was successful.    */   @DELETE   @Path("/users")   @Produces({"application/json"})   @ReturnType("java.lang.String")   public Response deleteUserlist(){     try {       List l = getAuthUsers();       List ul = new ArrayList<>();       int i = 0;       for(String l2 : l) {         ul.add(new UserList(l2, i));         i++;       }       return Response.ok().entity(ul).build();     } catch (SQLException e) {       e.printStackTrace();     }     return null;   }   /**    * Get the valid users from the database.    * @return a list of usernames    * @throws SQLException    */   private List getAuthUsers() throws SQLException {     return databaseManager.getUsers();   }   /**    * Get the user quota for existing users with no license    * @return a list of user quota.    */   @GET   @Produces("application/json")   @Path("/quota")   @ReturnType("java.util.List")   public Response getUserQuota(){     if(!userService.isAdmin()){       return Response.status(Response.Status.FORBIDDEN).build();     }     return Response.ok().entity(100000000).build();   }   /**    * Add users to the database.    * @param l List of usernames    * @throws SQLException    */   public void addUsers(List l) throws SQLException {     databaseManager.addUsers(l);   }   /**    * Add users to the database.    * @param l List of usernames    * @throws SQLException    */   public void updateUsers(List l) throws SQLException {     databaseManager.addUsers(l);   } }

  

saiku-core\\saiku-web\\src\\main\\java\\org\\saiku\\web\\service\\SessionService.java 

/*    *   Copyright 2012 OSBI Ltd  *  *   Licensed 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.saiku.web.service; import org.apache.commons.lang.StringUtils; import org.saiku.repository.ScopedRepo; import org.saiku.service.ISessionService; import org.saiku.service.license.ILicenseUtils; import bi.meteorite.license.LicenseException; import bi.meteorite.license.SaikuLicense2; import org.saiku.service.util.security.authorisation.AuthorisationPredicate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.authentication.AnonymousAuthenticationToken; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.web.context.request.RequestContextHolder; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; public class SessionService implements ISessionService { private static final Logger log = LoggerFactory.getLogger(SessionService.class); private AuthenticationManager authenticationManager; private AuthorisationPredicate authorisationPredicate; private final Map> sessionHolder = new HashMap<>(); private Boolean anonymous = false; private ScopedRepo sessionRepo; private Boolean orbisAuthEnabled = false; public void setAllowAnonymous(Boolean allow) { this.anonymous  = allow; } private ILicenseUtils l; public ILicenseUtils getL() { return l; } public void setL(ILicenseUtils l) { this.l = l; } /* (non-Javadoc)          * @see org.saiku.web.service.ISessionService#setAuthenticationManager(org.springframework.security.authentication.AuthenticationManager)          */ public void setAuthenticationManager(AuthenticationManager auth) { this.authenticationManager = auth; } public void setAuthorisationPredicate(AuthorisationPredicate authorisationPredicate) { this.authorisationPredicate = authorisationPredicate; } /* (non-Javadoc)  * @see org.saiku.web.service.ISessionService#login(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)  */ /**modify the login for getting rid of license validate 2019-03-29*/ public Map 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."); // } 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<>(); } /** The old login validation , have to validate license information public Map 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; } */ private void createSession(Authentication auth, String username, String password) { if (auth ==  null || !auth.isAuthenticated()) { return; } boolean isAnonymousUser = (auth instanceof AnonymousAuthenticationToken); Object p = auth.getPrincipal(); String authUser = getUsername(p); boolean isAnonymous = (isAnonymousUser || StringUtils.equals("anonymousUser", authUser)); boolean isAnonOk = (!isAnonymous || (isAnonymous && anonymous)); if (isAnonOk && auth.isAuthenticated() && p != null && !sessionHolder.containsKey(p)) { Map session = new HashMap<>(); if (isAnonymous) { log.debug("Creating Session for Anonymous User"); } if (StringUtils.isNotBlank(username)) { session.put("username", username); } else { session.put("username", authUser); } if (StringUtils.isNotBlank(password)) { session.put("password", password); } session.put("sessionid", UUID.randomUUID().toString()); session.put("authid", RequestContextHolder.currentRequestAttributes().getSessionId()); List roles = new ArrayList<>(); for (GrantedAuthority ga : SecurityContextHolder.getContext().getAuthentication().getAuthorities()) { roles.add(ga.getAuthority()); } session.put("roles", roles); sessionHolder.put(p, session); } } private String getUsername(Object p) { if (p instanceof UserDetails) {   return ((UserDetails)p).getUsername(); }  return p.toString(); } /* (non-Javadoc)  * @see org.saiku.web.service.ISessionService#logout(javax.servlet.http.HttpServletRequest)  */ public void logout(HttpServletRequest req) { if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) { Object p = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (sessionHolder.containsKey(p)) { sessionHolder.remove(p); } } SecurityContextHolder.getContext().setAuthentication(null); SecurityContextHolder.clearContext(); HttpSession session = req.getSession(false); if (session != null && !orbisAuthEnabled) { // Just invalidate if not under orbis authentication workflow session.invalidate(); } } /* (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); } } /* (non-Javadoc)  * @see org.saiku.web.service.ISessionService#getSession(javax.servlet.http.HttpServletRequest)  */ public Map getSession() { if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Object p = auth.getPrincipal();   if (sessionHolder.containsKey(p)) {   Map r = new HashMap<>();   r.putAll(sessionHolder.get(p));   r.remove("password");   if (!r.containsKey("sessionid")) {     r.put("sessionid", UUID.randomUUID().toString());   }   return r;   } } return new HashMap<>(); } public Map getAllSessionObjects() { if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Object p = auth.getPrincipal(); //createSession(auth, null, null); if (sessionHolder.containsKey(p)) { Map r = new HashMap<>(); r.putAll(sessionHolder.get(p));  return r; } } return new HashMap<>(); }   public void clearSessions(HttpServletRequest req, String username, String password) throws Exception { if (authenticationManager != null) {   authenticate(req, username, password); } if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) {   Authentication auth = SecurityContextHolder.getContext().getAuthentication();   Object p = auth.getPrincipal();   if (sessionHolder.containsKey(p)) { sessionHolder.remove(p);   } }   } public void setSessionRepo(org.saiku.repository.ScopedRepo sessionRepo) { this.sessionRepo = sessionRepo; } public Boolean isOrbisAuthEnabled() { return orbisAuthEnabled; } public void setOrbisAuthEnabled(Boolean orbisAuthEnabled) { this.orbisAuthEnabled = orbisAuthEnabled; } }

 

saiku-ui\\js\\saiku\\models\\Session.js 

/*  *   Copyright 2012 OSBI Ltd  *  *   Licensed 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.  */ /**  * Object which handles authentication and stores connections and cubes  * @param username  * @param password  * @returns {Session}  */ var Session = Backbone.Model.extend({     username: null,     password: null,     sessionid: null,     upgradeTimeout: null,     isAdmin: Settings.ORBIS_AUTH.hazelcast_enabled,     id: null, atemptedToLoginByCookie: false,     initialize: function(args, options) {         // Attach a custom event bus to this model         _.extend(this, Backbone.Events);         _.bindAll(this, "check_session", "process_session", "load_session","login", "brute_force");         // Check if credentials are being injected into session         if (options && options.username && options.password) {             this.username = options.username;             this.password = options.password;             if (!Settings.DEMO) {                 this.save({username:this.username, password:this.password},{success: this.check_session, error: this.check_session});             } else {                 this.check_session();             }         } else {             this.check_session();         }     },     check_session: function() { // This authentication cookie is used only by Orbis authentication strategy var authCookie = this.getCookie(Settings.ORBIS_AUTH.cookieName); if (Settings.ORBIS_AUTH.hazelcast_enabled && authCookie && !this.atemptedToLoginByCookie) {             this.sessionid               = 1;             this.username                = authCookie;             this.password                = authCookie;             this.atemptedToLoginByCookie = true;             // In this case we inject the proper license attributes             var ONE_YEAR = 31556952000;                          /**             Settings.LICENSE = {               licenseType: 'Orbis',               expiration: Date.now() + ONE_YEAR             }             */             this.login(authCookie, authCookie); } else { if (this.sessionid === null || this.username === null || this.password === null) { var that = this; this.clear(); this.fetch({ success: this.process_session, error: this.brute_force }); } else {                 if (!this.atemptedToLoginByCookie) {                     this.username = encodeURIComponent(options.username);                 } this.load_session(); } }     }, getCookie: function(name) { var value = "; " + document.cookie; var parts = value.split("; " + name + "=");          if (parts.length == 2) {             var cookieVal = parts.pop().split(";").shift();             return cookieVal;         } }, /**  * This is a complete hack to get the BI platform plugin working.  * @param obj  */ brute_force: function(model, response){ this.clear(); this.fetch({ success: this.process_session, error: this.show_error }); }, show_error: function(model, response){ // Open form and retrieve credentials Saiku.ui.unblock(); this.form = new SessionErrorModal({ issue: response.responseText }); this.form.render().open(); },     load_session: function() {         this.sessionworkspace = new SessionWorkspace();     },     process_session: function(model, response) {         if ((response === null || response.sessionid == null)) {             // Open form and retrieve credentials             Saiku.ui.unblock();             if (Settings.DEMO) {                 this.form = new DemoLoginForm({ session: this });             } else {                 this.form = new LoginForm({ session: this });             }             this.form.render().open();         } else {             this.sessionid = response.sessionid;             this.roles = response.roles;             this.isAdmin = Settings.ORBIS_AUTH.hazelcast_enabled || response.isadmin;             this.username = encodeURIComponent(response.username);             this.language = response.language;             if (typeof this.language != "undefined" && this.language != Saiku.i18n.locale) {                 Saiku.i18n.locale = this.language;                 Saiku.i18n.automatic_i18n();             }             /**                 var license =new License();                 license.fetch_license('api/license/', function(opt) {                     if (opt.status === 'success') {                         Settings.LICENSE = opt.data.toJSON();                     }                     if(Saiku.session.isAdmin) {                         var quota = new LicenseQuota();                         quota.fetch_quota('api/license/quota', function (opt) {                             if (opt.status === 'success') {                                 Settings.LICENSEQUOTA = opt.data.toJSON();                             }                         });                     }                 }); */             this.load_session();         }         return this;     },     error: function() {         $(this.form.el).dialog('open');     },     login: function(username, password) {         var that = this;         this.save({username:username, password:password},{dataType: "text", success: this.check_session, error: function(model, response){             that.login_failed(response.responseText);         }});     },     login_failed: function(response){         this.form = new LoginForm({ session: this });         this.form.render().open();         this.form.setError(response);     },     logout: function() {         // FIXME - This is a hack (inherited from old UI)         Saiku.ui.unblock();         $('#header').empty().hide();         $('#tab_panel').remove();         Saiku.tabs = new TabSet();         Saiku.toolbar.remove();         Saiku.toolbar = new Toolbar();         if (typeof localStorage !== "undefined" && localStorage) {             localStorage.clear();         }         this.set('id', _.uniqueId('queryaction_'));         this.destroy({async: false });         this.clear();         this.sessionid = null;         this.username = null;         this.password = null; this.roles = null;         this.isAdmin = false;         this.destroy({async: false });         //console.log("REFRESH!");         document.location.reload(false);     },     url: function() {         return "session";     } });

 

saiku-ui\\js\\saiku\\views\\Upgrade.js

 

/*  *   Copyright 2012 OSBI Ltd  *  *   Licensed 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.  */ /**  * The global toolbar  */ var Upgrade = Backbone.View.extend({ events: { }, initialize: function(a, b) { this.workspace = a.workspace; // Fire off workspace event this.workspace.trigger('workspace:toolbar:render', { workspace: this.workspace }); }, daydiff: function(first, second) { return Math.round((second-first)/(1000*60*60*24)); }, render: function() { /* var self = this; var license = new License(); if(Settings.BIPLUGIN5){ if(Saiku.session.get("notice") != undefined && Saiku.session.get("notice")!=null && Saiku.session.get("notice")!=""){ $(this.el).append("
Notice:"+Saiku.session.get("notice")+"
"); } if (Settings.LICENSE.licenseType != undefined && (Settings.LICENSE.licenseType != "trial" && Settings.LICENSE.licenseType != "Open Source License")) { return this; } if (Settings.LICENSE != undefined && Settings.LICENSE.licenseType === "trial") { var yourEpoch = parseFloat(Settings.LICENSE.expiration); var yourDate = new Date(yourEpoch); self.remainingdays = self.daydiff(new Date(), yourDate); $(this.el).append("
You are using a Saiku Enterprise" + " Trial license, you have "+ self.remainingdays+" days remaining. Buy licenses online.
"); return self; } else { $(this.el).append("
You are using Saiku Community" + " Edition, please consider upgrading to Saiku Enterprise, or entering a sponsorship agreement with us to support development. " + "Or contribute by joining our community and helping other users!
"); return self; } } else { if(Saiku.session.get("notice") != undefined && Saiku.session.get("notice")!=null && Saiku.session.get("notice")!=""){ $(this.el).append("
Notice:"+Saiku.session.get("notice")+"
"); } if (Settings.LICENSE.licenseType != undefined && (Settings.LICENSE.licenseType != "trial" && Settings.LICENSE.licenseType != "Open Source License")) { return this; } if (Settings.LICENSE.licenseType === "trial") { var yourEpoch = parseFloat(Settings.LICENSE.expiration); var yourDate = new Date(yourEpoch); self.remainingdays = self.daydiff(new Date(), yourDate); $(this.el).append("
You are using a Saiku Enterprise" + " Trial license, you have "+ self.remainingdays+" days remaining. Buy licenses online.
"); return self; } else { $(this.el).append("
You are using Saiku Community" + " Edition, please consider upgrading to Saiku Enterprise, or entering a sponsorship agreement with us to support development. " + "Or contribute by joining our community and helping other users!
"); return self; } } */ }, call: function(e) { } });

 

  

 

 

=================二次更新= (第一次通过操作以上步骤确实能正常打包编译saiku然后启动 也不需要上传license验证信息,但是我最近重新编译源码的时候发现license相关报错了。。)===start=========

 

所以我们开始根据报错信息找到配置文件 saiku-beans.xml文件,将关于License的bean注入都给注释掉,然后sessionService中的License对象注入也注释掉,以及plugin中的license也注释掉

 

需要注释的内容:

 

SessionService.java

 

/*private ILicenseUtils l; public ILicenseUtils getL() { return l; } public void setL(ILicenseUtils l) { this.l = l; }*/  

 

saiku-beans.xml

 

                                                                    

 

plugin.spring.xml

 

     

 

  

 

完整的SessionService.java

 

/*    *   Copyright 2012 OSBI Ltd  *  *   Licensed 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.saiku.web.service; import org.apache.commons.lang.StringUtils; import org.saiku.repository.ScopedRepo; import org.saiku.service.ISessionService; import org.saiku.service.license.ILicenseUtils; import bi.meteorite.license.LicenseException; import bi.meteorite.license.SaikuLicense2; import org.saiku.service.util.security.authorisation.AuthorisationPredicate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.authentication.AnonymousAuthenticationToken; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.web.context.request.RequestContextHolder; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import javax.jcr.RepositoryException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; public class SessionService implements ISessionService { private static final Logger log = LoggerFactory.getLogger(SessionService.class); private AuthenticationManager authenticationManager; private AuthorisationPredicate authorisationPredicate; private final Map> sessionHolder = new HashMap<>(); private Boolean anonymous = false; private ScopedRepo sessionRepo; private Boolean orbisAuthEnabled = false; public void setAllowAnonymous(Boolean allow) { this.anonymous  = allow; } /*private ILicenseUtils l; public ILicenseUtils getL() { return l; } public void setL(ILicenseUtils l) { this.l = l; }*/ /* (non-Javadoc)          * @see org.saiku.web.service.ISessionService#setAuthenticationManager(org.springframework.security.authentication.AuthenticationManager)          */ public void setAuthenticationManager(AuthenticationManager auth) { this.authenticationManager = auth; } public void setAuthorisationPredicate(AuthorisationPredicate authorisationPredicate) { this.authorisationPredicate = authorisationPredicate; } /* (non-Javadoc)  * @see org.saiku.web.service.ISessionService#login(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)  */ /**modify the login for getting rid of license validate 2019-03-29*/ public Map 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."); // } 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<>(); } /** The old login validation , have to validate license information public Map 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; } */ private void createSession(Authentication auth, String username, String password) { if (auth ==  null || !auth.isAuthenticated()) { return; } boolean isAnonymousUser = (auth instanceof AnonymousAuthenticationToken); Object p = auth.getPrincipal(); String authUser = getUsername(p); boolean isAnonymous = (isAnonymousUser || StringUtils.equals("anonymousUser", authUser)); boolean isAnonOk = (!isAnonymous || (isAnonymous && anonymous)); if (isAnonOk && auth.isAuthenticated() && p != null && !sessionHolder.containsKey(p)) { Map session = new HashMap<>(); if (isAnonymous) { log.debug("Creating Session for Anonymous User"); } if (StringUtils.isNotBlank(username)) { session.put("username", username); } else { session.put("username", authUser); } if (StringUtils.isNotBlank(password)) { session.put("password", password); } session.put("sessionid", UUID.randomUUID().toString()); session.put("authid", RequestContextHolder.currentRequestAttributes().getSessionId()); List roles = new ArrayList<>(); for (GrantedAuthority ga : SecurityContextHolder.getContext().getAuthentication().getAuthorities()) { roles.add(ga.getAuthority()); } session.put("roles", roles); sessionHolder.put(p, session); } } private String getUsername(Object p) { if (p instanceof UserDetails) {   return ((UserDetails)p).getUsername(); }  return p.toString(); } /* (non-Javadoc)  * @see org.saiku.web.service.ISessionService#logout(javax.servlet.http.HttpServletRequest)  */ public void logout(HttpServletRequest req) { if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) { Object p = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (sessionHolder.containsKey(p)) { sessionHolder.remove(p); } } SecurityContextHolder.getContext().setAuthentication(null); SecurityContextHolder.clearContext(); HttpSession session = req.getSession(false); if (session != null && !orbisAuthEnabled) { // Just invalidate if not under orbis authentication workflow session.invalidate(); } } /* (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); } } /* (non-Javadoc)  * @see org.saiku.web.service.ISessionService#getSession(javax.servlet.http.HttpServletRequest)  */ public Map getSession() { if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Object p = auth.getPrincipal();   if (sessionHolder.containsKey(p)) {   Map r = new HashMap<>();   r.putAll(sessionHolder.get(p));   r.remove("password");   if (!r.containsKey("sessionid")) {     r.put("sessionid", UUID.randomUUID().toString());   }   return r;   } } return new HashMap<>(); } public Map getAllSessionObjects() { if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Object p = auth.getPrincipal(); //createSession(auth, null, null); if (sessionHolder.containsKey(p)) { Map r = new HashMap<>(); r.putAll(sessionHolder.get(p));  return r; } } return new HashMap<>(); }   public void clearSessions(HttpServletRequest req, String username, String password) throws Exception { if (authenticationManager != null) {   authenticate(req, username, password); } if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) {   Authentication auth = SecurityContextHolder.getContext().getAuthentication();   Object p = auth.getPrincipal();   if (sessionHolder.containsKey(p)) { sessionHolder.remove(p);   } }   } public void setSessionRepo(org.saiku.repository.ScopedRepo sessionRepo) { this.sessionRepo = sessionRepo; } public Boolean isOrbisAuthEnabled() { return orbisAuthEnabled; } public void setOrbisAuthEnabled(Boolean orbisAuthEnabled) { this.orbisAuthEnabled = orbisAuthEnabled; } }

 

  

 

完整的saiku-beans.xml

 

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ROLE_ADMIN                                                                                                                                                                                                                                                                                                                                                                                                                                         

 

  

 

完整的plugin.spring.xml

 

                          Administrator                                                                                                                                                                                                            

 

  

 

=================二次更新= (第一次通过操作以上步骤确实能正常打包编译saiku然后启动 也不需要上传license验证信息,但是我最近重新编译源码的时候发现license相关报错了。。)=====end=======

 

 

 

best365官网中文版登录备份软件,best365官网中文版登录容灾备份系统,虚拟机备份,数据库备份,文件备份,实时备份,勒索软件,美国,图书馆

您可能感兴趣的新闻 换一批

分类目录

热门文章

相关文章

现在下载,可享15天免费试用

立即下载

请添加好友为您提供支持
jia7jia_7

微信售后服务二维码

请拨打电话
为您提供支持

400-9955-698

XML 地图