Search in sources :

Example 1 with User

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;
}
Also used : User(com.varsql.core.auth.User) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) DBConnTabEntity(com.varsql.web.model.entity.db.DBConnTabEntity) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeDataSort(com.vartech.common.sort.TreeDataSort) SQLException(java.sql.SQLException) DBMetadataException(com.varsql.core.exception.DBMetadataException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with User

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);
    }
}
Also used : RememberMeHttpServletRequestWapper(com.varsql.web.security.rememberme.RememberMeHttpServletRequestWapper) User(com.varsql.core.auth.User) SavedRequest(org.springframework.security.web.savedrequest.SavedRequest)

Example 3 with User

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);
    }
}
Also used : User(com.varsql.core.auth.User) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) PreparedStatement(java.sql.PreparedStatement) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) VarsqlAppException(com.varsql.web.exception.VarsqlAppException) SQLException(java.sql.SQLException) LinkedHashMap(java.util.LinkedHashMap) AuthorityType(com.varsql.core.auth.AuthorityType) ResultSet(java.sql.ResultSet)

Example 4 with User

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 "";
}
Also used : User(com.varsql.core.auth.User) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Authority(com.varsql.core.auth.Authority) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Example 5 with User

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));
}
Also used : User(com.varsql.core.auth.User)

Aggregations

User (com.varsql.core.auth.User)7 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Authority (com.varsql.core.auth.Authority)2 AuthorityType (com.varsql.core.auth.AuthorityType)2 DatabaseInfo (com.varsql.core.db.valueobject.DatabaseInfo)2 VarsqlAppException (com.varsql.web.exception.VarsqlAppException)2 HashMap (java.util.HashMap)2 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)2 BlockingUserException (com.varsql.core.exception.BlockingUserException)1 DBMetadataException (com.varsql.core.exception.DBMetadataException)1 DBConnTabEntity (com.varsql.web.model.entity.db.DBConnTabEntity)1 UserEntity (com.varsql.web.model.entity.user.UserEntity)1 RememberMeHttpServletRequestWapper (com.varsql.web.security.rememberme.RememberMeHttpServletRequestWapper)1 TreeDataSort (com.vartech.common.sort.TreeDataSort)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1