1
2
3
4
5
6
7
8
9
10
11
12package security.constraint;
13
14import security.user.User;
15import security.user.UserContext;
16
17public class AccessChecker
18{
19 public boolean isAccessAllowed(AccessControl control)
20 {
21 return isAccessAllowed(control.role());
22 }
23
24 public boolean isAccessAllowed(AccessAware access)
25 {
26 return isAccessAllowed(access.getRequiredRole());
27 }
28
29 private boolean isAccessAllowed(String role)
30 {
31 User user = UserContext.get().getUser();
32 if (user == null)
33 {
34 return false;
35 }
36 if (user.isInRole(role))
37 {
38 return true;
39 }
40 else
41 {
42 return false;
43 }
44 }
45}
// Copyright 2007, Tim Vernum
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package security.constraint;
import security.user.User;
import security.user.UserContext;
public class AccessChecker
{
public boolean isAccessAllowed(AccessControl control)
{
return isAccessAllowed(control.role());
}
public boolean isAccessAllowed(AccessAware access)
{
return isAccessAllowed(access.getRequiredRole());
}
private boolean isAccessAllowed(String role)
{
User user = UserContext.get().getUser();
if (user == null)
{
return false;
}
if (user.isInRole(role))
{
return true;
}
else
{
return false;
}
}
}