Commit ed5e952b by Tuomas Riihimäki

Added superadmin to user, Added PrintBill servlet, and started SecurityBean

1 parent eb293e5e
bortal realmin lisääminen glassfishiin.
1. Lisää code/LanBortalAuthModule.jar tiedosto hakemistoon glassfish/glassfish/lib/
2. lisää tiedostoon glassfish/glassfish/domains/login.conf tiedostoon:
bortalRealm {
fi.insomnia.bortal.BortalLoginModule required;
};
3. suorita seuraava komento hakemistossa glassfish/glassfish/bin/
./asadmin create-auth-realm --classname fi.insomnia.bortal.BortalRealm --property jaas-context=bortalRealm omniarealm
./asadmin create-jdbc-connection-pool --datasourceclassname org.postgresql.ds.PGSimpleDataSource --restype javax.sql.DataSource --ping true --property DatabaseName=BortalDb:Password=derkoppa:User=bortal Omniapossu
\ No newline at end of file
...@@ -26,43 +26,37 @@ public class SecurityBean implements SecurityBeanLocal { ...@@ -26,43 +26,37 @@ public class SecurityBean implements SecurityBeanLocal {
@EJB @EJB
private LogEntryFacade entryFacade; private LogEntryFacade entryFacade;
/**
* Default constructor.
*/
public SecurityBean() {
// TODO Auto-generated constructor stub
}
@Override @Override
public void logPermissionDenied(User user, Exception exception) { public LogEntry logPermissionDenied(User user, Exception exception) {
LogEntryType type = typeFacade.findOrCreate(SecurityLogType.permissionDenied); LogEntry entry = logMessage(SecurityLogType.permissionDenied, user, exception.getMessage());
LogEntry entry = new LogEntry();
entry.setType(type);
entry.setTime(Calendar.getInstance());
entry.setDescription(exception.getMessage());
entry.setUser(user);
logger.debug(entry.toString(), exception); logger.debug(entry.toString(), exception);
entryFacade.create(entry); return entry;
} }
public void logException(User user, Exception exception) { public LogEntry logException(User user, Exception exception) {
LogEntryType type = typeFacade.findOrCreate(SecurityLogType.unknownException);
LogEntry entry = new LogEntry();
entry.setType(type);
entry.setTime(Calendar.getInstance());
entry.setDescription(exception.getMessage());
entry.setUser(user);
LogEntry entry = logMessage(SecurityLogType.unknownException, user, exception.getMessage());
logger.debug(entry.toString(), exception); logger.debug(entry.toString(), exception);
entryFacade.create(entry); return entry;
}
public LogEntry logMessage(User user, String description) {
LogEntry entry = logMessage(SecurityLogType.genericMessage, user, description);
return entry;
} }
public void logMessage(User user, String description) { public LogEntry logMessage(String description) {
logMessage(SecurityLogType.genericMessage, user, description); LogEntry entry = logMessage(SecurityLogType.genericMessage, description);
return entry;
}
public LogEntry logMessage(SecurityLogType type, String description) {
return logMessage(type, null, description);
} }
public void logMessage(SecurityLogType paramType, User user, String description) { public LogEntry logMessage(SecurityLogType paramType, User user, String description) {
LogEntryType type = typeFacade.findOrCreate(paramType); LogEntryType type = typeFacade.findOrCreate(paramType);
LogEntry entry = new LogEntry(); LogEntry entry = new LogEntry();
...@@ -72,13 +66,10 @@ public class SecurityBean implements SecurityBeanLocal { ...@@ -72,13 +66,10 @@ public class SecurityBean implements SecurityBeanLocal {
entry.setUser(user); entry.setUser(user);
entryFacade.create(entry); entryFacade.create(entry);
return entry;
} }
public void logMessage(String description) { public void logPermissionDenied(User currentuser, String string) {
logMessage(SecurityLogType.genericMessage, description);
}
public void logMessage(SecurityLogType type, String description) {
logMessage(type, null, description);
} }
} }
...@@ -10,10 +10,11 @@ import java.util.logging.Logger; ...@@ -10,10 +10,11 @@ import java.util.logging.Logger;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.facade.EventFacade; import fi.insomnia.bortal.facade.EventFacade;
import fi.insomnia.bortal.facade.EventMapFacade; import fi.insomnia.bortal.facade.EventMapFacade;
import fi.insomnia.bortal.facade.EventOrganiserFacade; import fi.insomnia.bortal.facade.EventOrganiserFacade;
import fi.insomnia.bortal.facade.EventStatusFacade;
import fi.insomnia.bortal.facade.PlaceFacade; import fi.insomnia.bortal.facade.PlaceFacade;
import fi.insomnia.bortal.facade.UserFacade; import fi.insomnia.bortal.facade.UserFacade;
import fi.insomnia.bortal.model.Event; import fi.insomnia.bortal.model.Event;
...@@ -30,19 +31,21 @@ import fi.insomnia.bortal.model.User; ...@@ -30,19 +31,21 @@ import fi.insomnia.bortal.model.User;
public class TestDataBean implements TestDataBeanLocal { public class TestDataBean implements TestDataBeanLocal {
public static final String TEST_MAP_IMAGE_NAME = "testmap.png"; public static final String TEST_MAP_IMAGE_NAME = "testmap.png";
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestDataBean.class);
@EJB @EJB
private EventMapFacade eventMapFacade; private EventMapFacade eventMapFacade;
@EJB @EJB
private EventStatusFacade eventStatusFacade; private EventStatusBeanLocal eventStatusBean;
@EJB @EJB
private EventOrganiserFacade eventOrganiserFacade; private EventOrganiserFacade eventOrganiserFacade;
@EJB @EJB
private EventFacade eventFacade; private EventFacade eventFacade;
@EJB @EJB
private UserFacade userFacade; private UserFacade userFacade;
@EJB @EJB
private PlaceFacade placeFacade; private PlaceFacade placeFacade;
/** /**
* Default constructor. * Default constructor.
*/ */
...@@ -52,8 +55,8 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -52,8 +55,8 @@ public class TestDataBean implements TestDataBeanLocal {
public EventMap generateTestMap(Event event) { public EventMap generateTestMap(Event event) {
try { try {
EventMap map = new EventMap(); logger.info("Generating Test Map for event: " + event);
map.setEvent(event); EventMap map = new EventMap(event);
InputStream stream = getClass().getResourceAsStream(TEST_MAP_IMAGE_NAME); InputStream stream = getClass().getResourceAsStream(TEST_MAP_IMAGE_NAME);
File file = new File(getClass().getResource(TEST_MAP_IMAGE_NAME).toURI()); File file = new File(getClass().getResource(TEST_MAP_IMAGE_NAME).toURI());
...@@ -96,10 +99,8 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -96,10 +99,8 @@ public class TestDataBean implements TestDataBeanLocal {
* Generate all metashit, ex. events. * Generate all metashit, ex. events.
*/ */
public Event generateMetaData() { public Event generateMetaData() {
EventStatus status = new EventStatus();
status.setName("BLAAH"); EventStatus status = eventStatusBean.findOrCreateDefaultEventStatus();
eventStatusFacade.create(status);
EventOrganiser settings = new EventOrganiser(); EventOrganiser settings = new EventOrganiser();
settings.setOrganisation("MUN ORGANISAATIO; EI SUN!"); settings.setOrganisation("MUN ORGANISAATIO; EI SUN!");
...@@ -127,11 +128,11 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -127,11 +128,11 @@ public class TestDataBean implements TestDataBeanLocal {
return user; return user;
} }
public void generateTestPlaces(EventMap map) { public void generateTestPlaces(EventMap map, Event e) {
for (int x = 5; x < 400; x += 50) { for (int x = 5; x < 400; x += 50) {
for (int y = 5; y < 150; y += 50) { for (int y = 5; y < 150; y += 50) {
Place place = new Place(); Place place = new Place(e);
place.setMap(map); place.setMap(map);
place.setMapX(x); place.setMapX(x);
place.setMapY(y); place.setMapY(y);
......
...@@ -17,13 +17,16 @@ import com.pdfjet.PDF; ...@@ -17,13 +17,16 @@ import com.pdfjet.PDF;
import com.pdfjet.Page; import com.pdfjet.Page;
import com.pdfjet.TextLine; import com.pdfjet.TextLine;
import fi.insomnia.bortal.beanutil.pdfprinter.LineStyle;
import fi.insomnia.bortal.model.Bill; import fi.insomnia.bortal.model.Bill;
import fi.insomnia.bortal.model.BillLine; import fi.insomnia.bortal.model.BillLine;
import fi.insomnia.bortal.model.EventOrganiser; import fi.insomnia.bortal.model.EventOrganiser;
import fi.insomnia.bortal.utilities.BillUtils; import fi.insomnia.bortal.utilities.BillUtils;
public class PdfPrinter { public class PdfPrinter {
public enum LineStyle {
THIN, THICK, NORMAL
}
private static final String fontname = CoreFont.HELVETICA; private static final String fontname = CoreFont.HELVETICA;
private static final String boldfontname = CoreFont.HELVETICA_BOLD; private static final String boldfontname = CoreFont.HELVETICA_BOLD;
...@@ -55,14 +58,14 @@ public class PdfPrinter { ...@@ -55,14 +58,14 @@ public class PdfPrinter {
pankkisiirto(); pankkisiirto();
pdf.wrap(); pdf.wrap();
// String fileName = "/Users/tuomari/Example_01.pdf"; // String fileName = "/Users/tuomari/Example_01.pdf";
// FileOutputStream fos = new FileOutputStream(fileName); // FileOutputStream fos = new FileOutputStream(fileName);
// pdf.getData().writeTo(fos); // pdf.getData().writeTo(fos);
// fos.close(); // fos.close();
pdf.getData().writeTo(ostream); pdf.getData().writeTo(ostream);
} catch (Exception e) { } catch (Exception e) {
logger.warn("Error printing bill "+bill+" to stream", e); logger.warn("Error printing bill " + bill + " to stream", e);
return false; return false;
} }
...@@ -422,7 +425,7 @@ public class PdfPrinter { ...@@ -422,7 +425,7 @@ public class PdfPrinter {
// //
// //
// public static void main(String[] args) { // public static void main(String[] args) {
// PdfPrinter.printToStream(null); // PdfPrinter.printToStream(null);
// } // }
} }
package fi.insomnia.bortal.beanutil.pdfprinter;
public enum LineStyle {
THIN, THICK, NORMAL
}
...@@ -5,6 +5,8 @@ import javax.ejb.LocalBean; ...@@ -5,6 +5,8 @@ import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import fi.insomnia.bortal.model.EventStatus; import fi.insomnia.bortal.model.EventStatus;
import javax.persistence.NoResultException; import javax.persistence.NoResultException;
import javax.persistence.Query; import javax.persistence.Query;
...@@ -25,14 +27,9 @@ public class EventStatusFacade extends GenericFacade<Integer, EventStatus> { ...@@ -25,14 +27,9 @@ public class EventStatusFacade extends GenericFacade<Integer, EventStatus> {
} }
public EventStatus findEventStatus(EventStatusEnum eventStatusEnum) { public EventStatus findEventStatus(EventStatusEnum eventStatusEnum) {
try { TypedQuery<EventStatus> q = em.createNamedQuery("EventStatus.findByStatusName", EventStatus.class);
Query q = em.createNamedQuery("EventStatus.findByStatusName"); q.setParameter("name", eventStatusEnum.name());
q.setParameter("name", eventStatusEnum.name()); return this.getSingleNullableResult(q);
EventStatus shopSetting = (EventStatus) q.getSingleResult();
return shopSetting;
} catch (NoResultException x) {
return null;
}
} }
} }
...@@ -2,19 +2,22 @@ package fi.insomnia.bortal.beans; ...@@ -2,19 +2,22 @@ package fi.insomnia.bortal.beans;
import javax.ejb.Local; import javax.ejb.Local;
import fi.insomnia.bortal.model.LogEntry;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
@Local @Local
public interface SecurityBeanLocal { public interface SecurityBeanLocal {
void logPermissionDenied(User user, Exception exception); LogEntry logPermissionDenied(User user, Exception exception);
void logException(User user, Exception exception); LogEntry logException(User user, Exception exception);
void logMessage(User user, String description); LogEntry logMessage(User user, String description);
void logMessage(SecurityLogType type, User user, String description);
void logMessage(String description); LogEntry logMessage(SecurityLogType type, User user, String description);
void logMessage(SecurityLogType type, String description);
LogEntry logMessage(String description);
LogEntry logMessage(SecurityLogType type, String description);
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<jta-data-source>jdbc/bortal</jta-data-source> <jta-data-source>jdbc/bortal</jta-data-source>
<properties> <properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/>
</properties> </properties>
</persistence-unit> </persistence-unit>
</persistence> </persistence>
...@@ -276,10 +276,6 @@ public class Bill implements EventChildInterface { ...@@ -276,10 +276,6 @@ public class Bill implements EventChildInterface {
return jpaVersionField; return jpaVersionField;
} }
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() { public Event getEvent() {
return event; return event;
} }
......
...@@ -144,10 +144,6 @@ public class CardTemplate implements EventChildInterface { ...@@ -144,10 +144,6 @@ public class CardTemplate implements EventChildInterface {
return cards; return cards;
} }
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() { public Event getEvent() {
return event; return event;
} }
......
...@@ -254,10 +254,6 @@ public class Compo implements EventChildInterface { ...@@ -254,10 +254,6 @@ public class Compo implements EventChildInterface {
this.maxParticipantCount = maxParticipantCount; this.maxParticipantCount = maxParticipantCount;
} }
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() { public Event getEvent() {
return event; return event;
} }
......
...@@ -176,10 +176,6 @@ public class EventMap implements EventChildInterface { ...@@ -176,10 +176,6 @@ public class EventMap implements EventChildInterface {
return image; return image;
} }
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() { public Event getEvent() {
return event; return event;
} }
......
...@@ -23,7 +23,8 @@ import javax.persistence.Version; ...@@ -23,7 +23,8 @@ import javax.persistence.Version;
* *
*/ */
@Entity @Entity
@Table(name = "event_status", uniqueConstraints = { @UniqueConstraint(columnNames = { "status_name" }) }) @Table(name = "event_status")
//, uniqueConstraints = { @UniqueConstraint(columnNames = { "status_name" }) })
@NamedQueries( { @NamedQueries( {
@NamedQuery(name = "EventStatus.findAll", query = "SELECT e FROM EventStatus e"), @NamedQuery(name = "EventStatus.findAll", query = "SELECT e FROM EventStatus e"),
@NamedQuery(name = "EventStatus.findByStatusName", query = "SELECT e FROM EventStatus e WHERE e.name = :name") }) @NamedQuery(name = "EventStatus.findByStatusName", query = "SELECT e FROM EventStatus e WHERE e.name = :name") })
...@@ -34,7 +35,7 @@ public class EventStatus implements ModelInterface<Integer> { ...@@ -34,7 +35,7 @@ public class EventStatus implements ModelInterface<Integer> {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "event_status_id", nullable = false) @Column(name = "event_status_id", nullable = false)
private Integer id; private Integer id;
@Column(name = "status_name", nullable = false) @Column(name = "status_name", nullable = false, unique=true)
private String name; private String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "status") @OneToMany(cascade = CascadeType.ALL, mappedBy = "status")
......
...@@ -96,8 +96,8 @@ public class Place implements EventChildInterface { ...@@ -96,8 +96,8 @@ public class Place implements EventChildInterface {
public Place() { public Place() {
} }
public Place(EventPk placesId) { public Place(Event event) {
this.id = placesId; this.id = new EventPk(event);
} }
public String getDescription() { public String getDescription() {
......
...@@ -202,10 +202,6 @@ public class Reader implements EventChildInterface { ...@@ -202,10 +202,6 @@ public class Reader implements EventChildInterface {
this.eventMap = eventMap; this.eventMap = eventMap;
} }
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() { public Event getEvent() {
return event; return event;
} }
......
...@@ -217,10 +217,6 @@ public class Role implements EventChildInterface { ...@@ -217,10 +217,6 @@ public class Role implements EventChildInterface {
return newsGroups; return newsGroups;
} }
public void setEvent(Event event) {
this.event = event;
}
public Event getEvent() { public Event getEvent() {
return event; return event;
} }
......
...@@ -113,6 +113,9 @@ public class User implements ModelInterface<Integer> { ...@@ -113,6 +113,9 @@ public class User implements ModelInterface<Integer> {
@Column(name = "confirm_time") @Column(name = "confirm_time")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar confirmTime; private Calendar confirmTime;
@Column(name = "superadmin")
private boolean superadmin = false;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "voter") @OneToMany(cascade = CascadeType.ALL, mappedBy = "voter")
private List<Vote> votes; private List<Vote> votes;
...@@ -538,4 +541,12 @@ public class User implements ModelInterface<Integer> { ...@@ -538,4 +541,12 @@ public class User implements ModelInterface<Integer> {
public List<EventOrganiser> getEventOrganiser() { public List<EventOrganiser> getEventOrganiser() {
return eventOrganiser; return eventOrganiser;
} }
public void setSuperadmin(boolean superadmin) {
this.superadmin = superadmin;
}
public boolean isSuperadmin() {
return superadmin;
}
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>LanBortalWeb</display-name> <display-name>LanBortalWeb</display-name>
<context-param> <context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value> <param-value>true</param-value>
</context-param> </context-param>
<servlet-mapping> <servlet-mapping>
<servlet-name>PlaceMap</servlet-name> <servlet-name>PlaceMap</servlet-name>
<url-pattern>/PlaceMap</url-pattern> <url-pattern>/PlaceMap</url-pattern>
</servlet-mapping> </servlet-mapping>
<welcome-file-list> <welcome-file-list>
<welcome-file>index.html</welcome-file> <welcome-file>index.html</welcome-file>
<welcome-file>index.jsf</welcome-file> <welcome-file>index.jsf</welcome-file>
<welcome-file>index.jsp</welcome-file> <welcome-file>index.jsp</welcome-file>
</welcome-file-list> </welcome-file-list>
<servlet> <servlet>
<servlet-name>Faces Servlet</servlet-name> <servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet> </servlet>
<servlet> <servlet>
<servlet-name>PlaceMap</servlet-name> <servlet-name>PlaceMap</servlet-name>
<servlet-class>fi.insomnia.bortal.servlet.PlaceMap</servlet-class> <servlet-class>fi.insomnia.bortal.servlet.PlaceMap</servlet-class>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>Faces Servlet</servlet-name> <servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern> <url-pattern>*.jsf</url-pattern>
</servlet-mapping> </servlet-mapping>
<filter> <filter>
<display-name>HostnameFilter</display-name> <display-name>HostnameFilter</display-name>
<filter-name>HostnameFilter</filter-name> <filter-name>HostnameFilter</filter-name>
<filter-class>fi.insomnia.bortal.HostnameFilter</filter-class> <filter-class>fi.insomnia.bortal.HostnameFilter</filter-class>
</filter> </filter>
<filter-mapping> <filter-mapping>
<filter-name>HostnameFilter</filter-name> <filter-name>HostnameFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name> <servlet-name>Faces Servlet</servlet-name>
</filter-mapping> </filter-mapping>
<login-config> <login-config>
<auth-method>FORM</auth-method> <auth-method>FORM</auth-method>
<realm-name>omniarealm</realm-name> <realm-name>omniarealm</realm-name>
<form-login-config> <form-login-config>
<form-login-page>/auth/login.jsf</form-login-page> <form-login-page>/auth/login.jsf</form-login-page>
<form-error-page>/auth/loginError.jsf</form-error-page> <form-error-page>/auth/loginError.jsf</form-error-page>
</form-login-config> </form-login-config>
</login-config> </login-config>
<security-role> <security-role>
<role-name>admin</role-name> <role-name>admin</role-name>
</security-role> </security-role>
<security-role> <security-role>
<role-name>user</role-name> <role-name>user</role-name>
</security-role> </security-role>
<security-constraint> <security-constraint>
<web-resource-collection> <web-resource-collection>
<web-resource-name>forbidden</web-resource-name> <web-resource-name>forbidden</web-resource-name>
<url-pattern>*.xhtml</url-pattern> <url-pattern>*.xhtml</url-pattern>
</web-resource-collection> </web-resource-collection>
<auth-constraint> <auth-constraint>
<description>Thou shall not read the sources..</description> <description>Thou shall not read the sources..</description>
</auth-constraint> </auth-constraint>
</security-constraint> </security-constraint>
<servlet> <servlet>
<description></description> <description></description>
<display-name>BillPrint</display-name> <display-name>PrintBill</display-name>
<servlet-name>BillPrint</servlet-name> <servlet-name>PrintBill</servlet-name>
<servlet-class>fi.insomnia.bortal.servlet.BillPrint</servlet-class> <servlet-class>fi.insomnia.bortal.servlet.PrintBill</servlet-class>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>BillPrint</servlet-name> <servlet-name>PrintBill</servlet-name>
<url-pattern>/BillPrint</url-pattern> <url-pattern>/PrintBill</url-pattern>
</servlet-mapping> </servlet-mapping>
</web-app> </web-app>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!