Commit 5489609f by Juho Juopperi

Merge branch 'master' of dev.intra.insomnia.fi:/data/bortal

2 parents 7704fb3b 08f771a5
...@@ -10,6 +10,8 @@ import fi.insomnia.bortal.model.Role; ...@@ -10,6 +10,8 @@ import fi.insomnia.bortal.model.Role;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
...@@ -21,9 +23,24 @@ public class RoleBean implements RoleBeanLocal { ...@@ -21,9 +23,24 @@ public class RoleBean implements RoleBeanLocal {
@EJB @EJB
private RoleFacade roleFacade; private RoleFacade roleFacade;
private static final Logger logger = LoggerFactory.getLogger(RoleBean.class);
public List<Role> listRoles() { public List<Role> listRoles() {
return roleFacade.findAll(); return roleFacade.findAll();
} }
public void mergeChanges(Role role) {
roleFacade.merge(role);
}
public Role create(Role role) {
roleFacade.create(role);
return role;
}
// Add business logic below. (Right-click in editor and choose // Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method") // "Insert Code > Add Business Method")
......
...@@ -17,5 +17,9 @@ import javax.ejb.Local; ...@@ -17,5 +17,9 @@ import javax.ejb.Local;
public interface RoleBeanLocal { public interface RoleBeanLocal {
public List<Role> listRoles(); public List<Role> listRoles();
public void mergeChanges(Role role);
public Role create(Role role);
} }
...@@ -81,9 +81,24 @@ ...@@ -81,9 +81,24 @@
<to-view-id>/NotImplementedYet.xhtml</to-view-id> <to-view-id>/NotImplementedYet.xhtml</to-view-id>
</navigation-case> </navigation-case>
</navigation-rule> </navigation-rule>
<navigation-rule>
<from-view-id>/resources/tools/role/edit.xhtml</from-view-id>
<navigation-case>
<from-outcome>roleSaved</from-outcome>
<to-view-id>/modulePossibleReturnValues.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/resources/tools/role/create.xhtml</from-view-id>
<navigation-case>
<from-outcome>roleCreated</from-outcome>
<to-view-id>/modulePossibleReturnValues.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config> </faces-config>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<tools:canWrite target="roleManagement">
<f:facet name="errorMessage">
<h:outputText value="#{i18n['nasty.user']}" />
</f:facet>
<ui:include src="form.xhtml" />
<h:commandButton value="#{i18n['create']}" action="#{roleView.create}" />
</tools:canWrite>
</h:form>
</composite:implementation>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:role="http://java.sun.com/jsf/composite/tools/role">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<tools:canWrite target="roleManagement">
<f:facet name="errorMessage">
<h:outputText value="#{i18n['nasty.user']}" />
</f:facet>
<ui:include src="form.xhtml" />
<h:commandButton value="#{i18n['save']}" action="#{roleView.save}" />
</tools:canWrite>
</h:form>
</composite:implementation>
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<ui:composition>
<h:panelGrid>
<h:outputText value="#{i18n['role.name']}" /><h:inputText value="#{roleView.role.name}" />
</h:panelGrid>
</ui:composition>
</html>
...@@ -2,54 +2,55 @@ ...@@ -2,54 +2,55 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <html
xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite" xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools"> xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface> <composite:interface>
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<h:form> <h:form>
<tools:canRead target="roleManagement"> <tools:canRead target="roleManagement">
<h:dataTable <h:dataTable
border="1" border="1"
id="user" id="user"
value="#{roleView.roles}" value="#{roleView.roles}"
var="role"> var="role">
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#" /> <h:outputText value="#" />
</f:facet> </f:facet>
<h:outputText value="#{role.id}" /> <h:outputText value="#{role.id}" />
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="#{i18n['role.name']}" /> <h:outputText value="#{i18n['role.name']}" />
</f:facet> </f:facet>
<h:outputText value="#{role.name}" /> <h:outputText value="#{role.name}" />
</h:column> </h:column>
<tools:canWrite target="roleManagement"> <tools:canWrite target="roleManagement">
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="Edit" /> <h:outputText value="#{i18n['edit']}" />
</f:facet> </f:facet>
<h:commandButton <h:commandButton
action="#{roleView.edit()}" action="#{roleView.edit()}"
value="Edit" /> value="Edit" />
</h:column> </h:column>
</tools:canWrite> </tools:canWrite>
</h:dataTable> </h:dataTable>
</tools:canRead> </tools:canRead>
</h:form> </h:form>
</composite:implementation>
</composite:implementation>
</html> </html>
...@@ -2,15 +2,16 @@ ...@@ -2,15 +2,16 @@
* To change this template, choose Tools | Templates * To change this template, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package fi.insomnia.bortal.view; package fi.insomnia.bortal.view;
import fi.insomnia.bortal.beans.RoleBeanLocal; import fi.insomnia.bortal.beans.RoleBeanLocal;
import fi.insomnia.bortal.beans.SecurityBeanLocal;
import fi.insomnia.bortal.exceptions.PermissionDeniedException;
import fi.insomnia.bortal.handler.SessionHandler;
import fi.insomnia.bortal.model.Role; import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.model.User;
import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped; import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel; import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel; import javax.faces.model.ListDataModel;
...@@ -21,18 +22,22 @@ import org.slf4j.LoggerFactory; ...@@ -21,18 +22,22 @@ import org.slf4j.LoggerFactory;
* *
* @author tuukka * @author tuukka
*/ */
@ManagedBean(name="roleView") @ManagedBean(name = "roleView")
@SessionScoped @SessionScoped
public class RoleView { public class RoleView {
Role role = new Role(); @ManagedProperty("#{sessionHandler}")
DataModel<Role> items; private SessionHandler sessionhandler;
@EJB @EJB
private RoleBeanLocal roleBean; private RoleBeanLocal roleBean;
private static final Logger logger = LoggerFactory.getLogger(RoleView.class); private static final Logger logger = LoggerFactory.getLogger(RoleView.class);
@EJB
private SecurityBeanLocal securitybean;
private Role role = new Role();
DataModel<Role> items;
public DataModel<Role> getRoles() { public DataModel<Role> getRoles() {
items = new ListDataModel<Role>(roleBean.listRoles()); items = new ListDataModel<Role>(roleBean.listRoles());
logger.info("Fetching roles. Found {}", items.getRowCount()); logger.info("Fetching roles. Found {}", items.getRowCount());
...@@ -40,9 +45,33 @@ public class RoleView { ...@@ -40,9 +45,33 @@ public class RoleView {
return items; return items;
} }
public String save() {
if (!sessionhandler.canWrite("roleManagement")) {
// Give message to administration what happened here.
throw new PermissionDeniedException(securitybean, getSessionhandler().getUser(), "User " + getSessionhandler().getUser() + " does not have permission to modify role!");
}
roleBean.mergeChanges(role);
return "roleSaved";
}
public String create() {
if (!sessionhandler.canWrite("roleManagement")) {
// Give message to administration what happened here.
throw new PermissionDeniedException(securitybean, getSessionhandler().getUser(), "User " + getSessionhandler().getUser() + " does not have permission to create role!");
}
role = roleBean.create(role);
return "roleCreated";
}
public String edit() { public String edit() {
role = items.getRowData(); setRole(items.getRowData());
return "roleEdit"; return "roleEdit";
} }
...@@ -51,4 +80,31 @@ public class RoleView { ...@@ -51,4 +80,31 @@ public class RoleView {
public RoleView() { public RoleView() {
} }
/**
* @return the role
*/
public Role getRole() {
return role;
}
/**
* @param role the role to set
*/
public void setRole(Role role) {
this.role = role;
}
/**
* @return the sessionhandler
*/
public SessionHandler getSessionhandler() {
return sessionhandler;
}
/**
* @param sessionhandler the sessionhandler to set
*/
public void setSessionhandler(SessionHandler sessionhandler) {
this.sessionhandler = sessionhandler;
}
} }
...@@ -17,3 +17,4 @@ fallbackstr="fallback default" ...@@ -17,3 +17,4 @@ fallbackstr="fallback default"
teststr=default locale test teststr=default locale test
defaultstr="Something default..." defaultstr="Something default..."
logout=H\u00E4ivy logout=H\u00E4ivy
nasty.user=paha k\u00E4ytt\u00E4j\u00E4 ei yrit\u00E4 haxoroida meid\u00E4n softaa. Kts.
...@@ -17,3 +17,4 @@ fallbackstr="fallback default" ...@@ -17,3 +17,4 @@ fallbackstr="fallback default"
teststr=default locale test teststr=default locale test
defaultstr="Something default..." defaultstr="Something default..."
logout=H\u00E4ivy logout=H\u00E4ivy
nasty.user=paha k\u00E4ytt\u00E4j\u00E4 ei yrit\u00E4 haxoroida meid\u00E4n softaa. Kts.
...@@ -17,3 +17,4 @@ fallbackstr="fallback default" ...@@ -17,3 +17,4 @@ fallbackstr="fallback default"
teststr=default locale test teststr=default locale test
defaultstr="Something default..." defaultstr="Something default..."
logout=H\u00E4ivy logout=H\u00E4ivy
nasty.user=paha k\u00E4ytt\u00E4j\u00E4 ei yrit\u00E4 haxoroida meid\u00E4n softaa. Kts.
...@@ -17,3 +17,4 @@ fallbackstr="fallback default" ...@@ -17,3 +17,4 @@ fallbackstr="fallback default"
teststr=default locale test teststr=default locale test
defaultstr="Something default..." defaultstr="Something default..."
logout=H\u00E4ivy logout=H\u00E4ivy
nasty.user=paha k\u00E4ytt\u00E4j\u00E4 ei yrit\u00E4 haxoroida meid\u00E4n softaa. Kts.
...@@ -16,3 +16,4 @@ user.validate.notUniqueUsername=i18n K\u00E4ytt\u00E4j\u00E4tunnus on jo olemass ...@@ -16,3 +16,4 @@ user.validate.notUniqueUsername=i18n K\u00E4ytt\u00E4j\u00E4tunnus on jo olemass
teststr=brlocale test teststr=brlocale test
fallbackstr=InsomniaSpecific fallback fallbackstr=InsomniaSpecific fallback
logout=H\u00E4ivy logout=H\u00E4ivy
nasty.user=paha k\u00E4ytt\u00E4j\u00E4 ei yrit\u00E4 haxoroida meid\u00E4n softaa. Kts.
teststr=XII locale test teststr=XII locale test
logout=H\u00E4ivy logout=H\u00E4ivy
nasty.user=paha k\u00E4ytt\u00E4j\u00E4 ei yrit\u00E4 haxoroida meid\u00E4n softaa. Kts.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!