📄 securityinterceptor.java
字号:
/*
* Copyright (C) 2003 Erik Swenson - eswenson@opensourcesoft.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package org.efs.openreports.interceptors;
import com.opensymphony.xwork.*;
import com.opensymphony.xwork.interceptor.Interceptor;
import com.opensymphony.xwork.interceptor.component.ComponentManager;
import org.efs.openreports.objects.ReportUser;
import org.efs.openreports.providers.SchedulerProvider;
import org.efs.openreports.providers.SchedulerProviderAware;
import org.efs.openreports.util.LocalStrings;
public class SecurityInterceptor implements Interceptor, SchedulerProviderAware
{
private boolean loggedIn;
private boolean adminUser;
private SchedulerProvider schedulerProvider;
public String intercept(ActionInvocation actionInvocation) throws Exception
{
ComponentManager container =
(ComponentManager) ActionContext.getContext().get(
"com.opensymphony.xwork.interceptor.component.ComponentManager");
if (container != null)
{
container.initializeObject(this);
}
if (!isAuthorized(actionInvocation))
{
return Action.LOGIN;
}
ActionContext.getContext().getValueStack().push(this);
return actionInvocation.invoke();
}
protected boolean isAuthorized(ActionInvocation actionInvocation)
{
ReportUser user =
(ReportUser) actionInvocation
.getInvocationContext()
.getSession()
.get(
"user");
if (user == null)
{
ActionSupport action = (ActionSupport) actionInvocation.getAction();
action.addActionError(LocalStrings.getString(LocalStrings.ERROR_NOTLOGGEDIN));
loggedIn = false;
return false;
}
loggedIn = true;
adminUser = user.isAdmin();
return true;
}
public void destroy()
{
}
public void init()
{
}
public boolean isAdminUser()
{
return adminUser;
}
public void setAdminUser(boolean adminUser)
{
this.adminUser = adminUser;
}
public boolean isLoggedIn()
{
return loggedIn;
}
public void setLoggedIn(boolean loggedIn)
{
this.loggedIn = loggedIn;
}
public boolean isSchedulerAvailable()
{
if (schedulerProvider != null)
return true;
return false;
}
public void setSchedulerProvider(SchedulerProvider schedulerProvider)
{
this.schedulerProvider = schedulerProvider;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -