KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > DefaultAuthenticator


1
2 package org.roller.presentation;
3
4 import java.security.Principal JavaDoc;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7
8
9 /** Class used by Roller to check user authentication and role */
10 public class DefaultAuthenticator implements Authenticator
11 {
12     /** Return the name of the request's authenticated user, or null if none */
13     public String JavaDoc getAuthenticatedUserName( HttpServletRequest JavaDoc req )
14     {
15         String JavaDoc ret = null;
16         Principal JavaDoc prince = req.getUserPrincipal();
17         if ( prince != null )
18         {
19             ret = prince.getName();
20         }
21         return ret;
22     }
23
24     /** Return true if authenticated user is in the specified role */
25     public boolean isAuthenticatedUserInRole(HttpServletRequest JavaDoc req,String JavaDoc role)
26     {
27         return req.isUserInRole( role );
28     }
29 }
30
31
Popular Tags