Skip to content

Commit

Permalink
Added profile page. Added authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
bhoflack committed Aug 24, 2009
1 parent c94af0c commit 8e04eec
Show file tree
Hide file tree
Showing 19 changed files with 604 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ public interface UserProfileRepository {
*/
List<UserProfile> findAll();

/**
* Update the userProfile to the repository.
* @param u the userProfile
*/
void update(UserProfile u);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public UserProfile findUserOrCreateNew(String username) {
public List<UserProfile> findAll() {
return hibernateTemplate.findByNamedQuery("userProfile.findAll");
}

public void update(UserProfile u) {
hibernateTemplate.update(u);
}
}
5 changes: 5 additions & 0 deletions lunch_wicket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
<artifactId>wicket</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-auth-roles</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-spring</artifactId>
Expand Down
80 changes: 80 additions & 0 deletions lunch_wicket/src/main/java/com/melexis/DepositPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2009 brh.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/

package com.melexis;

import com.melexis.repository.DepositRepository;
import com.melexis.repository.UserProfileRepositoryBean;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
*
* @author brh
*/
public class DepositPage extends WebPage {

@SpringBean
private UserProfileRepositoryBean userProfileRepositoryBean;

@SpringBean
private DepositRepository depositRepository;

public DepositPage() {

}

// public class DepositForm extends Form<Deposit> {
//
// public DepositForm() {
// add(new TextField("name", null));
// }
// }

// public class DetachableDepositModel extends LoadableDetachableModel<DepositModel> {
//
// private final int id;
//
// public DetachableDepositModel(int id) {
// this.id = id;
// }
//
// @Override
// protected DepositModel load() {
// depo
// }
//
// }

public class DepositModel {

private final String who;
private final String user;
private final Double amount;

public DepositModel(String who, String user, Double amount) {
this.who = who;
this.user = user;
this.amount = amount;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2009 brh.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/

package com.melexis;

import com.melexis.repository.UserProfileRepository;
import org.apache.wicket.model.LoadableDetachableModel;

/**
*
* @author brh
*/
public class DetachableUserProfileModel extends LoadableDetachableModel<UserProfile> {

private final String name;
private final UserProfileRepository userProfileRepository;

public DetachableUserProfileModel(UserProfileRepository userProfileRepository,
String name) {
this.name = name;
this.userProfileRepository = userProfileRepository;
}

@Override
protected UserProfile load() {
return userProfileRepository.findUserOrCreateNew(name);
}

}
2 changes: 2 additions & 0 deletions lunch_wicket/src/main/java/com/melexis/HomePage.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<a href="#" wicket:id="productlist">Product List</a>
<br />
<a href="#" wicket:id="orderproduct">Order Product</a>
<br/>
<a href="#" wicket:id="userprofiles">User profiles</a>
</body>
</html>

21 changes: 15 additions & 6 deletions lunch_wicket/src/main/java/com/melexis/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ public void onClick() {
setResponsePage(ProductList.class);
}
});
add(new Link("orderproduct") {
@Override
public void onClick() {
setResponsePage(OrderProduct.class);
}
});
add(new Link("orderproduct") {

@Override
public void onClick() {
setResponsePage(OrderProduct.class);
}
});
add(new Link("userprofiles") {

@Override
public void onClick() {
setResponsePage(UserProfilePage.class);
}
});

}
}
10 changes: 10 additions & 0 deletions lunch_wicket/src/main/java/com/melexis/LoginPage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>Sign In</title>
</head>
<body>
<h2>Sign In</h2>
<p>
<span wicket:id="signInPanel"/>
</body>
</html>
29 changes: 29 additions & 0 deletions lunch_wicket/src/main/java/com/melexis/LoginPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2009 brh.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/

package com.melexis;

import org.apache.wicket.authentication.pages.SignInPage;

/**
*
* @author brh
*/

public class LoginPage extends SignInPage {

}
28 changes: 28 additions & 0 deletions lunch_wicket/src/main/java/com/melexis/LogoutPage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Copyright 2009 brh.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
under the License.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sign out</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h2>Bye!</h2>

<a href="#" wicket:id="home">Home</a>
</body>
</html>
33 changes: 33 additions & 0 deletions lunch_wicket/src/main/java/com/melexis/LogoutPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2009 brh.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/

package com.melexis;

import org.apache.wicket.authentication.pages.SignOutPage;
import org.apache.wicket.markup.html.link.PageLink;

/**
*
* @author brh
*/
public class LogoutPage extends SignOutPage {

public LogoutPage() {
add(new PageLink("home", HomePage.class));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2009 brh.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/

package com.melexis;

import com.melexis.repository.UserProfileRepository;
import org.apache.wicket.Request;
import org.apache.wicket.authentication.AuthenticatedWebSession;
import org.apache.wicket.authorization.strategies.role.Roles;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
*
* @author brh
*/
public class LunchAuthenticatedWebSession extends AuthenticatedWebSession {

@SpringBean
private UserProfileRepository userProfileRepository;

private String username;

public LunchAuthenticatedWebSession(Request r) {
super(r);
}

@Override
public boolean authenticate(String username, String password) {
this.username = username;
return username.equals(password);
}

@Override
public Roles getRoles() {
if (isSignedIn() && isAdmin()) {
return new Roles(Roles.ADMIN);
}
return null;
}

private boolean isAdmin() {
if (getUsername().equals("brh")) {
return true;
}

return userProfileRepository.findUserOrCreateNew(getUsername()).isAdmin();
}

/**
* @return the username
*/
public String getUsername() {
return username;
}

}
9 changes: 6 additions & 3 deletions lunch_wicket/src/main/java/com/melexis/ModelOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package com.melexis;

import java.util.Arrays;
import java.util.Date;

/**
*
* @author kry
Expand All @@ -40,8 +43,8 @@ public void setQuantity(int quantity) {
this.quantity = quantity;
}




public Order createOrder(UserProfile who, UserProfile user) throws InsufficientPriviledgesException {
return new Order(who, user, new Date(), Arrays.asList(new Product[] {this}));
}

}
Loading

0 comments on commit 8e04eec

Please sign in to comment.