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