Commit 2a7c9cde by Tuukka Kivilahti

login and logout stuff

1 parent b1b30814
...@@ -89,4 +89,12 @@ public class SessionHandlerBean implements SessionHandlerBeanLocal { ...@@ -89,4 +89,12 @@ public class SessionHandlerBean implements SessionHandlerBeanLocal {
return false; return false;
} }
public User tryLogin(String username, String password) {
throw new UnsupportedOperationException("Not supported yet.");
}
public User getDefaultUser() {
throw new UnsupportedOperationException("Not supported yet.");
}
} }
...@@ -9,4 +9,13 @@ public interface SessionHandlerBeanLocal { ...@@ -9,4 +9,13 @@ public interface SessionHandlerBeanLocal {
boolean hasPermission(String target, User user, RolePermission permission); boolean hasPermission(String target, User user, RolePermission permission);
/**
*
* @param username
* @param password
* @return User on success, null on fail
*/
User tryLogin(String username, String password);
User getDefaultUser();
} }
...@@ -67,9 +67,22 @@ ...@@ -67,9 +67,22 @@
<from-outcome>permissionDenied</from-outcome> <from-outcome>permissionDenied</from-outcome>
<to-view-id>/permissionDenied.xhtml</to-view-id> <to-view-id>/permissionDenied.xhtml</to-view-id>
</navigation-case> </navigation-case>
<navigation-case>
<from-outcome>logout</from-outcome>
<to-view-id>/NotImplementedYet.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>loginSuccess</from-outcome>
<to-view-id>/NotImplementedYet.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>loginFailed</from-outcome>
<to-view-id>/NotImplementedYet.xhtml</to-view-id>
</navigation-case>
</navigation-rule> </navigation-rule>
</faces-config> </faces-config>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<composite:interface>
<composite:attribute type="java.lang.Boolean" name="isOneliner" required="false" />
</composite:interface>
<composite:implementation>
<h:form>
<c:choose>
<c:when test="#{isOneliner}">
<h:inputText value="#{sessionHandler.username}" />
<h:inputSecret value="#{sessionHandler.password}" />
<h:commandButton action="#{sessionHandler.login}" />
</c:when>
<c:otherwise>
<h:panelGrid columns="2">
<h:inputText value="#{sessionHandler.username}" />
<h:inputSecret value="#{sessionHandler.password}" />
<h:commandButton action="#{sessionHandler.login}" />
</h:panelGrid>
</c:otherwise>
</c:choose>
</h:form>
</composite:implementation>
</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">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:form>
<h:commandButton action="#{sessionHandler.logout}" value="#{i18n['logout']}" />
</h:form>
</composite:implementation>
</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:login="http://java.sun.com/jsf/composite/tools/login"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface>
</composite:interface>
<composite:implementation>
<tools:canRead target="login">
<f:facet name="errorMessage">
<login:logout />
</f:facet>
<login:login isOneliner="true" />
</tools:canRead>
</composite:implementation>
</html>
\ No newline at end of file
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
userManagement userManagement
roleManagement roleManagement
login
\ No newline at end of file
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
* To change this template, choose Tools | Templates * To change this template, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package fi.insomnia.bortal.handler; package fi.insomnia.bortal.handler;
import javax.ejb.EJB; import javax.ejb.EJB;
...@@ -24,7 +23,9 @@ public class SessionHandler { ...@@ -24,7 +23,9 @@ public class SessionHandler {
@EJB @EJB
private SessionHandlerBeanLocal handlerbean; private SessionHandlerBeanLocal handlerbean;
private User user; private User user = null;
private String username = "";
private String password = "";
/** Creates a new instance of SessionHandler */ /** Creates a new instance of SessionHandler */
public SessionHandler() { public SessionHandler() {
...@@ -66,11 +67,56 @@ public class SessionHandler { ...@@ -66,11 +67,56 @@ public class SessionHandler {
} }
public User getUser() { public User getUser() {
if (user == null) {
user = handlerbean.getDefaultUser();
}
return user; return user;
} }
public boolean hasLoggedIn() { public String logout() {
throw new UnsupportedOperationException(); user = null;
return "logout";
} }
public String login() {
user = handlerbean.tryLogin(username, password);
if (user == null) {
return "loginFailed";
} else {
return "loginSuccess";
}
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!