use of com.varsql.core.auth.User in project varsql by varsqlinfo.
the class DatabaseServiceImpl method findTabInfo.
@Transactional(value = ResourceConfigConstants.APP_TRANSMANAGER, rollbackFor = Throwable.class)
public List findTabInfo() {
TreeDataSort tds = new TreeDataSort("conuid", "prevConuid");
try {
String viewid = SecurityUtil.userViewId();
List<DBConnTabEntity> tabList = dbConnTabEntityRepository.findAllByViewid(viewid);
User user = SecurityUtil.loginInfo();
Map<String, DatabaseInfo> databaseInfo = user.getDatabaseInfo();
Map<String, String> vconnidNconuid = user.getVconnidNconuid();
List<String> notExistsVconnid = new ArrayList<>();
tabList.forEach(item -> {
String vconnid = item.getVconnid();
if (vconnidNconuid.containsKey(vconnid)) {
String conuid = vconnidNconuid.get(vconnid);
DatabaseInfo di = databaseInfo.get(conuid);
tds.sortTreeData(DBConnTabResponseDTO.builder().conuid(conuid).name(di.getName()).prevConuid(vconnidNconuid.get(item.getPrevVconnid())).viewYn(item.isViewYn()).build());
} else {
notExistsVconnid.add(vconnid);
}
});
if (notExistsVconnid.size() > 0) {
dbConnTabEntityRepository.deleteAllTabInfo(viewid, notExistsVconnid);
}
} catch (Exception e) {
logger.error("findTabInfo : {} ", e.getMessage(), e);
}
List sortList = tds.getSortList();
return sortList == null ? new ArrayList() : sortList;
}
use of com.varsql.core.auth.User in project varsql by varsqlinfo.
the class VarsqlAuthenticationSuccessHandler method onAuthenticationSuccess.
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException, ServletException {
User userInfo = SecurityUtil.loginInfo();
String targetUrl = userRedirectTargetUrl(request, response, userInfo, authentication);
if (response.isCommitted()) {
logger.debug("Response has already been committed. Unable to redirect to {} ", targetUrl);
return;
}
securityLogDAO.addLog(userInfo, userInfo.isLoginRememberMe() ? "auto" : "login", CommUtils.getClientPcInfo(request));
if (userInfo.isLoginRememberMe()) {
try {
// database information reload
DatabaseUtils.reloadUserDatabaseInfo();
} catch (Throwable e) {
logger.error("database information reload error {} ", e.getMessage());
}
super.clearAuthenticationAttributes(request);
String queryStr = request.getQueryString();
// String reqUrl = request.getRequestURI().replaceFirst(request.getContextPath(), "") +(StringUtil.isBlank(queryStr)?"":"?"+queryStr);
String reqUrl = request.getRequestURI().replaceFirst(request.getContextPath(), "");
logger.debug("remember me forward request uri : {}, query string :{}", reqUrl, queryStr);
logger.debug("cookie values : {} ", HttpUtils.getAllCookieString(request));
logger.debug("request header : {} ", HttpUtils.getAllReqHeaderString(request));
logger.debug("response header : {} ", HttpUtils.getAllResHeaderString(response));
logger.debug("----------------------------------------------------------------------");
request.getRequestDispatcher(reqUrl).forward(new RememberMeHttpServletRequestWapper(request, response), response);
return;
} else {
if (!VarsqlUtils.isAjaxRequest(request)) {
SavedRequest savedRequest = requestCache.getRequest(request, response);
if (savedRequest != null) {
String contextPath = request.getContextPath();
int contextPosIdx = targetUrl.indexOf(contextPath);
if (contextPosIdx > -1) {
String url = targetUrl.substring(contextPosIdx + contextPath.length());
if (!"".equals(url) && !"/".equals(url)) {
targetUrl = savedRequest.getRedirectUrl();
}
}
}
}
logger.debug("login targer url : {}", targetUrl);
redirectStrategy.sendRedirect(request, response, targetUrl);
super.clearAuthenticationAttributes(request);
}
}
use of com.varsql.core.auth.User in project varsql by varsqlinfo.
the class AuthDAO method getUserDataBaseInfo.
/**
* @Method Name : getUserDataBaseInfo
* @Method 설명 :
* @작성일 : 2015. 6. 22.
* @작성자 : ytkim
* @변경이력 :
* @return
* @throws SQLException
*/
public void getUserDataBaseInfo() {
Connection conn = ConnectionFactory.getInstance().getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
User user = SecurityUtil.loginInfo();
StringBuffer query = new StringBuffer();
String dbColumnQuery = "select VCONNID, VNAME, VDBSCHEMA, VDBVERSION, BASETABLE_YN, LAZYLOAD_YN,SCHEMA_VIEW_YN, MAX_SELECT_COUNT, USE_COLUMN_LABEL, b.DB_TYPE from VTCONNECTION a left outer join VTDBTYPE_DRIVER_PROVIDER b on a.VDRIVER = b.DRIVER_PROVIDER_ID where USE_YN ='Y' and DEL_YN = 'N' AND ";
query.append(dbColumnQuery);
AuthorityType tmpAuthority = user.getTopAuthority();
if (tmpAuthority.equals(AuthorityType.ADMIN)) {
query.append(" 1 = 1 ");
} else if (tmpAuthority.equals(AuthorityType.GUEST)) {
query.append(" 1 != 1 ");
} else {
query.append(" A.VCONNID IN ( ");
query.append(" select d.VCONNID ");
query.append(" from VTDATABASE_GROUP a inner join VTDATABASE_GROUP_DB b on a.GROUP_ID = b.GROUP_ID ");
query.append(" inner join VTDATABASE_GROUP_USER c on b.GROUP_ID = c.GROUP_ID ");
query.append(" inner join VTCONNECTION d on b.VCONNID = d.VCONNID ");
query.append(" left outer join VTDATABASE_BLOCK_USER e on d.VCONNID = e.VCONNID and c.VIEWID =e.VIEWID ");
query.append(" where c.VIEWID = '" + user.getViewid() + "' ");
query.append(" and e.viewid is null ");
query.append(" and d.USE_YN = 'Y' ");
query.append(" group by d.VCONNID ");
query.append(" ) ");
if (tmpAuthority.equals(AuthorityType.MANAGER)) {
query.append(" union ");
query.append(dbColumnQuery + " A.VCONNID in ( select VCONNID from VTDATABASE_MANAGER where VIEWID = '" + user.getViewid() + "' ) ");
}
}
Map<String, DatabaseInfo> userDatabaseInfo = new LinkedHashMap<String, DatabaseInfo>();
if (!tmpAuthority.equals(AuthorityType.GUEST)) {
pstmt = conn.prepareStatement(query.toString());
rs = pstmt.executeQuery();
String vconnid;
String uuid = "";
String viewid = user.getViewid();
Map<String, String> vconnidNconuid = new HashMap<>();
List<String> newVconnidList = new ArrayList<String>();
while (rs.next()) {
vconnid = rs.getString(VarsqlKeyConstants.CONN_ID);
newVconnidList.add(vconnid);
uuid = UUIDUtil.vconnidUUID(viewid, vconnid);
try {
userDatabaseInfo.put(uuid, new DatabaseInfo(vconnid, uuid, rs.getString("DB_TYPE"), rs.getString(VarsqlKeyConstants.CONN_NAME), rs.getString(VarsqlKeyConstants.CONN_DBSCHEMA), rs.getString(VarsqlKeyConstants.CONN_BASETABLE_YN), rs.getString(VarsqlKeyConstants.CONN_LAZYLOAD_YN), rs.getLong(VarsqlKeyConstants.CONN_VDBVERSION), rs.getString(VarsqlKeyConstants.CONN_SCHEMA_VIEW_YN), rs.getInt(VarsqlKeyConstants.CONN_MAX_SELECT_COUNT), rs.getString(VarsqlKeyConstants.CONN_USE_COLUMN_LABEL)));
vconnidNconuid.put(vconnid, uuid);
} catch (Exception e) {
logger.error("DatabaseInfo not valid : " + vconnid);
}
}
user.setDatabaseInfo(userDatabaseInfo);
user.setVconnidNconuid(vconnidNconuid);
}
} catch (SQLException e) {
throw new VarsqlAppException("database load exception : " + e.getMessage(), e);
} finally {
JdbcUtils.close(conn, pstmt, rs);
}
}
use of com.varsql.core.auth.User in project varsql by varsqlinfo.
the class SecurityUtil method loginRole.
public static String loginRole(Authentication auth) {
if (auth == null)
return null;
if (auth instanceof AnonymousAuthenticationToken) {
return User.ANONYMOUS_USERNAME;
}
User user = (User) auth.getPrincipal();
java.util.Iterator<? extends GrantedAuthority> iter = user.getAuthorities().iterator();
while (iter.hasNext()) {
return ((Authority) iter.next()).getName();
}
return "";
}
use of com.varsql.core.auth.User in project varsql by varsqlinfo.
the class DatabaseParamInfo method setConuid.
public void setConuid(String conuid) {
User user = SecurityUtil.loginInfo();
setConuid(conuid, user.getViewid(), user.getDatabaseInfo().get(conuid));
}
Aggregations