diff --git a/account-ui/pom.xml b/account-ui/pom.xml
index 3522df6..e9f209d 100644
--- a/account-ui/pom.xml
+++ b/account-ui/pom.xml
@@ -66,6 +66,11 @@
shared-util
1.1-SNAPSHOT
+
+ de.muehlencord.shared
+ shared-jeeutil
+ 1.1-SNAPSHOT
+
de.muehlencord.sf
filter
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java
index 94e2695..89d16a6 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java
+++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/AccountView.java
@@ -1,7 +1,7 @@
package de.muehlencord.shared.account.web.presentation;
-import de.muehlencord.shared.account.business.account.boundary.AccountControl;
-import de.muehlencord.shared.account.business.account.boundary.ApplicationRoleControl;
+import de.muehlencord.shared.account.business.account.control.AccountControl;
+import de.muehlencord.shared.account.business.application.control.ApplicationRoleControl;
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
import de.muehlencord.shared.account.business.account.entity.AccountException;
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity;
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/ApplicationView.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/ApplicationView.java
index 8d07b57..5e03dd3 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/ApplicationView.java
+++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/ApplicationView.java
@@ -1,126 +1,126 @@
-package de.muehlencord.shared.account.web.presentation;
-
-import de.muehlencord.shared.account.business.application.boundary.ApplicationService;
-import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
-import de.muehlencord.shared.jeeutil.FacesUtil;
-import java.io.Serializable;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Named;
-import javax.enterprise.context.SessionScoped;
-import javax.inject.Inject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Joern Muehlencord
- */
-@SessionScoped
-@Named("applicationView")
-public class ApplicationView implements Serializable {
-
- private static final long serialVersionUID = -5515249316880163539L;
- private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationView.class);
-
- @Inject
- ApplicationService applicationService;
-
- private ApplicationEntity currentApplication = null;
- private ApplicationEntity editApplication = null;
- private List applicationList = null;
-
- @PostConstruct
- public void selectDefaultCurrentApplication() {
- // force applications to be loaded from database
- getAllApplications();
- if ((applicationList != null) && (!applicationList.isEmpty())) {
- currentApplication = applicationList.get(0);
- }
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("post construct executed");
- }
- }
-
- @PreDestroy
- public void predestroy() {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Predestroy executed");
- }
-
- }
-
- public List getAllApplications() {
- if (applicationList == null) {
- applicationList = applicationService.getAllApplications();
- }
- return applicationList;
- }
-
- public void selectApplication() {
- if (currentApplication != null) {
- LOGGER.info("selected application: {}", currentApplication.getApplicationName());
- FacesUtil.addGlobalInfoMessage("Success", "Selected application " + currentApplication.getApplicationName());
- }
- }
-
- public void newApplication() {
- this.editApplication = new ApplicationEntity();
- }
-
- public void cancelEditApplication() {
- this.editApplication = null;
- }
-
- public void saveEditApplication() {
- if (editApplication == null) {
- FacesUtil.addGlobalErrorMessage("Error", "Need to provide data");
- } else if ((editApplication.getApplicationName() == null) || (editApplication.getApplicationName().trim().equals(""))) {
- String hint;
- if (editApplication.getId() == null) {
- hint = "Cannot create application";
- } else {
- hint = "Cannot save application";
- }
- FacesUtil.addGlobalErrorMessage(hint, "Application name must not be empty");
- } else {
- currentApplication = applicationService.createOrUpdate(editApplication);
- // force reload of to update view
- applicationList = null;
- FacesUtil.addGlobalInfoMessage("Info", "Application saved");
- }
- }
-
- public void deleteApplication() {
- if (currentApplication == null) {
- FacesUtil.addGlobalErrorMessage("Error", "Need to provide data");
- } else if (currentApplication.getId() == null) {
- FacesUtil.addGlobalErrorMessage("Error", "Cannot delete non persistent data");
- } else {
- String applicationName = currentApplication.getApplicationName();
- applicationService.delete(currentApplication);
- applicationList = null; // force reload to update view
- currentApplication = null;
- selectDefaultCurrentApplication();
- FacesUtil.addGlobalInfoMessage("Info", "Application " + applicationName + " deleted");
- }
- }
-
- /* *** getter / setter *** */
- public ApplicationEntity getCurrentApplication() {
- return currentApplication;
- }
-
- public void setCurrentApplication(ApplicationEntity currentApplication) {
- this.currentApplication = currentApplication;
- }
-
- public ApplicationEntity getEditApplication() {
- return editApplication;
- }
-
- public void setEditApplication(ApplicationEntity editApplication) {
- this.editApplication = editApplication;
- }
-}
+package de.muehlencord.shared.account.web.presentation;
+
+import de.muehlencord.shared.account.business.application.boundary.ApplicationService;
+import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
+import de.muehlencord.shared.jeeutil.FacesUtil;
+import java.io.Serializable;
+import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Named;
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Joern Muehlencord
+ */
+@SessionScoped
+@Named("applicationView")
+public class ApplicationView implements Serializable {
+
+ private static final long serialVersionUID = -5515249316880163539L;
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationView.class);
+
+ @Inject
+ ApplicationService applicationService;
+
+ private ApplicationEntity currentApplication = null;
+ private ApplicationEntity editApplication = null;
+ private List applicationList = null;
+
+ @PostConstruct
+ public void selectDefaultCurrentApplication() {
+ // force applications to be loaded from database
+ getAllApplications();
+ if ((applicationList != null) && (!applicationList.isEmpty())) {
+ currentApplication = applicationList.get(0);
+ }
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("post construct executed");
+ }
+ }
+
+ @PreDestroy
+ public void predestroy() {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Predestroy executed");
+ }
+
+ }
+
+ public List getAllApplications() {
+ if (applicationList == null) {
+ applicationList = applicationService.getAllApplications();
+ }
+ return applicationList;
+ }
+
+ public void selectApplication() {
+ if (currentApplication != null) {
+ LOGGER.info("selected application: {}", currentApplication.getApplicationName());
+ FacesUtil.addGlobalInfoMessage("Success", "Selected application " + currentApplication.getApplicationName());
+ }
+ }
+
+ public void newApplication() {
+ this.editApplication = new ApplicationEntity();
+ }
+
+ public void cancelEditApplication() {
+ this.editApplication = null;
+ }
+
+ public void saveEditApplication() {
+ if (editApplication == null) {
+ FacesUtil.addGlobalErrorMessage("Error", "Need to provide data");
+ } else if ((editApplication.getApplicationName() == null) || (editApplication.getApplicationName().trim().equals(""))) {
+ String hint;
+ if (editApplication.getId() == null) {
+ hint = "Cannot create application";
+ } else {
+ hint = "Cannot save application";
+ }
+ FacesUtil.addGlobalErrorMessage(hint, "Application name must not be empty");
+ } else {
+ currentApplication = applicationService.createOrUpdate(editApplication);
+ // force reload of to update view
+ applicationList = null;
+ FacesUtil.addGlobalInfoMessage("Info", "Application saved");
+ }
+ }
+
+ public void deleteApplication() {
+ if (currentApplication == null) {
+ FacesUtil.addGlobalErrorMessage("Error", "Need to provide data");
+ } else if (currentApplication.getId() == null) {
+ FacesUtil.addGlobalErrorMessage("Error", "Cannot delete non persistent data");
+ } else {
+ String applicationName = currentApplication.getApplicationName();
+ applicationService.delete(currentApplication);
+ applicationList = null; // force reload to update view
+ currentApplication = null;
+ selectDefaultCurrentApplication();
+ FacesUtil.addGlobalInfoMessage("Info", "Application " + applicationName + " deleted");
+ }
+ }
+
+ /* *** getter / setter *** */
+ public ApplicationEntity getCurrentApplication() {
+ return currentApplication;
+ }
+
+ public void setCurrentApplication(ApplicationEntity currentApplication) {
+ this.currentApplication = currentApplication;
+ }
+
+ public ApplicationEntity getEditApplication() {
+ return editApplication;
+ }
+
+ public void setEditApplication(ApplicationEntity editApplication) {
+ this.editApplication = editApplication;
+ }
+}
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/InstanceView.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/InstanceView.java
index 0a3e436..9d99cdc 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/InstanceView.java
+++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/InstanceView.java
@@ -1,46 +1,46 @@
-package de.muehlencord.shared.account.web.presentation;
-
-import de.muehlencord.shared.account.business.config.boundary.ConfigService;
-import de.muehlencord.shared.account.business.config.entity.ConfigException;
-import javax.ejb.EJB;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Named;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Joern Muehlencord
- */
-@Named(value = "instanceView")
-@ApplicationScoped
-public class InstanceView {
-
- private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(InstanceView.class);
-
- @EJB
- ConfigService configService;
-
- public boolean isDevelopmentVersion() {
- String instanceName = getInstanceName();
- return !instanceName.equals("Production");
- }
-
- public String getInstanceName() {
- String instanceName;
- try {
- instanceName = configService.getConfigValue("base.instance");
- } catch (ConfigException ex) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(ex.toString(), ex);
- } else {
- LOGGER.error(ex.toString());
- }
- instanceName = "unknown (" + ex.toString() + ")";
- }
- if (instanceName == null) {
- return "unknown";
- } else {
- return instanceName;
- }
- }
-}
+package de.muehlencord.shared.account.web.presentation;
+
+import de.muehlencord.shared.account.business.config.boundary.ConfigService;
+import de.muehlencord.shared.account.business.config.entity.ConfigException;
+import javax.ejb.EJB;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Named;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Joern Muehlencord
+ */
+@Named(value = "instanceView")
+@ApplicationScoped
+public class InstanceView {
+
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(InstanceView.class);
+
+ @EJB
+ ConfigService configService;
+
+ public boolean isDevelopmentVersion() {
+ String instanceName = getInstanceName();
+ return !instanceName.equals("Production");
+ }
+
+ public String getInstanceName() {
+ String instanceName;
+ try {
+ instanceName = configService.getConfigValue("base.instance");
+ } catch (ConfigException ex) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(ex.toString(), ex);
+ } else {
+ LOGGER.error(ex.toString());
+ }
+ instanceName = "unknown (" + ex.toString() + ")";
+ }
+ if (instanceName == null) {
+ return "unknown";
+ } else {
+ return instanceName;
+ }
+ }
+}
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/PermissionView.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/PermissionView.java
index c38e5ba..292a624 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/PermissionView.java
+++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/PermissionView.java
@@ -15,9 +15,9 @@
*/
package de.muehlencord.shared.account.web.presentation;
-import de.muehlencord.shared.account.business.account.boundary.ApplicationPermissionControl;
import de.muehlencord.shared.account.business.account.entity.AccountException;
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
+import de.muehlencord.shared.account.business.application.control.ApplicationPermissionControl;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import de.muehlencord.shared.jeeutil.FacesUtil;
import java.io.Serializable;
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/RoleView.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/RoleView.java
index a5c15b9..63030d1 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/RoleView.java
+++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/RoleView.java
@@ -1,240 +1,240 @@
-/*
- * Copyright 2017 Joern Muehlencord .
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package de.muehlencord.shared.account.web.presentation;
-
-import de.muehlencord.shared.account.business.account.boundary.ApplicationRoleControl;
-import de.muehlencord.shared.account.business.account.entity.AccountException;
-import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
-import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
-import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
-import de.muehlencord.shared.jeeutil.FacesUtil;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import javax.ejb.EJB;
-import javax.faces.view.ViewScoped;
-import javax.inject.Named;
-import javax.inject.Inject;
-import org.primefaces.event.SelectEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author Joern Muehlencord
- */
-@ViewScoped
-@Named("roleView")
-public class RoleView implements Serializable {
-
- private static final long serialVersionUID = 1669321020398119007L;
- private static final Logger LOGGER = LoggerFactory.getLogger(RoleView.class);
-
- @Inject
- private ApplicationView applicationView;
-
- @EJB
- ApplicationRoleControl applicationRoleControl;
-
- private List allRoles = null;
- private List currentRolePermissions = null;
- private List missingApplicationsPermissions = null;
-
- private ApplicationRoleEntity currentRole;
- private ApplicationPermissionEntity currentPermission;
- private ApplicationPermissionEntity newPermission;
-
- public ApplicationEntity getCurrentApplication() {
- return applicationView.getCurrentApplication();
- }
-
- public List getAllRoles() {
- if (allRoles == null) {
- allRoles = applicationRoleControl.getAllRoles(applicationView.getCurrentApplication());
- }
- return allRoles;
- }
-
- public void startNewRole() {
- this.currentRole = new ApplicationRoleEntity(applicationView.getCurrentApplication());
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Created new current role: {}", currentRole.toString());
- }
-
- }
-
- public void cancelEditRole() {
- this.currentRole = null;
- }
-
- public void saveEditRole() {
- if ((currentRole == null) || (currentRole.getRoleName() == null) || (currentRole.getRoleName().trim().length() == 0)) {
- FacesUtil.addGlobalErrorMessage("Error", "Permission name must not be null");
- } else if (currentRole.getId() == null) {
- applicationRoleControl.create(currentRole);
- allRoles = null; // force reload
- FacesUtil.addGlobalInfoMessage("Info", "Role " + currentRole.getRoleName() + " created");
- } else {
- applicationRoleControl.update(currentRole);
- allRoles = null; // force reload
- FacesUtil.addGlobalInfoMessage("Info", "Role " + currentRole.getRoleName() + " updated");
- }
- }
-
- public void deleteRole() {
- if (currentRole == null) {
- FacesUtil.addGlobalErrorMessage("Error", "Please select a permission to edit");
- } else {
- try {
- applicationRoleControl.delete(currentRole);
- allRoles = null; // force reload
- currentRole = null;
- currentRolePermissions = null;
- } catch (AccountException ex) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(ex.toString(), ex);
- } else {
- LOGGER.debug(ex.toString());
- }
- FacesUtil.addGlobalErrorMessage("Error while deleting permission.", ex.toString());
- }
- }
- }
-
- public boolean getRoleSelected() {
- return currentRole != null;
- }
-
- public boolean getPermissionSelected() {
- return currentPermission != null;
- }
-
- public boolean getMissingPermissionAvailable() {
- return ((missingApplicationsPermissions != null) && (!missingApplicationsPermissions.isEmpty()));
- }
-
- public void onRoleSelect(SelectEvent event) {
- currentRolePermissions = null;
- currentRolePermissions = getRolePermissions();
- missingApplicationsPermissions = null;
- missingApplicationsPermissions = getMissingPermissions();
- }
-
- public List getRolePermissions() {
- if (currentRole == null) {
- currentRolePermissions = new ArrayList<>();
- return currentRolePermissions;
- } else {
- if (currentRolePermissions == null) {
- try {
- currentRolePermissions = applicationRoleControl.getRolePermissions(currentRole);
- } catch (AccountException ex) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(ex.toString(), ex);
- } else {
- LOGGER.debug(ex.toString());
- }
- FacesUtil.addGlobalErrorMessage("Error while fetching role permissions", "see log for details");
- currentRolePermissions = new ArrayList<>();
- }
- }
- return currentRolePermissions;
- }
- }
-
- public List getMissingPermissions() {
- if (currentRole == null) {
- missingApplicationsPermissions = new ArrayList<>();
- return missingApplicationsPermissions;
- } else {
- if (missingApplicationsPermissions == null) {
- missingApplicationsPermissions = applicationRoleControl.getNotAssignedApplicationPermissions(currentRole);
-
- }
- return missingApplicationsPermissions;
- }
- }
-
- public void addRolePermission() {
- if (newPermission == null) {
- FacesUtil.addGlobalErrorMessage("Error", "Please select a new permission first");
- } else {
- try {
- applicationRoleControl.addPermission(currentRole, newPermission);
- currentRolePermissions = null;
- missingApplicationsPermissions = null;
- } catch (AccountException ex) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(ex.toString(), ex);
- } else {
- LOGGER.debug(ex.toString());
- }
- FacesUtil.addGlobalErrorMessage("Error while adding permission", ex.getMessage());
- }
- }
-
- }
-
- public void removeRolePermission() {
- if (currentPermission == null) {
- FacesUtil.addGlobalErrorMessage("Error", "Please select a permission first");
- } else {
- try {
- applicationRoleControl.removePermission(currentRole, currentPermission);
- currentRolePermissions = null;
- missingApplicationsPermissions = null;
- } catch (AccountException ex) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(ex.toString(), ex);
- } else {
- LOGGER.debug(ex.toString());
- }
- FacesUtil.addGlobalErrorMessage("Error while adding permission", ex.getMessage());
- }
- }
-
- }
-
- /* *** getter / setter *** */
- public void setApplicationView(ApplicationView applicationView) {
- this.applicationView = applicationView;
- }
-
- public ApplicationRoleEntity getCurrentRole() {
- return currentRole;
- }
-
- public void setCurrentRole(ApplicationRoleEntity currentRole) {
- this.currentRole = currentRole;
- }
-
- public ApplicationPermissionEntity getCurrentPermission() {
- return currentPermission;
- }
-
- public void setCurrentPermission(ApplicationPermissionEntity currentPermission) {
- this.currentPermission = currentPermission;
- }
-
- public ApplicationPermissionEntity getNewPermission() {
- return newPermission;
- }
-
- public void setNewPermission(ApplicationPermissionEntity newPermission) {
- this.newPermission = newPermission;
- }
-
-}
+/*
+ * Copyright 2017 Joern Muehlencord .
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package de.muehlencord.shared.account.web.presentation;
+
+import de.muehlencord.shared.account.business.application.control.ApplicationRoleControl;
+import de.muehlencord.shared.account.business.account.entity.AccountException;
+import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
+import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
+import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
+import de.muehlencord.shared.jeeutil.FacesUtil;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.faces.view.ViewScoped;
+import javax.inject.Named;
+import javax.inject.Inject;
+import org.primefaces.event.SelectEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author Joern Muehlencord
+ */
+@ViewScoped
+@Named("roleView")
+public class RoleView implements Serializable {
+
+ private static final long serialVersionUID = 1669321020398119007L;
+ private static final Logger LOGGER = LoggerFactory.getLogger(RoleView.class);
+
+ @Inject
+ private ApplicationView applicationView;
+
+ @EJB
+ ApplicationRoleControl applicationRoleControl;
+
+ private List allRoles = null;
+ private List currentRolePermissions = null;
+ private List missingApplicationsPermissions = null;
+
+ private ApplicationRoleEntity currentRole;
+ private ApplicationPermissionEntity currentPermission;
+ private ApplicationPermissionEntity newPermission;
+
+ public ApplicationEntity getCurrentApplication() {
+ return applicationView.getCurrentApplication();
+ }
+
+ public List getAllRoles() {
+ if (allRoles == null) {
+ allRoles = applicationRoleControl.getAllRoles(applicationView.getCurrentApplication());
+ }
+ return allRoles;
+ }
+
+ public void startNewRole() {
+ this.currentRole = new ApplicationRoleEntity(applicationView.getCurrentApplication());
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Created new current role: {}", currentRole.toString());
+ }
+
+ }
+
+ public void cancelEditRole() {
+ this.currentRole = null;
+ }
+
+ public void saveEditRole() {
+ if ((currentRole == null) || (currentRole.getRoleName() == null) || (currentRole.getRoleName().trim().length() == 0)) {
+ FacesUtil.addGlobalErrorMessage("Error", "Permission name must not be null");
+ } else if (currentRole.getId() == null) {
+ applicationRoleControl.create(currentRole);
+ allRoles = null; // force reload
+ FacesUtil.addGlobalInfoMessage("Info", "Role " + currentRole.getRoleName() + " created");
+ } else {
+ applicationRoleControl.update(currentRole);
+ allRoles = null; // force reload
+ FacesUtil.addGlobalInfoMessage("Info", "Role " + currentRole.getRoleName() + " updated");
+ }
+ }
+
+ public void deleteRole() {
+ if (currentRole == null) {
+ FacesUtil.addGlobalErrorMessage("Error", "Please select a permission to edit");
+ } else {
+ try {
+ applicationRoleControl.delete(currentRole);
+ allRoles = null; // force reload
+ currentRole = null;
+ currentRolePermissions = null;
+ } catch (AccountException ex) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(ex.toString(), ex);
+ } else {
+ LOGGER.debug(ex.toString());
+ }
+ FacesUtil.addGlobalErrorMessage("Error while deleting permission.", ex.toString());
+ }
+ }
+ }
+
+ public boolean getRoleSelected() {
+ return currentRole != null;
+ }
+
+ public boolean getPermissionSelected() {
+ return currentPermission != null;
+ }
+
+ public boolean getMissingPermissionAvailable() {
+ return ((missingApplicationsPermissions != null) && (!missingApplicationsPermissions.isEmpty()));
+ }
+
+ public void onRoleSelect(SelectEvent event) {
+ currentRolePermissions = null;
+ currentRolePermissions = getRolePermissions();
+ missingApplicationsPermissions = null;
+ missingApplicationsPermissions = getMissingPermissions();
+ }
+
+ public List getRolePermissions() {
+ if (currentRole == null) {
+ currentRolePermissions = new ArrayList<>();
+ return currentRolePermissions;
+ } else {
+ if (currentRolePermissions == null) {
+ try {
+ currentRolePermissions = applicationRoleControl.getRolePermissions(currentRole);
+ } catch (AccountException ex) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(ex.toString(), ex);
+ } else {
+ LOGGER.debug(ex.toString());
+ }
+ FacesUtil.addGlobalErrorMessage("Error while fetching role permissions", "see log for details");
+ currentRolePermissions = new ArrayList<>();
+ }
+ }
+ return currentRolePermissions;
+ }
+ }
+
+ public List getMissingPermissions() {
+ if (currentRole == null) {
+ missingApplicationsPermissions = new ArrayList<>();
+ return missingApplicationsPermissions;
+ } else {
+ if (missingApplicationsPermissions == null) {
+ missingApplicationsPermissions = applicationRoleControl.getNotAssignedApplicationPermissions(currentRole);
+
+ }
+ return missingApplicationsPermissions;
+ }
+ }
+
+ public void addRolePermission() {
+ if (newPermission == null) {
+ FacesUtil.addGlobalErrorMessage("Error", "Please select a new permission first");
+ } else {
+ try {
+ applicationRoleControl.addPermission(currentRole, newPermission);
+ currentRolePermissions = null;
+ missingApplicationsPermissions = null;
+ } catch (AccountException ex) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(ex.toString(), ex);
+ } else {
+ LOGGER.debug(ex.toString());
+ }
+ FacesUtil.addGlobalErrorMessage("Error while adding permission", ex.getMessage());
+ }
+ }
+
+ }
+
+ public void removeRolePermission() {
+ if (currentPermission == null) {
+ FacesUtil.addGlobalErrorMessage("Error", "Please select a permission first");
+ } else {
+ try {
+ applicationRoleControl.removePermission(currentRole, currentPermission);
+ currentRolePermissions = null;
+ missingApplicationsPermissions = null;
+ } catch (AccountException ex) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(ex.toString(), ex);
+ } else {
+ LOGGER.debug(ex.toString());
+ }
+ FacesUtil.addGlobalErrorMessage("Error while adding permission", ex.getMessage());
+ }
+ }
+
+ }
+
+ /* *** getter / setter *** */
+ public void setApplicationView(ApplicationView applicationView) {
+ this.applicationView = applicationView;
+ }
+
+ public ApplicationRoleEntity getCurrentRole() {
+ return currentRole;
+ }
+
+ public void setCurrentRole(ApplicationRoleEntity currentRole) {
+ this.currentRole = currentRole;
+ }
+
+ public ApplicationPermissionEntity getCurrentPermission() {
+ return currentPermission;
+ }
+
+ public void setCurrentPermission(ApplicationPermissionEntity currentPermission) {
+ this.currentPermission = currentPermission;
+ }
+
+ public ApplicationPermissionEntity getNewPermission() {
+ return newPermission;
+ }
+
+ public void setNewPermission(ApplicationPermissionEntity newPermission) {
+ this.newPermission = newPermission;
+ }
+
+}
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniqueApplicationRoleNameValidator.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniqueApplicationRoleNameValidator.java
index f12b5bc..6882eff 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniqueApplicationRoleNameValidator.java
+++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniqueApplicationRoleNameValidator.java
@@ -1,8 +1,8 @@
package de.muehlencord.shared.account.web.presentation;
-import de.muehlencord.shared.account.business.account.boundary.ApplicationRoleControl;
+
import de.muehlencord.shared.account.business.account.entity.ApplicationRoleEntity;
-import de.muehlencord.shared.account.business.application.boundary.ApplicationService;
+import de.muehlencord.shared.account.business.application.control.ApplicationRoleControl;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import java.io.Serializable;
import javax.ejb.EJB;
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniquePermissionNameValidator.java b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniquePermissionNameValidator.java
index 1cf90b3..3ca5320 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniquePermissionNameValidator.java
+++ b/account-ui/src/main/java/de/muehlencord/shared/account/web/presentation/UniquePermissionNameValidator.java
@@ -1,7 +1,8 @@
package de.muehlencord.shared.account.web.presentation;
-import de.muehlencord.shared.account.business.account.boundary.ApplicationPermissionControl;
+
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
+import de.muehlencord.shared.account.business.application.control.ApplicationPermissionControl;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import java.io.Serializable;
import javax.ejb.EJB;
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/AccountProducer.java b/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountProducer.java
similarity index 94%
rename from account-ui/src/main/java/de/muehlencord/shared/account/web/AccountProducer.java
rename to account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountProducer.java
index dd1690b..9481bfd 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/AccountProducer.java
+++ b/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountProducer.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package de.muehlencord.shared.account.web;
+package de.muehlencord.shared.account.business.account.boundary;
-import de.muehlencord.shared.account.business.account.boundary.AccountControl;
+import de.muehlencord.shared.account.business.account.control.AccountControl;
import de.muehlencord.shared.account.business.account.entity.Account;
import java.io.Serializable;
import java.util.Locale;
diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountControl.java b/account/src/main/java/de/muehlencord/shared/account/business/account/control/AccountControl.java
similarity index 97%
rename from account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountControl.java
rename to account/src/main/java/de/muehlencord/shared/account/business/account/control/AccountControl.java
index 64ae49c..c5fe028 100644
--- a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/AccountControl.java
+++ b/account/src/main/java/de/muehlencord/shared/account/business/account/control/AccountControl.java
@@ -1,4 +1,4 @@
-package de.muehlencord.shared.account.business.account.boundary;
+package de.muehlencord.shared.account.business.account.control;
import de.muehlencord.shared.account.business.account.entity.AccountException;
import de.muehlencord.shared.account.business.account.entity.AccountStatus;
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/business/application/boundary/StartupBean.java b/account/src/main/java/de/muehlencord/shared/account/business/application/boundary/StartupBean.java
similarity index 94%
rename from account-ui/src/main/java/de/muehlencord/shared/account/web/business/application/boundary/StartupBean.java
rename to account/src/main/java/de/muehlencord/shared/account/business/application/boundary/StartupBean.java
index a3005dd..bfd3a7a 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/business/application/boundary/StartupBean.java
+++ b/account/src/main/java/de/muehlencord/shared/account/business/application/boundary/StartupBean.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package de.muehlencord.shared.account.web.business.application.boundary;
+package de.muehlencord.shared.account.business.application.boundary;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/business/application/control/ApplicationController.java b/account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationController.java
similarity index 95%
rename from account-ui/src/main/java/de/muehlencord/shared/account/web/business/application/control/ApplicationController.java
rename to account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationController.java
index a3154f6..512effc 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/business/application/control/ApplicationController.java
+++ b/account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationController.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package de.muehlencord.shared.account.web.business.application.control;
+package de.muehlencord.shared.account.business.application.control;
import de.muehlencord.shared.account.business.application.boundary.ApplicationService;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationPermissionControl.java b/account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationPermissionControl.java
similarity index 95%
rename from account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationPermissionControl.java
rename to account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationPermissionControl.java
index fffbc16..c2d12c7 100644
--- a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationPermissionControl.java
+++ b/account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationPermissionControl.java
@@ -1,4 +1,4 @@
-package de.muehlencord.shared.account.business.account.boundary;
+package de.muehlencord.shared.account.business.application.control;
import de.muehlencord.shared.account.business.account.entity.AccountException;
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
diff --git a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationRoleControl.java b/account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationRoleControl.java
similarity index 96%
rename from account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationRoleControl.java
rename to account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationRoleControl.java
index 3a0edbd..6bbbb79 100644
--- a/account/src/main/java/de/muehlencord/shared/account/business/account/boundary/ApplicationRoleControl.java
+++ b/account/src/main/java/de/muehlencord/shared/account/business/application/control/ApplicationRoleControl.java
@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
-package de.muehlencord.shared.account.business.account.boundary;
+package de.muehlencord.shared.account.business.application.control;
import de.muehlencord.shared.account.business.account.entity.AccountException;
import de.muehlencord.shared.account.business.account.entity.ApplicationPermissionEntity;
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/ConfigurationProducer.java b/account/src/main/java/de/muehlencord/shared/account/business/config/boundary/ConfigurationProducer.java
similarity index 94%
rename from account-ui/src/main/java/de/muehlencord/shared/account/web/ConfigurationProducer.java
rename to account/src/main/java/de/muehlencord/shared/account/business/config/boundary/ConfigurationProducer.java
index 2afebd5..c0e1535 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/ConfigurationProducer.java
+++ b/account/src/main/java/de/muehlencord/shared/account/business/config/boundary/ConfigurationProducer.java
@@ -1,53 +1,53 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package de.muehlencord.shared.account.web;
-
-import de.muehlencord.shared.account.business.config.boundary.ConfigService;
-import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey;
-import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue;
-import de.muehlencord.shared.account.business.config.entity.ConfigException;
-import javax.ejb.EJB;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-/**
- *
- * @author Joern Muehlencord
- */
-@Dependent
-public class ConfigurationProducer {
-
- @EJB
- ConfigService configService;
-
- @Produces
- @AccountConfigurationValue(key = AccountConfigurationKey.Producer)
- public String produceConfigurationValue(InjectionPoint injectionPoint) {
- Annotated annotated = injectionPoint.getAnnotated();
- AccountConfigurationValue annotation = annotated.getAnnotation(AccountConfigurationValue.class);
- if (annotation != null) {
- AccountConfigurationKey key = annotation.key();
- if (key != null) {
- try {
- switch (key) {
- case BaseUrl:
- return configService.getConfigValue("base.url");
- case PasswordResetUrl:
- return configService.getConfigValue("base.url") + "/login.xhtml";
- default:
- throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint);
- }
- } catch (ConfigException ex) {
- throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint + ". Exception: " + ex.getMessage());
- }
- }
- }
- throw new IllegalStateException("No key for injection point: " + injectionPoint);
- }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.muehlencord.shared.account.business.config.boundary;
+
+import de.muehlencord.shared.account.business.config.boundary.ConfigService;
+import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationKey;
+import de.muehlencord.shared.account.business.accountconfig.entity.AccountConfigurationValue;
+import de.muehlencord.shared.account.business.config.entity.ConfigException;
+import javax.ejb.EJB;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ *
+ * @author Joern Muehlencord
+ */
+@Dependent
+public class ConfigurationProducer {
+
+ @EJB
+ ConfigService configService;
+
+ @Produces
+ @AccountConfigurationValue(key = AccountConfigurationKey.Producer)
+ public String produceConfigurationValue(InjectionPoint injectionPoint) {
+ Annotated annotated = injectionPoint.getAnnotated();
+ AccountConfigurationValue annotation = annotated.getAnnotation(AccountConfigurationValue.class);
+ if (annotation != null) {
+ AccountConfigurationKey key = annotation.key();
+ if (key != null) {
+ try {
+ switch (key) {
+ case BaseUrl:
+ return configService.getConfigValue("base.url");
+ case PasswordResetUrl:
+ return configService.getConfigValue("base.url") + "/login.xhtml";
+ default:
+ throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint);
+ }
+ } catch (ConfigException ex) {
+ throw new IllegalStateException("Invalid key " + key + " for injection point: " + injectionPoint + ". Exception: " + ex.getMessage());
+ }
+ }
+ }
+ throw new IllegalStateException("No key for injection point: " + injectionPoint);
+ }
+
+}
diff --git a/account/src/main/java/de/muehlencord/shared/account/presentation/LoginView.java b/account/src/main/java/de/muehlencord/shared/account/presentation/LoginView.java
index eaf5094..dcd7856 100644
--- a/account/src/main/java/de/muehlencord/shared/account/presentation/LoginView.java
+++ b/account/src/main/java/de/muehlencord/shared/account/presentation/LoginView.java
@@ -1,185 +1,185 @@
-package de.muehlencord.shared.account.presentation;
-
-import de.muehlencord.shared.account.business.account.boundary.AccountControl;
-import de.muehlencord.shared.account.business.account.entity.AccountEntity;
-import de.muehlencord.shared.jeeutil.FacesUtil;
-import java.io.IOException;
-import java.io.Serializable;
-import javax.ejb.EJB;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.view.ViewScoped;
-import javax.inject.Named;
-import javax.naming.NamingException;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import org.apache.shiro.subject.Subject;
-import org.apache.shiro.SecurityUtils;
-import org.apache.shiro.authc.AuthenticationException;
-import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.web.util.WebUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author joern.muehlencord
- */
-@Named(value = "loginView")
-@ViewScoped
-public class LoginView implements Serializable {
-
- private static final long serialVersionUID = -1164860380769648432L;
-
- @EJB
- private AccountControl accountService;
-
- private String username = null;
- private String password = null;
- private boolean rememberMe = false;
-
- private String resetPasswordToken = null;
-
- private static final Logger LOGGER = LoggerFactory.getLogger(LoginView.class.getName());
-
- public void authenticate() {
-
- // Example using most common scenario of username/password pair:
- UsernamePasswordToken token = new UsernamePasswordToken(getUsername(), getPassword());
-
- // "Remember Me" built-in:
- token.setRememberMe(rememberMe);
- Subject currentUser = SecurityUtils.getSubject();
- LOGGER.info("Trying to login user {}", username);
-
- try {
- currentUser.login(token);
- LOGGER.info("User {} logged in", username);
- // user logged in, update account entity
- AccountEntity account = accountService.getAccountEntity(username, true);
- accountService.updateLogin(account);
-
- // redirect to home
- ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
- ServletResponse servletResponse = (ServletResponse) ec.getResponse();
- String fallbackUrl = "/web/index.xhtml"; // TODO make configurable
- // ec.redirect(url);
- if (LOGGER.isTraceEnabled()) {
- LOGGER.trace("redirecting to {}, fallbackUrl={}", servletResponse.toString(), fallbackUrl);
- }
-
- WebUtils.redirectToSavedRequest((ServletRequest) ec.getRequest(), servletResponse, fallbackUrl);
- } catch (IOException | AuthenticationException ex) {
- // Could catch a subclass of AuthenticationException if you like
- String hint = "Error while authenticating user " + username;
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(hint, ex);
- }
-
- if (ex.getMessage() != null) {
- hint += "Reason: " + ex.getMessage();
- } else {
- hint += "Reason: " + ex.toString();
- }
- if ((ex.getCause() != null) && (ex.getCause().getMessage() != null)) {
- hint += "Rootcause: " + ex.getMessage();
-
- LOGGER.error(hint);
- }
- FacesUtil.addGlobalErrorMessage("Login failed", hint);
-
- AccountEntity account = accountService.getAccountEntity(username, false);
- if (account != null) {
- accountService.addLoginError(account);
- }
- } finally {
- token.clear();
- }
- }
-
- public void logout() {
- Subject currentUser = SecurityUtils.getSubject();
- try {
- currentUser.logout();
-
- ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
-
- // check if redirect shall be executed
- // default setting is yes to /login.xhtml
- // can be overwritten using parameters
- // de.muehlencord.shared.account.loginview.executeredirect boolean true/false
- // de.muehlencord.shared.account.loginview.redirecttarget path to redirect to (without external context, will be added automatically)
- String executeRedirectString = ec.getInitParameter("de.muehlencord.shared.account.loginview.executeredirect");
- boolean executeRedirect = true;
- if (executeRedirectString != null) {
- executeRedirect = Boolean.parseBoolean(executeRedirectString);
- }
-
- String redirectTarget = ec.getInitParameter("de.muehlencord.shared.account.loginview.redirecttarget");
- if ((redirectTarget == null) || (redirectTarget.equals(""))) {
- redirectTarget = "/login.xhtml";
- }
-
- if (executeRedirect) {
- String url = ec.getRequestContextPath() + redirectTarget;
- ec.redirect(url);
- }
-
- } catch (Exception e) {
- LOGGER.warn(e.toString());
- }
- }
-
- public String executePasswordReset() {
- boolean passwordResetted = accountService.resetPassword(username, password, resetPasswordToken);
- if (passwordResetted) {
- // TODO add email notification on updated user account
- FacesUtil.addGlobalInfoMessage("Password resetted", null);
- return login();
- } else {
- // TODO add email notificaton on failed password reset
- FacesUtil.addGlobalErrorMessage("Password reset failed", null);
- return login();
- }
- }
-
- /* **** naviation rules **** */
- public String login() {
- return "/login.xhtml"; // TODO make configurable
- }
-
- /* *** getter / setter */
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String un) {
- this.username = un;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String pw) {
- this.password = pw;
- }
-
- public boolean isRememberMe() {
- return rememberMe;
- }
-
- public void setRememberMe(boolean rememberMe) {
- this.rememberMe = rememberMe;
- }
-
- public String getResetPasswordToken() {
- return resetPasswordToken;
- }
-
- public void setResetPasswordToken(String resetPasswordToken) {
- this.resetPasswordToken = resetPasswordToken;
- }
-
-}
+package de.muehlencord.shared.account.presentation;
+
+import de.muehlencord.shared.account.business.account.control.AccountControl;
+import de.muehlencord.shared.account.business.account.entity.AccountEntity;
+import de.muehlencord.shared.jeeutil.FacesUtil;
+import java.io.IOException;
+import java.io.Serializable;
+import javax.ejb.EJB;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.view.ViewScoped;
+import javax.inject.Named;
+import javax.naming.NamingException;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.web.util.WebUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author joern.muehlencord
+ */
+@Named(value = "loginView")
+@ViewScoped
+public class LoginView implements Serializable {
+
+ private static final long serialVersionUID = -1164860380769648432L;
+
+ @EJB
+ private AccountControl accountService;
+
+ private String username = null;
+ private String password = null;
+ private boolean rememberMe = false;
+
+ private String resetPasswordToken = null;
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(LoginView.class.getName());
+
+ public void authenticate() {
+
+ // Example using most common scenario of username/password pair:
+ UsernamePasswordToken token = new UsernamePasswordToken(getUsername(), getPassword());
+
+ // "Remember Me" built-in:
+ token.setRememberMe(rememberMe);
+ Subject currentUser = SecurityUtils.getSubject();
+ LOGGER.info("Trying to login user {}", username);
+
+ try {
+ currentUser.login(token);
+ LOGGER.info("User {} logged in", username);
+ // user logged in, update account entity
+ AccountEntity account = accountService.getAccountEntity(username, true);
+ accountService.updateLogin(account);
+
+ // redirect to home
+ ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
+ ServletResponse servletResponse = (ServletResponse) ec.getResponse();
+ String fallbackUrl = "/web/index.xhtml"; // TODO make configurable
+ // ec.redirect(url);
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace("redirecting to {}, fallbackUrl={}", servletResponse.toString(), fallbackUrl);
+ }
+
+ WebUtils.redirectToSavedRequest((ServletRequest) ec.getRequest(), servletResponse, fallbackUrl);
+ } catch (IOException | AuthenticationException ex) {
+ // Could catch a subclass of AuthenticationException if you like
+ String hint = "Error while authenticating user " + username;
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(hint, ex);
+ }
+
+ if (ex.getMessage() != null) {
+ hint += "Reason: " + ex.getMessage();
+ } else {
+ hint += "Reason: " + ex.toString();
+ }
+ if ((ex.getCause() != null) && (ex.getCause().getMessage() != null)) {
+ hint += "Rootcause: " + ex.getMessage();
+
+ LOGGER.error(hint);
+ }
+ FacesUtil.addGlobalErrorMessage("Login failed", hint);
+
+ AccountEntity account = accountService.getAccountEntity(username, false);
+ if (account != null) {
+ accountService.addLoginError(account);
+ }
+ } finally {
+ token.clear();
+ }
+ }
+
+ public void logout() {
+ Subject currentUser = SecurityUtils.getSubject();
+ try {
+ currentUser.logout();
+
+ ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
+
+ // check if redirect shall be executed
+ // default setting is yes to /login.xhtml
+ // can be overwritten using parameters
+ // de.muehlencord.shared.account.loginview.executeredirect boolean true/false
+ // de.muehlencord.shared.account.loginview.redirecttarget path to redirect to (without external context, will be added automatically)
+ String executeRedirectString = ec.getInitParameter("de.muehlencord.shared.account.loginview.executeredirect");
+ boolean executeRedirect = true;
+ if (executeRedirectString != null) {
+ executeRedirect = Boolean.parseBoolean(executeRedirectString);
+ }
+
+ String redirectTarget = ec.getInitParameter("de.muehlencord.shared.account.loginview.redirecttarget");
+ if ((redirectTarget == null) || (redirectTarget.equals(""))) {
+ redirectTarget = "/login.xhtml";
+ }
+
+ if (executeRedirect) {
+ String url = ec.getRequestContextPath() + redirectTarget;
+ ec.redirect(url);
+ }
+
+ } catch (Exception e) {
+ LOGGER.warn(e.toString());
+ }
+ }
+
+ public String executePasswordReset() {
+ boolean passwordResetted = accountService.resetPassword(username, password, resetPasswordToken);
+ if (passwordResetted) {
+ // TODO add email notification on updated user account
+ FacesUtil.addGlobalInfoMessage("Password resetted", null);
+ return login();
+ } else {
+ // TODO add email notificaton on failed password reset
+ FacesUtil.addGlobalErrorMessage("Password reset failed", null);
+ return login();
+ }
+ }
+
+ /* **** naviation rules **** */
+ public String login() {
+ return "/login.xhtml"; // TODO make configurable
+ }
+
+ /* *** getter / setter */
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String un) {
+ this.username = un;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String pw) {
+ this.password = pw;
+ }
+
+ public boolean isRememberMe() {
+ return rememberMe;
+ }
+
+ public void setRememberMe(boolean rememberMe) {
+ this.rememberMe = rememberMe;
+ }
+
+ public String getResetPasswordToken() {
+ return resetPasswordToken;
+ }
+
+ public void setResetPasswordToken(String resetPasswordToken) {
+ this.resetPasswordToken = resetPasswordToken;
+ }
+
+}
diff --git a/account/src/main/java/de/muehlencord/shared/account/presentation/LostPasswordView.java b/account/src/main/java/de/muehlencord/shared/account/presentation/LostPasswordView.java
index 439d2d6..b6168b6 100644
--- a/account/src/main/java/de/muehlencord/shared/account/presentation/LostPasswordView.java
+++ b/account/src/main/java/de/muehlencord/shared/account/presentation/LostPasswordView.java
@@ -1,48 +1,48 @@
-package de.muehlencord.shared.account.presentation;
-
-import de.muehlencord.shared.account.business.account.boundary.AccountControl;
-import de.muehlencord.shared.jeeutil.FacesUtil;
-import java.io.Serializable;
-import javax.ejb.EJB;
-import javax.faces.view.ViewScoped;
-import javax.inject.Named;
-
-/**
- *
- * @author joern@muehlencord.de
- */
-@Named (value = "lostPasswordView")
-@ViewScoped
-public class LostPasswordView implements Serializable {
-
- private static final long serialVersionUID = -1793445795465830069L;
-
- @EJB
- private AccountControl accountService;
-
- private String userName;
- private boolean passwordResetStarted = false;
-
- public String initPasswordReset() {
- if (accountService.initPasswordReset(userName)) {
- passwordResetStarted = true;
- FacesUtil.addGlobalInfoMessage("Password reset started.", "Please check your email account.");
- } else {
- FacesUtil.addGlobalErrorMessage("Error while resetting password.", "Please contact your administrator.");
- }
- return "/login.xhtml"; // TODO make configurable, get from LoginView?
- }
-
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public boolean getPasswordResetStarted() {
- return passwordResetStarted;
- }
-
-}
+package de.muehlencord.shared.account.presentation;
+
+import de.muehlencord.shared.account.business.account.control.AccountControl;
+import de.muehlencord.shared.jeeutil.FacesUtil;
+import java.io.Serializable;
+import javax.ejb.EJB;
+import javax.faces.view.ViewScoped;
+import javax.inject.Named;
+
+/**
+ *
+ * @author joern@muehlencord.de
+ */
+@Named (value = "lostPasswordView")
+@ViewScoped
+public class LostPasswordView implements Serializable {
+
+ private static final long serialVersionUID = -1793445795465830069L;
+
+ @EJB
+ private AccountControl accountService;
+
+ private String userName;
+ private boolean passwordResetStarted = false;
+
+ public String initPasswordReset() {
+ if (accountService.initPasswordReset(userName)) {
+ passwordResetStarted = true;
+ FacesUtil.addGlobalInfoMessage("Password reset started.", "Please check your email account.");
+ } else {
+ FacesUtil.addGlobalErrorMessage("Error while resetting password.", "Please contact your administrator.");
+ }
+ return "/login.xhtml"; // TODO make configurable, get from LoginView?
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public boolean getPasswordResetStarted() {
+ return passwordResetStarted;
+ }
+
+}
diff --git a/jeeutil/pom.xml b/jeeutil/pom.xml
index fb8fa04..34d1aae 100644
--- a/jeeutil/pom.xml
+++ b/jeeutil/pom.xml
@@ -1,62 +1,62 @@
-
-
- 4.0.0
-
- shared
- de.muehlencord
- 1.1-SNAPSHOT
-
-
- de.muehlencord.shared
- shared-jeeutil
- 1.1-SNAPSHOT
- jar
-
- shared-jeeutil
-
-
-
- com.inversoft
- prime-jwt
-
-
- javax
- javaee-api
- provided
-
-
- org.slf4j
- slf4j-api
- provided
-
-
- org.hibernate
- hibernate-core
- provided
-
-
- org.primefaces
- primefaces
- jar
- provided
-
-
- org.apache.shiro
- shiro-web
- provided
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-ejb-plugin
-
- 3.1
-
-
-
-
-
-
+
+
+ 4.0.0
+
+ shared
+ de.muehlencord
+ 1.1-SNAPSHOT
+
+
+ de.muehlencord.shared
+ shared-jeeutil
+ 1.1-SNAPSHOT
+ ejb
+
+ shared-jeeutil
+
+
+
+ com.inversoft
+ prime-jwt
+
+
+ javax
+ javaee-api
+ provided
+
+
+ org.slf4j
+ slf4j-api
+ provided
+
+
+ org.hibernate
+ hibernate-core
+ provided
+
+
+ org.primefaces
+ primefaces
+ jar
+ provided
+
+
+ org.apache.shiro
+ shiro-web
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-ejb-plugin
+
+ 3.1
+
+
+
+
+
+
diff --git a/account-ui/src/main/java/de/muehlencord/shared/account/web/TransactionJoinInterceptor.java b/jeeutil/src/main/java/de/muehlencord/shared/jeeutil/TransactionJoinInterceptor.java
similarity index 89%
rename from account-ui/src/main/java/de/muehlencord/shared/account/web/TransactionJoinInterceptor.java
rename to jeeutil/src/main/java/de/muehlencord/shared/jeeutil/TransactionJoinInterceptor.java
index 39f5089..c2f2755 100644
--- a/account-ui/src/main/java/de/muehlencord/shared/account/web/TransactionJoinInterceptor.java
+++ b/jeeutil/src/main/java/de/muehlencord/shared/jeeutil/TransactionJoinInterceptor.java
@@ -1,4 +1,4 @@
-package de.muehlencord.shared.account.web;
+package de.muehlencord.shared.jeeutil;
import javax.annotation.Priority;
import javax.inject.Inject;
@@ -38,9 +38,9 @@ public class TransactionJoinInterceptor {
@AroundInvoke
public Object joinTransaction(InvocationContext context) throws Exception {
if (em.isJoinedToTransaction()) {
- LOGGER.info("transaction already joined");
+ LOGGER.trace("transaction already joined");
} else {
- LOGGER.info("joining transaction");
+ LOGGER.trace("joining transaction");
em.joinTransaction();
}
return context.proceed();