fixed injection issue when using WF14
This commit is contained in:
@ -1,151 +1,151 @@
|
|||||||
<?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-account-ui</artifactId>
|
<artifactId>shared-account-ui</artifactId>
|
||||||
<version>1.1-SNAPSHOT</version>
|
<version>1.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<name>shared-account-ui</name>
|
<name>shared-account-ui</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<timestamp>${maven.build.timestamp}</timestamp>
|
<timestamp>${maven.build.timestamp}</timestamp>
|
||||||
<applicationUuid>143a2bd3-7e0b-4162-a76e-3031331c7dfe</applicationUuid>
|
<applicationUuid>143a2bd3-7e0b-4162-a76e-3031331c7dfe</applicationUuid>
|
||||||
<maven.compiler.source>10</maven.compiler.source>
|
<maven.compiler.source>10</maven.compiler.source>
|
||||||
<maven.compiler.target>10</maven.compiler.target>
|
<maven.compiler.target>10</maven.compiler.target>
|
||||||
|
|
||||||
<!-- defaul filter if not selected via profile -->
|
<!-- defaul filter if not selected via profile -->
|
||||||
<filter.name>development</filter.name>
|
<filter.name>development</filter.name>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.primefaces</groupId>
|
<groupId>org.primefaces</groupId>
|
||||||
<artifactId>primefaces</artifactId>
|
<artifactId>primefaces</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Admin faces template -->
|
<!-- Admin faces template -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.adminfaces</groupId>
|
<groupId>com.github.adminfaces</groupId>
|
||||||
<artifactId>admin-template</artifactId>
|
<artifactId>admin-template</artifactId>
|
||||||
<version>1.0.0-RC19</version>
|
<version>1.0.0-RC19</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Omnifaces, faces utils -->
|
<!-- Omnifaces, faces utils -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.omnifaces</groupId>
|
<groupId>org.omnifaces</groupId>
|
||||||
<artifactId>omnifaces</artifactId>
|
<artifactId>omnifaces</artifactId>
|
||||||
<version>2.7</version>
|
<version>3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Apache Shiro, Security API -->
|
<!-- Apache Shiro, Security API -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.shiro</groupId>
|
<groupId>org.apache.shiro</groupId>
|
||||||
<artifactId>shiro-core</artifactId>
|
<artifactId>shiro-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.shiro</groupId>
|
<groupId>org.apache.shiro</groupId>
|
||||||
<artifactId>shiro-web</artifactId>
|
<artifactId>shiro-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.muehlencord.shared</groupId>
|
<groupId>de.muehlencord.shared</groupId>
|
||||||
<artifactId>shared-shiro-faces</artifactId>
|
<artifactId>shared-shiro-faces</artifactId>
|
||||||
<version>1.1-SNAPSHOT</version>
|
<version>1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.muehlencord.shared</groupId>
|
<groupId>de.muehlencord.shared</groupId>
|
||||||
<artifactId>shared-account</artifactId>
|
<artifactId>shared-account</artifactId>
|
||||||
<version>1.1-SNAPSHOT</version>
|
<version>1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.muehlencord.shared</groupId>
|
<groupId>de.muehlencord.shared</groupId>
|
||||||
<artifactId>shared-util</artifactId>
|
<artifactId>shared-util</artifactId>
|
||||||
<version>1.1-SNAPSHOT</version>
|
<version>1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<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>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.muehlencord.sf</groupId>
|
<groupId>de.muehlencord.sf</groupId>
|
||||||
<artifactId>filter</artifactId>
|
<artifactId>filter</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax</groupId>
|
<groupId>javax</groupId>
|
||||||
<artifactId>javaee-web-api</artifactId>
|
<artifactId>javaee-web-api</artifactId>
|
||||||
<version>7.0</version>
|
<version>7.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<filters>
|
<filters>
|
||||||
<filter>${basedir}/src/main/filters/${filter.name}.properties</filter>
|
<filter>${basedir}/src/main/filters/${filter.name}.properties</filter>
|
||||||
</filters>
|
</filters>
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<!-- fill buildinformation file -->
|
<!-- fill buildinformation file -->
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*.properties</include>
|
<include>**/*.properties</include>
|
||||||
<include>**/*.xml</include>
|
<include>**/*.xml</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<finalName>account</finalName>
|
<finalName>account</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>10</source>
|
<source>10</source>
|
||||||
<target>10</target>
|
<target>10</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.2.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
<webResources>
|
<webResources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>${basedir}/src/main/webapp</directory>
|
<directory>${basedir}/src/main/webapp</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
<includes>
|
<includes>
|
||||||
<include>WEB-INF/web.xml</include>
|
<include>WEB-INF/web.xml</include>
|
||||||
<include>WEB-INF/shiro.ini</include>
|
<include>WEB-INF/shiro.ini</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</webResources>
|
</webResources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>development</id>
|
<id>development</id>
|
||||||
<properties>
|
<properties>
|
||||||
<filter.name>development</filter.name>
|
<filter.name>development</filter.name>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>production</id>
|
<id>production</id>
|
||||||
<properties>
|
<properties>
|
||||||
<filter.name>production</filter.name>
|
<filter.name>production</filter.name>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,57 +1,57 @@
|
|||||||
package de.muehlencord.shared.account.web.presentation;
|
package de.muehlencord.shared.account.web.presentation;
|
||||||
|
|
||||||
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.control.ApplicationRoleControl;
|
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 de.muehlencord.shared.account.util.AccountPU;
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.ejb.EJB;
|
import javax.ejb.EJB;
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.application.FacesMessage;
|
||||||
import javax.faces.component.UIComponent;
|
import javax.faces.component.UIComponent;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.faces.validator.FacesValidator;
|
import javax.faces.validator.FacesValidator;
|
||||||
import javax.faces.validator.Validator;
|
import javax.faces.validator.Validator;
|
||||||
import javax.faces.validator.ValidatorException;
|
import javax.faces.validator.ValidatorException;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
@FacesValidator("uniqueApplicationRoleNameValidator")
|
@FacesValidator("uniqueApplicationRoleNameValidator")
|
||||||
public class UniqueApplicationRoleNameValidator implements Validator, Serializable {
|
public class UniqueApplicationRoleNameValidator implements Validator, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 8165013107453616719L;
|
private static final long serialVersionUID = 8165013107453616719L;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@AccountPU
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
@EJB
|
@Inject
|
||||||
ApplicationRoleControl applicationRoleControl;
|
ApplicationRoleControl applicationRoleControl;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
|
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
|
||||||
Object applicationObj = component.getAttributes().get("application");
|
Object applicationObj = component.getAttributes().get("application");
|
||||||
if ((applicationObj != null) && (applicationObj instanceof ApplicationEntity)) {
|
if ((applicationObj != null) && (applicationObj instanceof ApplicationEntity)) {
|
||||||
ApplicationEntity application = (ApplicationEntity) applicationObj;
|
ApplicationEntity application = (ApplicationEntity) applicationObj;
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Role name invalid", "Role name must not be empty"));
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Role name invalid", "Role name must not be empty"));
|
||||||
}
|
}
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
String roleName = (String) value;
|
String roleName = (String) value;
|
||||||
ApplicationRoleEntity existingRole = applicationRoleControl.findByName(application, roleName);
|
ApplicationRoleEntity existingRole = applicationRoleControl.findByName(application, roleName);
|
||||||
if (existingRole != null) {
|
if (existingRole != null) {
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Role name invalid", "Role already exists"));
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Role name invalid", "Role already exists"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Role name invalid", "Role name must be a string value"));
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Role name invalid", "Role name must be a string value"));
|
||||||
// TODO add IPRS logger - someone is trying to cheat
|
// TODO add IPRS logger - someone is trying to cheat
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Application not set", "Permission name cannot be set if application is unknown"));
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Application not set", "Permission name cannot be set if application is unknown"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,13 +3,13 @@ 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 java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.ejb.EJB;
|
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.application.FacesMessage;
|
||||||
import javax.faces.component.UIComponent;
|
import javax.faces.component.UIComponent;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.faces.validator.FacesValidator;
|
import javax.faces.validator.FacesValidator;
|
||||||
import javax.faces.validator.Validator;
|
import javax.faces.validator.Validator;
|
||||||
import javax.faces.validator.ValidatorException;
|
import javax.faces.validator.ValidatorException;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public class UniqueApplicationValidator implements Validator, Serializable {
|
|||||||
private static final long serialVersionUID = 2526409681909574670L;
|
private static final long serialVersionUID = 2526409681909574670L;
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(UniqueApplicationValidator.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(UniqueApplicationValidator.class);
|
||||||
|
|
||||||
@EJB
|
@Inject
|
||||||
ApplicationService applicationService;
|
ApplicationService applicationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,61 +1,60 @@
|
|||||||
package de.muehlencord.shared.account.web.presentation;
|
package de.muehlencord.shared.account.web.presentation;
|
||||||
|
|
||||||
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.control.ApplicationPermissionControl;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
import de.muehlencord.shared.account.util.AccountPU;
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.ejb.EJB;
|
import javax.faces.application.FacesMessage;
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.component.UIComponent;
|
||||||
import javax.faces.component.UIComponent;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.validator.FacesValidator;
|
||||||
import javax.faces.validator.FacesValidator;
|
import javax.faces.validator.Validator;
|
||||||
import javax.faces.validator.Validator;
|
import javax.faces.validator.ValidatorException;
|
||||||
import javax.faces.validator.ValidatorException;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Inject;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManager;
|
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>
|
*/
|
||||||
*/
|
@FacesValidator("uniquePermissionNameValidator")
|
||||||
@FacesValidator("uniquePermissionNameValidator")
|
public class UniquePermissionNameValidator implements Validator, Serializable {
|
||||||
public class UniquePermissionNameValidator implements Validator, Serializable {
|
|
||||||
|
private static final long serialVersionUID = 2526409681909574670L;
|
||||||
private static final long serialVersionUID = 2526409681909574670L;
|
private static final Logger LOGGER = LoggerFactory.getLogger(UniquePermissionNameValidator.class);
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(UniquePermissionNameValidator.class);
|
|
||||||
|
@Inject
|
||||||
@Inject
|
@AccountPU
|
||||||
@AccountPU
|
EntityManager em;
|
||||||
EntityManager em;
|
|
||||||
|
@Inject
|
||||||
@EJB
|
ApplicationPermissionControl applicationPermissionControl;
|
||||||
ApplicationPermissionControl applicationPermissionControl;
|
|
||||||
|
@Override
|
||||||
@Override
|
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
|
||||||
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
|
Object applicationObj = component.getAttributes().get("application");
|
||||||
Object applicationObj = component.getAttributes().get("application");
|
if ((applicationObj != null) && (applicationObj instanceof ApplicationEntity)) {
|
||||||
if ((applicationObj != null) && (applicationObj instanceof ApplicationEntity)) {
|
ApplicationEntity application = (ApplicationEntity) applicationObj;
|
||||||
ApplicationEntity application = (ApplicationEntity) applicationObj;
|
if (value == null) {
|
||||||
if (value == null) {
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Permission name invalid", "Permission name must not be empty"));
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Permission name invalid", "Permission name must not be empty"));
|
}
|
||||||
}
|
if (value instanceof String) {
|
||||||
if (value instanceof String) {
|
String permissionName = (String) value;
|
||||||
String permissionName = (String) value;
|
ApplicationPermissionEntity existingPermission = applicationPermissionControl.findPermissionByName(application, permissionName);
|
||||||
ApplicationPermissionEntity existingPermission = applicationPermissionControl.findPermissionByName(application, permissionName);
|
if (existingPermission != null) {
|
||||||
if (existingPermission != null) {
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Permission name invalid", "Permission already exists"));
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Permission name invalid", "Permission already exists"));
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Permission name invalid", "Permission name must be a string value"));
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Permission name invalid", "Permission name must be a string value"));
|
// TODO add IPRS logger - someone is trying to cheat
|
||||||
// TODO add IPRS logger - someone is trying to cheat
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Application not set", "Permission name cannot be set if application is unknown"));
|
||||||
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Application not set", "Permission name cannot be set if application is unknown"));
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,149 +1,150 @@
|
|||||||
/*
|
/*
|
||||||
* 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.business.application.control;
|
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;
|
||||||
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.account.util.AccountPU;
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
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.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.OptimisticLockException;
|
import javax.persistence.OptimisticLockException;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
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>
|
||||||
*/
|
*/
|
||||||
@Stateless
|
@Stateless
|
||||||
public class ApplicationRoleControl implements Serializable {
|
public class ApplicationRoleControl implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 5962478269550134748L;
|
private static final long serialVersionUID = 5962478269550134748L;
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationRoleControl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationRoleControl.class);
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
ApplicationPermissionControl applicationPermissionControl;
|
ApplicationPermissionControl applicationPermissionControl;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@AccountPU
|
@AccountPU
|
||||||
EntityManager em;
|
EntityManager em;
|
||||||
|
|
||||||
public List<ApplicationRoleEntity> getAllRoles(ApplicationEntity app) {
|
public List<ApplicationRoleEntity> getAllRoles(ApplicationEntity app) {
|
||||||
Query query = em.createNamedQuery("ApplicationRoleEntity.findAll");
|
Query query = em.createNamedQuery("ApplicationRoleEntity.findAll");
|
||||||
query.setParameter("application", app);
|
query.setParameter("application", app);
|
||||||
|
|
||||||
List<ApplicationRoleEntity> roles = query.getResultList();
|
List<ApplicationRoleEntity> roles = query.getResultList();
|
||||||
if (roles == null) {
|
if (roles == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void createOrUpdate(ApplicationEntity application, String name, String description) {
|
public void createOrUpdate(ApplicationEntity application, String name, String description) {
|
||||||
ApplicationRoleEntity role = findByName(application, name);
|
ApplicationRoleEntity role = findByName(application, name);
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
role = new ApplicationRoleEntity(application, name, description);
|
role = new ApplicationRoleEntity(application, name, description);
|
||||||
em.persist(role);
|
em.persist(role);
|
||||||
} else {
|
} else {
|
||||||
role.setRoleDescription(description);
|
role.setRoleDescription(description);
|
||||||
em.merge(role);
|
em.merge(role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void create(ApplicationRoleEntity role) {
|
public void create(ApplicationRoleEntity role) {
|
||||||
em.persist(role);
|
em.persist(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void update(ApplicationRoleEntity role) {
|
public void update(ApplicationRoleEntity role) {
|
||||||
em.merge(role);
|
em.merge(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(ApplicationRoleEntity role) throws AccountException {
|
@Transactional
|
||||||
ApplicationRoleEntity existingRole = attach(role);
|
public void delete(ApplicationRoleEntity role) throws AccountException {
|
||||||
em.remove(existingRole);
|
ApplicationRoleEntity existingRole = attach(role);
|
||||||
}
|
em.remove(existingRole);
|
||||||
|
}
|
||||||
public ApplicationRoleEntity attach(ApplicationRoleEntity role) throws AccountException {
|
|
||||||
try {
|
public ApplicationRoleEntity attach(ApplicationRoleEntity role) throws AccountException {
|
||||||
return em.merge(role);
|
try {
|
||||||
} catch (OptimisticLockException ex) {
|
return em.merge(role);
|
||||||
throw new AccountException("Entity updated / deleted, please reload", true);
|
} catch (OptimisticLockException ex) {
|
||||||
}
|
throw new AccountException("Entity updated / deleted, please reload", true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public ApplicationRoleEntity findByName(ApplicationEntity application, String name) {
|
|
||||||
Query query = em.createNamedQuery("ApplicationRoleEntity.findByRoleName");
|
public ApplicationRoleEntity findByName(ApplicationEntity application, String name) {
|
||||||
query.setParameter("application", application);
|
Query query = em.createNamedQuery("ApplicationRoleEntity.findByRoleName");
|
||||||
query.setParameter("roleName", name);
|
query.setParameter("application", application);
|
||||||
List<ApplicationRoleEntity> permissions = query.getResultList();
|
query.setParameter("roleName", name);
|
||||||
if ((permissions == null) || (permissions.isEmpty())) {
|
List<ApplicationRoleEntity> permissions = query.getResultList();
|
||||||
return null;
|
if ((permissions == null) || (permissions.isEmpty())) {
|
||||||
} else {
|
return null;
|
||||||
return permissions.get(0);
|
} else {
|
||||||
}
|
return permissions.get(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public List<ApplicationPermissionEntity> getRolePermissions(ApplicationRoleEntity role) throws AccountException {
|
|
||||||
ApplicationRoleEntity existingRole = em.find(ApplicationRoleEntity.class, role.getId());
|
public List<ApplicationPermissionEntity> getRolePermissions(ApplicationRoleEntity role) throws AccountException {
|
||||||
List<ApplicationPermissionEntity> permissions = existingRole.getApplicationPermissionList();
|
ApplicationRoleEntity existingRole = em.find(ApplicationRoleEntity.class, role.getId());
|
||||||
permissions.size(); // force list to load
|
List<ApplicationPermissionEntity> permissions = existingRole.getApplicationPermissionList();
|
||||||
return permissions;
|
permissions.size(); // force list to load
|
||||||
}
|
return permissions;
|
||||||
|
}
|
||||||
public List<ApplicationPermissionEntity> getNotAssignedApplicationPermissions(ApplicationRoleEntity role) {
|
|
||||||
try {
|
public List<ApplicationPermissionEntity> getNotAssignedApplicationPermissions(ApplicationRoleEntity role) {
|
||||||
List<ApplicationPermissionEntity> rolePermissions = getRolePermissions(role);
|
try {
|
||||||
List<ApplicationPermissionEntity> allPermssions = applicationPermissionControl.getApplicationPermissions(role.getApplication());
|
List<ApplicationPermissionEntity> rolePermissions = getRolePermissions(role);
|
||||||
|
List<ApplicationPermissionEntity> allPermssions = applicationPermissionControl.getApplicationPermissions(role.getApplication());
|
||||||
List<ApplicationPermissionEntity> missingPermissions = new ArrayList<>();
|
|
||||||
allPermssions.stream().filter((perm) -> (!rolePermissions.contains(perm))).forEachOrdered((perm) -> {
|
List<ApplicationPermissionEntity> missingPermissions = new ArrayList<>();
|
||||||
missingPermissions.add(perm);
|
allPermssions.stream().filter((perm) -> (!rolePermissions.contains(perm))).forEachOrdered((perm) -> {
|
||||||
});
|
missingPermissions.add(perm);
|
||||||
return missingPermissions;
|
});
|
||||||
} catch (AccountException ex) {
|
return missingPermissions;
|
||||||
if (LOGGER.isDebugEnabled()) {
|
} catch (AccountException ex) {
|
||||||
LOGGER.debug(ex.toString(), ex);
|
if (LOGGER.isDebugEnabled()) {
|
||||||
} else {
|
LOGGER.debug(ex.toString(), ex);
|
||||||
LOGGER.debug(ex.toString());
|
} else {
|
||||||
}
|
LOGGER.debug(ex.toString());
|
||||||
return null;
|
}
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@Transactional
|
|
||||||
public void addPermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
@Transactional
|
||||||
ApplicationRoleEntity existingRole = attach(role);
|
public void addPermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
||||||
if (existingRole.getApplicationPermissionList() == null) {
|
ApplicationRoleEntity existingRole = attach(role);
|
||||||
existingRole.setApplicationPermissionList(new ArrayList<>());
|
if (existingRole.getApplicationPermissionList() == null) {
|
||||||
}
|
existingRole.setApplicationPermissionList(new ArrayList<>());
|
||||||
existingRole.getApplicationPermissionList().add(permission);
|
}
|
||||||
em.merge(role);
|
existingRole.getApplicationPermissionList().add(permission);
|
||||||
}
|
em.merge(role);
|
||||||
|
}
|
||||||
@Transactional
|
|
||||||
public void removePermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
@Transactional
|
||||||
ApplicationRoleEntity existingRole = attach(role);
|
public void removePermission(ApplicationRoleEntity role, ApplicationPermissionEntity permission) throws AccountException {
|
||||||
if ((existingRole.getApplicationPermissionList() != null) && (existingRole.getApplicationPermissionList().contains(permission))) {
|
ApplicationRoleEntity existingRole = attach(role);
|
||||||
existingRole.getApplicationPermissionList().remove(permission);
|
if ((existingRole.getApplicationPermissionList() != null) && (existingRole.getApplicationPermissionList().contains(permission))) {
|
||||||
}
|
existingRole.getApplicationPermissionList().remove(permission);
|
||||||
em.merge(role);
|
}
|
||||||
}
|
em.merge(role);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user