当前位置: 首页>>代码示例>>Java>>正文


Java UserManager.isAdmin方法代码示例

本文整理汇总了Java中org.apache.ftpserver.ftplet.UserManager.isAdmin方法的典型用法代码示例。如果您正苦于以下问题:Java UserManager.isAdmin方法的具体用法?Java UserManager.isAdmin怎么用?Java UserManager.isAdmin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ftpserver.ftplet.UserManager的用法示例。


在下文中一共展示了UserManager.isAdmin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.ftpserver.ftplet.UserManager; //导入方法依赖的package包/类
/**
 * Execute command.
 */
public void execute(final FtpIoSession session,
        final FtpServerContext context, final FtpRequest request)
        throws IOException, FtpException {

    // reset state variables
    session.resetState();

    // only administrator can execute this
    UserManager userManager = context.getUserManager();
    boolean isAdmin = userManager.isAdmin(session.getUser().getName());
    if (!isAdmin) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_530_NOT_LOGGED_IN, "SITE", null));
        return;
    }

    // get the user name
    String argument = request.getArgument();
    int spIndex = argument.indexOf(' ');
    if (spIndex == -1) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
                "SITE.DESCUSER", null));
        return;
    }
    String userName = argument.substring(spIndex + 1);

    // check the user existance
    UserManager usrManager = context.getUserManager();
    User user = null;
    try {
        if (usrManager.doesExist(userName)) {
            user = usrManager.getUserByName(userName);
        }
    } catch (FtpException ex) {
        LOG.debug("Exception trying to get user from user manager", ex);
    }
    if (user == null) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
                "SITE.DESCUSER", userName));
        return;
    }

    // send the user information
    StringBuilder sb = new StringBuilder(128);
    sb.append("\n");
    sb.append("userid          : ").append(user.getName()).append("\n");
    sb.append("userpassword    : ********\n");
    sb.append("homedirectory   : ").append(user.getHomeDirectory()).append(
            "\n");
    sb.append("writepermission : ").append(
            user.authorize(new WriteRequest()) != null).append("\n");
    sb.append("enableflag      : ").append(user.getEnabled()).append("\n");
    sb.append("idletime        : ").append(user.getMaxIdleTime()).append(
            "\n");

    TransferRateRequest transferRateRequest = new TransferRateRequest();
    transferRateRequest = (TransferRateRequest) session.getUser()
            .authorize(transferRateRequest);

    if (transferRateRequest != null) {
        sb.append("uploadrate      : ").append(
                transferRateRequest.getMaxUploadRate()).append("\n");
        sb.append("downloadrate    : ").append(
                transferRateRequest.getMaxDownloadRate()).append("\n");
    } else {
        sb.append("uploadrate      : 0\n");
        sb.append("downloadrate    : 0\n");
    }
    sb.append('\n');
    session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY, sb
            .toString()));
}
 
开发者ID:saaconsltd,项目名称:mina-ftpserver,代码行数:78,代码来源:SITE_DESCUSER.java

示例2: execute

import org.apache.ftpserver.ftplet.UserManager; //导入方法依赖的package包/类
/**
 * Execute command.
 */
public void execute(final FtpIoSession session,
        final FtpServerContext context, final FtpRequest request)
        throws IOException, FtpException {

    // reset state variables
    session.resetState();

    // only administrator can execute this
    UserManager userManager = context.getUserManager();
    boolean isAdmin = userManager.isAdmin(session.getUser().getName());
    if (!isAdmin) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_530_NOT_LOGGED_IN, "SITE", null));
        return;
    }

    // get statistics information
    FtpStatistics stat = context.getFtpStatistics();
    StringBuilder sb = new StringBuilder(256);
    sb.append('\n');
    sb.append("Start Time               : ").append(
            DateUtils.getISO8601Date(stat.getStartTime().getTime()))
            .append('\n');
    sb.append("File Upload Number       : ").append(
            stat.getTotalUploadNumber()).append('\n');
    sb.append("File Download Number     : ").append(
            stat.getTotalDownloadNumber()).append('\n');
    sb.append("File Delete Number       : ").append(
            stat.getTotalDeleteNumber()).append('\n');
    sb.append("File Upload Bytes        : ").append(
            stat.getTotalUploadSize()).append('\n');
    sb.append("File Download Bytes      : ").append(
            stat.getTotalDownloadSize()).append('\n');
    sb.append("Directory Create Number  : ").append(
            stat.getTotalDirectoryCreated()).append('\n');
    sb.append("Directory Remove Number  : ").append(
            stat.getTotalDirectoryRemoved()).append('\n');
    sb.append("Current Logins           : ").append(
            stat.getCurrentLoginNumber()).append('\n');
    sb.append("Total Logins             : ").append(
            stat.getTotalLoginNumber()).append('\n');
    sb.append("Current Anonymous Logins : ").append(
            stat.getCurrentAnonymousLoginNumber()).append('\n');
    sb.append("Total Anonymous Logins   : ").append(
            stat.getTotalAnonymousLoginNumber()).append('\n');
    sb.append("Current Connections      : ").append(
            stat.getCurrentConnectionNumber()).append('\n');
    sb.append("Total Connections        : ").append(
            stat.getTotalConnectionNumber()).append('\n');
    sb.append('\n');
    session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY, sb
            .toString()));
}
 
开发者ID:saaconsltd,项目名称:mina-ftpserver,代码行数:57,代码来源:SITE_STAT.java

示例3: execute

import org.apache.ftpserver.ftplet.UserManager; //导入方法依赖的package包/类
/**
 * Execute command.
 */
public void execute(final FtpIoSession session,
        final FtpServerContext context, final FtpRequest request)
        throws IOException, FtpException {

    // reset state variables
    session.resetState();

    // only administrator can execute this
    UserManager userManager = context.getUserManager();
    boolean isAdmin = userManager.isAdmin(session.getUser().getName());
    if (!isAdmin) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_530_NOT_LOGGED_IN, "SITE", null));
        return;
    }

    // print all the connected user information
    StringBuilder sb = new StringBuilder();

    Map<Long, IoSession> sessions = session.getService()
            .getManagedSessions();

    sb.append('\n');
    Iterator<IoSession> sessionIterator = sessions.values().iterator();

    while (sessionIterator.hasNext()) {
        FtpIoSession managedSession = new FtpIoSession(sessionIterator
                .next(), context);

        if (!managedSession.isLoggedIn()) {
            continue;
        }

        User tmpUsr = managedSession.getUser();
        sb.append(StringUtils.pad(tmpUsr.getName(), ' ', true, 16));

        if (managedSession.getRemoteAddress() instanceof InetSocketAddress) {
            sb.append(StringUtils.pad(((InetSocketAddress) managedSession
                    .getRemoteAddress()).getAddress().getHostAddress(),
                    ' ', true, 16));
        }
        sb.append(StringUtils.pad(DateUtils.getISO8601Date(managedSession
                .getLoginTime().getTime()), ' ', true, 20));
        sb.append(StringUtils.pad(DateUtils.getISO8601Date(managedSession
                .getLastAccessTime().getTime()), ' ', true, 20));
        sb.append('\n');
    }
    sb.append('\n');
    session.write(new DefaultFtpReply(FtpReply.REPLY_200_COMMAND_OKAY, sb
            .toString()));
}
 
开发者ID:saaconsltd,项目名称:mina-ftpserver,代码行数:55,代码来源:SITE_WHO.java


注:本文中的org.apache.ftpserver.ftplet.UserManager.isAdmin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。