📄 localejbcahardtokenbatchjobsessionbean.java
字号:
String msg = intres.getLocalizedMessage("hardtoken.userdatasent", alias); getLogSession().log(admin, returnval.getCAId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),returnval.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKEN_USERDATASENT, msg); } }catch(Exception e){ String msg = intres.getLocalizedMessage("hardtoken.errorsenduserdata", alias); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_HARDTOKEN_USERDATASENT, msg); throw new EJBException(e); } finally { JDBCUtil.close(con, ps, rs); } } debug("<getNextHardTokenToGenerate()"); return returnval; }// getNextHardTokenToGenerate /** * Returns a Collection of users scheduled for batch generation for the given issuer. * A maximum of MAX_RETURNED_QUEUE_SIZE users will be returned by call. * * @param admin the administrator performing the actions * * @return A Collection of users to generate or NULL if there are no users i queue. * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public Collection getNextHardTokensToGenerate(Admin admin, String alias) throws UnavailableTokenException{ debug(">getNextHardTokensToGenerate()"); ArrayList returnval = new ArrayList(); int issuerid = getHardTokenSession().getHardTokenIssuerId(admin, alias); if(issuerid != LocalHardTokenSessionBean.NO_ISSUER){ ResultSet rs = null; Connection con = null; PreparedStatement ps = null; try{ // Construct SQL query. con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE); ps = con.prepareStatement("select " + USERDATA_COL + " from UserData where hardTokenIssuerId=? and tokenType>? and (status=? or status=?)" ); ps.setInt(1,issuerid); ps.setInt(2,SecConst.TOKEN_SOFT); ps.setInt(3,UserDataConstants.STATUS_NEW); ps.setInt(4,UserDataConstants.STATUS_KEYRECOVERY); // Assemble result. while(rs.next() && returnval.size() <= MAX_RETURNED_QUEUE_SIZE){ // TODO add support for Extended Information UserDataVO data = new UserDataVO(rs.getString(1), rs.getString(2), rs.getInt(14), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getInt(6) , rs.getInt(10), rs.getInt(11) , new java.util.Date(rs.getLong(8)), new java.util.Date(rs.getLong(9)) , rs.getInt(12), rs.getInt(13), null); data.setPassword(rs.getString(7)); getHardTokenSession().getIsHardTokenProfileAvailableToIssuer(admin, issuerid, data); returnval.add(data); String msg = intres.getLocalizedMessage("hardtoken.userdatasent", alias); getLogSession().log(admin, data.getCAId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),data.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKEN_USERDATASENT, msg); } }catch(Exception e){ String msg = intres.getLocalizedMessage("hardtoken.errorsenduserdata", alias); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_HARDTOKEN_USERDATASENT, msg); throw new EJBException(e); }finally{ JDBCUtil.close(con, ps, rs); } } if(returnval.size()==0) returnval=null; debug("<getNextHardTokensToGenerate()"); return returnval; }// getNextHardTokensToGenerate /** * Returns the indexed user in queue scheduled for batch generation for the given issuer. * * @param admin the administrator performing the actions * @param index index in queue of user to retrieve. * * @return The next token to generate or NULL if the given user doesn't exist in queue. * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public UserDataVO getNextHardTokenToGenerateInQueue(Admin admin, String alias, int index) throws UnavailableTokenException{ debug(">getNextHardTokenToGenerateInQueue()"); UserDataVO returnval=null; int issuerid = getHardTokenSession().getHardTokenIssuerId(admin, alias); if(issuerid != LocalHardTokenSessionBean.NO_ISSUER){ Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try{ // Construct SQL query. con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE); ps = con.prepareStatement("select " + USERDATA_COL + " from UserData where hardTokenIssuerId=? and tokenType>? and (status=? or status=?)" ); ps.setInt(1,issuerid); ps.setInt(2,SecConst.TOKEN_SOFT); ps.setInt(3,UserDataConstants.STATUS_NEW); ps.setInt(4,UserDataConstants.STATUS_KEYRECOVERY); // Assemble result. if(rs.relative(index)){ // TODO add support for Extended Information returnval = new UserDataVO(rs.getString(1), rs.getString(2), rs.getInt(14), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getInt(6) , rs.getInt(10), rs.getInt(11) , new java.util.Date(rs.getLong(8)), new java.util.Date(rs.getLong(9)) , rs.getInt(12), rs.getInt(13), null); returnval.setPassword(rs.getString(7)); } if(returnval !=null){ getHardTokenSession().getIsHardTokenProfileAvailableToIssuer(admin, issuerid, returnval); String msg = intres.getLocalizedMessage("hardtoken.userdatasent", alias); getLogSession().log(admin, returnval.getCAId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),returnval.getUsername(), null, LogEntry.EVENT_INFO_HARDTOKEN_USERDATASENT, msg); } }catch(Exception e){ String msg = intres.getLocalizedMessage("hardtoken.errorsenduserdata", alias); getLogSession().log(admin, admin.getCaId(), LogEntry.MODULE_HARDTOKEN, new java.util.Date(),null, null, LogEntry.EVENT_ERROR_HARDTOKEN_USERDATASENT, msg); throw new EJBException(e); }finally{ JDBCUtil.close(con, ps, rs); } } debug("<getNextHardTokenToGenerateInQueue()"); return returnval; }// getNextHardTokenToGenerateInQueue /** * Returns the number of users scheduled for batch generation for the given issuer. * * @param admin the administrator performing the actions * * @return the number of users to generate. * @throws EJBException if a communication or other error occurs. * @ejb.interface-method view-type="both" */ public int getNumberOfHardTokensToGenerate(Admin admin, String alias){ debug(">getNumberOfHardTokensToGenerate()"); int count = 0; int issuerid = getHardTokenSession().getHardTokenIssuerId(admin, alias); if(issuerid != LocalHardTokenSessionBean.NO_ISSUER){ Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try{ // Construct SQL query. con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE); ps = con.prepareStatement("select COUNT(*) from UserData where hardTokenIssuerId=? and tokenType>? and (status=? or status=?)"); ps.setInt(1,issuerid); ps.setInt(2,SecConst.TOKEN_SOFT); ps.setInt(3,UserDataConstants.STATUS_NEW); ps.setInt(4,UserDataConstants.STATUS_KEYRECOVERY); // Execute query. rs = ps.executeQuery(); // Assemble result. while(rs.next()){ count = rs.getInt(1); } }catch(Exception e){ throw new EJBException(e); }finally{ JDBCUtil.close(con, ps, rs); } } debug("<getNumberOfHardTokensToGenerate()"); return count; }// getNumberOfHardTokensToGenerate /** * Methods that checks if a user exists in the database having the given hard token issuer id. This function is mainly for avoiding * desyncronisation when a hard token issuer is deleted. * * @param hardtokenissuerid the id of hard token issuer to look for. * @return true if hardtokenissuerid exists in userdatabase. * @ejb.interface-method view-type="both" */ public boolean checkForHardTokenIssuerId(Admin admin, int hardtokenissuerid){ debug(">checkForHardTokenIssuerId(id: " + hardtokenissuerid + ")"); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; int count = 1; // return true as default. try{ // Construct SQL query. con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE); ps = con.prepareStatement("select COUNT(*) from UserData where hardTokenIssuerId=?"); ps.setInt(1,hardtokenissuerid); // Execute query. rs = ps.executeQuery(); // Assemble result. if(rs.next()){ count = rs.getInt(1); } debug("<checkForHardTokenIssuerId()"); return count > 0; }catch(Exception e){ throw new EJBException(e); }finally{ JDBCUtil.close(con, ps, rs); } } // checkForHardTokenIssuerId} // LocalRaAdminSessionBean
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -