1 19 20 package com.sslexplorer.applications; 21 22 import javax.servlet.http.HttpServletRequest ; 23 24 import com.sslexplorer.core.CoreEvent; 25 import com.sslexplorer.core.CoreServlet; 26 import com.sslexplorer.extensions.ExtensionDescriptor; 27 import com.sslexplorer.extensions.store.ExtensionStore; 28 import com.sslexplorer.navigation.FavoriteResourceType; 29 import com.sslexplorer.navigation.WrappedFavoriteItem; 30 import com.sslexplorer.policyframework.DefaultResourceType; 31 import com.sslexplorer.policyframework.PolicyConstants; 32 import com.sslexplorer.policyframework.PolicyDatabaseFactory; 33 import com.sslexplorer.policyframework.Resource; 34 import com.sslexplorer.security.LogonControllerFactory; 35 import com.sslexplorer.security.SessionInfo; 36 37 43 public class ApplicationShortcutResourceType extends DefaultResourceType implements FavoriteResourceType { 44 45 48 public ApplicationShortcutResourceType() { 49 super(ApplicationsPlugin.APPLICATION_SHORTCUT_RESOURCE_TYPE_ID, "policyframework", PolicyConstants.DELEGATION_CLASS); 50 } 51 52 public WrappedFavoriteItem createWrappedFavoriteItem(int resourceId, HttpServletRequest request, String type) throws Exception { 53 SessionInfo sessionInfo = LogonControllerFactory.getInstance().getSessionInfo(request); 54 ApplicationShortcut as = ApplicationShortcutDatabaseFactory.getInstance().getShortcut(resourceId); 55 if (as == null) { 56 return null; 57 } 58 ExtensionDescriptor des = ExtensionStore.getInstance().getExtensionDescriptor(as.getApplication()); 59 if (des == null) { 60 throw new Exception ("No application extension with ID of " + as.getApplication() + ", skipping favorite."); 61 } else { 62 SessionInfo inf = LogonControllerFactory.getInstance().getSessionInfo(request); 63 ApplicationShortcutItem it = new ApplicationShortcutItem(des, as, PolicyDatabaseFactory.getInstance() 64 .getPoliciesAttachedToResource(as, sessionInfo.getUser().getRealm()), inf.getNavigationContext(), as 65 .sessionPasswordRequired(inf)); 66 if (as.getApplication() != null) { 67 return new WrappedFavoriteItem(it, type); 68 } else { 69 throw new Exception ("No application."); 70 } 71 } 72 } 73 74 79 public Resource getResourceById(int resourceId) throws Exception { 80 return ApplicationShortcutDatabaseFactory.getInstance().getShortcut(resourceId); 81 } 82 83 89 public Resource getResourceByName(String resourceName, SessionInfo session) throws Exception { 90 return ApplicationShortcutDatabaseFactory.getInstance().getShortcut(resourceName, session.getUser().getRealm().getRealmID()); 91 } 92 93 99 public Resource removeResource(int resourceId, SessionInfo session) throws Exception { 100 try { 101 ApplicationShortcut resource = ApplicationShortcutDatabaseFactory.getInstance().deleteShortcut(resourceId); 102 CoreServlet.getServlet().fireCoreEvent( 103 new ApplicationShortcutDeleteEvent(this, ApplicationShortcutEventConstants.REMOVE_APPLICATION_SHORTCUT, resource, 104 session, CoreEvent.STATE_SUCCESSFUL)); 105 return resource; 106 } catch (Exception e) { 107 CoreServlet.getServlet().fireCoreEvent( 108 new ApplicationShortcutDeleteEvent(this, ApplicationShortcutEventConstants.REMOVE_APPLICATION_SHORTCUT, session, e)); 109 throw e; 110 } 111 } 112 113 119 public void updateResource(Resource resource, SessionInfo session) throws Exception { 120 try { 121 ApplicationShortcutDatabaseFactory.getInstance().updateApplicationShortcut(resource.getResourceId(), 122 resource.getResourceName(), resource.getResourceDescription(), 123 ((ApplicationShortcut) resource).getParameters()); 124 CoreServlet.getServlet().fireCoreEvent( 125 new ApplicationShortcutChangeEvent(this, ApplicationShortcutEventConstants.UPDATE_APPLICATION_SHORTCUT, 126 (ApplicationShortcut) resource, session, CoreEvent.STATE_SUCCESSFUL)); 127 } catch (Exception e) { 128 CoreServlet.getServlet().fireCoreEvent( 129 new ApplicationShortcutChangeEvent(this, ApplicationShortcutEventConstants.UPDATE_APPLICATION_SHORTCUT, session, e)); 130 throw e; 131 } 132 } 133 134 } 135 | Popular Tags |