forked from bhoflack/lunch_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added profile page. Added authentication
- Loading branch information
Showing
19 changed files
with
604 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
lunch_wicket/src/main/java/com/melexis/DetachableUserProfileModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
lunch_wicket/src/main/java/com/melexis/LunchAuthenticatedWebSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.