Commit 7031e766 by Tuukka Kivilahti

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

Conflicts:
	code/LanBortalWeb/WebContent/WEB-INF/web.xml
2 parents 39dabd6b 5da87cc4
Showing with 745 additions and 134 deletions
bortal realmin lisääminen glassfishiin.
1. Lisää code/LanBortalAuthModule.jar tiedosto hakemistoon glassfish/glassfish/lib/
2. lisää tiedostoon glassfish/glassfish/domains/domain1/config/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
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<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.jst.server.core.container/com.sun.enterprise.jst.server.runtimeTarget/GlassFish v3 Java EE 6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LanBortalAuthModule</name>
<comment></comment>
<projects>
<project>LanBortalBeansClient</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
#Sat Apr 17 01:39:34 EEST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fi.insomnia.bortal;
import java.util.Enumeration;
import javax.security.auth.login.LoginException;
import com.sun.appserv.security.AppservPasswordLoginModule;
import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException;
import fi.insomnia.bortal.beans.SessionHandlerBeanRemote;
/**
*
* @author nithyasubramanian SampleLoginModule - extends
* AppservPasswordLoginModule Sample class to be referenced by the
* SampleRealm class . Overrides the authenticateUser() method that
* authenticates the user using user-password information and calls
* commitUserAuthentication
*/
public class BortalLoginModule extends AppservPasswordLoginModule {
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(BortalLoginModule.class);
/**
* Overrides the authenticateUser() method in AppservPasswordLoginModule
* Performs authentication of user
*
* @throws javax.security.auth.login.LoginException
*/
protected void authenticateUser() throws LoginException {
log((new StringBuilder()).append("CustomRealm Auth Info:_username:")
.append(_username).append(";_password:").append(_password)
.append(";_currentrealm:").append(_currentRealm).toString());
// Check if the given realm is SampleRealm
if (!(_currentRealm instanceof BortalRealm)) {
throw new LoginException("Realm not SampleRealm");
}
SessionHandlerBeanRemote authbean = BortalRealm.getAuthBean();
if (authbean == null) {
throw new LoginException("Error. Could not get authentication bean!");
}
// Authenticate User
BortalRealm samplerealm = (BortalRealm) _currentRealm;
if (!authbean.authenticate(_username, _password)) {
// Login fails
throw new LoginException((new StringBuilder())
.append("customrealm:Login Failed for user ")
.append(_username).toString());
}
// Login succeeds
log((new StringBuilder()).append("SimpleRealm:login succeeded for ")
.append(_username).toString());
// Get group names for the authenticated user from the Realm class
Enumeration<String> enumeration = null;
String authenticatedGroups[] = new String[2];
try {
enumeration = samplerealm.getGroupNames(_username);
} catch (InvalidOperationException invalidoperationexception) {
throw new LoginException((new StringBuilder())
.append("An InvalidOperationException was thrown " +
" while calling getGroupNames() on the SampleRealm ")
.append(invalidoperationexception).toString());
} catch (NoSuchUserException nosuchuserexception) {
throw new LoginException((new StringBuilder())
.append("A NoSuchUserException was thrown " +
" while calling getGroupNames() on the SampleRealm ")
.append(nosuchuserexception).toString());
}
for (int i = 0; enumeration != null && enumeration.hasMoreElements(); i++)
authenticatedGroups[i] = (String) enumeration.nextElement();
// Call commitUserAuthentication with the groupNames the user belongs to
commitUserAuthentication(authenticatedGroups);
}
private void log(String s) {
System.out.println((new StringBuilder())
.append("SimpleCustomLoginModule::").append(s).toString());
}
}
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fi.insomnia.bortal;
import java.util.Enumeration;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.sun.appserv.security.AppservRealm;
import com.sun.enterprise.security.auth.realm.BadRealmException;
import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException;
import fi.insomnia.bortal.beans.SessionHandlerBeanRemote;
/**
*
* @author nithyasubramanian SampleRealm - class extending AppservRealm Sample
* Custom Realm Class that stores user-group information
*/
public class BortalRealm extends AppservRealm {
// private static final Logger logger = LoggerFactory.getLogger(BortalRealm.class);
/**
* Initialization - set the jaas-context property, Set UserA to devGroup and
* user B to testGroup
*
* @param properties
* - Key-Value pairs defined in the Realm
* @throws com.sun.enterprise.security.auth.realm.BadRealmException
* @throws com.sun.enterprise.security.auth.realm.NoSuchRealmException
*/
public void init(Properties properties)
throws BadRealmException, NoSuchRealmException {
super.init(properties);
log("Init SampleRealm");
String propJaasContext = properties.getProperty(JAAS_CONTEXT_PARAM);
if (propJaasContext != null) {
setProperty(JAAS_CONTEXT_PARAM, propJaasContext);
}
}
/**
*
* @return authType
*/
public String getAuthType() {
return "Omnia Lan system authentication Realm";
}
/**
*
* @param user
* @return Enumeration - List of groups to which user belongs
* @throws com.sun.enterprise.security.auth.realm.InvalidOperationException
* @throws com.sun.enterprise.security.auth.realm.NoSuchUserException
*/
public Enumeration<String> getGroupNames(String user)
throws InvalidOperationException, NoSuchUserException {
return getAuthBean().getGroupNames(user);
}
private static void log(String s) {
System.out.println((new StringBuilder()).append("BortalRealm::").
append(s).toString());
}
public static SessionHandlerBeanRemote getAuthBean() {
Object beanObj = null;
try {
beanObj = new InitialContext().lookup("java:global/LanBortal/LanBortalBeans/SessionHandlerBean!fi.insomnia.bortal.beans.SessionHandlerBeanRemote");
} catch (NamingException e) {
log("Error fetching LoginHandlerRemote bean from initial context");
e.printStackTrace();
return null;
}
if (beanObj instanceof SessionHandlerBeanRemote) {
return (SessionHandlerBeanRemote) beanObj;
}
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
<enterprise-beans/>
<enterprise-beans />
</sun-ejb-jar>
package fi.insomnia.bortal.beans;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import fi.insomnia.bortal.facade.ProductFacade;
import fi.insomnia.bortal.model.Product;
/**
* Session Bean implementation class ProductBean
*/
@Stateless
public class ProductBean implements ProductBeanLocal {
@EJB
ProductFacade productFacade;
/**
* Default constructor.
*/
public ProductBean() {
// TODO Auto-generated constructor stub
}
@Override
public List<Product> listUserShoppableProducts() {
// XXX: Only user shoppable products
return productFacade.findAll();
}
}
package fi.insomnia.bortal.beans;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import javax.annotation.Resource;
import javax.annotation.security.DeclareRoles;
import javax.ejb.EJB;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import org.slf4j.Logger;
......@@ -22,7 +28,8 @@ import fi.insomnia.bortal.model.User;
* Session Bean implementation class SessionHandlerBean
*/
@Stateless
public class SessionHandlerBean implements SessionHandlerBeanLocal {
@DeclareRoles("admin")
public class SessionHandlerBean implements SessionHandlerBeanLocal, SessionHandlerBeanRemote{
private static final Logger logger = LoggerFactory.getLogger(SessionHandlerBean.class);
@EJB
......@@ -31,7 +38,10 @@ public class SessionHandlerBean implements SessionHandlerBeanLocal {
private AccessRightFacade accessRightFacade;
@EJB
private RoleFacade roleFacade;
@Resource
SessionContext context;
/**
* Default constructor.
*/
......@@ -118,4 +128,24 @@ public class SessionHandlerBean implements SessionHandlerBeanLocal {
}
return defaultUser;
}
public void testing()
{
Principal principal = context.getCallerPrincipal();
logger.warn("principal {}",principal.getName());
logger.warn("Principal in admin: {}",context.isCallerInRole("admin"));
}
@Override
public boolean authenticate(String username, String password) {
return (tryLogin(username,password) != null);
}
@Override
public Enumeration<String> getGroupNames(String user) {
Vector<String> foo = new Vector<String>();
foo.add("admin");
return foo.elements();
}
}
......@@ -35,12 +35,10 @@ public class UserBean implements UserBeanLocal {
}
@Override
public User createNewUser(String nick, String password) {
public User createNewUser(String login, String password) {
User returnUser = new User();
returnUser.setNick(nick);
// TODO: Hash function....
returnUser.setPassword(password);
returnUser.setLogin(login);
returnUser.resetPassword(password);
// Tallennetaan olio kantaan...
userFacade.create(returnUser);
return returnUser;
......
......@@ -8,7 +8,7 @@ import fi.insomnia.bortal.model.Event;
@Stateless
@LocalBean
public class EventFacade extends IntegerPkGenericFacade<Event> {
public class EventFacade extends GenericFacade<Integer, Event> {
@PersistenceContext
private EntityManager em;
......
......@@ -8,7 +8,7 @@ import fi.insomnia.bortal.model.EventSettings;
@Stateless
@LocalBean
public class EventSettingsFacade extends EventChildGenericFacade<EventSettings> {
public class EventSettingsFacade extends GenericFacade<Integer, EventSettings> {
@PersistenceContext
private EntityManager em;
......
......@@ -8,7 +8,7 @@ import fi.insomnia.bortal.model.EventStatus;
@Stateless
@LocalBean
public class EventStatusFacade extends EventChildGenericFacade<EventStatus> {
public class EventStatusFacade extends GenericFacade<Integer, EventStatus> {
@PersistenceContext
private EntityManager em;
......
......@@ -12,7 +12,7 @@ import fi.insomnia.bortal.model.ModelInterface;
/**
* Session Bean implementation class GenericFacade
*/
public abstract class GenericFacade<PK,T extends ModelInterface<PK>> implements GenericFacadeLocal<PK,T> {
public abstract class GenericFacade<PK,T extends ModelInterface<PK>> implements GenericFacadeLocal<PK,T> {
private Class<T> entClass;
public GenericFacade(Class<T>entityClass)
......@@ -26,19 +26,21 @@ public abstract class GenericFacade<PK,T extends ModelInterface<PK>> implements
protected abstract EntityManager getEm();
@Override
public void create(T entity) {
getEm().persist(entity);
}
@Override
public void remove(T entity) {
getEm().remove(entity);
}
@Override
public T merge(T entity) {
return getEm().merge(entity);
}
public T find(Object id) {
public T find(PK id) {
return getEm().find(getEntityClass(), id);
}
......
......@@ -4,13 +4,14 @@ import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import fi.insomnia.bortal.model.User;
@Stateless
@LocalBean
public class UserFacade extends IntegerPkGenericFacade<User> {
public class UserFacade extends GenericFacade<Integer, User> {
public static final String DEFAULT_USER_LOGIN = "default";
......@@ -26,9 +27,14 @@ public class UserFacade extends IntegerPkGenericFacade<User> {
}
public User findByLogin(String login) {
TypedQuery<User> q = em.createNamedQuery("User.findByLogin", User.class);
// TODO: Bug in glassfish.... change when fixed...
// TypedQuery<User> q = em.createNamedQuery("User.findByLogin",
// User.class);
// q.setParameter("login", login);
// return q.getSingleResult();
TypedQuery<User> q = em.createQuery("SELECT u FROM User u WHERE u.login = :login", User.class);
q.setParameter("login", login);
return q.getSingleResult();
return (User) q.getSingleResult();
}
public User getOrCreateDefaultUser() {
......
package fi.insomnia.bortal.beans;
import java.util.List;
import javax.ejb.Local;
import fi.insomnia.bortal.model.Product;
@Local
public interface UserBeanLocal {
public interface ProductBeanLocal {
List<Product> listUserShoppableProducts();
}
......@@ -7,6 +7,7 @@ package fi.insomnia.bortal.beans;
import fi.insomnia.bortal.model.Role;
import java.util.List;
import javax.ejb.Local;
/**
......
......@@ -3,7 +3,7 @@ import javax.ejb.Local;
import fi.insomnia.bortal.model.User;
@Local
@Local
public interface SessionHandlerBeanLocal {
......@@ -18,4 +18,6 @@ public interface SessionHandlerBeanLocal {
User tryLogin(String username, String password);
User getDefaultUser();
void testing();
}
package fi.insomnia.bortal.beans;
import java.util.Enumeration;
import javax.ejb.Remote;
@Remote
public interface SessionHandlerBeanRemote {
boolean authenticate(String username, String password);
Enumeration<String> getGroupNames(String user);
}
......@@ -59,23 +59,17 @@ public class Event implements ModelInterface<Integer> {
@Column(name = "referer")
private String referer;
@JoinColumns({
@JoinColumn(name = "event_id", referencedColumnName = "entity_id", nullable = false, updatable = false, insertable = false),
@JoinColumn(name="event_event_id",referencedColumnName = "events_pk_id", nullable = false, updatable = false, insertable = false)
})
@JoinColumn(name = "event_settings_id", referencedColumnName = "event_settings_id", nullable = false, updatable = false)
@ManyToOne(optional = false)
private EventSettings settings;
@JoinColumns({
@JoinColumn(name = "event_status_id", referencedColumnName = "entity_id", nullable = false, updatable = false, insertable = false),
@JoinColumn(name="event_status_event_id",referencedColumnName = "events_pk_id", nullable = false, updatable = false, insertable = false)
})
@JoinColumn(name = "event_status_id", referencedColumnName = "event_status_id", nullable = false)
@ManyToOne(optional = false)
private EventStatus status;
@JoinColumns({
@JoinColumn(name = "default_role_id", referencedColumnName = "entity_id", nullable = false, updatable = false, insertable = false),
@JoinColumn(name="default_role_event_id",referencedColumnName = "events_pk_id", nullable = false, updatable = false, insertable = false)
})
@JoinColumns( {
@JoinColumn(name = "default_role_id", referencedColumnName = "id"),
@JoinColumn(name = "events_id", referencedColumnName = "events_pk_id", nullable = false, updatable = false, insertable = false) })
@OneToOne
private Role defaultRole;
......@@ -94,10 +88,10 @@ public class Event implements ModelInterface<Integer> {
@Version
@Column(nullable = false)
private int jpaVersionField;
@OneToMany(mappedBy = "event")
private List<Bill> bills;
@OneToMany(mappedBy = "event")
private List<Reader> readers;
......@@ -270,7 +264,8 @@ public class Event implements ModelInterface<Integer> {
}
/**
* @param bills the bills to set
* @param bills
* the bills to set
*/
public void setBills(List<Bill> bills) {
this.bills = bills;
......@@ -284,7 +279,8 @@ public class Event implements ModelInterface<Integer> {
}
/**
* @param readers the readers to set
* @param readers
* the readers to set
*/
public void setReaders(List<Reader> readers) {
this.readers = readers;
......
......@@ -11,12 +11,11 @@ import javax.persistence.*;
public class EventPk implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "entity_id", nullable = false)
@Column(name = "id", nullable = false)
private Integer id;
@Column(name = "events_pk_id", nullable = false, updatable = false)
private Integer eventId;
private static final long serialVersionUID = 1L;
......@@ -24,8 +23,6 @@ public class EventPk implements Serializable {
super();
}
public void setId(Integer id) {
this.id = id;
}
......@@ -34,30 +31,27 @@ public class EventPk implements Serializable {
return id;
}
public void setEventId(Integer eventId) {
this.eventId = eventId;
}
public Integer getEventId() {
return eventId;
}
public int hashCode() {
return id.hashCode()+eventId.hashCode();
return id.hashCode() + eventId.hashCode();
}
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj == this) return true;
if (!(obj instanceof EventPk)) return false;
if (obj == null)
return false;
if (obj == this)
return true;
if (!(obj instanceof EventPk))
return false;
EventPk pk = (EventPk) obj;
return pk.id == this.id && pk.eventId == this.eventId;
}
}
......@@ -10,6 +10,9 @@ import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
......@@ -25,13 +28,14 @@ import javax.persistence.Version;
@Table(name = "event_settings")
@NamedQueries( {
@NamedQuery(name = "EventSettings.findAll", query = "SELECT e FROM EventSettings e"),
@NamedQuery(name = "EventSettings.findByBundleCountry", query = "SELECT e FROM EventSettings e WHERE e.bundleCountry = :bundleCountry")
})
public class EventSettings implements EventChildInterface{
@NamedQuery(name = "EventSettings.findByBundleCountry", query = "SELECT e FROM EventSettings e WHERE e.bundleCountry = :bundleCountry") })
public class EventSettings implements ModelInterface<Integer> {
private static final long serialVersionUID = 1L;
@EmbeddedId
private EventPk id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "event_settings_id", nullable = false)
private Integer id;
@Column(name = "organisation")
private String organisation;
......@@ -42,7 +46,6 @@ public class EventSettings implements EventChildInterface{
@OneToMany(cascade = CascadeType.ALL, mappedBy = "settings")
private List<Event> events;
@ManyToOne
@JoinColumn(name = "users_id", referencedColumnName = "users_id", nullable = false)
private User admin;
......@@ -54,10 +57,6 @@ public class EventSettings implements EventChildInterface{
public EventSettings() {
}
public EventSettings(EventPk eventSettingsId) {
this.id = eventSettingsId;
}
public List<Event> getEvents() {
return events;
}
......@@ -97,7 +96,7 @@ public class EventSettings implements EventChildInterface{
* @return the id
*/
@Override
public EventPk getId() {
public Integer getId() {
return id;
}
......@@ -106,7 +105,7 @@ public class EventSettings implements EventChildInterface{
* the id to set
*/
@Override
public void setId(EventPk id) {
public void setId(Integer id) {
this.id = id;
}
......@@ -135,7 +134,8 @@ public class EventSettings implements EventChildInterface{
}
/**
* @param organisation the organisation to set
* @param organisation
* the organisation to set
*/
public void setOrganisation(String organisation) {
this.organisation = organisation;
......@@ -149,7 +149,8 @@ public class EventSettings implements EventChildInterface{
}
/**
* @param bundleCountry the bundleCountry to set
* @param bundleCountry
* the bundleCountry to set
*/
public void setBundleCountry(String bundleCountry) {
this.bundleCountry = bundleCountry;
......@@ -163,7 +164,8 @@ public class EventSettings implements EventChildInterface{
}
/**
* @param admin the admin to set
* @param admin
* the admin to set
*/
public void setAdmin(User admin) {
this.admin = admin;
......
......@@ -10,6 +10,9 @@ import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
......@@ -26,12 +29,14 @@ import javax.persistence.Version;
@NamedQuery(name = "EventStatus.findAll", query = "SELECT e FROM EventStatus e"),
@NamedQuery(name = "EventStatus.findByStatusName", query = "SELECT e FROM EventStatus e WHERE e.statusName = :statusName") })
public class EventStatus implements EventChildInterface{
public class EventStatus implements ModelInterface<Integer> {
private static final long serialVersionUID = 1L;
@EmbeddedId
private EventPk id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "event_status_id", nullable = false)
private Integer id;
@Column(name = "status_name", nullable = false)
private String statusName;
......@@ -46,12 +51,7 @@ public class EventStatus implements EventChildInterface{
public EventStatus() {
}
public EventStatus(EventPk eventStatusId) {
this.id = eventStatusId;
}
public EventStatus(EventPk eventStatusId, String statusName) {
this.id = eventStatusId;
public EventStatus(String statusName) {
this.statusName = statusName;
}
......@@ -102,7 +102,7 @@ public class EventStatus implements EventChildInterface{
* @return the id
*/
@Override
public EventPk getId() {
public Integer getId() {
return id;
}
......@@ -111,7 +111,7 @@ public class EventStatus implements EventChildInterface{
* the id to set
*/
@Override
public void setId(EventPk id) {
public void setId(Integer id) {
this.id = id;
}
......
......@@ -44,10 +44,12 @@ public class PasswordFunctions {
public static boolean checkPlainPassword(String plainPassword,
String saltedPassword) {
String oldBase64 = saltedPassword.substring("{SSHA}".length());
String decodedHashedAndSalt;
try {
decodedHashedAndSalt = new String(decoder.decodeBuffer(oldBase64));
logger.debug("HashAndSalt: {}", decodedHashedAndSalt);
} catch (IOException e) {
logger.error("Something awful happened...", e);
return false;
......@@ -64,7 +66,7 @@ public class PasswordFunctions {
}
private static int getSaltLenght() {
return 8;
return 4;
}
private static String generateSalt() {
......
<?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">
<sun-web-app error-url="">
<context-root>/LanBortalWeb</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class java code.</description>
</property>
</jsp-config>
<context-root>/LanBortalWeb</context-root>
<security-role-mapping>
<role-name>admin</role-name>
<group-name>admin</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>user</role-name>
<group-name>user</group-name>
</security-role-mapping>
<class-loader delegate="true" />
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class java code.</description>
</property>
</jsp-config>
</sun-web-app>
......@@ -9,39 +9,56 @@
<servlet-name>PlaceMap</servlet-name>
<url-pattern>/PlaceMap</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsf</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>PlaceMap</servlet-name>
<servlet-class>fi.insomnia.bortal.servlet.PlaceMap</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<filter>
<display-name>HostnameFilter</display-name>
<filter-name>HostnameFilter</filter-name>
<filter-class>fi.insomnia.bortal.HostnameFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HostnameFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>forbidden</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>asdasd</description>
</auth-constraint>
</security-constraint>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsf</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<filter>
<display-name>HostnameFilter</display-name>
<filter-name>HostnameFilter</filter-name>
<filter-class>fi.insomnia.bortal.HostnameFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HostnameFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>omniarealm</realm-name>
<form-login-config>
<form-login-page>/auth/login.jsf</form-login-page>
<form-error-page>/auth/loginError.jsf</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>forbidden</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>Thou shall not read the sources..</description>
</auth-constraint>
</security-constraint>
</web-app>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"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:users="http://java.sun.com/jsf/composite/tools/user" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title></title>
</h:head>
<h:body>
<ui:composition template="/layout/default-template.xhtml">
<ui:define name="title">CreateUser</ui:define>
<ui:define name="header">Add new user</ui:define>
<ui:define name="content">
<
<form method="post" action="j_security_check">
<table border="0">
<tr>
<td>#{i18n['login.username']}</td>
<td><input type="text" name="j_username" /></td>
</tr>
<tr>
<td>#{i18n['login.password']}</td>
<td><input type="password" name="j_password" /></td>
</tr>
</table>
<input type="submit" value="#{i18n['login.submit']}" />
</form>
</ui:define>
<ui:define name="footer">footer</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"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:users="http://java.sun.com/jsf/composite/tools/user" xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title></title>
</h:head>
<h:body>
<ui:composition template="/layout/default-template.xhtml">
<ui:define name="title">CreateUser</ui:define>
<ui:define name="header">Add new user</ui:define>
<ui:define name="content">
Logged out.${userView.logout() }
</ui:define>
<ui:define name="footer">footer</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<h:dataTable border="1" id="productListTable"
value="#{productView.userShoppableProducts}"
var="product">
<h:column>
<f:facet name="header">
<h:outputText value="#" />
</f:facet>
<h:outputText value="#{product.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['product.name']}" />
</f:facet>
<h:outputText value="#{product.name}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{i18n['product.price']}" />
</f:facet>
<h:outputText value="#{product.price}" />
</h:column>
</h:dataTable>
</h:form>
</composite:implementation>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:shop="http://java.sun.com/jsf/composite/tools/shop"
>
<h:head>
<title></title>
</h:head>
<h:body>
<ui:composition template="/layout/default-template.xhtml">
<ui:define name="title">Omnia</ui:define>
<ui:define name="header">Lippukauppa</ui:define>
<ui:define name="content">
<shop:productlist />
</ui:define>
<ui:define name="footer">Osta liput</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -17,7 +17,7 @@
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Nick:" /><h:inputText value="#{userView.nick}" />
<h:outputLabel value="Login name:" /><h:inputText value="#{userView.login}" />
<h:outputLabel value="Password:" /><h:inputSecret value="#{userView.password}" />
<h:commandButton action="#{userView.createUser()}" value="Create" />
</h:panelGrid>
......
......@@ -16,6 +16,7 @@
<ui:define name="header">Edit user</ui:define>
<ui:define name="content">
<h:outputText value="productlist"/>
<users:list />
</ui:define>
......
package fi.insomnia.bortal;
import java.util.ResourceBundle;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;
/***
* Access i18n localisations from Java code. Feel free to make up a better way.
* @author jkj
*
*/
public class I18n {
public static ResourceBundle GetResourceBundle()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ResourceBundle bundle = app.getResourceBundle(facesContext, "i18n");
return bundle;
}
public static String Get(String key)
{
String value = GetResourceBundle().getString(key);
if(key==null) {
return "########";
}
return value;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.view;
import fi.insomnia.bortal.beans.ProductBeanLocal;
import fi.insomnia.bortal.beans.RoleBeanLocal;
import fi.insomnia.bortal.beans.SecurityBeanLocal;
import fi.insomnia.bortal.exceptions.PermissionDeniedException;
import fi.insomnia.bortal.handler.SessionHandler;
import fi.insomnia.bortal.model.Product;
import fi.insomnia.bortal.model.Role;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author jkj
*/
@ManagedBean(name = "productView")
@SessionScoped
public class ProductView {
@EJB
private ProductBeanLocal productBean;
private static final Logger logger = LoggerFactory.getLogger(ProductView.class);
@EJB
private SecurityBeanLocal securitybean;
public DataModel<Product> getUserShoppableProducts() {
ListDataModel<Product> items = new ListDataModel<Product>(productBean.listUserShoppableProducts());
logger.info("Fetching products. Found {}", items.getRowCount());
return items;
}
}
......@@ -24,10 +24,10 @@ import fi.insomnia.bortal.model.User;
@ManagedBean(name = "userView")
@SessionScoped
public class UserView {
@ManagedProperty("#{sessionHandler}")
private SessionHandler sessionhandler;
@EJB
private SessionHandlerBeanLocal sessionbean;
......@@ -36,7 +36,7 @@ public class UserView {
private static final Logger logger = LoggerFactory.getLogger(UserView.class);
private User user;
private ListDataModel<User> items;
private String nick;
private String login;
private String password;
@EJB
private SecurityBeanLocal securitybean;
......@@ -46,8 +46,6 @@ public class UserView {
return "userEdit";
}
public String getLocale() {
return "en_ST_v7";
}
......@@ -59,11 +57,11 @@ public class UserView {
}
logger.info("Saving user");
// Luodaan uusi kÔøΩyttÔøΩjÔøΩ UserBeanin funktiolla createNewUser jolle
// annetaan parametrina pakolliset tiedot ( nick ja salasana )
// Paluuarvona saadaan uusi uljas k�ytt�j�-olio.
setUser(userBean.createNewUser(nick, password));
nick = "";
// Luodaan uusi käyttäjä UserBeanin funktiolla createNewUser jolle
// annetaan parametrina pakolliset tiedot ( login ja salasana )
// Paluuarvona saadaan uusi uljas käyttäjä-olio.
setUser(userBean.createNewUser(login, password));
login = "";
password = "";
if (getUser() == null) {
logger.warn("Could not create user. function returned null!");
......@@ -88,12 +86,12 @@ public class UserView {
}
// Getters and setters...
public String getNick() {
return nick;
public String getLogin() {
return login;
}
public void setNick(String nick) {
this.nick = nick;
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
......@@ -111,6 +109,7 @@ public class UserView {
public User getUser() {
return user;
}
public void setSessionhandler(SessionHandler sessionhandler) {
this.sessionhandler = sessionhandler;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!