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;
}
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;
}
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);
}
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();
}
Aggregations