diff --git a/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/FileManager.java b/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/NwsRoleDataManager.java similarity index 69% rename from cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/FileManager.java rename to cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/NwsRoleDataManager.java index 7934ecd493..764a66cc5d 100644 --- a/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/FileManager.java +++ b/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/NwsRoleDataManager.java @@ -19,33 +19,24 @@ **/ package com.raytheon.uf.viz.plugin.nwsauth; -import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - +import com.raytheon.uf.common.auth.resp.SuccessfulExecution; import com.raytheon.uf.common.auth.user.IPermission; import com.raytheon.uf.common.auth.user.IRole; -import com.raytheon.uf.common.localization.IPathManager; -import com.raytheon.uf.common.localization.LocalizationContext; -import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; -import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; -import com.raytheon.uf.common.localization.LocalizationFile; -import com.raytheon.uf.common.localization.PathManagerFactory; -import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; import com.raytheon.uf.common.plugin.nwsauth.NwsPermission; import com.raytheon.uf.common.plugin.nwsauth.NwsRole; +import com.raytheon.uf.common.plugin.nwsauth.NwsRoleDataRequest; +import com.raytheon.uf.common.plugin.nwsauth.NwsRoleDataRequest.NwsRoleDataRequestType; import com.raytheon.uf.common.plugin.nwsauth.xml.NwsRoleData; import com.raytheon.uf.common.plugin.nwsauth.xml.PermissionXML; import com.raytheon.uf.common.plugin.nwsauth.xml.RoleXML; import com.raytheon.uf.common.plugin.nwsauth.xml.UserXML; +import com.raytheon.uf.common.serialization.comm.RequestRouter; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -61,6 +52,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * ------------ ---------- ----------- -------------------------- * May 30, 2012 mpduff Initial creation * Nov 06, 2012 1302 djohnson Move to nwsauth plugin. + * Jan 09, 2013 1412 djohnson Move localization file writing to the server. * * * @@ -68,34 +60,17 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * @version 1.0 */ -public class FileManager { +public class NwsRoleDataManager { /** Status handler */ private static final IUFStatusHandler statusHandler = UFStatus - .getHandler(FileManager.class); + .getHandler(NwsRoleDataManager.class); - private static final FileManager instance = new FileManager(); + private static final NwsRoleDataManager instance = new NwsRoleDataManager(); - private final String ROLE_DIR = "roles"; + private Map roleDataMap = new HashMap(); - /** JAXB context */ - private JAXBContext jax; - - /** Marshaller object */ - private Marshaller marshaller; - - /** Unmarshaller object */ - private Unmarshaller unmarshaller; - - private final Map roleDataMap = new HashMap(); - - /** - * Application name -> LocalizationFile map. - */ - private final Map roleFileMap = new HashMap(); - - private FileManager() { - createContext(); - readXML(); + private NwsRoleDataManager() { + retrieveRoleDataFromServer(); } /** @@ -103,28 +78,10 @@ public class FileManager { * * @return an instance */ - public static FileManager getInstance() { + public static NwsRoleDataManager getInstance() { return instance; } - private void createContext() { - @SuppressWarnings("rawtypes") - Class[] classes = new Class[] { NwsRoleData.class, PermissionXML.class, - RoleXML.class, UserXML.class }; - - try { - jax = JAXBContext.newInstance(classes); - this.unmarshaller = jax.createUnmarshaller(); - this.marshaller = jax.createMarshaller(); - - // format the output xml file - this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - - } catch (JAXBException e) { - e.printStackTrace(); - } - } - /** * Get the NwsRoleData object. * @@ -318,65 +275,54 @@ public class FileManager { } /** - * Save the NwsRoleData object. - * - * @param application + * {@inheritDoc} */ public void save(String application) { - NwsRoleData roleData = roleDataMap.get(application); - LocalizationFile lf = roleFileMap.get(application); - - IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationContext context = pm.getContext( - LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); - LocalizationFile locFile = pm - .getLocalizationFile(context, lf.getName()); - ; - - try { - marshaller.marshal(roleData, locFile.getFile()); - locFile.save(); - } catch (JAXBException e) { - statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); - } catch (LocalizationOpFailedException e) { - statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); - } - + updateRoleDataOnTheServer(application); } - private void readXML() { - try { - IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationContext[] contexts = new LocalizationContext[2]; - contexts[0] = pm.getContext(LocalizationType.COMMON_STATIC, - LocalizationLevel.BASE); - contexts[1] = pm.getContext(LocalizationType.COMMON_STATIC, - LocalizationLevel.SITE); - LocalizationFile[] roleFiles = pm.listFiles(contexts, ROLE_DIR, - null, false, true); + /** + * Updates the role data on the server. + * + * @param application + * the application to send updated role data for + */ + private void updateRoleDataOnTheServer(String application) { + Map roleDataMapUpdates = new HashMap(); + roleDataMapUpdates.put(application, roleDataMap.get(application)); - for (LocalizationFile lf : roleFiles) { - File f = lf.getFile(true); - if (f != null && f.exists()) { - System.out.println(f.getAbsolutePath()); - NwsRoleData roleData = (NwsRoleData) unmarshaller - .unmarshal(f); - this.roleDataMap.put(roleData.getApplication(), roleData); - this.roleFileMap.put(roleData.getApplication(), lf); - } - } - } catch (JAXBException e1) { + NwsRoleDataRequest request = new NwsRoleDataRequest(); + request.setRoleDataMap(roleDataMapUpdates); + request.setType(NwsRoleDataRequestType.SUBMIT); + try { + RequestRouter.route(request); + } catch (Exception e) { statusHandler - .handle(Priority.PROBLEM, e1.getLocalizedMessage(), e1); + .handle(Priority.PROBLEM, + "Unable to send updated role data to the server.", + e); + } + } + + private void retrieveRoleDataFromServer() { + try { + NwsRoleDataRequest request = new NwsRoleDataRequest(); + request.setType(NwsRoleDataRequestType.REQUEST); + + NwsRoleDataRequest response = (NwsRoleDataRequest) ((SuccessfulExecution) RequestRouter + .route(request)).getResponse(); + + this.roleDataMap = response.getRoleDataMap(); } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } } + /** * Reload theXML files from disk. */ - public void reloadXML() { - readXML(); + public void reloadRoleData() { + retrieveRoleDataFromServer(); } } diff --git a/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/NwsUserManager.java b/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/NwsUserManager.java index b3d527f677..d68f4fb81f 100644 --- a/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/NwsUserManager.java +++ b/cave/com.raytheon.uf.viz.plugin.nwsauth/src/com/raytheon/uf/viz/plugin/nwsauth/NwsUserManager.java @@ -88,7 +88,7 @@ public class NwsUserManager implements IUserManager { @Override public List getPermissions(String application) { // TODO: Should this pass through to EDEX to get this stuff? - return FileManager.getInstance().getPermissions(application); + return NwsRoleDataManager.getInstance().getPermissions(application); } /** @@ -97,6 +97,6 @@ public class NwsUserManager implements IUserManager { @Override public List getRoles(String application) { // TODO: Should this pass through to EDEX to get this stuff? - return FileManager.getInstance().getRoles(application); + return NwsRoleDataManager.getInstance().getRoles(application); } } diff --git a/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/ManageUserDlg.java b/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/ManageUserDlg.java index 1b896c4b5a..f0a44cbd90 100644 --- a/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/ManageUserDlg.java +++ b/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/ManageUserDlg.java @@ -36,7 +36,7 @@ import org.eclipse.swt.widgets.Shell; import com.raytheon.uf.common.plugin.nwsauth.xml.NwsRoleData; import com.raytheon.uf.common.plugin.nwsauth.xml.RoleXML; import com.raytheon.uf.common.plugin.nwsauth.xml.UserXML; -import com.raytheon.uf.viz.plugin.nwsauth.FileManager; +import com.raytheon.uf.viz.plugin.nwsauth.NwsRoleDataManager; import com.raytheon.viz.ui.dialogs.CaveSWTDialog; import com.raytheon.viz.ui.widgets.duallist.DualList; import com.raytheon.viz.ui.widgets.duallist.DualListConfig; @@ -66,10 +66,10 @@ public class ManageUserDlg extends CaveSWTDialog implements IUpdate { private final StackLayout stackLayout = new StackLayout(); /** Type of permissions */ - private String type; + private final String type; /** Selection */ - private String selection; + private final String selection; /** Edit combo box */ private Combo editCbo; @@ -87,7 +87,7 @@ public class ManageUserDlg extends CaveSWTDialog implements IUpdate { private Composite stackComp; /** The application currently selected.*/ - private String application; + private final String application; /** * Constructor. @@ -165,7 +165,7 @@ public class ManageUserDlg extends CaveSWTDialog implements IUpdate { stackComp = new Composite(shell, SWT.NONE); stackComp.setLayout(stackLayout); - FileManager manager = FileManager.getInstance(); + NwsRoleDataManager manager = NwsRoleDataManager.getInstance(); ArrayList selectedList = new ArrayList(); ArrayList fullList = new ArrayList(); String availableLabel = "Available Roles:"; @@ -291,7 +291,7 @@ public class ManageUserDlg extends CaveSWTDialog implements IUpdate { String[] permissions = permDualList.getSelectedListItems(); String[] roles = roleDualList.getSelectedListItems(); - FileManager man = FileManager.getInstance(); + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); NwsRoleData roleData = man.getRoleData(application); if (type.equalsIgnoreCase("User")) { diff --git a/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/NewDlg.java b/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/NewDlg.java index a6ac01f725..91b130a0ce 100644 --- a/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/NewDlg.java +++ b/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/NewDlg.java @@ -31,7 +31,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import com.raytheon.uf.common.plugin.nwsauth.xml.NwsRoleData; -import com.raytheon.uf.viz.plugin.nwsauth.FileManager; +import com.raytheon.uf.viz.plugin.nwsauth.NwsRoleDataManager; import com.raytheon.viz.ui.dialogs.CaveSWTDialog; /** @@ -52,13 +52,13 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog; */ public class NewDlg extends CaveSWTDialog { - private String type; + private final String type; private Text newTextField; private Text description; - private String application; + private final String application; /** * Constructor. @@ -154,7 +154,7 @@ public class NewDlg extends CaveSWTDialog { private void handleOK() { if (newTextField.getText() != null && newTextField.getText().length() > 0) { - FileManager manager = FileManager.getInstance(); + NwsRoleDataManager manager = NwsRoleDataManager.getInstance(); NwsRoleData roleData = manager.getRoleData(application); if (type.equalsIgnoreCase("User")) { roleData.addUser(newTextField.getText().trim()); diff --git a/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/UserAdminSelectDlg.java b/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/UserAdminSelectDlg.java index ed25bd801f..215c9c43ee 100644 --- a/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/UserAdminSelectDlg.java +++ b/cave/com.raytheon.uf.viz.useradmin/src/com/raytheon/uf/viz/useradmin/ui/UserAdminSelectDlg.java @@ -22,6 +22,8 @@ package com.raytheon.uf.viz.useradmin.ui; import java.util.ArrayList; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; @@ -43,28 +45,35 @@ import org.eclipse.swt.widgets.TabItem; import com.raytheon.uf.common.plugin.nwsauth.xml.PermissionXML; import com.raytheon.uf.common.plugin.nwsauth.xml.RoleXML; -import com.raytheon.uf.viz.plugin.nwsauth.FileManager; +import com.raytheon.uf.common.useradmin.request.UserAdminConstants; +import com.raytheon.uf.viz.core.VizApp; +import com.raytheon.uf.viz.core.notification.INotificationObserver; +import com.raytheon.uf.viz.core.notification.NotificationMessage; +import com.raytheon.uf.viz.core.notification.jobs.NotificationManagerJob; +import com.raytheon.uf.viz.plugin.nwsauth.NwsRoleDataManager; import com.raytheon.viz.ui.dialogs.CaveSWTDialog; /** * Main User Administration Dialog. - * + * *
- *
+ * 
  * SOFTWARE HISTORY
- *
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * May 23, 2012            mpduff     Initial creation.
  * Nov 26, 2012   1347     mpduff     Make resizable.
- *
+ * Jan 09, 2013 1412        djohnson    Listen for user authentication data changes.
+ * 
  * 
- * + * * @author mpduff * @version 1.0 */ -public class UserAdminSelectDlg extends CaveSWTDialog { +public class UserAdminSelectDlg extends CaveSWTDialog implements + INotificationObserver { private Combo appCombo; private TabFolder tabFolder; @@ -95,18 +104,19 @@ public class UserAdminSelectDlg extends CaveSWTDialog { /** * Constructor. - * + * * @param parent * The parent shell */ public UserAdminSelectDlg(Shell parent) { - super(parent, SWT.DIALOG_TRIM | SWT.RESIZE, CAVE.PERSPECTIVE_INDEPENDENT); + super(parent, SWT.DIALOG_TRIM | SWT.RESIZE, + CAVE.PERSPECTIVE_INDEPENDENT); setText("User Admin"); } @Override protected void initializeComponents(Shell shell) { - FileManager man = FileManager.getInstance(); + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); GridData gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false); GridLayout gl = new GridLayout(1, false); shell.setLayout(gl); @@ -130,7 +140,8 @@ public class UserAdminSelectDlg extends CaveSWTDialog { appCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - selectedApplication = appCombo.getItem(appCombo.getSelectionIndex()); + selectedApplication = appCombo.getItem(appCombo + .getSelectionIndex()); populateLists(); } }); @@ -181,13 +192,14 @@ public class UserAdminSelectDlg extends CaveSWTDialog { @Override public void widgetSelected(SelectionEvent e) { if (dirty) { - MessageBox messageDialog = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.YES | SWT.NO); + MessageBox messageDialog = new MessageBox(getShell(), + SWT.ICON_WARNING | SWT.YES | SWT.NO); messageDialog.setText("Unsaved Changes"); - messageDialog.setMessage("Unsaved changes are present.\n" + - "Are you sure you want to close without saving?"); + messageDialog.setMessage("Unsaved changes are present.\n" + + "Are you sure you want to close without saving?"); int answer = messageDialog.open(); if (answer == SWT.YES) { - FileManager.getInstance().reloadXML(); + NwsRoleDataManager.getInstance().reloadRoleData(); close(); return; } @@ -198,10 +210,24 @@ public class UserAdminSelectDlg extends CaveSWTDialog { } }); + NotificationManagerJob.addObserver( + UserAdminConstants.USER_AUTHENTICATION_CHANGED_TOPIC, this); + + getShell().addDisposeListener(new DisposeListener() { + @Override + public void widgetDisposed(DisposeEvent e) { + NotificationManagerJob.removeObserver( + UserAdminConstants.USER_AUTHENTICATION_CHANGED_TOPIC, + UserAdminSelectDlg.this); + } + }); + populateLists(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see com.raytheon.viz.ui.dialogs.CaveSWTDialog#preOpened() */ @Override @@ -238,7 +264,8 @@ public class UserAdminSelectDlg extends CaveSWTDialog { GridData listData = new GridData(SWT.FILL, SWT.FILL, true, true); listData.widthHint = 150; listData.heightHint = 175; - userList = new List(listComp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); + userList = new List(listComp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL + | SWT.H_SCROLL); userList.setLayoutData(listData); userList.addSelectionListener(new SelectionAdapter() { @Override @@ -310,7 +337,8 @@ public class UserAdminSelectDlg extends CaveSWTDialog { Label l = new Label(userRoleComp, SWT.NONE); l.setText("Defined Roles/Permissions:"); - userPermList = new List(userRoleComp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); + userPermList = new List(userRoleComp, SWT.BORDER | SWT.MULTI + | SWT.V_SCROLL | SWT.H_SCROLL); userPermList.setLayoutData(listData); userPermList.addMouseListener(new MouseAdapter() { @Override @@ -322,17 +350,21 @@ public class UserAdminSelectDlg extends CaveSWTDialog { item1.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { - String selection = userPermList.getItem(userPermList.getSelectionIndex()); + String selection = userPermList + .getItem(userPermList.getSelectionIndex()); StringBuilder messageText = new StringBuilder(); boolean roleFlag = false; - FileManager man = FileManager.getInstance(); - for (RoleXML role : man.getRoleData(selectedApplication).getRoleList()) { + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); + for (RoleXML role : man.getRoleData( + selectedApplication).getRoleList()) { if (selection.equals(role.getRoleId())) { messageText.append("Role: " + selection); - messageText.append("\n\nDescription: " + role.getRoleDescription().trim()); + messageText.append("\n\nDescription: " + + role.getRoleDescription().trim()); if (role.getPermissionList().size() > 0) { messageText.append("\n\nPermissions: "); - for (String perm : role.getPermissionList()) { + for (String perm : role + .getPermissionList()) { messageText.append("\n " + perm); } } @@ -342,10 +374,14 @@ public class UserAdminSelectDlg extends CaveSWTDialog { } if (roleFlag == false) { - for (PermissionXML perm : man.getRoleData(selectedApplication).getPermissionList()) { + for (PermissionXML perm : man.getRoleData( + selectedApplication) + .getPermissionList()) { if (perm.getId().equals(selection)) { - messageText.append("Permission: " + selection); - messageText.append("\nDescription: " + perm.getDescription()); + messageText.append("Permission: " + + selection); + messageText.append("\nDescription: " + + perm.getDescription()); break; } } @@ -353,7 +389,8 @@ public class UserAdminSelectDlg extends CaveSWTDialog { if (messageText.length() == 0) { messageText.append("No Description"); } - MessageBox messageDialog = new MessageBox(shell, SWT.ICON_INFORMATION); + MessageBox messageDialog = new MessageBox(shell, + SWT.ICON_INFORMATION); if (roleFlag) { messageDialog.setText("Role Description"); } else { @@ -412,7 +449,8 @@ public class UserAdminSelectDlg extends CaveSWTDialog { listData = new GridData(SWT.FILL, SWT.DEFAULT, true, false); listData.widthHint = 150; listData.heightHint = 175; - roleList = new List(listComp2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); + roleList = new List(listComp2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL + | SWT.H_SCROLL); roleList.setLayoutData(listData); roleList.addSelectionListener(new SelectionAdapter() { @Override @@ -444,17 +482,21 @@ public class UserAdminSelectDlg extends CaveSWTDialog { item1.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { - String selection = roleList.getItem(roleList.getSelectionIndex()); + String selection = roleList.getItem(roleList + .getSelectionIndex()); String messageText = null; - FileManager man = FileManager.getInstance(); - String app = appCombo.getItem(appCombo.getSelectionIndex()); - for (RoleXML role : man.getRoleData(app).getRoleList()) { + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); + String app = appCombo.getItem(appCombo + .getSelectionIndex()); + for (RoleXML role : man.getRoleData(app) + .getRoleList()) { if (selection.equals(role.getRoleId())) { messageText = role.getRoleDescription(); break; } } - MessageBox messageDialog = new MessageBox(shell, SWT.ICON_INFORMATION); + MessageBox messageDialog = new MessageBox(shell, + SWT.ICON_INFORMATION); messageDialog.setText("Role Description"); messageDialog.setMessage(messageText.toString()); messageDialog.open(); @@ -527,12 +569,13 @@ public class UserAdminSelectDlg extends CaveSWTDialog { Label l2 = new Label(permComp, SWT.NONE); l2.setText("Roles/Permissions:"); - rolePermList = new List(permComp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); + rolePermList = new List(permComp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL + | SWT.H_SCROLL); rolePermList.setLayoutData(listData); } private void populateLists() { - FileManager man = FileManager.getInstance(); + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); String app = appCombo.getItem(appCombo.getSelectionIndex()); userTab.setText(app + " Users"); @@ -563,7 +606,7 @@ public class UserAdminSelectDlg extends CaveSWTDialog { } private void populateUserRoleList() { - FileManager man = FileManager.getInstance(); + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); String app = appCombo.getItem(appCombo.getSelectionIndex()); if (userList.getSelectionIndex() != -1) { @@ -585,7 +628,7 @@ public class UserAdminSelectDlg extends CaveSWTDialog { } private void populatePermissionList() { - FileManager man = FileManager.getInstance(); + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); rolePermList.removeAll(); String app = appCombo.getItem(appCombo.getSelectionIndex()); if (roleList.getSelectionIndex() != -1) { @@ -608,11 +651,12 @@ public class UserAdminSelectDlg extends CaveSWTDialog { MessageBox messageDialog = new MessageBox(this.shell, SWT.YES | SWT.NO); messageDialog.setText("Title"); - messageDialog.setMessage("Are you sure you wish to delete user " + user); + messageDialog + .setMessage("Are you sure you wish to delete user " + user); int response = messageDialog.open(); if (response == SWT.YES) { - FileManager man = FileManager.getInstance(); + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); String app = appCombo.getItem(appCombo.getSelectionIndex()); man.deleteUser(user, app); dirty = true; @@ -623,7 +667,8 @@ public class UserAdminSelectDlg extends CaveSWTDialog { private void handleEditRole() { String role = roleList.getItem(roleList.getSelectionIndex()); - ManageUserDlg mud = new ManageUserDlg(this.shell, "Role", role, selectedApplication); + ManageUserDlg mud = new ManageUserDlg(this.shell, "Role", role, + selectedApplication); boolean changes = (Boolean) mud.open(); if (changes) { dirty = true; @@ -635,11 +680,12 @@ public class UserAdminSelectDlg extends CaveSWTDialog { MessageBox messageDialog = new MessageBox(this.shell, SWT.YES | SWT.NO); messageDialog.setText("Title"); - messageDialog.setMessage("Are you sure you wish to delete role " + role); + messageDialog + .setMessage("Are you sure you wish to delete role " + role); int response = messageDialog.open(); if (response == SWT.YES) { - FileManager man = FileManager.getInstance(); + NwsRoleDataManager man = NwsRoleDataManager.getInstance(); String app = appCombo.getItem(appCombo.getSelectionIndex()); man.deleteRole(role, app); dirty = true; @@ -663,7 +709,8 @@ public class UserAdminSelectDlg extends CaveSWTDialog { private void handleEditUser() { String user = userList.getItem(userList.getSelectionIndex()); - ManageUserDlg mud = new ManageUserDlg(this.shell, "User", user, selectedApplication); + ManageUserDlg mud = new ManageUserDlg(this.shell, "User", user, + selectedApplication); boolean changes = (Boolean) mud.open(); if (changes) { dirty = true; @@ -671,8 +718,25 @@ public class UserAdminSelectDlg extends CaveSWTDialog { } private void handleOK() { - FileManager manager = FileManager.getInstance(); + NwsRoleDataManager manager = NwsRoleDataManager.getInstance(); manager.save(selectedApplication); dirty = false; } + + /** + * {@inheritDoc} + */ + @Override + public void notificationArrived(NotificationMessage[] messages) { + VizApp.runAsync(new Runnable() { + @Override + public void run() { + NwsRoleDataManager.getInstance().reloadRoleData(); + + if (!UserAdminSelectDlg.this.isDisposed()) { + populateLists(); + } + } + }); + } } diff --git a/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/META-INF/MANIFEST.MF index 32501c5d08..76e9413bb9 100644 --- a/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/META-INF/MANIFEST.MF @@ -9,7 +9,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Require-Bundle: com.raytheon.uf.common.serialization;bundle-version="1.12.2", com.raytheon.uf.common.auth;bundle-version="1.12.1174", com.raytheon.uf.common.status;bundle-version="1.12.1174", - com.raytheon.uf.common.localization;bundle-version="1.12.1174" + com.raytheon.uf.common.localization;bundle-version="1.12.1174", + com.raytheon.uf.common.serialization.comm;bundle-version="1.12.1174" Export-Package: com.raytheon.uf.common.plugin.nwsauth, com.raytheon.uf.common.plugin.nwsauth.exception, com.raytheon.uf.common.plugin.nwsauth.user, diff --git a/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/src/com/raytheon/uf/common/plugin/nwsauth/NwsRoleDataRequest.java b/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/src/com/raytheon/uf/common/plugin/nwsauth/NwsRoleDataRequest.java new file mode 100644 index 0000000000..6198ebec5e --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/src/com/raytheon/uf/common/plugin/nwsauth/NwsRoleDataRequest.java @@ -0,0 +1,87 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.plugin.nwsauth; + +import java.util.Map; + +import com.raytheon.uf.common.auth.req.AbstractPrivilegedRequest; +import com.raytheon.uf.common.plugin.nwsauth.xml.NwsRoleData; +import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; +import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; + +/** + * A request to retrieve, or submit, the NWS role date. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 09, 2013 1412       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +@DynamicSerialize +public class NwsRoleDataRequest extends AbstractPrivilegedRequest { + // Ticket #1315 should use this class to actually retrieve/submit role data + // changes + + public static enum NwsRoleDataRequestType { + REQUEST, SUBMIT; + } + + @DynamicSerializeElement + private NwsRoleDataRequestType type; + + @DynamicSerializeElement + private Map roleDataMap; + + /** + * @return the type + */ + public NwsRoleDataRequestType getType() { + return type; + } + + /** + * @param request + */ + public void setType(NwsRoleDataRequestType type) { + this.type = type; + } + + /** + * @return + */ + public Map getRoleDataMap() { + return roleDataMap; + } + + /** + * @param roleDataMap2 + */ + public void setRoleDataMap(Map roleDataMap2) { + this.roleDataMap = roleDataMap2; + } +} diff --git a/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/src/com/raytheon/uf/common/plugin/nwsauth/xml/RoleXML.java b/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/src/com/raytheon/uf/common/plugin/nwsauth/xml/RoleXML.java index e7837915a3..d17db43ea3 100644 --- a/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/src/com/raytheon/uf/common/plugin/nwsauth/xml/RoleXML.java +++ b/edexOsgi/com.raytheon.uf.common.plugin.nwsauth/src/com/raytheon/uf/common/plugin/nwsauth/xml/RoleXML.java @@ -82,7 +82,7 @@ public class RoleXML implements ISerializableObject { * @return the description */ public String getRoleDescription() { - return roleDescription.trim(); + return roleDescription == null ? null : roleDescription.trim(); } /** diff --git a/edexOsgi/com.raytheon.uf.common.useradmin/build.properties b/edexOsgi/com.raytheon.uf.common.useradmin/build.properties index 34d2e4d2da..5791d48d5f 100644 --- a/edexOsgi/com.raytheon.uf.common.useradmin/build.properties +++ b/edexOsgi/com.raytheon.uf.common.useradmin/build.properties @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + res/ diff --git a/edexOsgi/com.raytheon.uf.common.useradmin/res/spring/useradmin-common.xml b/edexOsgi/com.raytheon.uf.common.useradmin/res/spring/useradmin-common.xml new file mode 100644 index 0000000000..74a107766a --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.useradmin/res/spring/useradmin-common.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.useradmin/src/com/raytheon/uf/common/useradmin/request/UserAdminConstants.java b/edexOsgi/com.raytheon.uf.common.useradmin/src/com/raytheon/uf/common/useradmin/request/UserAdminConstants.java new file mode 100644 index 0000000000..0f109997fd --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.useradmin/src/com/raytheon/uf/common/useradmin/request/UserAdminConstants.java @@ -0,0 +1,48 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.useradmin.request; + +/** + * Constants for working with user administration. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 09, 2013 1412       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +public final class UserAdminConstants { + + /** + * The topic uri on which user authentication data changes are sent. + */ + public static final String USER_AUTHENTICATION_CHANGED_TOPIC = "user.authentication.changed"; + + private UserAdminConstants() { + + } +} diff --git a/edexOsgi/com.raytheon.uf.common.useradmin/src/com/raytheon/uf/common/useradmin/request/UserAuthenticationDataChanged.java b/edexOsgi/com.raytheon.uf.common.useradmin/src/com/raytheon/uf/common/useradmin/request/UserAuthenticationDataChanged.java new file mode 100644 index 0000000000..ff028fe2b0 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.useradmin/src/com/raytheon/uf/common/useradmin/request/UserAuthenticationDataChanged.java @@ -0,0 +1,45 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.useradmin.request; + +import com.raytheon.uf.common.auth.req.AbstractPrivilegedRequest; +import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; + +/** + * A marker object that informs observers in the system that user authentication + * data has changed. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 09, 2013 1412       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +@DynamicSerialize +public class UserAuthenticationDataChanged extends AbstractPrivilegedRequest { + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/res/spring/datadelivery-request.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/res/spring/datadelivery-request.xml index c4412fe6d8..c9532a124d 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.service/res/spring/datadelivery-request.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.service/res/spring/datadelivery-request.xml @@ -1,48 +1,24 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util-2.5.xsd"> - - - - - + + + + + - - - - - - - - - - - - - - - - + - - + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/META-INF/MANIFEST.MF index db55acc1af..32525a99e7 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/META-INF/MANIFEST.MF @@ -9,7 +9,9 @@ Require-Bundle: com.raytheon.uf.edex.auth;bundle-version="1.12.2", com.raytheon.uf.common.auth;bundle-version="1.12.2", com.raytheon.uf.common.plugin.nwsauth;bundle-version="1.0.0", com.raytheon.uf.common.status;bundle-version="1.12.1174", - com.raytheon.uf.common.localization + com.raytheon.uf.common.localization, + com.raytheon.uf.common.serialization.comm;bundle-version="1.12.1174", + com.raytheon.uf.common.useradmin;bundle-version="1.0.0" Import-Package: com.raytheon.uf.common.localization, com.raytheon.uf.common.serialization, com.raytheon.uf.common.status, diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/res/spring/nwsauth-request.xml b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/res/spring/nwsauth-request.xml index 8157f3b3f6..d467715147 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/res/spring/nwsauth-request.xml +++ b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/res/spring/nwsauth-request.xml @@ -1,21 +1,34 @@ - - - - - - - - - - - - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util-2.5.xsd"> + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/src/com/raytheon/uf/edex/plugin/nwsauth/EdexNwsRoleManager.java b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/src/com/raytheon/uf/edex/plugin/nwsauth/EdexNwsRoleManager.java new file mode 100644 index 0000000000..c998c750f6 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/src/com/raytheon/uf/edex/plugin/nwsauth/EdexNwsRoleManager.java @@ -0,0 +1,85 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.edex.plugin.nwsauth; + +import java.util.Map; + +import com.raytheon.uf.common.auth.exception.AuthorizationException; +import com.raytheon.uf.common.auth.user.IUser; +import com.raytheon.uf.common.plugin.nwsauth.NwsRoleDataRequest; +import com.raytheon.uf.common.plugin.nwsauth.NwsRoleDataRequest.NwsRoleDataRequestType; +import com.raytheon.uf.common.plugin.nwsauth.xml.NwsRoleData; +import com.raytheon.uf.common.serialization.comm.RequestRouter; +import com.raytheon.uf.common.useradmin.request.UserAuthenticationDataChanged; +import com.raytheon.uf.edex.auth.req.AbstractPrivilegedRequestHandler; +import com.raytheon.uf.edex.auth.resp.AuthorizationResponse; + +/** + * Receives requests to retrieve or submit NWS role data. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 09, 2013 1412       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ + +public class EdexNwsRoleManager extends + AbstractPrivilegedRequestHandler { + + /** + * {@inheritDoc} + */ + @Override + public Object handleRequest(NwsRoleDataRequest request) throws Exception { + final FileManager fileManager = FileManager.getInstance(); + final NwsRoleDataRequestType type = request.getType(); + switch (type) { + case REQUEST: + request.setRoleDataMap(fileManager.getRoleDataMap()); + break; + case SUBMIT: + final Map roleDataMap = request + .getRoleDataMap(); + fileManager.writeApplicationRoleData(roleDataMap); + + RequestRouter.route(new UserAuthenticationDataChanged()); + break; + } + + return request; + } + + /** + * {@inheritDoc} + */ + @Override + public AuthorizationResponse authorized(IUser user, + NwsRoleDataRequest request) throws AuthorizationException { + return new AuthorizationResponse(true); + } +} diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/src/com/raytheon/uf/edex/plugin/nwsauth/FileManager.java b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/src/com/raytheon/uf/edex/plugin/nwsauth/FileManager.java new file mode 100644 index 0000000000..c308db748d --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.plugin.nwsauth/src/com/raytheon/uf/edex/plugin/nwsauth/FileManager.java @@ -0,0 +1,171 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.edex.plugin.nwsauth; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import javax.xml.bind.JAXBException; + +import com.raytheon.uf.common.localization.IPathManager; +import com.raytheon.uf.common.localization.LocalizationContext; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; +import com.raytheon.uf.common.localization.LocalizationFile; +import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; +import com.raytheon.uf.common.plugin.nwsauth.xml.NwsRoleData; +import com.raytheon.uf.common.plugin.nwsauth.xml.PermissionXML; +import com.raytheon.uf.common.plugin.nwsauth.xml.RoleXML; +import com.raytheon.uf.common.plugin.nwsauth.xml.UserXML; +import com.raytheon.uf.common.serialization.JAXBManager; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; + +/** + * Uses localization data to determine role/permissions. Intentionally + * package-private as all access should remain localized to the NWS plugin. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 09, 2013 1412       djohnson   Moved file writing from viz plugin to server-side.
+ * 
+ * 
+ * + * @author mpduff + * @version 1.0 + */ +class FileManager { + /** Status handler */ + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(FileManager.class); + + private static final FileManager instance = new FileManager(); + + private static JAXBManager jaxbManager; + + private final String ROLE_DIR = "roles"; + + private final Map roleDataMap = new HashMap(); + + /** + * Application name -> LocalizationFile map. + */ + private final Map roleFileMap = new HashMap(); + + private FileManager() { + readXML(); + } + + /** + * Get an instance. + * + * @return an instance + */ + public static FileManager getInstance() { + return instance; + } + + /** + * {@inheritDoc} + */ + public void save(String application) { + NwsRoleData roleData = roleDataMap.get(application); + LocalizationFile lf = roleFileMap.get(application); + + IPathManager pm = PathManagerFactory.getPathManager(); + LocalizationContext context = pm.getContext( + LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); + LocalizationFile locFile = pm + .getLocalizationFile(context, lf.getName()); + try { + JAXBManager jaxbManager = getJaxbManager(); + jaxbManager.getJaxbContext().createMarshaller() + .marshal(roleData, locFile.getFile()); + locFile.save(); + + } catch (JAXBException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } catch (LocalizationOpFailedException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } + + } + + private void readXML() { + try { + getJaxbManager(); + + IPathManager pm = PathManagerFactory.getPathManager(); + LocalizationContext[] contexts = new LocalizationContext[2]; + contexts[0] = pm.getContext(LocalizationType.COMMON_STATIC, + LocalizationLevel.BASE); + contexts[1] = pm.getContext(LocalizationType.COMMON_STATIC, + LocalizationLevel.SITE); + LocalizationFile[] roleFiles = pm.listFiles(contexts, ROLE_DIR, + new String[] { ".xml" }, false, true); + + for (LocalizationFile lf : roleFiles) { + NwsRoleData roleData = lf.jaxbUnmarshal(NwsRoleData.class, + getJaxbManager()); + + if (roleData != null) { + this.roleDataMap.put(roleData.getApplication(), roleData); + this.roleFileMap.put(roleData.getApplication(), lf); + } + } + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } + } + + private JAXBManager getJaxbManager() throws JAXBException { + if (jaxbManager == null) { + jaxbManager = new JAXBManager(NwsRoleData.class, + PermissionXML.class, RoleXML.class, UserXML.class); + } + return jaxbManager; + } + + /** + * @return + */ + public Map getRoleDataMap() { + return roleDataMap; + } + + /** + * @param roleDataWithChanges + */ + public void writeApplicationRoleData(Map roleDataWithChanges) { + for (Entry entry : roleDataWithChanges.entrySet()) { + final String application = entry.getKey(); + roleDataMap.put(application, entry.getValue()); + + save(application); + } + } +} diff --git a/edexOsgi/com.raytheon.uf.edex.useradmin/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.useradmin/META-INF/MANIFEST.MF index 540ac0bdf4..31bd8e1d90 100644 --- a/edexOsgi/com.raytheon.uf.edex.useradmin/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.useradmin/META-INF/MANIFEST.MF @@ -10,7 +10,6 @@ Require-Bundle: com.raytheon.uf.common.auth;bundle-version="1.12.1174", com.raytheon.uf.common.serialization.comm;bundle-version="1.12.1174", com.raytheon.uf.common.useradmin;bundle-version="1.0.0", com.raytheon.uf.common.status;bundle-version="1.12.1174", - com.raytheon.uf.edex.plugin.nwsauth;bundle-version="1.12.1174", com.raytheon.uf.common.serialization;bundle-version="1.12.1174", com.raytheon.uf.edex.core;bundle-version="1.12.1174", com.raytheon.uf.common.localization;bundle-version="1.12.1174" diff --git a/edexOsgi/com.raytheon.uf.edex.useradmin/res/spring/useradmin-request.xml b/edexOsgi/com.raytheon.uf.edex.useradmin/res/spring/useradmin-request.xml index 1e32d1b7f5..57271e585e 100644 --- a/edexOsgi/com.raytheon.uf.edex.useradmin/res/spring/useradmin-request.xml +++ b/edexOsgi/com.raytheon.uf.edex.useradmin/res/spring/useradmin-request.xml @@ -1,34 +1,28 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util-2.5.xsd"> - - - - - + + + + - - - + + + + - - - - - - - - - + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.useradmin/src/com/raytheon/uf/edex/useradmin/services/UserAuthenticationDataChangedHandler.java b/edexOsgi/com.raytheon.uf.edex.useradmin/src/com/raytheon/uf/edex/useradmin/services/UserAuthenticationDataChangedHandler.java new file mode 100644 index 0000000000..0b1b8d13d4 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.useradmin/src/com/raytheon/uf/edex/useradmin/services/UserAuthenticationDataChangedHandler.java @@ -0,0 +1,106 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.edex.useradmin.services; + +import com.raytheon.uf.common.auth.exception.AuthorizationException; +import com.raytheon.uf.common.auth.user.IUser; +import com.raytheon.uf.common.serialization.SerializationException; +import com.raytheon.uf.common.serialization.SerializationUtil; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.useradmin.request.UserAuthenticationDataChanged; +import com.raytheon.uf.edex.auth.req.AbstractPrivilegedRequestHandler; +import com.raytheon.uf.edex.auth.resp.AuthorizationResponse; +import com.raytheon.uf.edex.core.EDEXUtil; +import com.raytheon.uf.edex.core.EdexException; + +/** + * Receives requests signifying that user authentication data has changed, and + * publishes them on the observer topic. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 09, 2013 1412       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ + +public class UserAuthenticationDataChangedHandler extends + AbstractPrivilegedRequestHandler { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(UserAuthenticationDataChangedHandler.class); + + private final String topicUri; + + public UserAuthenticationDataChangedHandler(String topicUri) { + this.topicUri = topicUri; + } + + /** + * {@inheritDoc} + */ + @Override + public Object handleRequest(UserAuthenticationDataChanged request) + throws Exception { + + send(request, topicUri); + + return request; + } + + /** + * {@inheritDoc} + */ + @Override + public AuthorizationResponse authorized(IUser user, + UserAuthenticationDataChanged request) + throws AuthorizationException { + // Returns false because it should only ever be invoked from another + // plugin implements the useradmin API running in the local EDEX, which + // does not require authentication + return new AuthorizationResponse(false); + } + + /** + * Sends the object to the topic observers are listening on. + * + * @param obj + * @param endpoint + * the endpoint to send to + */ + public void send(Object obj, String endpoint) { + try { + byte[] bytes = SerializationUtil.transformToThrift(obj); + EDEXUtil.getMessageProducer().sendAsyncUri(endpoint, bytes); + } catch (EdexException e) { + statusHandler.error("Error sending object to " + endpoint, e); + } catch (SerializationException e) { + statusHandler.error("Error serializing object to " + endpoint, e); + } + } +}