Permalink
Browse files

Including registration process and refactoring to

the latest abstraction
  • Loading branch information...
1 parent f718b92 commit bbb73373f57c806dab784787cf6dae4275bedb1d @abstractj abstractj committed Oct 2, 2012
@@ -2,7 +2,6 @@
import org.jboss.aerogear.controller.demo.model.User;
import org.jboss.aerogear.security.dsl.AuthenticationManager;
-import org.jboss.aerogear.security.dsl.IDMHelper;
import javax.ejb.Stateless;
import javax.inject.Inject;
@@ -13,33 +12,20 @@
@Inject
private AuthenticationManager authenticationManager;
- @Inject
- private IDMHelper idm;
-
public void index() {
System.out.println("Login page!");
}
public User login(User user) {
- System.out.println(user.getName());
+ System.out.println(user.getId());
System.out.println(user.getPassword());
- boolean logged = authenticationManager.login(user.getName(), user.getPassword());
+ boolean logged = authenticationManager.login(user.getId(), user.getPassword());
System.out.println("Logged? " + logged);
return user;
}
- public User register(User user) {
- System.out.println(user.getName());
- System.out.println(user.getPassword());
-
-// idm.grant(user.getRole()).to(user);
-// boolean logged = authenticationManager.login(user.getUsername(), user.getPassword());
-// System.out.println("Registered? " + logged);
- return user;
- }
-
public void logout() {
System.out.println("User logout!");
}
@@ -0,0 +1,31 @@
+package org.jboss.aerogear.controller.demo;
+
+import org.jboss.aerogear.controller.demo.model.User;
+import org.jboss.aerogear.security.dsl.AuthenticationManager;
+import org.jboss.aerogear.security.dsl.IDMHelper;
+import org.jboss.aerogear.security.model.AeroGearUser;
+import org.jboss.picketlink.idm.model.SimpleUser;
+
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+
+@Stateless
+public class Register {
+
+ @Inject
+ private IDMHelper idm;
+
+ @Inject
+ private AuthenticationManager authenticationManager;
+
+ public void index() {
+ System.out.println("Login page!");
+ }
+
+ public AeroGearUser register(User user) {
+
+ idm.grant("admin").to(user);
+ boolean logged = authenticationManager.login(user.getId(), user.getPassword());
+ return user;
+ }
+}
@@ -60,6 +60,10 @@ public void configuration() {
route()
.from("/register")
.on(RequestMethod.GET)
- .to(Login.class).register(param(User.class));
+ .to(Register.class).index();
+ route()
+ .from("/create")
+ .on(RequestMethod.POST)
+ .to(Register.class).register(param(User.class));
}
}
@@ -1,24 +1,65 @@
package org.jboss.aerogear.controller.demo.model;
-public class User {
- private String name;
+import org.jboss.aerogear.security.model.AeroGearUser;
+
+public class User extends AeroGearUser {
+
+ private String id;
+ private String firstName;
+ private String lastName;
+ private String email;
private String password;
- public String getName() {
- return name;
+ public User(){
+ }
+
+ public User(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
}
- public void setName(String name) {
- this.name = name;
+ public String getFullName() {
+ return String.format("%s %s", firstName, lastName);
}
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getKey() {
+ return String.format("%s%s", KEY_PREFIX, id);
+ }
+
+ @Override
public String getPassword() {
return password;
}
+ @Override
public void setPassword(String password) {
- this.password = password;
+ this.password = password;
}
-
-
}
@@ -11,7 +11,7 @@
<form action="signin" method="post">
<label>Username:</label>
- <input type="text" name="user.name"/>
+ <input type="text" name="user.id"/>
<label>Password:</label>
<input type="password" name="user.password"/>
<input type="submit"/>
@@ -8,7 +8,7 @@
<div class="sixteen columns">
<p>maybe you should try the <a href="delorean">delorean page</a></p>
- hello ${user.name} to the authentication page!
+ hello ${user.id} to the authentication page!
</div>
</div>
<jsp:include page="../../template/footer.jsp" />
@@ -0,0 +1,23 @@
+<jsp:include page="../../template/header.jsp" />
+<div class="container">
+ <div class="sixteen columns">
+ <h1 class="remove-bottom" style="margin-top: 40px">Register</h1>
+ <hr />
+ </div>
+ <div class="sixteen columns">
+ <p>maybe you should try the <a href="delorean">restricted delorean page</a></p>
+ </div>
+ <div class="sixteen columns">
+ <form action="create" method="post">
+
+ <label>Username:</label>
+ <input type="text" name="user.id"/>
+ <label>Password:</label>
+ <input type="password" name="user.password"/>
+ <input type="submit"/>
+
+ </form>
+ </div>
+
+</div>
+<jsp:include page="../../template/footer.jsp" />
@@ -1,17 +1,14 @@
+<jsp:include page="../../template/header.jsp" />
<%@page pageEncoding="UTF-8" %>
-<html>
-<body>
-<p>hello, index!</p>
-<p>maybe you should try the <a href="delorean">delorean page</a></p>
+<div class="container">
+ <div class="sixteen columns">
+ <h1 class="remove-bottom" style="margin-top: 40px">Logged in</h1>
+ <hr />
+ </div>
+ <div class="sixteen columns">
+ <p>maybe you should try the <a href="delorean">delorean page</a></p>
-<p>
-<form action="cars" method="post">
- <ul>
- <li><label>Color:</label><input type="text" name="car.color"/></li>
- <li><label>Brand:</label><input type="text" name="car.brand"/></li>
- <li><input type="submit"/></li>
- </ul>
-</form>
-</p>
-</body>
-</html>
+ hello ${user.id} to the authentication page!
+ </div>
+</div>
+<jsp:include page="../../template/footer.jsp" />
@@ -8,7 +8,7 @@
<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8">
- <title>Your Page Title Here :)</title>
+ <title>AeroGear Security Demo Page</title>
<meta name="description" content="">
<meta name="author" content="">

0 comments on commit bbb7337

Please sign in to comment.