001: package org.osbl.client;
002:
003: import org.osbl.client.action.*;
004: import org.osbl.client.wings.shell.Client;
005:
006: import org.osbl.authorization.Authorization;
007: import org.osbl.ServiceProvider;
008: import org.wings.session.SessionManager;
009:
010: import javax.swing.*;
011: import java.security.*;
012:
013: /**
014: * @author hengels
015: * @version $Revision$
016: */
017: class SessionActionProvider extends DelegatingActionProvider {
018: private final static String KEY_MICRO_HELP_POSTFIX = ".help";
019: private Authorization authorization;
020:
021: protected SessionActionProvider(ActionProvider parent) {
022: super (parent);
023: }
024:
025: public Action configure(Action action) {
026: String command = (String) action
027: .getValue(Action.ACTION_COMMAND_KEY);
028: if (command == null) {
029: if (action.getValue(Action.NAME) == null)
030: action.putValue(Action.NAME, "no command");
031: return action;
032: }
033:
034: if (action.isEnabled()) {
035: // Disable only enabled buttons. Already disabled buttons shouldn't be enabled
036: String userid = SessionManager.getSession()
037: .getServletRequest().getUserPrincipal().getName();
038: String key = (String) action
039: .getValue(AuthorizedAction.PERMISSION_KEY);
040: String actions;
041:
042: if (key != null) {
043: int pos = key.lastIndexOf('[');
044: actions = key.substring(pos + 1, key.length() - 1);
045: key = key.substring(0, pos);
046: } else {
047: key = command;
048: actions = "x";
049: }
050:
051: action.setEnabled(getAuthorization().checkPermission(
052: userid, key, actions));
053: }
054:
055: if (action.getValue(Action.NAME) == null)
056: action.putValue(Action.NAME, Client.getInstance()
057: .getResourceProvider().getMessage(command));
058:
059: String help = Client
060: .getInstance()
061: .getResourceProvider()
062: .getMessage(
063: command
064: + SessionActionProvider.KEY_MICRO_HELP_POSTFIX);
065: if (!help.endsWith(".help"))
066: action.putValue(Action.SHORT_DESCRIPTION, help);
067:
068: return action;
069: }
070:
071: protected org.osbl.authorization.Authorization getAuthorization() {
072: if (authorization == null) {
073: try {
074: authorization = (org.osbl.authorization.Authorization) ServiceProvider
075: .getInstance().getService(
076: "AuthorizationService");
077: } catch (Exception e) {
078: authorization = new Authorization() {
079: public boolean checkPermission(String userid,
080: String permission, String action) {
081: return true;
082: }
083:
084: public PermissionCollection getPermissions(
085: String userid) {
086: return null;
087: }
088:
089: public Permission getPermission(String userid,
090: String permission) {
091: return null;
092: }
093:
094: public void clearCache(String userid) {
095: }
096: };
097: }
098: }
099: return authorization;
100: }
101: }
|