Search in sources :

Example 6 with Action

use of org.apache.struts2.convention.annotation.Action in project KeyBox by skavanagh.

the class UploadAndPushAction method upload.

@Action(value = "/admin/upload", results = { @Result(name = "input", location = "/admin/upload.jsp"), @Result(name = "success", location = "/admin/upload_result.jsp") })
public String upload() {
    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    try {
        File destination = new File(UPLOAD_PATH, uploadFileName);
        FileUtils.copyFile(upload, destination);
        pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
        hostSystemList = SystemStatusDB.getAllSystemStatus(userId);
    } catch (Exception e) {
        log.error(e.toString(), e);
        return INPUT;
    }
    return SUCCESS;
}
Also used : File(java.io.File) Action(org.apache.struts2.convention.annotation.Action)

Example 7 with Action

use of org.apache.struts2.convention.annotation.Action in project KeyBox by skavanagh.

the class LoginAction method loginSubmit.

@Action(value = "/loginSubmit", results = { @Result(name = "input", location = "/login.jsp"), @Result(name = "change_password", location = "/admin/userSettings.action", type = "redirect"), @Result(name = "otp", location = "/admin/viewOTP.action", type = "redirect"), @Result(name = "success", location = "/admin/menu.action", type = "redirect") })
public String loginSubmit() {
    String retVal = SUCCESS;
    String authToken = AuthDB.login(auth);
    //get client IP
    String clientIP = null;
    if (StringUtils.isNotEmpty(AppConfig.getProperty("clientIPHeader"))) {
        clientIP = servletRequest.getHeader(AppConfig.getProperty("clientIPHeader"));
    }
    if (StringUtils.isEmpty(clientIP)) {
        clientIP = servletRequest.getRemoteAddr();
    }
    if (authToken != null) {
        User user = AuthDB.getUserByAuthToken(authToken);
        if (user != null) {
            String sharedSecret = null;
            if (otpEnabled) {
                sharedSecret = AuthDB.getSharedSecret(user.getId());
                if (StringUtils.isNotEmpty(sharedSecret) && (auth.getOtpToken() == null || !OTPUtil.verifyToken(sharedSecret, auth.getOtpToken()))) {
                    loginAuditLogger.info(auth.getUsername() + " (" + clientIP + ") - " + AUTH_ERROR);
                    addActionError(AUTH_ERROR);
                    return INPUT;
                }
            }
            //check to see if admin has any assigned profiles
            if (!User.MANAGER.equals(user.getUserType()) && (user.getProfileList() == null || user.getProfileList().size() <= 0)) {
                loginAuditLogger.info(auth.getUsername() + " (" + clientIP + ") - " + AUTH_ERROR_NO_PROFILE);
                addActionError(AUTH_ERROR_NO_PROFILE);
                return INPUT;
            }
            AuthUtil.setAuthToken(servletRequest.getSession(), authToken);
            AuthUtil.setUserId(servletRequest.getSession(), user.getId());
            AuthUtil.setAuthType(servletRequest.getSession(), user.getAuthType());
            AuthUtil.setTimeout(servletRequest.getSession());
            //for first time login redirect to set OTP
            if (otpEnabled && StringUtils.isEmpty(sharedSecret)) {
                retVal = "otp";
            } else if ("changeme".equals(auth.getPassword()) && Auth.AUTH_BASIC.equals(user.getAuthType())) {
                retVal = "change_password";
            }
            loginAuditLogger.info(auth.getUsername() + " (" + clientIP + ") - Authentication Success");
        }
    } else {
        loginAuditLogger.info(auth.getUsername() + " (" + clientIP + ") - " + AUTH_ERROR);
        addActionError(AUTH_ERROR);
        retVal = INPUT;
    }
    return retVal;
}
Also used : User(com.keybox.manage.model.User) Action(org.apache.struts2.convention.annotation.Action)

Example 8 with Action

use of org.apache.struts2.convention.annotation.Action in project qi4j-sdk by Qi4j.

the class Qi4jCodebehindPackageProvider method processActionClass.

/**
     * Create a default action mapping for a class instance.
     *
     * The namespace annotation is honored, if found, otherwise
     * the Java package is converted into the namespace
     * by changing the dots (".") to slashes ("/").
     *
     * @param cls  Action or POJO instance to process
     * @param pkgs List of packages that were scanned for Actions
     */
protected void processActionClass(Class<?> cls, String[] pkgs) {
    String name = cls.getName();
    String actionPackage = cls.getPackage().getName();
    String actionNamespace = null;
    String actionName = null;
    org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) cls.getAnnotation(org.apache.struts2.config.Action.class);
    if (actionAnn != null) {
        actionName = actionAnn.name();
        if (actionAnn.namespace().equals(org.apache.struts2.config.Action.DEFAULT_NAMESPACE)) {
            actionNamespace = "";
        } else {
            actionNamespace = actionAnn.namespace();
        }
    } else {
        for (String pkg : pkgs) {
            if (name.startsWith(pkg)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("ClasspathPackageProvider: Processing class " + name);
                }
                name = name.substring(pkg.length() + 1);
                actionNamespace = "";
                actionName = name;
                int pos = name.lastIndexOf('.');
                if (pos > -1) {
                    actionNamespace = "/" + name.substring(0, pos).replace('.', '/');
                    actionName = name.substring(pos + 1);
                }
                break;
            }
        }
        // Truncate Action suffix if found
        if (actionName.endsWith(getClassSuffix())) {
            actionName = actionName.substring(0, actionName.length() - getClassSuffix().length());
        }
        // Force initial letter of action to lowercase, if desired
        if ((forceLowerCase) && (actionName.length() > 1)) {
            int lowerPos = actionName.lastIndexOf('/') + 1;
            StringBuilder sb = new StringBuilder();
            sb.append(actionName.substring(0, lowerPos));
            sb.append(Character.toLowerCase(actionName.charAt(lowerPos)));
            sb.append(actionName.substring(lowerPos + 1));
            actionName = sb.toString();
        }
    }
    PackageConfig.Builder pkgConfig = loadPackageConfig(actionNamespace, actionPackage, cls);
    // In case the package changed due to namespace annotation processing
    if (!actionPackage.equals(pkgConfig.getName())) {
        actionPackage = pkgConfig.getName();
    }
    Annotation annotation = cls.getAnnotation(ParentPackage.class);
    if (annotation != null) {
        String parent = ((ParentPackage) annotation).value()[0];
        PackageConfig parentPkg = configuration.getPackageConfig(parent);
        if (parentPkg == null) {
            throw new ConfigurationException("ClasspathPackageProvider: Unable to locate parent package " + parent, annotation);
        }
        pkgConfig.addParent(parentPkg);
        if (!isNotEmpty(pkgConfig.getNamespace()) && isNotEmpty(parentPkg.getNamespace())) {
            pkgConfig.namespace(parentPkg.getNamespace());
        }
    }
    ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig);
    ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName()).addResultConfigs(new ResultMap<String, ResultConfig>(cls, actionName, defaultResultType)).build();
    pkgConfig.addActionConfig(actionName, actionConfig);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) Annotation(java.lang.annotation.Annotation) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) org.apache.struts2.config(org.apache.struts2.config)

Example 9 with Action

use of org.apache.struts2.convention.annotation.Action in project bamboobsc by billchen198318.

the class ActionInfoSupportInterceptor method intercept.

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    /*
		ActionInvocation ai=(ActionInvocation)ActionContext.getContext().get(ActionContext.ACTION_INVOCATION); 
		String action=ai.getProxy().getActionName(); 
		String namespace=ai.getProxy().getNamespace();
		*/
    HttpServletRequest request = ServletActionContext.getRequest();
    ActionContext context = actionInvocation.getInvocationContext();
    String action = actionInvocation.getProxy().getActionName();
    String namespace = actionInvocation.getProxy().getNamespace();
    String remoteAddr = request.getRemoteAddr();
    String referer = request.getHeader("referer");
    context.getSession().put(Constants.SESS_PAGE_INFO_ACTION_ByInterceptor, action);
    context.getSession().put(Constants.SESS_PAGE_INFO_NAMESPACE_ByInterceptor, namespace);
    context.getSession().put(Constants.SESS_PAGE_INFO_RemoteAddr_ByInterceptor, remoteAddr);
    context.getSession().put(Constants.SESS_PAGE_INFO_Referer_ByInterceptor, referer);
    return actionInvocation.invoke();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionContext(com.opensymphony.xwork2.ActionContext) ServletActionContext(org.apache.struts2.ServletActionContext)

Aggregations

Action (org.apache.struts2.convention.annotation.Action)6 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)2 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)2 File (java.io.File)2 org.apache.struts2.config (org.apache.struts2.config)2 EncodeHintType (com.google.zxing.EncodeHintType)1 BitMatrix (com.google.zxing.common.BitMatrix)1 QRCodeWriter (com.google.zxing.qrcode.QRCodeWriter)1 ChannelShell (com.jcraft.jsch.ChannelShell)1 SchSession (com.keybox.manage.model.SchSession)1 SortedSet (com.keybox.manage.model.SortedSet)1 User (com.keybox.manage.model.User)1 ActionContext (com.opensymphony.xwork2.ActionContext)1 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)1 BufferedImage (java.awt.image.BufferedImage)1 Annotation (java.lang.annotation.Annotation)1 Hashtable (java.util.Hashtable)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AgeFileFilter (org.apache.commons.io.filefilter.AgeFileFilter)1