01: /*
02: * (C) Janne Jalkanen 2005
03: *
04: */
05: package com.ecyrd.jspwiki;
06:
07: import java.security.Principal;
08: import java.util.Properties;
09:
10: import javax.servlet.http.HttpServletRequest;
11:
12: import com.ecyrd.jspwiki.auth.authorize.Role;
13: import com.ecyrd.jspwiki.auth.authorize.WebAuthorizer;
14:
15: /**
16: * A very fast authorizer that does almost nothing. The WebContainerAuthorizer module
17: * is very slow, as it parses the web.xml each time, so we use this for most of
18: * the different tests.
19: * @author Janne Jalkanen
20: * @author Andrew R. Jaquith
21: * @since 2.3
22: */
23: public class TestAuthorizer implements WebAuthorizer {
24: private Role[] m_roles = new Role[] { new Role("Admin"),
25: Role.AUTHENTICATED, new Role("IT"), new Role("Finance"),
26: new Role("Engineering") };
27:
28: public TestAuthorizer() {
29: super ();
30: }
31:
32: public Principal findRole(String role) {
33: return null;
34: }
35:
36: public void initialize(WikiEngine engine, Properties props) {
37: }
38:
39: /**
40: * Returns an array of Principal objects containing five elements:
41: * Role "Admin", Role.AUTHENTICATED, Role "IT", Role "Finance" and
42: * Role "Engineering."
43: */
44: public Principal[] getRoles() {
45: return (Principal[]) m_roles.clone();
46: }
47:
48: /**
49: * Returns <code>true</code> if the WikiSession's Subject contains
50: * a particular role principal.
51: */
52: public boolean isUserInRole(WikiSession session, Principal role) {
53: if (session == null || role == null) {
54: return false;
55: }
56:
57: return session.hasPrincipal(role);
58: }
59:
60: /**
61: * Returns <code>true</code> if the HTTP request contains
62: * a particular role principal. Delegates to
63: * {@link javax.servlet.http.HttpServletRequest#isUserInRole(String)}.
64: * @see com.ecyrd.jspwiki.auth.authorize.WebAuthorizer#isUserInRole(javax.servlet.http.HttpServletRequest, java.security.Principal)
65: */
66: public boolean isUserInRole(HttpServletRequest request,
67: Principal role) {
68: return request.isUserInRole(role.getName());
69: }
70:
71: }
|