Commit 6f594ea5 by Tuomas Riihimäki

AAA stuff.. ( I touched everythinggit status \o/ )

1 parent 99af43cc
Showing with 334 additions and 134 deletions
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<runtime name="GlassFish v3 Java EE 6"/>
<fixed facet="jst.ear"/> <fixed facet="jst.ear"/>
<installed facet="jst.ear" version="5.0"/> <installed facet="jst.ear" version="5.0"/>
<installed facet="sun.facet" version="9"/> <installed facet="sun.facet" version="9"/>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/LanBortalBeansClient"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6"/> <classpathentry kind="lib" path="/Users/tuomari/bin/glassfishv31_0507_2/glassfish/lib/appserv-rt.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
...@@ -44,7 +44,6 @@ import com.sun.appserv.security.AppservPasswordLoginModule; ...@@ -44,7 +44,6 @@ import com.sun.appserv.security.AppservPasswordLoginModule;
import com.sun.enterprise.security.auth.realm.InvalidOperationException; import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException; import com.sun.enterprise.security.auth.realm.NoSuchUserException;
import fi.insomnia.bortal.beans.JaasBeanRemote;
/** /**
* *
...@@ -77,7 +76,7 @@ public class BortalLoginModule extends AppservPasswordLoginModule { ...@@ -77,7 +76,7 @@ public class BortalLoginModule extends AppservPasswordLoginModule {
throw new LoginException("Realm not SampleRealm"); throw new LoginException("Realm not SampleRealm");
} }
JaasBeanRemote authbean = BortalRealm.getAuthBean(); RealmBeanRemote authbean = BortalRealm.getAuthBean();
if (authbean == null) { if (authbean == null) {
throw new LoginException("Error. Could not get authentication bean!"); throw new LoginException("Error. Could not get authentication bean!");
} }
......
...@@ -48,7 +48,7 @@ import com.sun.enterprise.security.auth.realm.InvalidOperationException; ...@@ -48,7 +48,7 @@ import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchRealmException; import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException; import com.sun.enterprise.security.auth.realm.NoSuchUserException;
import fi.insomnia.bortal.beans.JaasBeanRemote;
/** /**
* *
...@@ -109,7 +109,7 @@ public class BortalRealm extends AppservRealm { ...@@ -109,7 +109,7 @@ public class BortalRealm extends AppservRealm {
append(s).toString()); append(s).toString());
} }
public static JaasBeanRemote getAuthBean() { public static RealmBeanRemote getAuthBean() {
Object beanObj = null; Object beanObj = null;
try { try {
beanObj = new InitialContext().lookup(JAAS_BEAN_JNDI); beanObj = new InitialContext().lookup(JAAS_BEAN_JNDI);
...@@ -118,8 +118,8 @@ public class BortalRealm extends AppservRealm { ...@@ -118,8 +118,8 @@ public class BortalRealm extends AppservRealm {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
if (beanObj instanceof JaasBeanRemote) { if (beanObj instanceof RealmBeanRemote) {
return (JaasBeanRemote) beanObj; return (RealmBeanRemote) beanObj;
} }
return null; return null;
......
...@@ -4,14 +4,15 @@ ...@@ -4,14 +4,15 @@
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6"> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.ejb"/> <attribute name="owner.project.facets" value="jst.ejb;#system#"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> <classpathentry kind="lib" path="libs/PDFjet.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.6">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.java"/> <attribute name="owner.project.facets" value="java"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="libs/PDFjet.jar"/> <classpathentry combineaccessrules="false" kind="src" path="/LanBortalAuthModule"/>
<classpathentry kind="output" path="build/classes"/> <classpathentry kind="output" path="build/classes"/>
</classpath> </classpath>
#Sun Mar 07 12:30:43 EET 2010 #Thu Jun 10 02:19:46 EEST 2010
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
...@@ -12,9 +12,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error ...@@ -12,9 +12,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=1
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
...@@ -22,6 +23,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 ...@@ -22,6 +23,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
...@@ -66,10 +68,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true ...@@ -66,10 +68,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80 org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
...@@ -84,6 +91,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8 ...@@ -84,6 +91,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
...@@ -266,5 +274,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 ...@@ -266,5 +274,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<runtime name="GlassFish v3 Java EE 6"/>
<fixed facet="jst.ejb"/> <fixed facet="jst.ejb"/>
<fixed facet="jst.java"/> <fixed facet="jst.java"/>
<installed facet="jst.java" version="6.0"/> <installed facet="jst.java" version="6.0"/>
......
...@@ -11,6 +11,9 @@ import fi.insomnia.bortal.model.AccessRight; ...@@ -11,6 +11,9 @@ import fi.insomnia.bortal.model.AccessRight;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
* @author tuukka * @author tuukka
...@@ -20,6 +23,7 @@ public class AccessRightBean implements AccessRightBeanLocal { ...@@ -20,6 +23,7 @@ public class AccessRightBean implements AccessRightBeanLocal {
@EJB @EJB
private AccessRightFacade accessRightFacade; private AccessRightFacade accessRightFacade;
private static final Logger logger = LoggerFactory.getLogger(AccessRightBean.class);
public AccessRight findOrCreate(Permission permission) { public AccessRight findOrCreate(Permission permission) {
AccessRight right = accessRightFacade.findByPermission(permission); AccessRight right = accessRightFacade.findByPermission(permission);
...@@ -29,6 +33,7 @@ public class AccessRightBean implements AccessRightBeanLocal { ...@@ -29,6 +33,7 @@ public class AccessRightBean implements AccessRightBeanLocal {
right.setName(permission.name()); right.setName(permission.name());
right.setDescription(permission.getDescription()); right.setDescription(permission.getDescription());
accessRightFacade.create(right); accessRightFacade.create(right);
logger.info("Access right permission {} not found. created {}", permission, right);
} }
return right; return right;
......
...@@ -44,7 +44,6 @@ public class EventBean implements EventBeanLocal { ...@@ -44,7 +44,6 @@ public class EventBean implements EventBeanLocal {
public Event findOrCreateDefaultEvent() { public Event findOrCreateDefaultEvent() {
Event ret = eventFacade.findByName(DEFAULT_EVENT_NAME); Event ret = eventFacade.findByName(DEFAULT_EVENT_NAME);
if (ret == null) { if (ret == null) {
ret = new Event(); ret = new Event();
ret.setReferer(""); ret.setReferer("");
......
...@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; ...@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.enums.BeanRole; import fi.insomnia.bortal.enums.BeanRole;
import fi.insomnia.bortal.facade.UserFacade; import fi.insomnia.bortal.facade.UserFacade;
import fi.insomnia.bortal.model.Role;
import fi.insomnia.bortal.model.User; import fi.insomnia.bortal.model.User;
/** /**
...@@ -23,7 +24,8 @@ public class JaasBean implements JaasBeanLocal, JaasBeanRemote { ...@@ -23,7 +24,8 @@ public class JaasBean implements JaasBeanLocal, JaasBeanRemote {
@EJB @EJB
private UserFacade userfacade; private UserFacade userfacade;
@EJB
private SecurityBeanLocal secubean;
@EJB @EJB
private UserBean userbean; private UserBean userbean;
...@@ -35,38 +37,49 @@ public class JaasBean implements JaasBeanLocal, JaasBeanRemote { ...@@ -35,38 +37,49 @@ public class JaasBean implements JaasBeanLocal, JaasBeanRemote {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public User tryLogin(String username, String password) { public User tryLogin(String username, String password) {
User user = userfacade.findByLogin(username.trim());
if (user != null && user.checkPassword(password)) { User user = userfacade.findByLogin(username.trim());
return user; logger.debug("Trying to login as {}", username);
logger.info("Logging test");
User ret = null;
if (user != null) {
if (user.checkPassword(password)) {
ret = user;
} else {
secubean.logMessage(SecurityLogType.permissionDenied, user, "Login failed: wrong password!");
} }
} else {
secubean.logMessage(SecurityLogType.permissionDenied, "Login failed: Username not found: " + username);
return null;
} }
return ret;
}
@Override @Override
public boolean authenticate(String username, String password) { public boolean authenticate(String username, String password) {
return (tryLogin(username, password) != null); boolean ret = (tryLogin(username, password) != null);
return ret;
} }
@Override @Override
public Enumeration<String> getGroupNames(String user) { public Enumeration<String> getGroupNames(String user) {
User usr = userbean.getUser(user); User usr = userbean.getUser(user);
Vector<String> roles = new Vector<String>();
Vector<String> rights = new Vector<String>();
if (usr != null) { if (usr != null) {
rights.add(BeanRole.USER_BASE.name()); for (Role r : usr.getRoles()) {
roles.add(r.getName());
}
if (usr.isSuperadmin()) { if (usr.isSuperadmin()) {
rights.add(BeanRole.SUPERADMIN.name()); roles.add(BeanRole.SUPERADMIN.name());
} }
} }
return rights.elements(); logger.debug("group names for user {}: {}", user, roles);
return roles.elements();
} }
} }
...@@ -47,7 +47,6 @@ public class PlaceMapBean implements PlaceMapBeanLocal { ...@@ -47,7 +47,6 @@ public class PlaceMapBean implements PlaceMapBeanLocal {
@EJB @EJB
private UserFacade userFacade; private UserFacade userFacade;
@Override
public void printPlaceMapToStream(OutputStream outputStream, String filetype, Event event, Integer mapId, Integer userId, List<Integer> placeIds) throws IOException { public void printPlaceMapToStream(OutputStream outputStream, String filetype, Event event, Integer mapId, Integer userId, List<Integer> placeIds) throws IOException {
long begin = new Date().getTime(); long begin = new Date().getTime();
......
...@@ -4,18 +4,20 @@ ...@@ -4,18 +4,20 @@
*/ */
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import fi.insomnia.bortal.enums.BeanRole;
import fi.insomnia.bortal.facade.RoleFacade;
import fi.insomnia.bortal.model.Role;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.facade.RoleFacade;
import fi.insomnia.bortal.model.Role;
/** /**
* *
* @author tuukka * @author tuukka
...@@ -23,7 +25,12 @@ import org.slf4j.LoggerFactory; ...@@ -23,7 +25,12 @@ import org.slf4j.LoggerFactory;
@Stateless @Stateless
public class RoleBean implements RoleBeanLocal { public class RoleBean implements RoleBeanLocal {
public static final String[] DECLARED_ROLES = { BeanRole.SUPERADMIN.name(), BeanRole.ADMIN_BASE.name(), BeanRole.USER_BASE.name() }; // public static final String[] DECLARED_ROLES =
// {
// BeanRole.SUPERADMIN.toString(),
// BeanRole.ADMIN_BASE.name(),
// BeanRole.USER_BASE.name()
// };
@EJB @EJB
private RoleFacade roleFacade; private RoleFacade roleFacade;
...@@ -54,8 +61,8 @@ public class RoleBean implements RoleBeanLocal { ...@@ -54,8 +61,8 @@ public class RoleBean implements RoleBeanLocal {
List<Role> children = getAllChilds(role, new HashSet<Role>()); List<Role> children = getAllChilds(role, new HashSet<Role>());
for (Role unit : children) { for (Role unit : children) {
if (roleList.contains(role)) { if (roleList.contains(unit)) {
roleList.remove(role); roleList.remove(unit);
} }
} }
...@@ -80,9 +87,11 @@ public class RoleBean implements RoleBeanLocal { ...@@ -80,9 +87,11 @@ public class RoleBean implements RoleBeanLocal {
return returnList; return returnList;
} }
public static String[] getDeclaredRoles() { // public static String[] getDeclaredRoles() {
return DECLARED_ROLES; // return DECLARED_ROLES;
} // }
// 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")
......
...@@ -19,6 +19,7 @@ import fi.insomnia.bortal.model.User; ...@@ -19,6 +19,7 @@ import fi.insomnia.bortal.model.User;
@Stateless @Stateless
public class SecurityBean implements SecurityBeanLocal { public class SecurityBean implements SecurityBeanLocal {
private static final boolean DEBUG = true;
private final Logger logger = org.slf4j.LoggerFactory.getLogger(SecurityBean.class); private final Logger logger = org.slf4j.LoggerFactory.getLogger(SecurityBean.class);
@EJB @EJB
...@@ -43,6 +44,7 @@ public class SecurityBean implements SecurityBeanLocal { ...@@ -43,6 +44,7 @@ public class SecurityBean implements SecurityBeanLocal {
public LogEntry logMessage(User user, String description) { public LogEntry logMessage(User user, String description) {
LogEntry entry = logMessage(SecurityLogType.genericMessage, user, description); LogEntry entry = logMessage(SecurityLogType.genericMessage, user, description);
return entry; return entry;
} }
...@@ -56,16 +58,17 @@ public class SecurityBean implements SecurityBeanLocal { ...@@ -56,16 +58,17 @@ public class SecurityBean implements SecurityBeanLocal {
return logMessage(type, null, description); return logMessage(type, null, description);
} }
public LogEntry 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(Calendar.getInstance());
entry.setType(type); entry.setType(type);
entry.setTime(Calendar.getInstance());
entry.setDescription(description); entry.setDescription(description);
entry.setUser(user); entry.setUser(user);
entryFacade.create(entry); entryFacade.create(entry);
if (DEBUG) {
logger.debug("SECURITY DEBUG: Type: \"{}\" user \"{}\", description \"{}\"", new String[] { paramType.name(), (user == null)?"null":user.getLogin(), description });
}
return entry; return entry;
} }
......
...@@ -17,6 +17,7 @@ import javax.ejb.Stateless; ...@@ -17,6 +17,7 @@ import javax.ejb.Stateless;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.enums.BeanRole;
import fi.insomnia.bortal.facade.CompoEntryFacade; import fi.insomnia.bortal.facade.CompoEntryFacade;
import fi.insomnia.bortal.facade.CompoFacade; import fi.insomnia.bortal.facade.CompoFacade;
import fi.insomnia.bortal.facade.BillFacade; import fi.insomnia.bortal.facade.BillFacade;
...@@ -38,8 +39,8 @@ import fi.insomnia.bortal.model.User; ...@@ -38,8 +39,8 @@ import fi.insomnia.bortal.model.User;
* Session Bean implementation class TestDataBean * Session Bean implementation class TestDataBean
*/ */
@Stateless @Stateless
// @DeclareRoles(JaasBean.JAAS_SUPERADMINGROUP) // @DeclareRoles("ADMIN_BASE")
//@RolesAllowed(JaasBean.JAAS_SUPERADMINGROUP) // @RolesAllowed("ADMIN_BASE")
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";
...@@ -64,6 +65,16 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -64,6 +65,16 @@ public class TestDataBean implements TestDataBeanLocal {
private BillFacade billFacade; private BillFacade billFacade;
@EJB @EJB
private BillLineFacade billLineFacade; private BillLineFacade billLineFacade;
@EJB
private RoleBeanLocal role;
@EJB
private UserBeanLocal userbean;
public void bootstrap()
{
}
/** /**
* Default constructor. * Default constructor.
...@@ -73,6 +84,7 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -73,6 +84,7 @@ public class TestDataBean implements TestDataBeanLocal {
} }
public User createUser() { public User createUser() {
User u = new User(); User u = new User();
u.setActive(true); u.setActive(true);
u.setAddress("Pallokorvankatu 1"); u.setAddress("Pallokorvankatu 1");
...@@ -96,6 +108,34 @@ public class TestDataBean implements TestDataBeanLocal { ...@@ -96,6 +108,34 @@ public class TestDataBean implements TestDataBeanLocal {
return u; return u;
} }
public User createAdmin() {
User u = new User();
u.setActive(true);
u.setAddress("Elite 1337");
u.setNick("admin");
Calendar bday = Calendar.getInstance();
bday.set(Calendar.YEAR, 1980);
u.setBirthday(bday);
u.setCreated(Calendar.getInstance());
u.setEmail("admin@inter.net");
u.setFemale(false);
u.setFirstnames("Asko Admin");
u.setLastname("admin");
u.setLogin("admin");
u.setNick("admin");
u.resetPassword("admin");
u.setPhone("1337");
u.setTown("Adminila");
u.setPostalTown("Adminila ");
u.setZip("6666");
u.setSuperadmin(true);
userFacade.create(u);
return u;
}
public Bill createBill(Event e, User u) { public Bill createBill(Event e, User u) {
Bill b = new Bill(e); Bill b = new Bill(e);
b.setUser(u); b.setUser(u);
......
...@@ -3,9 +3,7 @@ package fi.insomnia.bortal.beans; ...@@ -3,9 +3,7 @@ package fi.insomnia.bortal.beans;
import java.security.Principal; import java.security.Principal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -13,7 +11,6 @@ import javax.ejb.EJB; ...@@ -13,7 +11,6 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.SessionContext; import javax.ejb.SessionContext;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.xml.rpc.handler.MessageContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -81,6 +78,10 @@ public class UserBean implements UserBeanLocal { ...@@ -81,6 +78,10 @@ public class UserBean implements UserBeanLocal {
return userFacade.findByLogin(nick); return userFacade.findByLogin(nick);
} }
public boolean isCurrentUser(User user) {
return (context.getCallerPrincipal() == null || user == null) ? false: context.getCallerPrincipal().getName().equals(user.getNick());
}
@Override @Override
public User getCurrentUser(Event event) { public User getCurrentUser(Event event) {
...@@ -112,6 +113,13 @@ public class UserBean implements UserBeanLocal { ...@@ -112,6 +113,13 @@ public class UserBean implements UserBeanLocal {
if (user == null) { if (user == null) {
return false; return false;
} }
//TODO: FIX THIS!! really bad idea....
if(user.isSuperadmin())
{
return true;
}
AccessRight expectedRight = accessRightBeanLocal.findOrCreate(target); AccessRight expectedRight = accessRightBeanLocal.findOrCreate(target);
User dbusr = userFacade.find(user.getId()); User dbusr = userFacade.find(user.getId());
...@@ -164,4 +172,5 @@ public class UserBean implements UserBeanLocal { ...@@ -164,4 +172,5 @@ public class UserBean implements UserBeanLocal {
} }
} }
...@@ -8,7 +8,7 @@ import fi.insomnia.bortal.model.LogEntry; ...@@ -8,7 +8,7 @@ import fi.insomnia.bortal.model.LogEntry;
@Stateless @Stateless
@LocalBean @LocalBean
public class LogEntryFacade extends EventChildGenericFacade<LogEntry> { public class LogEntryFacade extends GenericFacade<Integer,LogEntry> {
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
......
...@@ -28,8 +28,9 @@ public class LogEntryTypeFacade extends GenericFacade<Integer, LogEntryType> { ...@@ -28,8 +28,9 @@ public class LogEntryTypeFacade extends GenericFacade<Integer, LogEntryType> {
// Fetch log entry type // Fetch log entry type
TypedQuery<LogEntryType> q = em.createNamedQuery("LogEntryType.findByName", LogEntryType.class); TypedQuery<LogEntryType> q = em.createNamedQuery("LogEntryType.findByName", LogEntryType.class);
q.setParameter("login", type.name()); q.setParameter("name", type.name());
LogEntryType logEntryType = q.getSingleResult();
LogEntryType logEntryType = this.getSingleNullableResult(q);
// Might not exist yet // Might not exist yet
if (logEntryType == null) { if (logEntryType == null) {
......
...@@ -6,6 +6,7 @@ import javax.persistence.EntityManager; ...@@ -6,6 +6,7 @@ import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import fi.insomnia.bortal.enums.BeanRole;
import fi.insomnia.bortal.model.Event; import fi.insomnia.bortal.model.Event;
import fi.insomnia.bortal.model.Role; import fi.insomnia.bortal.model.Role;
...@@ -13,7 +14,7 @@ import fi.insomnia.bortal.model.Role; ...@@ -13,7 +14,7 @@ import fi.insomnia.bortal.model.Role;
@LocalBean @LocalBean
public class RoleFacade extends EventChildGenericFacade<Role> { public class RoleFacade extends EventChildGenericFacade<Role> {
private static final String PUBLIC_ROLE_NAME = "public"; private static final String PUBLIC_ROLE_NAME = BeanRole.ANONYMOUS.toString();
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6"> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.utility"/> <attribute name="owner.project.facets" value="#system#;jst.utility"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.6">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.java"/> <attribute name="owner.project.facets" value="java"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="/LanBortalAuthModule"/>
<classpathentry kind="output" path="ejbModule"/> <classpathentry kind="output" path="ejbModule"/>
</classpath> </classpath>
#Sun Mar 07 12:30:50 EET 2010 #Thu Jun 10 02:19:46 EEST 2010
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.compliance=1.5
...@@ -7,9 +7,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error ...@@ -7,9 +7,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=1
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
...@@ -17,6 +18,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 ...@@ -17,6 +18,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
...@@ -61,10 +63,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true ...@@ -61,10 +63,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80 org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
...@@ -79,6 +86,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8 ...@@ -79,6 +86,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
...@@ -261,5 +269,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 ...@@ -261,5 +269,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<runtime name="GlassFish v3 Java EE 6"/>
<fixed facet="jst.utility"/> <fixed facet="jst.utility"/>
<fixed facet="jst.java"/> <fixed facet="jst.java"/>
<installed facet="jst.java" version="5.0"/> <installed facet="jst.java" version="5.0"/>
......
package fi.insomnia.bortal.beans; package fi.insomnia.bortal.beans;
import java.util.Enumeration;
import javax.ejb.Remote; import javax.ejb.Remote;
@Remote import fi.insomnia.bortal.RealmBeanRemote;
public interface JaasBeanRemote {
boolean authenticate(String username, String password); @Remote
public interface JaasBeanRemote extends RealmBeanRemote{
Enumeration<String> getGroupNames(String user);
} }
...@@ -26,4 +26,6 @@ public interface TestDataBeanLocal { ...@@ -26,4 +26,6 @@ public interface TestDataBeanLocal {
void generateTestCompos(Event event); void generateTestCompos(Event event);
User createAdmin();
} }
...@@ -27,5 +27,7 @@ public interface UserBeanLocal { ...@@ -27,5 +27,7 @@ public interface UserBeanLocal {
boolean hasPermission(Permission target, User user, RolePermission permission); boolean hasPermission(Permission target, User user, RolePermission permission);
boolean isCurrentUser(User thisuser);
} }
...@@ -3,7 +3,7 @@ package fi.insomnia.bortal.enums; ...@@ -3,7 +3,7 @@ package fi.insomnia.bortal.enums;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public enum Role { public enum BeanRole {
// Bean level access // Bean level access
ANONYMOUS, // Unauthenticated web user ANONYMOUS, // Unauthenticated web user
...@@ -17,9 +17,9 @@ public enum Role { ...@@ -17,9 +17,9 @@ public enum Role {
; ;
private boolean inDatabase; private boolean inDatabase;
private Set<Role> parents = new HashSet<Role>(); private Set<BeanRole> parents = new HashSet<BeanRole>();
Role() { BeanRole() {
} }
/** /**
...@@ -27,8 +27,8 @@ public enum Role { ...@@ -27,8 +27,8 @@ public enum Role {
* *
* @param parent * @param parent
*/ */
Role(Role... parent) { BeanRole(BeanRole... parent) {
for (Role role : parent) { for (BeanRole role : parent) {
parents.add(role); parents.add(role);
} }
} }
...@@ -42,7 +42,7 @@ public enum Role { ...@@ -42,7 +42,7 @@ public enum Role {
* @param parent * @param parent
* default (create time) parent roles * default (create time) parent roles
*/ */
Role(boolean inDb, Role... parent) { BeanRole(boolean inDb, BeanRole... parent) {
this(parent); this(parent);
this.inDatabase = inDb; this.inDatabase = inDb;
} }
...@@ -56,7 +56,7 @@ public enum Role { ...@@ -56,7 +56,7 @@ public enum Role {
* *
* @return * @return
*/ */
public Set<Role> getParents() { public Set<BeanRole> getParents() {
return parents; return parents;
} }
} }
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
*/ */
package fi.insomnia.bortal.enums; package fi.insomnia.bortal.enums;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* *
...@@ -17,14 +15,12 @@ public enum Permission { ...@@ -17,14 +15,12 @@ public enum Permission {
LOGIN("User can see loginbutton. (only defaultuser should have permission to that one)"), LOGIN("User can see loginbutton. (only defaultuser should have permission to that one)"),
USER_MANAGEMENT("User has right to manage users.... "); USER_MANAGEMENT("User has right to manage users.... ");
private static final Logger logger = LoggerFactory.getLogger(Permission.class);
private String description; private String description;
public static Permission getPermission(String name) { public static Permission getPermission(String name) {
try { try {
return valueOf(name); return valueOf(name);
} catch (IllegalArgumentException x) { } catch (IllegalArgumentException x) {
logger.error("There is no permission named: " + name);
throw x; throw x;
} }
} }
......
#Sun Mar 07 12:30:58 EET 2010 #Thu Jun 10 02:19:46 EEST 2010
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
...@@ -12,9 +12,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error ...@@ -12,9 +12,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=1
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
...@@ -22,6 +23,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 ...@@ -22,6 +23,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
...@@ -66,10 +68,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true ...@@ -66,10 +68,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80 org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
...@@ -84,6 +91,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8 ...@@ -84,6 +91,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
...@@ -266,5 +274,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 ...@@ -266,5 +274,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<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="both"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/>
<property name="eclipselink.cache.type.default" value="NONE"/> <property name="eclipselink.cache.type.default" value="NONE"/>
</properties> </properties>
</persistence-unit> </persistence-unit>
</persistence> </persistence>
...@@ -48,6 +48,8 @@ public class Event implements ModelInterface<Integer> { ...@@ -48,6 +48,8 @@ public class Event implements ModelInterface<Integer> {
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar startTime; private Calendar startTime;
@Column(name = "end_time") @Column(name = "end_time")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar endTime; private Calendar endTime;
...@@ -74,6 +76,10 @@ public class Event implements ModelInterface<Integer> { ...@@ -74,6 +76,10 @@ public class Event implements ModelInterface<Integer> {
@ManyToOne(optional = false) @ManyToOne(optional = false)
private EventStatus status; private EventStatus status;
@OneToMany(mappedBy="parentEvent")
private List<LogEntry> logEntries;
@JoinColumns( { @JoinColumns( {
@JoinColumn(name = "default_role_id", referencedColumnName = "id"), @JoinColumn(name = "default_role_id", referencedColumnName = "id"),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) })
...@@ -297,4 +303,14 @@ public class Event implements ModelInterface<Integer> { ...@@ -297,4 +303,14 @@ public class Event implements ModelInterface<Integer> {
public Integer getReferenceNumberBase() { public Integer getReferenceNumberBase() {
return referenceNumberBase; return referenceNumberBase;
} }
public void setLogEntries(List<LogEntry> logEntries) {
this.logEntries = logEntries;
}
public List<LogEntry> getLogEntries() {
return logEntries;
}
} }
...@@ -11,6 +11,9 @@ import java.util.Calendar; ...@@ -11,6 +11,9 @@ import java.util.Calendar;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.EmbeddedId; import javax.persistence.EmbeddedId;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
...@@ -29,12 +32,17 @@ import javax.persistence.Version; ...@@ -29,12 +32,17 @@ import javax.persistence.Version;
@NamedQuery(name = "LogEntry.findAll", query = "SELECT l FROM LogEntry l"), @NamedQuery(name = "LogEntry.findAll", query = "SELECT l FROM LogEntry l"),
@NamedQuery(name = "LogEntry.findByTime", query = "SELECT l FROM LogEntry l WHERE l.time = :time"), @NamedQuery(name = "LogEntry.findByTime", query = "SELECT l FROM LogEntry l WHERE l.time = :time"),
@NamedQuery(name = "LogEntry.findByDescription", query = "SELECT l FROM LogEntry l WHERE l.description = :description") }) @NamedQuery(name = "LogEntry.findByDescription", query = "SELECT l FROM LogEntry l WHERE l.description = :description") })
public class LogEntry implements EventChildInterface { public class LogEntry implements ModelInterface<Integer> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@EmbeddedId @Id
private EventPk id; @Column(name = "log_id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
private Event parentEvent;
@Column(name = "event_time", nullable = false) @Column(name = "event_time", nullable = false)
@Temporal(TIMESTAMP) @Temporal(TIMESTAMP)
...@@ -56,15 +64,10 @@ public class LogEntry implements EventChildInterface { ...@@ -56,15 +64,10 @@ public class LogEntry implements EventChildInterface {
@Column(nullable = false) @Column(nullable = false)
private int jpaVersionField = 0; private int jpaVersionField = 0;
public LogEntry() { public LogEntry()
} {}
public LogEntry(Event event) { public LogEntry(Calendar eventTime) {
this.id = new EventPk(event);
}
public LogEntry(Event event, Calendar eventTime) {
this(event);
this.time = eventTime; this.time = eventTime;
} }
...@@ -127,22 +130,7 @@ public class LogEntry implements EventChildInterface { ...@@ -127,22 +130,7 @@ public class LogEntry implements EventChildInterface {
return "fi.insomnia.bortal.model.LogEntry[eventLogId=" + getId() + "]"; return "fi.insomnia.bortal.model.LogEntry[eventLogId=" + getId() + "]";
} }
/**
* @return the id
*/
@Override
public EventPk getId() {
return id;
}
/**
* @param id
* the id to set
*/
@Override
public void setId(EventPk id) {
this.id = id;
}
/** /**
* @return the jpaVersionField * @return the jpaVersionField
...@@ -160,4 +148,22 @@ public class LogEntry implements EventChildInterface { ...@@ -160,4 +148,22 @@ public class LogEntry implements EventChildInterface {
public void setJpaVersionField(int jpaVersionField) { public void setJpaVersionField(int jpaVersionField) {
this.jpaVersionField = jpaVersionField; this.jpaVersionField = jpaVersionField;
} }
@Override
public Integer getId() {
return id;
}
@Override
public void setId(Integer id) {
this.id = id;
}
public void setParentEvent(Event parentEvent) {
this.parentEvent = parentEvent;
}
public Event getParentEvent() {
return parentEvent;
}
} }
...@@ -35,7 +35,7 @@ public class LogEntryType implements ModelInterface<Integer> { ...@@ -35,7 +35,7 @@ public class LogEntryType implements ModelInterface<Integer> {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "event_log_type_id", nullable = false) @Column(name = "id", nullable = false)
private Integer id; private Integer id;
/** /**
......
...@@ -61,8 +61,8 @@ public class Role implements EventChildInterface { ...@@ -61,8 +61,8 @@ public class Role implements EventChildInterface {
private List<RoleRight> roleRights; private List<RoleRight> roleRights;
@JoinColumns( { @JoinColumns( {
@JoinColumn(name = "card_template_id", referencedColumnName = "id", nullable = false, updatable = false, insertable = false), @JoinColumn(name = "card_template_id", referencedColumnName = "id", updatable = false, insertable = false),
@JoinColumn(name = "event_id", referencedColumnName = "event_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "event_id", referencedColumnName = "event_id", updatable = false, insertable = false) })
@ManyToOne @ManyToOne
private CardTemplate cardTemplate; private CardTemplate cardTemplate;
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6">
<attributes>
<attribute name="owner.project.facets" value="jst.utility"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.6">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="build/classes"/> <classpathentry kind="output" path="build/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<runtime name="GlassFish v3 Java EE 6"/>
<fixed facet="jst.java"/> <fixed facet="jst.java"/>
<fixed facet="jst.utility"/> <fixed facet="jst.utility"/>
<installed facet="jst.java" version="6.0"/> <installed facet="jst.java" version="6.0"/>
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6"> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.web"/> <attribute name="owner.project.facets" value="#system#;jst.web"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.6">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.java"/> <attribute name="owner.project.facets" value="java"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="build/classes"/> <classpathentry kind="output" path="build/classes"/>
......
#Sun Mar 07 12:33:11 EET 2010 #Thu Jun 10 02:19:46 EEST 2010
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.6
...@@ -7,9 +7,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error ...@@ -7,9 +7,10 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=1
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
...@@ -17,6 +18,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 ...@@ -17,6 +18,7 @@ org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
...@@ -61,10 +63,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true ...@@ -61,10 +63,15 @@ org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80 org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.compact_else_if=true org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2 org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
...@@ -79,6 +86,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8 ...@@ -79,6 +86,7 @@ org.eclipse.jdt.core.formatter.indentation.size=8
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
...@@ -261,5 +269,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 ...@@ -261,5 +269,7 @@ org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=space org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<runtime name="GlassFish v3 Java EE 6"/>
<fixed facet="jst.web"/> <fixed facet="jst.web"/>
<fixed facet="jst.java"/> <fixed facet="jst.java"/>
<installed facet="jst.java" version="6.0"/> <installed facet="jst.java" version="6.0"/>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd"> <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url=""> <sun-web-app error-url="/auth/login.jsf">
<context-root>/LanBortalWeb</context-root> <context-root>/LanBortalWeb</context-root>
<security-role-mapping> <security-role-mapping>
<role-name>SUPERADMIN</role-name> <role-name>SUPERADMIN</role-name>
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<role-name>USER_BASE</role-name> <role-name>USER_BASE</role-name>
<group-name>USER_BASE</group-name> <group-name>USER_BASE</group-name>
</security-role-mapping> </security-role-mapping>
<class-loader delegate="true" /> <class-loader delegate="true" />
<jsp-config> <jsp-config>
<property name="keepgenerated" value="true"> <property name="keepgenerated" value="true">
......
<?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>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<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>
...@@ -71,4 +74,13 @@ ...@@ -71,4 +74,13 @@
<servlet-name>PrintBill</servlet-name> <servlet-name>PrintBill</servlet-name>
<url-pattern>/PrintBill</url-pattern> <url-pattern>/PrintBill</url-pattern>
</servlet-mapping> </servlet-mapping>
<error-page>
<error-code>401</error-code>
<location>/auth/notauthorized.jsf</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/auth/notauthorized.jsf</location>
</error-page>
</web-app> </web-app>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:ui="http://java.sun.com/jsf/facelets"
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:tools="http://java.sun.com/jsf/composite/tools" xmlns:login="http://java.sun.com/jsf/composite/tools/login"
xmlns:c="http://java.sun.com/jsp/jstl/core"> xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head> <h:head>
<title></title> <title></title>
...@@ -16,7 +16,7 @@ xmlns:c="http://java.sun.com/jsp/jstl/core"> ...@@ -16,7 +16,7 @@ xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:define name="header">Add new user</ui:define> <ui:define name="header">Add new user</ui:define>
<ui:define name="content"> <ui:define name="content">
<tools:login /> <login:login />
</ui:define> </ui:define>
<ui:define name="footer">footer</ui:define> <ui:define name="footer">footer</ui:define>
</ui:composition> </ui:composition>
......
<!DOCTYPE html <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:c="http://java.sun.com/jsp/jstl/core"> <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools/auth"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head> <h:head>
<title></title> <title></title>
</h:head> </h:head>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<ui:define name="header">Add new user</ui:define> <ui:define name="header">Add new user</ui:define>
<ui:define name="content"> <ui:define name="content">
<h:outputText value="#{i18n['logoutmessage'] }" /> <h:outputText value="#{i18n['logoutmessage'] }" />
${userView.logout() } ${sessionHandler.logout() }
</ui:define> </ui:define>
<ui:define name="footer">footer</ui:define> <ui:define name="footer">footer</ui:define>
</ui:composition> </ui:composition>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<form> <form action="j_security_check" method="post">
<c:choose> <c:choose>
<c:when test="#{not empty cc.attrs.isOneliner}"> <c:when test="#{not empty cc.attrs.isOneliner}">
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
</tools:canRead> </tools:canRead>
</composite:implementation> </composite:implementation>
</html> </html>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<ui:define name="header">Edit user</ui:define> <ui:define name="header">Edit user</ui:define>
<ui:define name="content"> <ui:define name="content">
<h:outputText value="productlist"/> <h:outputText value="${i18n['userlist.title']}"/>
<users:list /> <users:list />
</ui:define> </ui:define>
......
package fi.insomnia.bortal; package fi.insomnia.bortal;
import java.io.IOException; import java.io.IOException;
import java.security.AccessController;
import javax.ejb.AccessLocalException;
import javax.ejb.EJBAccessException;
import javax.security.auth.Subject;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
...@@ -9,6 +13,7 @@ import javax.servlet.ServletException; ...@@ -9,6 +13,7 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -40,16 +45,18 @@ public class HostnameFilter implements Filter { ...@@ -40,16 +45,18 @@ public class HostnameFilter implements Filter {
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/ */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = null;
if (request != null && request instanceof HttpServletRequest) { if (request != null && request instanceof HttpServletRequest) {
HttpServletRequest httpRequest = ((HttpServletRequest) request); httpRequest = ((HttpServletRequest) request);
StringBuffer url = httpRequest.getRequestURL(); StringBuffer url = httpRequest.getRequestURL();
Subject subj = Subject.getSubject(AccessController.getContext());
logger.warn("request URL: {}", url); logger.warn("request URL: {}", url);
int beginindex = 7; // Let's skip http:// int beginindex = 7; // Let's skip http://
int slashindex = url.indexOf("/", beginindex); // Find the first int slashindex = url.indexOf("/", beginindex);
// / from URL // Find the first / from URL after http://
// after http://
int colonindex = url.indexOf(":", beginindex); int colonindex = url.indexOf(":", beginindex);
int lastindex = slashindex; int lastindex = slashindex;
if (slashindex > colonindex) { if (slashindex > colonindex) {
...@@ -61,12 +68,22 @@ public class HostnameFilter implements Filter { ...@@ -61,12 +68,22 @@ public class HostnameFilter implements Filter {
logger.warn("begin: {}, last {}", beginindex, lastindex); logger.warn("begin: {}, last {}", beginindex, lastindex);
String hostname = url.substring(beginindex, lastindex); String hostname = url.substring(beginindex, lastindex);
logger.info("Setting hostname to {} ", hostname); logger.info("Setting hostname to {} ", hostname);
httpRequest.getSession().setAttribute(HTTP_URL_HOSTNAME, hostname); httpRequest.getSession().setAttribute(
HTTP_URL_HOSTNAME, hostname);
} }
// pass the request along the filter chain // pass the request along the filter chain
chain.doFilter(request, response); chain.doFilter(request, response);
} }
private void error401(ServletResponse response) throws IOException {
if (response instanceof HttpServletResponse) {
((HttpServletResponse) response).sendError(401);
} else {
logger.warn("Error sending errorcode! response not http but {}" + response.getClass());
}
}
/** /**
* @see Filter#init(FilterConfig) * @see Filter#init(FilterConfig)
*/ */
......
...@@ -11,6 +11,9 @@ import javax.faces.bean.SessionScoped; ...@@ -11,6 +11,9 @@ import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.HostnameFilter; import fi.insomnia.bortal.HostnameFilter;
import fi.insomnia.bortal.beans.EventBeanLocal; import fi.insomnia.bortal.beans.EventBeanLocal;
import fi.insomnia.bortal.beans.SecurityBeanLocal; import fi.insomnia.bortal.beans.SecurityBeanLocal;
...@@ -29,9 +32,11 @@ import fi.insomnia.bortal.model.User; ...@@ -29,9 +32,11 @@ import fi.insomnia.bortal.model.User;
@SessionScoped @SessionScoped
public class SessionHandler { public class SessionHandler {
private static final Logger logger = LoggerFactory.getLogger(SessionHandler.class);
@EJB @EJB
private JaasBeanLocal handlerbean; private JaasBeanLocal handlerbean;
private User user = null; private User thisuser = null;
@EJB @EJB
private SecurityBeanLocal secubean; private SecurityBeanLocal secubean;
@EJB @EJB
...@@ -80,8 +85,6 @@ public class SessionHandler { ...@@ -80,8 +85,6 @@ public class SessionHandler {
if (target == null || target.isEmpty()) { if (target == null || target.isEmpty()) {
throw new RuntimeException("Empty target"); throw new RuntimeException("Empty target");
} }
return userbean.hasPermission(Permission.getPermission(target), getUser(), permission); return userbean.hasPermission(Permission.getPermission(target), getUser(), permission);
} }
...@@ -98,13 +101,15 @@ public class SessionHandler { ...@@ -98,13 +101,15 @@ public class SessionHandler {
return hasPermission(target, RolePermission.EXECUTE); return hasPermission(target, RolePermission.EXECUTE);
} }
public void setUser(User user) { private boolean impersonating = false;
public void impersonateUser(User user) {
if (user == null) { if (user == null) {
this.user = getUser(); this.thisuser = getUser();
impersonating = false;
} else if (canExecute("user")) { } else if (canExecute("user")) {
secubean.logMessage(userbean.getCurrentUser(getCurrentEvent()), "Successfully impersonating user id: " + user.getId() + " and login: " + user.getLogin()); secubean.logMessage(userbean.getCurrentUser(getCurrentEvent()), "Successfully impersonating user id: " + user.getId() + " and login: " + user.getLogin());
this.user = user; this.thisuser = user;
impersonating = true;
} else { } else {
secubean.logMessage(userbean.getCurrentUser(getCurrentEvent()), "User tried to impersonate as id: " + user.getId() + " login: " + user.getLogin() + " but did not have enough rights"); secubean.logMessage(userbean.getCurrentUser(getCurrentEvent()), "User tried to impersonate as id: " + user.getId() + " login: " + user.getLogin() + " but did not have enough rights");
} }
...@@ -112,21 +117,24 @@ public class SessionHandler { ...@@ -112,21 +117,24 @@ public class SessionHandler {
public User getUser() { public User getUser() {
if (user == null) { boolean iscurruser = userbean.isCurrentUser(thisuser);
user = userbean.getCurrentUser(getCurrentEvent()); logger.debug("Current user {}", (thisuser == null)?"null":thisuser.getNick() );
if (thisuser == null || (!impersonating && !iscurruser)) {
thisuser = userbean.getCurrentUser(getCurrentEvent());
} }
return user; return thisuser;
} }
public String logout() { public String logout() {
user = null;
FacesContext ctx = FacesContext.getCurrentInstance(); FacesContext ctx = FacesContext.getCurrentInstance();
HttpSession sess = (HttpSession) ctx.getExternalContext().getSession(false); HttpSession sess = (HttpSession) ctx.getExternalContext().getSession(false);
if (sess != null) { if (sess != null) {
sess.invalidate(); sess.invalidate();
} }
thisuser = null;
return "logout"; return "logout";
} }
} }
...@@ -36,6 +36,8 @@ public class TestDataView { ...@@ -36,6 +36,8 @@ public class TestDataView {
Event event = getSessionhandler().getCurrentEvent(); Event event = getSessionhandler().getCurrentEvent();
User user = testdatabean.createUser(); User user = testdatabean.createUser();
User admin = testdatabean.createAdmin();
testdatabean.createBill(event, user); testdatabean.createBill(event, user);
EventMap map = testdatabean.generateTestMap(event); EventMap map = testdatabean.generateTestMap(event);
testdatabean.generateTestPlaces(map); testdatabean.generateTestPlaces(map);
......
...@@ -88,6 +88,7 @@ public class UserView { ...@@ -88,6 +88,7 @@ public class UserView {
return login; return login;
} }
public void setLogin(String login) { public void setLogin(String login) {
this.login = login; this.login = login;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!