Refactor formatter and clean up code.

This commit is contained in:
Christian P. MOMON 2016-09-08 03:45:06 +02:00
parent 90a8d57df4
commit 4de5e49850
20 changed files with 1922 additions and 1814 deletions

View file

@ -282,7 +282,7 @@ org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4 org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false

View file

@ -1,2 +1,109 @@
cleanup.add_default_serial_version_id=false
cleanup.add_generated_serial_version_id=true
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=false
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=true
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=true
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_to_enhanced_for_loop=false
cleanup.correct_indentation=false
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.make_local_variable_final=false
cleanup.make_parameters_final=true
cleanup.make_private_fields_final=false
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=true
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=true
cleanup.organize_imports=false
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=true
cleanup.sort_members_all=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_parentheses_in_expressions=false
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
cleanup.use_this_for_non_static_method_access=false
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup_profile=_Kiss4web
cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Kiss4web
formatter_settings_version=12 formatter_settings_version=12
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=true
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=true
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=true
sp_cleanup.make_private_fields_final=false
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_trailing_whitespaces=false
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=true
sp_cleanup.sort_members_all=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=true
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true

View file

@ -33,193 +33,193 @@ import org.slf4j.LoggerFactory;
*/ */
public class CookieHelper public class CookieHelper
{ {
public enum Scope public enum Scope
{ {
HTTP_AND_HTTPS, HTTP_AND_HTTPS,
HTTPS_ONLY HTTPS_ONLY
} }
private static final Logger logger = LoggerFactory.getLogger(CookieHelper.class); private static final Logger logger = LoggerFactory.getLogger(CookieHelper.class);
/** /**
* *
*/ */
public static Cookie buildCookie(final String name, final String value, final int duration) public static Cookie buildCookie(final String name, final String value, final int duration)
{ {
Cookie result; Cookie result;
result = buildCookie(name, value, duration, Scope.HTTP_AND_HTTPS); result = buildCookie(name, value, duration, Scope.HTTP_AND_HTTPS);
// //
return (result); return (result);
} }
/** /**
* Warning: value is UTF-8 URLEncoded! * Warning: value is UTF-8 URLEncoded!
*/ */
public static Cookie buildCookie(final String name, final String value, final int duration, final Scope secure) public static Cookie buildCookie(final String name, final String value, final int duration, final Scope secure)
{ {
Cookie result; Cookie result;
// //
try try
{ {
result = new Cookie(name, java.net.URLEncoder.encode(value, "UTF-8")); result = new Cookie(name, java.net.URLEncoder.encode(value, "UTF-8"));
result.setMaxAge(duration); result.setMaxAge(duration);
result.setPath("/"); result.setPath("/");
// //
boolean secureValue; boolean secureValue;
if (secure == Scope.HTTPS_ONLY) if (secure == Scope.HTTPS_ONLY)
{ {
secureValue = true; secureValue = true;
} }
else else
{ {
secureValue = false; secureValue = false;
} }
result.setSecure(secureValue); result.setSecure(secureValue);
} }
catch (UnsupportedEncodingException exception) catch (UnsupportedEncodingException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
throw new IllegalArgumentException("value is unsupported encoding."); throw new IllegalArgumentException("value is unsupported encoding.");
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static boolean exists(final HttpServletRequest request, final String key) public static boolean exists(final HttpServletRequest request, final String key)
{ {
boolean result; boolean result;
if (getCookieValue(request, key) == null) if (getCookieValue(request, key) == null)
{ {
result = false; result = false;
} }
else else
{ {
result = true; result = true;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static Cookie getCookie(final Cookie[] cookies, final String key) public static Cookie getCookie(final Cookie[] cookies, final String key)
{ {
Cookie result = null; Cookie result = null;
if (cookies == null) if (cookies == null)
{ {
result = null; result = null;
} }
else else
{ {
boolean ended = false; boolean ended = false;
int cookieCounter = 0; int cookieCounter = 0;
while (!ended) while (!ended)
{ {
if (cookieCounter < cookies.length) if (cookieCounter < cookies.length)
{ {
if (key.equals(cookies[cookieCounter].getName())) if (key.equals(cookies[cookieCounter].getName()))
{ {
ended = true; ended = true;
result = cookies[cookieCounter]; result = cookies[cookieCounter];
} }
else else
{ {
cookieCounter += 1; cookieCounter += 1;
} }
} }
else else
{ {
ended = true; ended = true;
result = null; result = null;
} }
} }
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static Cookie getCookie(final HttpServletRequest request, final String key) public static Cookie getCookie(final HttpServletRequest request, final String key)
{ {
Cookie result = null; Cookie result = null;
result = getCookie(request.getCookies(), key); result = getCookie(request.getCookies(), key);
// //
return (result); return (result);
} }
/** /**
* Note: value is UTF-8 decoded. * Note: value is UTF-8 decoded.
*/ */
static public Object getCookieValue(final Cookie[] cookies, final String key) static public Object getCookieValue(final Cookie[] cookies, final String key)
{ {
Object result; Object result;
try try
{ {
Cookie cookie = getCookie(cookies, key); Cookie cookie = getCookie(cookies, key);
if (cookie == null) if (cookie == null)
{ {
result = null; result = null;
} }
else else
{ {
result = java.net.URLDecoder.decode(cookie.getValue(), "UTF-8"); result = java.net.URLDecoder.decode(cookie.getValue(), "UTF-8");
} }
} }
catch (UnsupportedEncodingException exception) catch (UnsupportedEncodingException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static Object getCookieValue(final HttpServletRequest request, final String key) public static Object getCookieValue(final HttpServletRequest request, final String key)
{ {
Object result; Object result;
result = getCookieValue(request.getCookies(), key); result = getCookieValue(request.getCookies(), key);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static void reset(final HttpServletResponse response, final String key) public static void reset(final HttpServletResponse response, final String key)
{ {
response.addCookie(buildCookie(key, "", 0)); response.addCookie(buildCookie(key, "", 0));
} }
/** /**
* *
*/ */
public static void set(final HttpServletResponse response, final String name, final String value, final int duration) public static void set(final HttpServletResponse response, final String name, final String value, final int duration)
{ {
response.addCookie(buildCookie(name, value, duration)); response.addCookie(buildCookie(name, value, duration));
} }
} }

View file

@ -27,74 +27,74 @@ import org.apache.commons.fileupload.FileItem;
*/ */
public class FileItemHelper public class FileItemHelper
{ {
// static private final Logger logger = // static private final Logger logger =
// LoggerFactory.getLogger(FileItemHelper.class); // LoggerFactory.getLogger(FileItemHelper.class);
/** /**
* List FileItem * List FileItem
*/ */
public static FileItem getItem(final List items, final String name) public static FileItem getItem(final List items, final String name)
{ {
FileItem result; FileItem result;
if (name == null) if (name == null)
{ {
result = null; result = null;
} }
else else
{ {
result = null; result = null;
boolean ended = false; boolean ended = false;
int itemIndex = 0; int itemIndex = 0;
while (!ended) while (!ended)
{ {
if (itemIndex < items.size()) if (itemIndex < items.size())
{ {
FileItem item = (FileItem) items.get(itemIndex); FileItem item = (FileItem) items.get(itemIndex);
if (name.equals(item.getFieldName())) if (name.equals(item.getFieldName()))
{ {
ended = true; ended = true;
result = item; result = item;
} }
else else
{ {
itemIndex += 1; itemIndex += 1;
} }
} }
else else
{ {
ended = true; ended = true;
result = null; result = null;
} }
} }
} }
// //
return (result); return (result);
} }
/** /**
* List FileItem * List FileItem
*/ */
public static String getItemValue(final List items, final String name) public static String getItemValue(final List items, final String name)
{ {
String result; String result;
FileItem item = getItem(items, name); FileItem item = getItem(items, name);
if (item == null) if (item == null)
{ {
result = null; result = null;
} }
else else
{ {
result = item.getString(); result = item.getString();
} }
// //
return (result); return (result);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load diff

View file

@ -29,8 +29,8 @@ import javax.servlet.http.HttpServletResponse;
*/ */
public interface Page public interface Page
{ {
/** /**
* *
*/ */
public void doIt(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; public void doIt(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
} }

View file

@ -35,387 +35,387 @@ import fr.devinsy.kiss4web.security.User;
*/ */
public class PageManager extends HttpServlet public class PageManager extends HttpServlet
{ {
private static final long serialVersionUID = 1983715791417570578L; private static final long serialVersionUID = 1983715791417570578L;
private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(PageManager.class); private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(PageManager.class);
private static PageManager instance = null; private static PageManager instance = null;
private SecurityAgent securityAgent; private SecurityAgent securityAgent;
/** /**
* *
*/ */
@Override @Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{ {
logger.info("=================================================="); logger.info("==================================================");
logger.info("getContextPath=[" + request.getContextPath() + "]"); logger.info("getContextPath=[" + request.getContextPath() + "]");
logger.info("getPathInfo=[" + request.getPathInfo() + "]"); logger.info("getPathInfo=[" + request.getPathInfo() + "]");
logger.info("getPathTranslated=[" + request.getPathTranslated() + "]"); logger.info("getPathTranslated=[" + request.getPathTranslated() + "]");
logger.info("getQueryString=[" + request.getQueryString() + "]"); logger.info("getQueryString=[" + request.getQueryString() + "]");
logger.info("getRequestURI=[" + request.getRequestURI() + "]"); logger.info("getRequestURI=[" + request.getRequestURI() + "]");
logger.info("getRequestURL=[" + request.getRequestURL() + "]"); logger.info("getRequestURL=[" + request.getRequestURL() + "]");
logger.info("getServletPath=[" + request.getServletPath() + "]"); logger.info("getServletPath=[" + request.getServletPath() + "]");
String className = buildClassName(request.getPathInfo()); String className = buildClassName(request.getPathInfo());
logger.info("className=" + className); logger.info("className=" + className);
Page page = this.instanciatePage("site." + className); Page page = this.instanciatePage("site." + className);
if (page == null) if (page == null)
{ {
response.setContentType("text/html"); response.setContentType("text/html");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
out.println("Unknow page."); out.println("Unknow page.");
} }
else else
{ {
HttpSession session = request.getSession(false); HttpSession session = request.getSession(false);
String login; String login;
if (session == null) if (session == null)
{ {
login = null; login = null;
} }
else else
{ {
login = (String) session.getAttribute("login"); login = (String) session.getAttribute("login");
} }
if (this.securityAgent.checkPermission(request.getPathInfo(), login)) if (this.securityAgent.checkPermission(request.getPathInfo(), login))
{ {
page.doIt(request, response); page.doIt(request, response);
logger.info("securityAgent say 'permission OK': (" + login + ", " + request.getPathInfo() + ")"); logger.info("securityAgent say 'permission OK': (" + login + ", " + request.getPathInfo() + ")");
} }
else else
{ {
logger.info("securityAgent say 'permission KO': (" + login + ", " + request.getPathInfo() + ")"); logger.info("securityAgent say 'permission KO': (" + login + ", " + request.getPathInfo() + ")");
if (login == null) if (login == null)
{ {
response.sendRedirect("/gestion/login.xhtml"); response.sendRedirect("/gestion/login.xhtml");
} }
else else
{ {
response.setContentType("text/html"); response.setContentType("text/html");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
out.println("<html><head></head><body>"); out.println("<html><head></head><body>");
out.println("Permission denied."); out.println("Permission denied.");
out.println("<form method='get' action='javascript:window.back ();'>"); out.println("<form method='get' action='javascript:window.back ();'>");
out.println(" <input type='submit' name='retour' value='Retour' />"); out.println(" <input type='submit' name='retour' value='Retour' />");
out.println("</form>"); out.println("</form>");
out.println("</body></html>"); out.println("</body></html>");
} }
} }
} }
} }
/** /**
* *
*/ */
@Override @Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
{ {
doGet(request, response); doGet(request, response);
} }
/** /**
* *
*/ */
@Override @Override
public void init() throws ServletException public void init() throws ServletException
{ {
// //
instance = this; instance = this;
try try
{ {
this.securityAgent = new SecurityAgent(getInitParameter("securityDataPath")); this.securityAgent = new SecurityAgent(getInitParameter("securityDataPath"));
} }
catch (Exception exception) catch (Exception exception)
{ {
throw new ServletException("SecurityAgent initialization failed.", exception); throw new ServletException("SecurityAgent initialization failed.", exception);
} }
} }
/** /**
*/ */
public Page instanciatePage(final String className) public Page instanciatePage(final String className)
{ {
Page result; Page result;
Class<Page> pageClass = null; Class<Page> pageClass = null;
try try
{ {
pageClass = (Class<Page>) Class.forName(className); pageClass = (Class<Page>) Class.forName(className);
} }
catch (java.lang.ClassNotFoundException exception) catch (java.lang.ClassNotFoundException exception)
{ {
result = null; result = null;
} }
logger.info("class=" + pageClass); logger.info("class=" + pageClass);
if (pageClass == null) if (pageClass == null)
{ {
result = null; result = null;
logger.error("Unknow page: (" + className + ")"); logger.error("Unknow page: (" + className + ")");
} }
else else
{ {
try try
{ {
result = pageClass.newInstance(); result = pageClass.newInstance();
} }
catch (java.lang.InstantiationException exception) catch (java.lang.InstantiationException exception)
{ {
logger.error("Can't instanciate page (" + className + ")"); logger.error("Can't instanciate page (" + className + ")");
result = null; result = null;
} }
catch (java.lang.IllegalAccessException exception) catch (java.lang.IllegalAccessException exception)
{ {
logger.error("(2) Can't instanciate page (" + className + ")"); logger.error("(2) Can't instanciate page (" + className + ")");
result = null; result = null;
} }
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public SecurityAgent securityAgent() public SecurityAgent securityAgent()
{ {
SecurityAgent result; SecurityAgent result;
result = this.securityAgent; result = this.securityAgent;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
static public String buildClassName(final String pathInfo) static public String buildClassName(final String pathInfo)
{ {
String result; String result;
result = null; result = null;
if (pathInfo.equals("/")) if (pathInfo.equals("/"))
{ {
result = "Accueil"; result = "Accueil";
} }
else else
{ {
String[] tokens = pathInfo.split("/"); String[] tokens = pathInfo.split("/");
StringBuffer name = new StringBuffer(); StringBuffer name = new StringBuffer();
for (int tokenCounter = 1; tokenCounter < tokens.length - 1; tokenCounter++) for (int tokenCounter = 1; tokenCounter < tokens.length - 1; tokenCounter++)
{ {
name.append(tokens[tokenCounter]); name.append(tokens[tokenCounter]);
name.append('.'); name.append('.');
} }
if (pathInfo.endsWith("/")) if (pathInfo.endsWith("/"))
{ {
name.append(tokens[tokens.length - 1]); name.append(tokens[tokens.length - 1]);
name.append('.'); name.append('.');
} }
logger.info("==>[" + tokens[tokens.length - 1] + "]"); logger.info("==>[" + tokens[tokens.length - 1] + "]");
name.append(formatClassName(tokens[tokens.length - 1])); name.append(formatClassName(tokens[tokens.length - 1]));
result = name.toString(); result = name.toString();
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static String buildClassName2(final String pathInfo) public static String buildClassName2(final String pathInfo)
{ {
String result; String result;
if (pathInfo.endsWith(".xhtml")) if (pathInfo.endsWith(".xhtml"))
{ {
char[] source = pathInfo.toCharArray(); char[] source = pathInfo.toCharArray();
StringBuffer out = new StringBuffer(); StringBuffer out = new StringBuffer();
for (char c : source) for (char c : source)
{ {
out.append("[" + c + "]"); out.append("[" + c + "]");
} }
logger.debug(out.toString()); logger.debug(out.toString());
char[] target = new char[source.length - 7]; char[] target = new char[source.length - 7];
int lastStartToken = 0; int lastStartToken = 0;
for (int nChar = 1; nChar < source.length - 5; nChar++) for (int nChar = 1; nChar < source.length - 5; nChar++)
{ {
char charSource = source[nChar]; char charSource = source[nChar];
switch (charSource) switch (charSource)
{ {
case '/': case '/':
target[nChar - 1] = '.'; target[nChar - 1] = '.';
lastStartToken = nChar; lastStartToken = nChar;
break; break;
case '.': case '.':
target[lastStartToken] = Character.toUpperCase(target[lastStartToken]); target[lastStartToken] = Character.toUpperCase(target[lastStartToken]);
break; break;
default: default:
target[nChar - 1] = source[nChar]; target[nChar - 1] = source[nChar];
} }
} }
out = new StringBuffer(); out = new StringBuffer();
for (char c : target) for (char c : target)
{ {
out.append("[" + c + "]"); out.append("[" + c + "]");
} }
logger.debug(out.toString()); logger.debug(out.toString());
result = new String(target); result = new String(target);
} }
else if (pathInfo.equals("/")) else if (pathInfo.equals("/"))
{ {
result = "Accueil"; result = "Accueil";
} }
else if (pathInfo.endsWith("/")) else if (pathInfo.endsWith("/"))
{ {
char[] source = pathInfo.toCharArray(); char[] source = pathInfo.toCharArray();
StringBuffer out = new StringBuffer(); StringBuffer out = new StringBuffer();
for (char c : source) for (char c : source)
{ {
out.append("[" + c + "]"); out.append("[" + c + "]");
} }
logger.debug(out.toString()); logger.debug(out.toString());
char[] target = new char[source.length - 2]; char[] target = new char[source.length - 2];
int lastStartToken = 0; int lastStartToken = 0;
for (int nChar = 1; nChar < source.length - 1; nChar++) for (int nChar = 1; nChar < source.length - 1; nChar++)
{ {
char charSource = source[nChar]; char charSource = source[nChar];
switch (charSource) switch (charSource)
{ {
case '/': case '/':
target[nChar - 1] = '.'; target[nChar - 1] = '.';
lastStartToken = nChar + 1; lastStartToken = nChar + 1;
break; break;
default: default:
target[nChar - 1] = source[nChar]; target[nChar - 1] = source[nChar];
} }
} }
char[] targetPlus = new char[source.length - lastStartToken]; char[] targetPlus = new char[source.length - lastStartToken];
targetPlus[0] = '.'; targetPlus[0] = '.';
targetPlus[1] = Character.toUpperCase(source[lastStartToken]); targetPlus[1] = Character.toUpperCase(source[lastStartToken]);
int index = 2; int index = 2;
for (int nChar = lastStartToken + 1; nChar < source.length - 1; nChar++) for (int nChar = lastStartToken + 1; nChar < source.length - 1; nChar++)
{ {
targetPlus[index] = source[nChar]; targetPlus[index] = source[nChar];
index += 1; index += 1;
} }
out = new StringBuffer(); out = new StringBuffer();
for (char c : target) for (char c : target)
{ {
out.append("[" + c + "]"); out.append("[" + c + "]");
} }
logger.debug(out.toString()); logger.debug(out.toString());
out = new StringBuffer(); out = new StringBuffer();
for (char c : targetPlus) for (char c : targetPlus)
{ {
out.append("[" + c + "]"); out.append("[" + c + "]");
} }
logger.debug(out.toString()); logger.debug(out.toString());
result = new String(target) + new String(targetPlus); result = new String(target) + new String(targetPlus);
} }
else else
{ {
logger.debug("unknow case"); logger.debug("unknow case");
result = null; result = null;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static String formatClassName(final String name) public static String formatClassName(final String name)
{ {
String result; String result;
result = null; result = null;
String[] splittedLastToken = name.split("\\."); String[] splittedLastToken = name.split("\\.");
String last = splittedLastToken[0]; String last = splittedLastToken[0];
// logger.info ("last=" + last); // logger.info ("last=" + last);
String[] tokens = last.split("_"); String[] tokens = last.split("_");
StringBuffer all = new StringBuffer(); StringBuffer all = new StringBuffer();
for (String token : tokens) for (String token : tokens)
{ {
// logger.info ("tok=" + token); // logger.info ("tok=" + token);
all.append(Character.toUpperCase(token.charAt(0))); all.append(Character.toUpperCase(token.charAt(0)));
all.append(token.substring(1)); all.append(token.substring(1));
} }
result = all.toString(); result = all.toString();
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static User getUserFromSession(final HttpServletRequest request) public static User getUserFromSession(final HttpServletRequest request)
{ {
User result; User result;
if (request == null) if (request == null)
{ {
result = null; result = null;
} }
else else
{ {
HttpSession session = request.getSession(false); HttpSession session = request.getSession(false);
String login; String login;
if (session == null) if (session == null)
{ {
result = null; result = null;
} }
else else
{ {
login = (String) session.getAttribute("login"); login = (String) session.getAttribute("login");
result = PageManager.instance().securityAgent().users().getByLogin(login); result = PageManager.instance().securityAgent().users().getByLogin(login);
} }
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static PageManager instance() public static PageManager instance()
{ {
return instance; return instance;
} }
} }

View file

@ -28,18 +28,18 @@ import org.slf4j.LoggerFactory;
*/ */
public class Redirector public class Redirector
{ {
private static final Logger logger = LoggerFactory.getLogger(Redirector.class); private static final Logger logger = LoggerFactory.getLogger(Redirector.class);
/** /**
* *
*/ */
public static void redirect(final HttpServletResponse response, final String destination) public static void redirect(final HttpServletResponse response, final String destination)
{ {
logger.info("Redirect to <" + destination + ">"); logger.info("Redirect to <" + destination + ">");
response.setHeader("Location", destination); response.setHeader("Location", destination);
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -34,56 +34,56 @@ import org.slf4j.LoggerFactory;
*/ */
public class ServletDispatcher extends KissDispatcher public class ServletDispatcher extends KissDispatcher
{ {
private static final long serialVersionUID = -3471226305721330069L; private static final long serialVersionUID = -3471226305721330069L;
private static Logger logger; private static Logger logger;
// protected Servlets servlets; // protected Servlets servlets;
/** /**
* *
*/ */
@Override @Override
public void doIt(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException public void doIt(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{ {
logger.info("=================================================="); logger.info("==================================================");
logger.info("getContextPath=[" + request.getContextPath() + "]"); logger.info("getContextPath=[" + request.getContextPath() + "]");
logger.info("getPathInfo=[" + request.getPathInfo() + "]"); logger.info("getPathInfo=[" + request.getPathInfo() + "]");
logger.info("getPathTranslated=[" + request.getPathTranslated() + "]"); logger.info("getPathTranslated=[" + request.getPathTranslated() + "]");
logger.info("getQueryString=[" + request.getQueryString() + "]"); logger.info("getQueryString=[" + request.getQueryString() + "]");
logger.info("getRequestURI=[" + request.getRequestURI() + "]"); logger.info("getRequestURI=[" + request.getRequestURI() + "]");
logger.info("getRequestURL=[" + request.getRequestURL() + "]"); logger.info("getRequestURL=[" + request.getRequestURL() + "]");
logger.info("getServletPath=[" + request.getServletPath() + "]"); logger.info("getServletPath=[" + request.getServletPath() + "]");
String className = pathInfoToClassName(request.getPathInfo()); String className = pathInfoToClassName(request.getPathInfo());
logger.info("className=" + className); logger.info("className=" + className);
HttpServlet servlet = instanciateServlet(className); HttpServlet servlet = instanciateServlet(className);
if (servlet == null) if (servlet == null)
{ {
response.setContentType("text/html"); response.setContentType("text/html");
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
out.println("<html><head></head><body>"); out.println("<html><head></head><body>");
out.println("Unknow page."); out.println("Unknow page.");
out.println("</body></html>"); out.println("</body></html>");
out.close(); out.close();
} }
else else
{ {
servlet.service(request, response); servlet.service(request, response);
} }
} }
/** /**
* *
*/ */
@Override @Override
public void init() throws ServletException public void init() throws ServletException
{ {
super.init(); super.init();
logger = LoggerFactory.getLogger(this.getClass()); logger = LoggerFactory.getLogger(this.getClass());
// this.servlets = new Servlets(); // this.servlets = new Servlets();
} }
} }

View file

@ -29,39 +29,39 @@ import fr.devinsy.util.StringList;
*/ */
public class ServletTools public class ServletTools
{ {
/** /**
* *
* @param request * @param request
* @return * @return
*/ */
public static String showParameters(final HttpServletRequest request) public static String showParameters(final HttpServletRequest request)
{ {
String result; String result;
// //
StringList buffer = new StringList(); StringList buffer = new StringList();
// //
boolean ended = false; boolean ended = false;
Enumeration<String> names = request.getParameterNames(); Enumeration<String> names = request.getParameterNames();
buffer.appendln("Parameter list:"); buffer.appendln("Parameter list:");
while (!ended) while (!ended)
{ {
if (names.hasMoreElements()) if (names.hasMoreElements())
{ {
String name = names.nextElement(); String name = names.nextElement();
buffer.append("[").append(name).append("]=[").append(request.getParameter(name)).appendln("]"); buffer.append("[").append(name).append("]=[").append(request.getParameter(name)).appendln("]");
} }
else else
{ {
ended = true; ended = true;
} }
} }
// //
result = buffer.toString(); result = buffer.toString();
// //
return result; return result;
} }
} }

View file

@ -32,220 +32,220 @@ import fr.devinsy.util.StringList;
*/ */
public class SimpleSecurityAgent public class SimpleSecurityAgent
{ {
private static final Logger logger = LoggerFactory.getLogger(SimpleSecurityAgent.class); private static final Logger logger = LoggerFactory.getLogger(SimpleSecurityAgent.class);
public static final String USERID_LABEL = "securityAgent.userId"; public static final String USERID_LABEL = "securityAgent.userId";
public static final String ACCOUNTID_LABEL = "securityAgent.accountId"; public static final String ACCOUNTID_LABEL = "securityAgent.accountId";
public static final String AUTH_LABEL = "securityAgent.auth"; public static final String AUTH_LABEL = "securityAgent.auth";
private String userIdLabel; private String userIdLabel;
private String accountIdLabel; private String accountIdLabel;
private String authLabel; private String authLabel;
private String secretKey; private String secretKey;
private static final int DEFAULT_AUTHENTICATION_DURATION = 60 * 60; private static final int DEFAULT_AUTHENTICATION_DURATION = 60 * 60;
private int authenticationDuration; private int authenticationDuration;
/** /**
* *
*/ */
public SimpleSecurityAgent(final String prefix, final String secretKey) public SimpleSecurityAgent(final String prefix, final String secretKey)
{ {
this.userIdLabel = prefix + "." + USERID_LABEL; this.userIdLabel = prefix + "." + USERID_LABEL;
this.accountIdLabel = prefix + "." + ACCOUNTID_LABEL; this.accountIdLabel = prefix + "." + ACCOUNTID_LABEL;
this.authLabel = prefix + "." + AUTH_LABEL; this.authLabel = prefix + "." + AUTH_LABEL;
this.secretKey = secretKey; this.secretKey = secretKey;
this.authenticationDuration = DEFAULT_AUTHENTICATION_DURATION; this.authenticationDuration = DEFAULT_AUTHENTICATION_DURATION;
} }
/** /**
* *
*/ */
public String accountId(final HttpServletRequest request) public String accountId(final HttpServletRequest request)
{ {
String result; String result;
result = (String) CookieHelper.getCookieValue(request, this.accountIdLabel); result = (String) CookieHelper.getCookieValue(request, this.accountIdLabel);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public String auth(final HttpServletRequest request) public String auth(final HttpServletRequest request)
{ {
String result; String result;
result = (String) CookieHelper.getCookieValue(request, this.authLabel); result = (String) CookieHelper.getCookieValue(request, this.authLabel);
// //
return (result); return (result);
} }
/** /**
* This method builds a key from keys and a secret key. * This method builds a key from keys and a secret key.
*/ */
public String computeAuth(final String... keys) public String computeAuth(final String... keys)
{ {
String result; String result;
if (keys == null) if (keys == null)
{ {
result = null; result = null;
} }
else else
{ {
// Add a secret key to the key list. // Add a secret key to the key list.
String[] targetKeys = new String[keys.length + 1]; String[] targetKeys = new String[keys.length + 1];
for (int keyIndex = 0; keyIndex < keys.length; keyIndex++) for (int keyIndex = 0; keyIndex < keys.length; keyIndex++)
{ {
targetKeys[keyIndex] = keys[keyIndex]; targetKeys[keyIndex] = keys[keyIndex];
} }
targetKeys[keys.length] = this.secretKey; targetKeys[keys.length] = this.secretKey;
// //
result = digest(targetKeys); result = digest(targetKeys);
} }
// //
return (result); return (result);
} }
/** /**
* *
* @return * @return
*/ */
public int getAuthenticationDuration() public int getAuthenticationDuration()
{ {
return this.authenticationDuration; return this.authenticationDuration;
} }
/** /**
* Check authentication and refresh it (reset countdown). * Check authentication and refresh it (reset countdown).
*/ */
public boolean isAuthenticated(final HttpServletRequest request, final HttpServletResponse response) public boolean isAuthenticated(final HttpServletRequest request, final HttpServletResponse response)
{ {
boolean result; boolean result;
String accountId = accountId(request); String accountId = accountId(request);
String userId = userId(request); String userId = userId(request);
String auth = auth(request); String auth = auth(request);
logger.info("cook=[" + auth + "]"); logger.info("cook=[" + auth + "]");
if (auth == null) if (auth == null)
{ {
result = false; result = false;
} }
else if (auth.equals(computeAuth(accountId, userId, request.getRemoteAddr()))) else if (auth.equals(computeAuth(accountId, userId, request.getRemoteAddr())))
{ {
result = true; result = true;
// Refresh cookies. // Refresh cookies.
setAuthenticated(request, response, accountId, userId); setAuthenticated(request, response, accountId, userId);
} }
else else
{ {
result = false; result = false;
} }
// //
return (result); return (result);
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public String md5sumWithSecret(final String source) public String md5sumWithSecret(final String source)
{ {
String result; String result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else else
{ {
String key = source + this.secretKey; String key = source + this.secretKey;
result = digest(key); result = digest(key);
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
public void reset(final HttpServletRequest request, final HttpServletResponse response) public void reset(final HttpServletRequest request, final HttpServletResponse response)
{ {
CookieHelper.reset(response, this.authLabel); CookieHelper.reset(response, this.authLabel);
CookieHelper.reset(response, this.accountIdLabel); CookieHelper.reset(response, this.accountIdLabel);
CookieHelper.reset(response, this.userIdLabel); CookieHelper.reset(response, this.userIdLabel);
} }
/** /**
* *
*/ */
public void setAuthenticated(final HttpServletRequest request, final HttpServletResponse response, final String accountId, final String userId) public void setAuthenticated(final HttpServletRequest request, final HttpServletResponse response, final String accountId, final String userId)
{ {
// Refresh cookie. // Refresh cookie.
String auth = computeAuth(String.valueOf(accountId), userId, request.getRemoteAddr()); String auth = computeAuth(String.valueOf(accountId), userId, request.getRemoteAddr());
response.addCookie(CookieHelper.buildCookie(this.authLabel, auth, this.authenticationDuration)); response.addCookie(CookieHelper.buildCookie(this.authLabel, auth, this.authenticationDuration));
response.addCookie(CookieHelper.buildCookie(this.accountIdLabel, accountId, this.authenticationDuration)); response.addCookie(CookieHelper.buildCookie(this.accountIdLabel, accountId, this.authenticationDuration));
response.addCookie(CookieHelper.buildCookie(this.userIdLabel, userId, this.authenticationDuration)); response.addCookie(CookieHelper.buildCookie(this.userIdLabel, userId, this.authenticationDuration));
logger.info("set [" + auth + "," + accountId + "," + userId + "," + request.getRemoteAddr() + ")"); logger.info("set [" + auth + "," + accountId + "," + userId + "," + request.getRemoteAddr() + ")");
} }
/** /**
* *
* @param duration * @param duration
*/ */
public void setAuthenticationDuration(final int duration) public void setAuthenticationDuration(final int duration)
{ {
this.authenticationDuration = duration; this.authenticationDuration = duration;
} }
/** /**
* *
*/ */
public String userId(final HttpServletRequest request) public String userId(final HttpServletRequest request)
{ {
String result; String result;
result = (String) CookieHelper.getCookieValue(request, this.userIdLabel); result = (String) CookieHelper.getCookieValue(request, this.userIdLabel);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static String digest(final String... keys) public static String digest(final String... keys)
{ {
String result; String result;
if (keys == null) if (keys == null)
{ {
result = null; result = null;
} }
else else
{ {
// //
StringList targetKey = new StringList(); StringList targetKey = new StringList();
for (String key : keys) for (String key : keys)
{ {
targetKey.append(key); targetKey.append(key);
} }
// //
result = DigestUtils.sha256Hex(targetKey.toString()); result = DigestUtils.sha256Hex(targetKey.toString());
} }
// //
return (result); return (result);
} }
} }

View file

@ -25,92 +25,92 @@ import java.util.Vector;
*/ */
public class Group public class Group
{ {
private String name; private String name;
private Vector<String> members; private Vector<String> members;
/** /**
* *
*/ */
public Group() public Group()
{ {
this.name = null; this.name = null;
this.members = new Vector<String>(); this.members = new Vector<String>();
} }
/** /**
* *
*/ */
public void addMember(final String login) public void addMember(final String login)
{ {
if ((login != null) && (login.length() != 0)) if ((login != null) && (login.length() != 0))
{ {
this.members.add(login); this.members.add(login);
} }
} }
/** /**
* *
*/ */
public boolean contains(final String name) public boolean contains(final String name)
{ {
boolean result = false; boolean result = false;
result = this.members.contains(name); result = this.members.contains(name);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public Vector<String> members() public Vector<String> members()
{ {
Vector<String> result; Vector<String> result;
result = this.members; result = this.members;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public String name() public String name()
{ {
String result; String result;
result = this.name; result = this.name;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public Group setName(final String name) public Group setName(final String name)
{ {
this.name = name; this.name = name;
// //
return (this); return (this);
} }
/** /**
* *
*/ */
@Override @Override
public String toString() public String toString()
{ {
String result; String result;
result = "|" + this.name + "|" + this.members + "|"; result = "|" + this.name + "|" + this.members + "|";
// //
return (result); return (result);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -26,152 +26,152 @@ import java.util.Vector;
*/ */
public class Groups extends Vector<Group> public class Groups extends Vector<Group>
{ {
private static final long serialVersionUID = 6238581648850758903L; private static final long serialVersionUID = 6238581648850758903L;
/** /**
* *
*/ */
public Groups() public Groups()
{ {
super(); super();
} }
/* /*
*
*/
public boolean contains(final String name)
{
boolean result;
if (get(name) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
* *
*/ */
public boolean contains(final String name) public Group get(final String name)
{ {
boolean result; Group result;
if (get(name) == null) if (name == null)
{ {
result = false; result = null;
} }
else else
{ {
result = true; result = null;
} boolean ended = false;
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
Group group = iterator.next();
if (group.name().equals(name))
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
}
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public Group get(final String name) public Vector<String> getLoginGroups(final String login)
{ {
Group result; Vector<String> result;
if (name == null) result = new Vector<String>();
{ Iterator<Group> iterator = this.iterator();
result = null;
}
else
{
result = null;
boolean ended = false;
Iterator<Group> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
Group group = iterator.next();
if (group.name().equals(name))
{
ended = true;
result = group;
}
}
else
{
ended = true;
result = null;
}
}
}
// while (iterator.hasNext())
return (result); {
} Group group = iterator.next();
/** if (group.members().contains(login))
* {
*/ result.add(group.name());
public Vector<String> getLoginGroups(final String login) }
{ }
Vector<String> result;
result = new Vector<String>(); //
Iterator<Group> iterator = this.iterator(); return (result);
}
while (iterator.hasNext()) /**
{
Group group = iterator.next();
if (group.members().contains(login))
{
result.add(group.name());
}
}
//
return (result);
}
/**
* *
*/ */
public String getLoginGroupsString(final String login) public String getLoginGroupsString(final String login)
{ {
String result; String result;
Vector<String> groups = getLoginGroups(login); Vector<String> groups = getLoginGroups(login);
StringBuffer string = new StringBuffer(); StringBuffer string = new StringBuffer();
for (String group : groups) for (String group : groups)
{ {
if (string.length() == 0) if (string.length() == 0)
{ {
string.append(group); string.append(group);
} }
else else
{ {
string.append(","); string.append(",");
string.append(group); string.append(group);
} }
} }
result = string.toString(); result = string.toString();
// //
return (result); return (result);
} }
/** /**
* *
*/ */
@Override @Override
public String toString() public String toString()
{ {
String result; String result;
StringBuffer out; StringBuffer out;
out = new StringBuffer(); out = new StringBuffer();
Iterator<Group> iterator = this.iterator(); Iterator<Group> iterator = this.iterator();
while (iterator.hasNext()) while (iterator.hasNext())
{ {
out.append(iterator.next().toString() + "\n"); out.append(iterator.next().toString() + "\n");
} }
result = out.toString(); result = out.toString();
// //
return (result); return (result);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -27,47 +27,47 @@ import java.util.Properties;
*/ */
public class GroupsFileReader public class GroupsFileReader
{ {
/** /**
* *
*/ */
public static Groups load(final String fileName) throws Exception public static Groups load(final String fileName) throws Exception
{ {
Groups result; Groups result;
result = new Groups(); result = new Groups();
Properties properties = new Properties(); Properties properties = new Properties();
try try
{ {
properties.load(new FileInputStream(fileName)); properties.load(new FileInputStream(fileName));
Iterator<Object> iterator = properties.keySet().iterator(); Iterator<Object> iterator = properties.keySet().iterator();
while (iterator.hasNext()) while (iterator.hasNext())
{ {
String key = (String) iterator.next(); String key = (String) iterator.next();
String valueLine = (String) properties.get(key); String valueLine = (String) properties.get(key);
// //
String[] values = valueLine.split(","); String[] values = valueLine.split(",");
Group group = new Group(); Group group = new Group();
group.setName(key); group.setName(key);
for (String value : values) for (String value : values)
{ {
group.addMember(value.trim()); group.addMember(value.trim());
} }
result.add(group); result.add(group);
} }
} }
catch (Exception exception) catch (Exception exception)
{ {
throw new Exception("can't load (" + fileName + ")", exception); throw new Exception("can't load (" + fileName + ")", exception);
} }
// //
return (result); return (result);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -25,140 +25,140 @@ import java.util.Iterator;
*/ */
public class SecurityAgent public class SecurityAgent
{ {
private Users users; private Users users;
private Groups groups; private Groups groups;
private Groups permissions; private Groups permissions;
/** /**
* *
*/ */
public SecurityAgent(final String path) throws Exception public SecurityAgent(final String path) throws Exception
{ {
this.users = UsersFileReader.load(path + "users.conf"); this.users = UsersFileReader.load(path + "users.conf");
this.groups = GroupsFileReader.load(path + "groups.conf"); this.groups = GroupsFileReader.load(path + "groups.conf");
this.permissions = GroupsFileReader.load(path + "permissions.conf"); this.permissions = GroupsFileReader.load(path + "permissions.conf");
} }
/** /**
* *
*/ */
public boolean authenticate(final String login, final String password) public boolean authenticate(final String login, final String password)
{ {
boolean result; boolean result;
User user = this.users.getByLogin(login); User user = this.users.getByLogin(login);
if (user == null) if (user == null)
{ {
result = false; result = false;
} }
else if (user.password().equals(password)) else if (user.password().equals(password))
{ {
result = true; result = true;
} }
else else
{ {
result = false; result = false;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public boolean checkPermission(final String url, final String login) public boolean checkPermission(final String url, final String login)
{ {
boolean result = false; boolean result = false;
Group permitGroups = this.permissions.get(url); Group permitGroups = this.permissions.get(url);
if (permitGroups == null) if (permitGroups == null)
{ {
result = false; result = false;
} }
else else
{ {
// //
boolean ended = false; boolean ended = false;
Iterator<String> iterator = permitGroups.members().iterator(); Iterator<String> iterator = permitGroups.members().iterator();
while (!ended) while (!ended)
{ {
if (!iterator.hasNext()) if (!iterator.hasNext())
{ {
ended = true; ended = true;
result = false; result = false;
} }
else else
{ {
String groupName = iterator.next(); String groupName = iterator.next();
if (groupName.equals("*")) if (groupName.equals("*"))
{ {
result = true; result = true;
ended = true; ended = true;
} }
else else
{ {
Group members = this.groups.get(groupName); Group members = this.groups.get(groupName);
if (members == null) if (members == null)
{ {
result = false; result = false;
} }
else else
{ {
if (members.contains(login)) if (members.contains(login))
{ {
ended = true; ended = true;
result = true; result = true;
} }
} }
} }
} }
} }
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public Groups groups() public Groups groups()
{ {
Groups result; Groups result;
result = this.groups; result = this.groups;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public Groups permissions() public Groups permissions()
{ {
Groups result; Groups result;
result = this.permissions; result = this.permissions;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public Users users() public Users users()
{ {
Users result; Users result;
result = this.users; result = this.users;
// //
return (result); return (result);
} }
} }

View file

@ -23,129 +23,129 @@ package fr.devinsy.kiss4web.security;
*/ */
public class User public class User
{ {
private String login; private String login;
private String password; private String password;
private String realName; private String realName;
private String email; private String email;
/** /**
* *
*/ */
public User() public User()
{ {
this.login = null; this.login = null;
this.password = null; this.password = null;
this.realName = null; this.realName = null;
this.email = null; this.email = null;
} }
/** /**
* *
*/ */
public String email() public String email()
{ {
String result; String result;
result = this.email; result = this.email;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public String login() public String login()
{ {
String result; String result;
result = this.login; result = this.login;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public String password() public String password()
{ {
String result; String result;
result = this.password; result = this.password;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public String realName() public String realName()
{ {
String result; String result;
result = this.realName; result = this.realName;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public User setEmail(final String email) public User setEmail(final String email)
{ {
this.email = email; this.email = email;
// //
return (this); return (this);
} }
/** /**
* *
*/ */
public User setLogin(final String login) public User setLogin(final String login)
{ {
this.login = login; this.login = login;
// //
return (this); return (this);
} }
/** /**
* *
*/ */
public User setPassword(final String password) public User setPassword(final String password)
{ {
this.password = password; this.password = password;
// //
return (this); return (this);
} }
/** /**
* *
*/ */
public User setRealName(final String realName) public User setRealName(final String realName)
{ {
this.realName = realName; this.realName = realName;
// //
return (this); return (this);
} }
/** /**
* *
*/ */
@Override @Override
public String toString() public String toString()
{ {
String result; String result;
result = "|" + this.login + "|" + this.password + "|" + this.realName + "|"; result = "|" + this.login + "|" + this.password + "|" + this.realName + "|";
// //
return (result); return (result);
} }
} }

View file

@ -26,98 +26,98 @@ import java.util.Vector;
*/ */
public class Users extends Vector<User> public class Users extends Vector<User>
{ {
private static final long serialVersionUID = 6140538630004281217L; private static final long serialVersionUID = 6140538630004281217L;
/** /**
* *
*/ */
public Users() public Users()
{ {
super(); super();
} }
/* /*
*
*/
public boolean contains(final String login)
{
boolean result;
if (getByLogin(login) == null)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
/**
* *
*/ */
public boolean contains(final String login) public User getByLogin(final String login)
{ {
boolean result; User result;
if (getByLogin(login) == null) if (login == null)
{ {
result = false; result = null;
} }
else else
{ {
result = true; result = null;
} boolean ended = false;
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
User user = iterator.next();
if (user.login().equals(login))
{
ended = true;
result = user;
}
}
else
{
ended = true;
result = null;
}
}
}
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public User getByLogin(final String login) @Override
{ public String toString()
User result; {
String result;
if (login == null) StringBuffer out;
{ out = new StringBuffer();
result = null;
}
else
{
result = null;
boolean ended = false;
Iterator<User> iterator = this.iterator();
while (!ended)
{
if (iterator.hasNext())
{
User user = iterator.next();
if (user.login().equals(login))
{
ended = true;
result = user;
}
}
else
{
ended = true;
result = null;
}
}
}
// Iterator<User> iterator = this.iterator();
return (result);
}
/** while (iterator.hasNext())
* {
*/ out.append(iterator.next().toString() + "\n");
@Override }
public String toString()
{
String result;
StringBuffer out; result = out.toString();
out = new StringBuffer();
Iterator<User> iterator = this.iterator(); //
return (result);
while (iterator.hasNext()) }
{
out.append(iterator.next().toString() + "\n");
}
result = out.toString();
//
return (result);
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -27,47 +27,47 @@ import java.util.Properties;
*/ */
public class UsersFileReader public class UsersFileReader
{ {
/** /**
* *
*/ */
public static Users load(final String fileName) throws Exception public static Users load(final String fileName) throws Exception
{ {
Users result; Users result;
result = new Users(); result = new Users();
Properties properties = new Properties(); Properties properties = new Properties();
try try
{ {
properties.load(new FileInputStream(fileName)); properties.load(new FileInputStream(fileName));
Iterator<Object> iterator = properties.keySet().iterator(); Iterator<Object> iterator = properties.keySet().iterator();
while (iterator.hasNext()) while (iterator.hasNext())
{ {
String key = (String) iterator.next(); String key = (String) iterator.next();
String valueLine = (String) properties.get(key); String valueLine = (String) properties.get(key);
// //
String[] values = valueLine.split(","); String[] values = valueLine.split(",");
User user = new User(); User user = new User();
user.setLogin(key); user.setLogin(key);
user.setPassword(values[0]); user.setPassword(values[0]);
user.setRealName(values[1]); user.setRealName(values[1]);
user.setEmail(values[2]); user.setEmail(values[2]);
result.add(user); result.add(user);
// //
} }
} }
catch (Exception exception) catch (Exception exception)
{ {
throw new Exception("can't load (" + fileName + ")", exception); throw new Exception("can't load (" + fileName + ")", exception);
} }
// //
return (result); return (result);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/> * along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/ */
import fr.devinsy.kiss4web.KissDispatcher;
import fr.devinsy.kiss4web.ServletDispatcher; import fr.devinsy.kiss4web.ServletDispatcher;
/** /**
@ -23,76 +24,76 @@ import fr.devinsy.kiss4web.ServletDispatcher;
*/ */
class FooSandbox class FooSandbox
{ {
static private org.apache.log4j.Logger logger; static private org.apache.log4j.Logger logger;
static static
{ {
// Initialize logger. // Initialize logger.
org.apache.log4j.Logger logger = null; org.apache.log4j.Logger logger = null;
org.apache.log4j.BasicConfigurator.configure(); org.apache.log4j.BasicConfigurator.configure();
logger = org.apache.log4j.Logger.getRootLogger(); logger = org.apache.log4j.Logger.getRootLogger();
// logger.setLevel (org.apache.log4j.Level.INFO); // logger.setLevel (org.apache.log4j.Level.INFO);
logger.setLevel(org.apache.log4j.Level.INFO); logger.setLevel(org.apache.log4j.Level.INFO);
logger.info("Enter"); logger.info("Enter");
// //
logger.info("Set the log file format..."); logger.info("Set the log file format...");
// log = // log =
// org.apache.log4j.Category.getInstance(Application.class.getName()); // org.apache.log4j.Category.getInstance(Application.class.getName());
logger.info("... done."); logger.info("... done.");
logger.debug("Exit"); logger.debug("Exit");
logger = org.apache.log4j.Logger.getLogger(FooSandbox.class.getName()); logger = org.apache.log4j.Logger.getLogger(FooSandbox.class.getName());
} }
/** /**
* *
*/ */
public static String check(final String title, final StringBuffer source, final String model) public static String check(final String title, final StringBuffer source, final String model)
{ {
String result; String result;
if (source.indexOf(model) == -1) if (source.indexOf(model) == -1)
{ {
result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model; result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
} }
else else
{ {
result = String.format("%-40s [ OK ] ", title); result = String.format("%-40s [ OK ] ", title);
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static void main(final String[] args) public static void main(final String[] args)
{ {
System.out.println("----------------------------"); System.out.println("----------------------------");
System.out.println(testCaller("/", "fr.devinsy.website")); System.out.println(testCaller("/", "fr.devinsy.website"));
System.out.println(testCaller("/good/", "fr.devinsy.website")); System.out.println(testCaller("/good/", "fr.devinsy.website"));
System.out.println(testCaller("/good/morning", "fr.devinsy.website")); System.out.println(testCaller("/good/morning", "fr.devinsy.website"));
System.out.println(testCaller("/good/day_day", "fr.devinsy.website")); System.out.println(testCaller("/good/day_day", "fr.devinsy.website"));
System.out.println(testCaller("/good/day.xhtml", "fr.devinsy.website")); System.out.println(testCaller("/good/day.xhtml", "fr.devinsy.website"));
} }
/** /**
* *
*/ */
public static String testCaller(final String pathInfo, final String prefix) public static String testCaller(final String pathInfo, final String prefix)
{ {
String result; String result;
result = "[" + pathInfo + "]=>[" + ServletDispatcher.pathInfoToClassName(pathInfo, prefix) + "]"; result = "[" + pathInfo + "]=>[" + KissDispatcher.pathInfoToClassName(pathInfo, prefix) + "]";
// //
return (result); return (result);
} }
} }

View file

@ -22,18 +22,18 @@ import org.junit.Test;
public class Foo2Test public class Foo2Test
{ {
// private Logger logger = // private Logger logger =
// LoggerFactory.getLogger(PdfGenerationAmqpServiceInjectedTest.class); // LoggerFactory.getLogger(PdfGenerationAmqpServiceInjectedTest.class);
/** /**
* *
*/ */
@Test @Test
public void test2a() public void test2a()
{ {
// logger.debug("===== test starting..."); // logger.debug("===== test starting...");
// logger.debug("===== test done."); // logger.debug("===== test done.");
} }
} }