fixed account handling
fixed view CDI integration
This commit is contained in:
@ -12,9 +12,10 @@ 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.enterprise.context.SessionScoped;
|
import javax.faces.view.ViewScoped;
|
||||||
import javax.faces.bean.ManagedBean;
|
import javax.inject.Named;
|
||||||
import javax.faces.bean.ManagedProperty;
|
import javax.inject.Inject;
|
||||||
|
import org.primefaces.event.SelectEvent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -22,14 +23,14 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author jomu
|
* @author jomu
|
||||||
*/
|
*/
|
||||||
@ManagedBean(name = "accountView")
|
@ViewScoped
|
||||||
@SessionScoped
|
@Named("accountView")
|
||||||
public class AccountView implements Serializable {
|
public class AccountView implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -8050582392249849438L;
|
private static final long serialVersionUID = -8050582392249849438L;
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(AccountView.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(AccountView.class);
|
||||||
|
|
||||||
@ManagedProperty(value = "#{applicationView}")
|
@Inject
|
||||||
private ApplicationView applicationView;
|
private ApplicationView applicationView;
|
||||||
@EJB
|
@EJB
|
||||||
private AccountControl accountService;
|
private AccountControl accountService;
|
||||||
@ -50,8 +51,6 @@ public class AccountView implements Serializable {
|
|||||||
// account currently on edit
|
// account currently on edit
|
||||||
private AccountEntity currentAccount;
|
private AccountEntity currentAccount;
|
||||||
private List<ApplicationRoleEntity> currentAccountRoles = null;
|
private List<ApplicationRoleEntity> currentAccountRoles = null;
|
||||||
// boolean flag to toggle buttons which require an account to be selected
|
|
||||||
private boolean accountSelected = false;
|
|
||||||
|
|
||||||
public List<AccountEntity> getAccounts() {
|
public List<AccountEntity> getAccounts() {
|
||||||
if (accountList == null) {
|
if (accountList == null) {
|
||||||
@ -68,6 +67,17 @@ public class AccountView implements Serializable {
|
|||||||
return applicationRoles;
|
return applicationRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void selectAccount(SelectEvent event) {
|
||||||
|
if (currentAccount == null) {
|
||||||
|
applicationRoles = null;
|
||||||
|
currentAccountRoles = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getAccountSelected() {
|
||||||
|
return currentAccount != null;
|
||||||
|
}
|
||||||
|
|
||||||
public void newAccount() {
|
public void newAccount() {
|
||||||
currentAccount = new AccountEntity();
|
currentAccount = new AccountEntity();
|
||||||
currentAccount.setUsername(null);
|
currentAccount.setUsername(null);
|
||||||
@ -84,7 +94,7 @@ public class AccountView implements Serializable {
|
|||||||
this.currentAccountRoles = new ArrayList<>();
|
this.currentAccountRoles = new ArrayList<>();
|
||||||
if (currentAccount.getApplicationRoleList() != null) {
|
if (currentAccount.getApplicationRoleList() != null) {
|
||||||
currentAccountRoles.addAll(currentAccount.getApplicationRoleList());
|
currentAccountRoles.addAll(currentAccount.getApplicationRoleList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +111,7 @@ public class AccountView implements Serializable {
|
|||||||
currentAccount.setUsername(null);
|
currentAccount.setUsername(null);
|
||||||
FacesUtil.addErrorMessage("editDialogMessaegs", "Create new account failed", "Account with username " + username + " already exists");
|
FacesUtil.addErrorMessage("editDialogMessaegs", "Create new account failed", "Account with username " + username + " already exists");
|
||||||
} else {
|
} else {
|
||||||
accountService.saveAccount(currentAccount, currentAccountRoles);
|
accountService.saveAccount(applicationView.getCurrentApplication(), currentAccount, currentAccountRoles);
|
||||||
selectAccount();
|
|
||||||
if (currentAccount.getId() == null) {
|
if (currentAccount.getId() == null) {
|
||||||
// this was a new account
|
// this was a new account
|
||||||
// force accounts to be loaded from database again
|
// force accounts to be loaded from database again
|
||||||
@ -117,8 +126,7 @@ public class AccountView implements Serializable {
|
|||||||
accountList.remove(currentAccount);
|
accountList.remove(currentAccount);
|
||||||
FacesUtil.addGlobalInfoMessage("Info", "Account " + currentAccount.getUsername() + " deleted");
|
FacesUtil.addGlobalInfoMessage("Info", "Account " + currentAccount.getUsername() + " deleted");
|
||||||
currentAccount = null;
|
currentAccount = null;
|
||||||
currentAccountRoles = null;
|
currentAccountRoles = null;
|
||||||
deselectAccount();
|
|
||||||
} catch (AccountException ex) {
|
} catch (AccountException ex) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug(ex.toString(), ex);
|
LOGGER.debug(ex.toString(), ex);
|
||||||
@ -130,14 +138,6 @@ public class AccountView implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectAccount() {
|
|
||||||
this.accountSelected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deselectAccount() {
|
|
||||||
this.accountSelected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showDisabledAccountsChange() {
|
public void showDisabledAccountsChange() {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("show diabled accounts changed to {}", showDisabledAccounts);
|
LOGGER.debug("show diabled accounts changed to {}", showDisabledAccounts);
|
||||||
@ -150,11 +150,11 @@ public class AccountView implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* **** getter / setter **** */
|
/* **** getter / setter **** */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setter for managed property applicationView
|
* setter for managed property applicationView
|
||||||
|
*
|
||||||
* @param applicationView the applicaton view to inject
|
* @param applicationView the applicaton view to inject
|
||||||
*/
|
*/
|
||||||
public void setApplicationView(ApplicationView applicationView) {
|
public void setApplicationView(ApplicationView applicationView) {
|
||||||
this.applicationView = applicationView;
|
this.applicationView = applicationView;
|
||||||
}
|
}
|
||||||
@ -167,14 +167,6 @@ public class AccountView implements Serializable {
|
|||||||
this.currentAccount = currentAccount;
|
this.currentAccount = currentAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAccountSelected() {
|
|
||||||
return accountSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAccountSelected(boolean accountSelected) {
|
|
||||||
this.accountSelected = accountSelected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isShowDisabledAccounts() {
|
public boolean isShowDisabledAccounts() {
|
||||||
return showDisabledAccounts;
|
return showDisabledAccounts;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,9 @@ 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.faces.bean.ManagedBean;
|
import javax.annotation.PreDestroy;
|
||||||
import javax.faces.bean.SessionScoped;
|
import javax.inject.Named;
|
||||||
|
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;
|
||||||
@ -16,8 +17,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
@ManagedBean (name="applicationView")
|
|
||||||
@SessionScoped
|
@SessionScoped
|
||||||
|
@Named("applicationView")
|
||||||
public class ApplicationView implements Serializable {
|
public class ApplicationView implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -5515249316880163539L;
|
private static final long serialVersionUID = -5515249316880163539L;
|
||||||
@ -29,14 +30,25 @@ public class ApplicationView implements Serializable {
|
|||||||
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()) {
|
||||||
|
LOGGER.debug("post construct executed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void predestroy() {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("Predestroy executed");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApplicationEntity> getAllApplications() {
|
public List<ApplicationEntity> getAllApplications() {
|
||||||
@ -79,19 +91,19 @@ public class ApplicationView implements Serializable {
|
|||||||
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,9 +23,9 @@ import de.muehlencord.shared.jeeutil.FacesUtil;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.ejb.EJB;
|
import javax.ejb.EJB;
|
||||||
import javax.faces.bean.ManagedBean;
|
import javax.inject.Named;
|
||||||
import javax.faces.bean.ManagedProperty;
|
import javax.faces.view.ViewScoped;
|
||||||
import javax.faces.bean.SessionScoped;
|
import javax.inject.Inject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -33,14 +33,14 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
@ManagedBean(name = "permissionView")
|
@ViewScoped
|
||||||
@SessionScoped
|
@Named("permissionView")
|
||||||
public class PermissionView implements Serializable {
|
public class PermissionView implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -1469453490360990772L;
|
private static final long serialVersionUID = -1469453490360990772L;
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(PermissionView.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(PermissionView.class);
|
||||||
|
|
||||||
@ManagedProperty(value = "#{applicationView}")
|
@Inject
|
||||||
private ApplicationView applicationView;
|
private ApplicationView applicationView;
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
|
|||||||
@ -25,9 +25,9 @@ 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.bean.ManagedBean;
|
import javax.faces.view.ViewScoped;
|
||||||
import javax.faces.bean.ManagedProperty;
|
import javax.inject.Named;
|
||||||
import javax.faces.bean.SessionScoped;
|
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;
|
||||||
@ -36,14 +36,14 @@ import org.slf4j.LoggerFactory;
|
|||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
@ManagedBean(name = "roleView")
|
@ViewScoped
|
||||||
@SessionScoped
|
@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);
|
||||||
|
|
||||||
@ManagedProperty(value = "#{applicationView}")
|
@Inject
|
||||||
private ApplicationView applicationView;
|
private ApplicationView applicationView;
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
|
|||||||
@ -32,9 +32,6 @@
|
|||||||
<span>Accounts</span>
|
<span>Accounts</span>
|
||||||
</p:link>
|
</p:link>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<p:commandLink target="/logout.xhtml" actionListener="#{loginView.logout}">
|
<p:commandLink target="/logout.xhtml" actionListener="#{loginView.logout}">
|
||||||
<i class="fa fa-sign-out"></i>
|
<i class="fa fa-sign-out"></i>
|
||||||
|
|||||||
@ -21,7 +21,7 @@ limitations under the License.
|
|||||||
xmlns:h="http://xmlns.jcp.org/jsf/html">
|
xmlns:h="http://xmlns.jcp.org/jsf/html">
|
||||||
|
|
||||||
<ui:define name="head">
|
<ui:define name="head">
|
||||||
<title>Product Catalog Designer</title>
|
<title>Account UI</title>
|
||||||
<link rel="shortcut icon" href="#{resource['images/favicon/favicon.ico']}" />
|
<link rel="shortcut icon" href="#{resource['images/favicon/favicon.ico']}" />
|
||||||
<h:outputStylesheet name="css/admin.css" />
|
<h:outputStylesheet name="css/admin.css" />
|
||||||
</ui:define>
|
</ui:define>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<p:dataTable id="accountTable" value="#{accountView.accounts}" var="account" rowKey="#{account.username}" selectionMode="single" selection="#{accountView.currentAccount}"
|
<p:dataTable id="accountTable" value="#{accountView.accounts}" var="account" rowKey="#{account.username}" selectionMode="single" selection="#{accountView.currentAccount}"
|
||||||
styleClass="box-primary">
|
styleClass="box-primary">
|
||||||
<p:ajax event="rowSelect" update="deleteButton,editButton" listener="#{accountView.selectAccount}" />
|
<p:ajax event="rowSelect" update="deleteButton,editButton" listener="#{accountView.selectAccount}" />
|
||||||
<p:ajax event="rowUnselect" update="deleteButton,editButton" listener="#{accountView.deselectAccount}" />
|
<p:ajax event="rowUnselect" update="deleteButton,editButton" listener="#{accountView.selectAccount}" />
|
||||||
<p:column headerText="Username">
|
<p:column headerText="Username">
|
||||||
<h:outputText value="#{account.username}" />
|
<h:outputText value="#{account.username}" />
|
||||||
</p:column>
|
</p:column>
|
||||||
@ -220,10 +220,10 @@
|
|||||||
<p:outputLabel for="roles" value="Roles" />
|
<p:outputLabel for="roles" value="Roles" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-6">
|
<div class="col-sm-12 col-md-6">
|
||||||
<p:selectManyMenu id="roles" var="role" label="#{role.roleName}" value="#{accountView.currentAccountRoles}" converter="omnifaces.SelectItemsConverter" required="true" >
|
<p:selectManyMenu id="roles" var="role" label="#{role.roleName}" value="#{accountView.currentAccountRoles}" converter="omnifaces.SelectItemsConverter" required="false" >
|
||||||
<f:selectItems value="#{accountView.allApplicationRoles}" var="roleItem" itemLabel="#{roleItem.roleName}" itemValue="#{role}" />
|
<f:selectItems value="#{accountView.allApplicationRoles}" var="roleItem" itemValue="#{roleItem}" />
|
||||||
<p:column>
|
<p:column>
|
||||||
<h:outputText value="#{role.roleName}"/>
|
<h:outputText value="#{role.application.applicationName}-#{role.roleName}"/>
|
||||||
</p:column>
|
</p:column>
|
||||||
</p:selectManyMenu>
|
</p:selectManyMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
CAUTION: Do not modify this file unless you know what you are doing.
|
CAUTION: Do not modify this file unless you know what you are doing.
|
||||||
Unexpected results may occur if the code is changed deliberately.
|
Unexpected results may occur if the code is changed deliberately.
|
||||||
-->
|
-->
|
||||||
<dbmodel pgmodeler-ver="0.9.1" author="Joern Muehlencord" last-position="259,0" last-zoom="0.85"
|
<dbmodel pgmodeler-ver="0.9.1" author="Joern Muehlencord" last-position="0,0" last-zoom="0.85"
|
||||||
default-schema="public" default-owner="postgres">
|
default-schema="public" default-owner="postgres">
|
||||||
<database name="account_test" encoding="UTF8" lc-collate="German_Germany.1252" lc-ctype="German_Germany.1252" is-template="false" allow-conns="true" sql-disabled="true">
|
<database name="account_test" encoding="UTF8" lc-collate="German_Germany.1252" lc-ctype="German_Germany.1252" is-template="false" allow-conns="true" sql-disabled="true">
|
||||||
</database>
|
</database>
|
||||||
@ -49,6 +49,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
|
|||||||
<constraint name="application_role_pk" type="pk-constr" table="public.application_role">
|
<constraint name="application_role_pk" type="pk-constr" table="public.application_role">
|
||||||
<columns names="id" ref-type="src-columns"/>
|
<columns names="id" ref-type="src-columns"/>
|
||||||
</constraint>
|
</constraint>
|
||||||
|
<constraint name="application_role_name_uidx" type="uq-constr" table="public.application_role">
|
||||||
|
<columns names="application,role_name" ref-type="src-columns"/>
|
||||||
|
</constraint>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table name="account">
|
<table name="account">
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import de.muehlencord.shared.account.business.mail.entity.MailException;
|
|||||||
import de.muehlencord.shared.account.business.mail.boundary.MailService;
|
import de.muehlencord.shared.account.business.mail.boundary.MailService;
|
||||||
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.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.config.entity.ConfigException;
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
import de.muehlencord.shared.account.util.SecurityUtil;
|
import de.muehlencord.shared.account.util.SecurityUtil;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -78,7 +79,7 @@ public class AccountControl implements Serializable {
|
|||||||
StringBuilder queryBuilder = new StringBuilder();
|
StringBuilder queryBuilder = new StringBuilder();
|
||||||
queryBuilder.append("SELECT a FROM AccountEntity a ");
|
queryBuilder.append("SELECT a FROM AccountEntity a ");
|
||||||
if (loadRoles) {
|
if (loadRoles) {
|
||||||
queryBuilder.append("JOIN FETCH a.applicationRoleList ");
|
queryBuilder.append("LEFT JOIN FETCH a.applicationRoleList ");
|
||||||
}
|
}
|
||||||
queryBuilder.append("WHERE a.username = :username");
|
queryBuilder.append("WHERE a.username = :username");
|
||||||
Query query = em.createQuery(queryBuilder.toString());
|
Query query = em.createQuery(queryBuilder.toString());
|
||||||
@ -91,7 +92,7 @@ public class AccountControl implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public AccountEntity saveAccount(AccountEntity account, List<ApplicationRoleEntity> applicationRoles) {
|
public AccountEntity saveAccount(ApplicationEntity application, AccountEntity account, List<ApplicationRoleEntity> applicationRoles) {
|
||||||
Date now = new Date(); // Todo now in UTC
|
Date now = new Date(); // Todo now in UTC
|
||||||
Subject currentUser = SecurityUtils.getSubject();
|
Subject currentUser = SecurityUtils.getSubject();
|
||||||
String currentLoggedInUser = currentUser.getPrincipal().toString();
|
String currentLoggedInUser = currentUser.getPrincipal().toString();
|
||||||
@ -117,39 +118,42 @@ public class AccountControl implements Serializable {
|
|||||||
// reload account from db and join roles
|
// reload account from db and join roles
|
||||||
account = getAccountEntity(account.getUsername(), true);
|
account = getAccountEntity(account.getUsername(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign roles to account
|
// assign roles to account
|
||||||
if (account.getApplicationRoleList() == null) {
|
if (account.getApplicationRoleList() == null) {
|
||||||
account.setApplicationRoleList(new ArrayList<>());
|
account.setApplicationRoleList(new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean roleSetupChanged = false;
|
boolean roleSetupChanged = false;
|
||||||
// remove roles which are no longer listed
|
// remove roles which are no longer listed
|
||||||
for (ApplicationRoleEntity currentlyAssignedRole : account.getApplicationRoleList()) {
|
// ensure this is only done for the given application - keep the other applications untouched
|
||||||
if (!applicationRoles.contains (currentlyAssignedRole)) {
|
List<ApplicationRoleEntity> assignedRoles = new ArrayList<>();
|
||||||
account.getApplicationRoleList().remove(currentlyAssignedRole);
|
assignedRoles.addAll(account.getApplicationRoleList());
|
||||||
|
for (ApplicationRoleEntity currentlyAssignedRole : assignedRoles) {
|
||||||
|
if ((currentlyAssignedRole.getApplication().equals(application) && (!applicationRoles.contains(currentlyAssignedRole)))) {
|
||||||
|
account.getApplicationRoleList().remove(currentlyAssignedRole);
|
||||||
roleSetupChanged = true;
|
roleSetupChanged = true;
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Removed role {} from user {}", currentlyAssignedRole.getRoleName(), account.getUsername());
|
LOGGER.debug("Removed role {} ({}) from user {}", currentlyAssignedRole.getRoleName(), application.getApplicationName(), account.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add newly added roles to role list
|
// add newly added roles to role list
|
||||||
for (ApplicationRoleEntity applicationRole : applicationRoles) {
|
for (ApplicationRoleEntity applicationRole : applicationRoles) {
|
||||||
if (!account.getApplicationRoleList().contains(applicationRole)) {
|
if (!account.getApplicationRoleList().contains(applicationRole)) {
|
||||||
account.addApplicationRole (applicationRole);
|
account.addApplicationRole(applicationRole);
|
||||||
roleSetupChanged = true;
|
roleSetupChanged = true;
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Added role {} to account {}", applicationRole.getRoleName(), account.getUsername());
|
LOGGER.debug("Added role {} ({}) to account {}", applicationRole.getRoleName(), application.getApplicationName(), account.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update account in database if roles changed
|
// update account in database if roles changed
|
||||||
if (roleSetupChanged) {
|
if (roleSetupChanged) {
|
||||||
em.merge(account);
|
em.merge(account);
|
||||||
}
|
}
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user