head	1.135;
access;
symbols
	TIGRIS_1_1_0RC2:1.87.2.2.4.2
	TIGRIS_1_1_0RC1:1.87.2.2.4.2
	TIGRIS_1_1:1.87.2.2.4.2.0.2
	TIGRIS_1_0_8:1.87.2.2.4.2
	TIGRIS_1_0_8RC3:1.87.2.2.4.2
	TIGRIS_1_0_8RC2:1.87.2.2.4.2
	TIGRIS_1_0_8RC1:1.87.2.2.4.2
	TIGRIS_1_0_7:1.87.2.2.4.2
	TIGRIS_1_0_7RC3:1.87.2.2.4.2
	TIGRIS_1_0_7RC2:1.87.2.2.4.2
	TIGRIS_1_0_7RC1:1.87.2.2.4.2
	TIGRIS_1_0_6:1.87.2.2.4.2
	TIGRIS_1_0_6RC5:1.87.2.2.4.2
	TIGRIS_1_0_6RC4:1.87.2.2.4.1
	TIGRIS_1_0_6RC3:1.87.2.2.4.1
	TIGRIS_1_0_6RC2:1.87.2.2.4.1
	TIGRIS_1_0_6RC1:1.87.2.2.4.1
	TIGRIS_1_0_5:1.87.2.2.4.1
	TIGRIS_1_0_5RC6:1.87.2.2.4.1
	TIGRIS_1_0_5RC5:1.87.2.2.4.1
	TIGRIS_1_0_5RC4:1.87.2.2.4.1
	TIGRIS_1_0_5RC3:1.87.2.2.4.1
	TIGRIS_1_0_5RC2:1.87.2.2.4.1
	TIGRIS_1_0_5RC1:1.87.2.2.4.1
	TIGRIS_1_0_4:1.87.2.2.4.1
	TIGRIS_1_0_3:1.87.2.2.4.1
	TIGRIS_1_0_2:1.87.2.2
	TIGRIS_1_0_1:1.87.2.2
	TIGRIS_1_0:1.87.2.2.0.4
	TIGRIS_1_0_0:1.87.2.2
	TIGRIS_1_0_0_RC1:1.87.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.57.2.2
	TIGRIS_0_9_2_3:1.57.2.2
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.60
	TIGRIS_0_9_2_1:1.60
	TIGRIS_0_9_2:1.57.0.2
	TIGRIS_0_9_0:1.44.0.2
	TIGRIS_0_8_4:1.25.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.135
date	2001.08.28.22.45.45;	author dlr;	state Exp;
branches;
next	1.134;

1.134
date	2001.08.28.17.45.18;	author leonardr;	state Exp;
branches;
next	1.133;

1.133
date	2001.08.24.22.39.03;	author leonardr;	state Exp;
branches;
next	1.132;

1.132
date	2001.08.22.15.42.34;	author leonardr;	state Exp;
branches;
next	1.131;

1.131
date	2001.08.11.09.08.08;	author dlr;	state Exp;
branches;
next	1.130;

1.130
date	2001.08.06.23.09.54;	author dlr;	state Exp;
branches;
next	1.129;

1.129
date	2001.08.06.22.00.05;	author dlr;	state Exp;
branches;
next	1.128;

1.128
date	2001.08.03.18.43.40;	author leonardr;	state Exp;
branches;
next	1.127;

1.127
date	2001.07.27.19.58.46;	author leonardr;	state Exp;
branches;
next	1.126;

1.126
date	2001.07.26.20.56.53;	author leonardr;	state Exp;
branches;
next	1.125;

1.125
date	2001.07.26.20.54.52;	author leonardr;	state Exp;
branches;
next	1.124;

1.124
date	2001.07.26.01.46.51;	author dlr;	state Exp;
branches;
next	1.123;

1.123
date	2001.07.25.20.01.59;	author leonardr;	state Exp;
branches;
next	1.122;

1.122
date	2001.07.25.19.39.26;	author leonardr;	state Exp;
branches;
next	1.121;

1.121
date	2001.07.24.00.02.28;	author leonardr;	state Exp;
branches;
next	1.120;

1.120
date	2001.07.23.20.32.00;	author dlr;	state Exp;
branches;
next	1.119;

1.119
date	2001.07.20.00.23.00;	author dlr;	state Exp;
branches;
next	1.118;

1.118
date	2001.07.19.19.54.05;	author dlr;	state Exp;
branches;
next	1.117;

1.117
date	2001.07.19.19.08.43;	author dlr;	state Exp;
branches;
next	1.116;

1.116
date	2001.07.17.23.20.23;	author leonardr;	state Exp;
branches;
next	1.115;

1.115
date	2001.07.17.16.00.43;	author leonardr;	state Exp;
branches;
next	1.114;

1.114
date	2001.07.16.03.18.07;	author jrobbins;	state Exp;
branches;
next	1.113;

1.113
date	2001.07.13.21.47.11;	author leonardr;	state Exp;
branches;
next	1.112;

1.112
date	2001.07.13.21.39.29;	author leonardr;	state Exp;
branches;
next	1.111;

1.111
date	2001.07.13.19.47.34;	author leonardr;	state Exp;
branches;
next	1.110;

1.110
date	2001.07.06.15.42.28;	author leonardr;	state Exp;
branches;
next	1.109;

1.109
date	2001.07.05.22.21.39;	author leonardr;	state Exp;
branches;
next	1.108;

1.108
date	2001.06.29.00.57.49;	author leonardr;	state Exp;
branches;
next	1.107;

1.107
date	2001.06.20.21.32.25;	author leonardr;	state Exp;
branches;
next	1.106;

1.106
date	2001.06.18.22.12.21;	author leonardr;	state Exp;
branches;
next	1.105;

1.105
date	2001.06.13.01.46.33;	author leonardr;	state Exp;
branches;
next	1.104;

1.104
date	2001.06.13.01.35.23;	author elicia;	state Exp;
branches;
next	1.103;

1.103
date	2001.06.12.00.37.09;	author elicia;	state Exp;
branches;
next	1.102;

1.102
date	2001.06.09.01.02.15;	author leonardr;	state Exp;
branches;
next	1.101;

1.101
date	2001.06.07.19.06.51;	author elicia;	state Exp;
branches;
next	1.100;

1.100
date	2001.06.07.03.07.20;	author elicia;	state Exp;
branches;
next	1.99;

1.99
date	2001.06.04.16.42.00;	author leonardr;	state Exp;
branches;
next	1.98;

1.98
date	2001.06.01.20.13.52;	author leonardr;	state Exp;
branches;
next	1.97;

1.97
date	2001.05.25.21.05.26;	author leonardr;	state Exp;
branches;
next	1.96;

1.96
date	2001.05.25.00.53.26;	author dlr;	state Exp;
branches;
next	1.95;

1.95
date	2001.05.23.01.50.20;	author dlr;	state Exp;
branches;
next	1.94;

1.94
date	2001.04.19.15.41.46;	author leonardr;	state Exp;
branches;
next	1.93;

1.93
date	2001.04.17.00.19.40;	author leonardr;	state Exp;
branches;
next	1.92;

1.92
date	2001.04.16.19.52.42;	author dlr;	state Exp;
branches;
next	1.91;

1.91
date	2001.04.16.18.05.09;	author dlr;	state Exp;
branches;
next	1.90;

1.90
date	2001.04.16.17.06.57;	author leonardr;	state Exp;
branches;
next	1.89;

1.89
date	2001.04.05.07.07.36;	author manoj;	state Exp;
branches;
next	1.88;

1.88
date	2001.04.04.00.24.53;	author jrobbins;	state Exp;
branches;
next	1.87;

1.87
date	2001.03.27.06.57.53;	author jrobbins;	state Exp;
branches
	1.87.2.1;
next	1.86;

1.86
date	2001.03.26.18.49.54;	author dlr;	state Exp;
branches;
next	1.85;

1.85
date	2001.03.23.23.10.58;	author leonardr;	state Exp;
branches;
next	1.84;

1.84
date	2001.03.23.19.25.22;	author leonardr;	state Exp;
branches;
next	1.83;

1.83
date	2001.03.23.03.49.35;	author leonardr;	state Exp;
branches;
next	1.82;

1.82
date	2001.03.23.02.45.37;	author leonardr;	state Exp;
branches;
next	1.81;

1.81
date	2001.03.22.01.13.56;	author dlr;	state Exp;
branches;
next	1.80;

1.80
date	2001.03.15.19.58.35;	author leonardr;	state Exp;
branches;
next	1.79;

1.79
date	2001.03.15.19.19.28;	author leonardr;	state Exp;
branches;
next	1.78;

1.78
date	2001.03.09.20.06.42;	author dlr;	state Exp;
branches;
next	1.77;

1.77
date	2001.03.09.19.32.05;	author leonardr;	state Exp;
branches;
next	1.76;

1.76
date	2001.03.09.01.59.38;	author leonardr;	state Exp;
branches;
next	1.75;

1.75
date	2001.03.08.01.00.54;	author dlr;	state Exp;
branches;
next	1.74;

1.74
date	2001.03.08.00.52.48;	author dlr;	state Exp;
branches;
next	1.73;

1.73
date	2001.03.07.01.53.27;	author lucas;	state Exp;
branches;
next	1.72;

1.72
date	2001.03.05.02.35.26;	author jrobbins;	state Exp;
branches;
next	1.71;

1.71
date	2001.02.27.04.25.49;	author dlr;	state Exp;
branches;
next	1.70;

1.70
date	2001.02.27.01.32.22;	author dlr;	state Exp;
branches;
next	1.69;

1.69
date	2001.02.27.00.48.35;	author leonardr;	state Exp;
branches;
next	1.68;

1.68
date	2001.02.23.23.56.57;	author leonardr;	state Exp;
branches;
next	1.67;

1.67
date	2001.02.23.19.04.11;	author stack;	state Exp;
branches;
next	1.66;

1.66
date	2001.02.22.23.56.33;	author leonardr;	state Exp;
branches;
next	1.65;

1.65
date	2001.02.22.18.08.52;	author leonardr;	state Exp;
branches;
next	1.64;

1.64
date	2001.02.22.09.20.14;	author dlr;	state Exp;
branches;
next	1.63;

1.63
date	2001.02.21.01.08.25;	author dlr;	state Exp;
branches;
next	1.62;

1.62
date	2001.02.07.08.56.23;	author jrobbins;	state Exp;
branches;
next	1.61;

1.61
date	2001.01.29.23.55.11;	author leonardr;	state Exp;
branches;
next	1.60;

1.60
date	2001.01.26.23.38.44;	author stack;	state Exp;
branches
	1.60.2.1;
next	1.59;

1.59
date	2001.01.26.18.29.08;	author edk;	state Exp;
branches;
next	1.58;

1.58
date	2001.01.26.05.24.07;	author edk;	state dead;
branches;
next	1.57;

1.57
date	2001.01.17.21.56.13;	author leonardr;	state Exp;
branches
	1.57.2.1;
next	1.56;

1.56
date	2001.01.17.18.35.36;	author dlr;	state Exp;
branches;
next	1.55;

1.55
date	2001.01.12.22.54.27;	author dlr;	state Exp;
branches;
next	1.54;

1.54
date	2001.01.11.20.20.07;	author dlr;	state Exp;
branches;
next	1.53;

1.53
date	2001.01.11.19.53.23;	author dlr;	state Exp;
branches;
next	1.52;

1.52
date	2001.01.11.03.03.38;	author dlr;	state Exp;
branches;
next	1.51;

1.51
date	2001.01.10.01.52.19;	author leonardr;	state Exp;
branches;
next	1.50;

1.50
date	2001.01.09.07.52.59;	author dlr;	state Exp;
branches;
next	1.49;

1.49
date	2001.01.08.23.25.03;	author dlr;	state Exp;
branches;
next	1.48;

1.48
date	2001.01.05.15.44.13;	author leonardr;	state Exp;
branches;
next	1.47;

1.47
date	2001.01.03.22.32.55;	author dlr;	state Exp;
branches;
next	1.46;

1.46
date	2000.12.30.00.34.35;	author dlr;	state Exp;
branches;
next	1.45;

1.45
date	2000.12.23.00.48.19;	author dlr;	state Exp;
branches;
next	1.44;

1.44
date	2000.12.20.23.05.27;	author kmaples;	state Exp;
branches
	1.44.2.1;
next	1.43;

1.43
date	2000.12.20.18.39.55;	author leonardr;	state Exp;
branches;
next	1.42;

1.42
date	2000.12.19.00.14.30;	author leonardr;	state Exp;
branches;
next	1.41;

1.41
date	2000.12.15.04.37.57;	author leonardr;	state Exp;
branches;
next	1.40;

1.40
date	2000.12.14.03.04.17;	author edk;	state Exp;
branches;
next	1.39;

1.39
date	2000.12.13.22.05.13;	author leonardr;	state Exp;
branches;
next	1.38;

1.38
date	2000.12.13.19.37.04;	author leonardr;	state Exp;
branches;
next	1.37;

1.37
date	2000.12.13.18.59.06;	author leonardr;	state Exp;
branches;
next	1.36;

1.36
date	2000.12.13.18.23.53;	author leonardr;	state Exp;
branches;
next	1.35;

1.35
date	2000.12.13.02.00.41;	author leonardr;	state Exp;
branches;
next	1.34;

1.34
date	2000.12.11.18.26.34;	author leonardr;	state Exp;
branches;
next	1.33;

1.33
date	2000.12.11.18.23.35;	author leonardr;	state Exp;
branches;
next	1.32;

1.32
date	2000.12.11.18.19.36;	author leonardr;	state Exp;
branches;
next	1.31;

1.31
date	2000.12.09.02.13.37;	author leonardr;	state Exp;
branches;
next	1.30;

1.30
date	2000.12.06.23.04.47;	author leonardr;	state Exp;
branches;
next	1.29;

1.29
date	2000.12.06.20.49.04;	author dlr;	state Exp;
branches;
next	1.28;

1.28
date	2000.12.06.20.45.41;	author leonardr;	state Exp;
branches;
next	1.27;

1.27
date	2000.12.06.19.03.13;	author dlr;	state Exp;
branches;
next	1.26;

1.26
date	2000.12.05.21.28.52;	author dlr;	state Exp;
branches;
next	1.25;

1.25
date	2000.12.04.06.25.28;	author edk;	state Exp;
branches;
next	1.24;

1.24
date	2000.12.04.06.16.16;	author edk;	state Exp;
branches;
next	1.23;

1.23
date	2000.12.01.08.35.42;	author dlr;	state Exp;
branches;
next	1.22;

1.22
date	2000.11.29.23.57.51;	author leonardr;	state Exp;
branches;
next	1.21;

1.21
date	2000.11.27.21.30.27;	author leonardr;	state Exp;
branches;
next	1.20;

1.20
date	2000.11.23.09.45.05;	author dlr;	state Exp;
branches;
next	1.19;

1.19
date	2000.11.23.09.42.22;	author dlr;	state Exp;
branches;
next	1.18;

1.18
date	2000.11.23.09.40.19;	author dlr;	state Exp;
branches;
next	1.17;

1.17
date	2000.11.23.08.42.05;	author dlr;	state Exp;
branches;
next	1.16;

1.16
date	2000.11.22.21.16.14;	author leonardr;	state Exp;
branches;
next	1.15;

1.15
date	2000.11.21.22.07.54;	author leonardr;	state Exp;
branches;
next	1.14;

1.14
date	2000.11.21.22.07.12;	author leonardr;	state Exp;
branches;
next	1.13;

1.13
date	2000.11.20.10.04.47;	author dlr;	state Exp;
branches;
next	1.12;

1.12
date	2000.11.19.22.34.32;	author dlr;	state Exp;
branches;
next	1.11;

1.11
date	2000.11.16.18.54.55;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2000.11.16.01.43.59;	author stack;	state Exp;
branches;
next	1.9;

1.9
date	2000.11.15.21.57.34;	author leonardr;	state Exp;
branches;
next	1.8;

1.8
date	2000.11.15.19.20.50;	author stack;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.15.17.18.57;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2000.11.15.03.50.07;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2000.11.15.01.38.10;	author susank;	state Exp;
branches;
next	1.4;

1.4
date	2000.11.13.22.39.52;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2000.11.13.22.17.37;	author stack;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.13.19.51.49;	author stack;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.12.21.16.41;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.16.41;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.35.16;	author dlr;	state Exp;
branches;
next	;

1.44.2.1
date	2001.01.13.02.53.08;	author stack;	state Exp;
branches;
next	1.44.2.2;

1.44.2.2
date	2001.02.07.09.05.11;	author jrobbins;	state Exp;
branches;
next	;

1.57.2.1
date	2001.01.26.23.36.52;	author stack;	state Exp;
branches;
next	1.57.2.2;

1.57.2.2
date	2001.01.30.00.36.21;	author leonardr;	state Exp;
branches;
next	1.57.2.3;

1.57.2.3
date	2001.02.08.06.04.49;	author jrobbins;	state Exp;
branches;
next	;

1.60.2.1
date	2001.01.28.01.02.19;	author dlr;	state dead;
branches;
next	1.60.2.2;

1.60.2.2
date	2001.01.31.02.54.24;	author dlr;	state Exp;
branches;
next	1.60.2.3;

1.60.2.3
date	2001.01.31.03.11.53;	author dlr;	state Exp;
branches;
next	1.60.2.4;

1.60.2.4
date	2001.01.31.20.52.30;	author leonardr;	state Exp;
branches;
next	1.60.2.5;

1.60.2.5
date	2001.02.01.02.57.47;	author leonardr;	state Exp;
branches;
next	1.60.2.6;

1.60.2.6
date	2001.02.01.18.03.00;	author leonardr;	state Exp;
branches;
next	1.60.2.7;

1.60.2.7
date	2001.02.01.20.40.24;	author leonardr;	state Exp;
branches;
next	1.60.2.8;

1.60.2.8
date	2001.02.05.22.53.18;	author leonardr;	state Exp;
branches;
next	1.60.2.9;

1.60.2.9
date	2001.02.06.01.06.39;	author leonardr;	state Exp;
branches;
next	1.60.2.10;

1.60.2.10
date	2001.02.06.01.49.06;	author leonardr;	state Exp;
branches;
next	1.60.2.11;

1.60.2.11
date	2001.02.07.02.23.55;	author leonardr;	state Exp;
branches;
next	1.60.2.12;

1.60.2.12
date	2001.02.07.19.49.07;	author leonardr;	state Exp;
branches;
next	1.60.2.13;

1.60.2.13
date	2001.02.07.23.07.31;	author dlr;	state Exp;
branches;
next	1.60.2.14;

1.60.2.14
date	2001.02.09.03.06.48;	author dlr;	state Exp;
branches;
next	1.60.2.15;

1.60.2.15
date	2001.02.12.16.24.32;	author leonardr;	state Exp;
branches;
next	1.60.2.16;

1.60.2.16
date	2001.02.12.21.35.45;	author dlr;	state Exp;
branches;
next	1.60.2.17;

1.60.2.17
date	2001.02.14.23.20.30;	author leonardr;	state Exp;
branches;
next	1.60.2.18;

1.60.2.18
date	2001.02.15.20.50.43;	author leonardr;	state Exp;
branches;
next	1.60.2.19;

1.60.2.19
date	2001.02.16.02.43.35;	author leonardr;	state Exp;
branches;
next	1.60.2.20;

1.60.2.20
date	2001.02.16.03.01.35;	author dlr;	state Exp;
branches;
next	1.60.2.21;

1.60.2.21
date	2001.02.17.20.33.41;	author leonardr;	state Exp;
branches;
next	;

1.87.2.1
date	2001.04.04.20.50.47;	author dlr;	state Exp;
branches;
next	1.87.2.2;

1.87.2.2
date	2001.04.05.22.02.55;	author dlr;	state Exp;
branches
	1.87.2.2.4.1;
next	;

1.87.2.2.4.1
date	2001.04.25.23.52.16;	author dlr;	state Exp;
branches;
next	1.87.2.2.4.2;

1.87.2.2.4.2
date	2001.06.13.22.48.22;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.135
log
@Added constant for current project.
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ================================================================
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.security;

import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.torque.util.Criteria;
import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;
import org.apache.commons.util.StringUtils;
import org.apache.fulcrum.TurbineServices;

import org.apache.velocity.context.Context;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.domain.*;
import org.tigris.helm.tool.BOFactoryService;
import org.tigris.helm.tool.ContextAPI;
import org.tigris.helm.tool.ServletHelp;
import org.tigris.helm.tool.ServletTaskBar;
import org.tigris.helm.tool.SessionManager;
import org.tigris.helm.tool.paginate.PeerBackedList;
import org.tigris.helm.util.URL;

/**
 * Adds session tracking and user authentication to WebMacro-based Helm 
 * servlets.  See the
 * <a href="http://helm.tigris.org/docs/fieldguide-HelmServlet.html">field
 * guide</a> for more information.
 *
 * @@author <a href="mailto:jrobbins@@collab.net">Jason Elliot Robbins</a>
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: HelmServlet.java,v 1.134 2001/08/28 17:45:18 leonardr Exp $
 *
 * Copyright (c) 2000-2001 CollabNet, Inc.
 */
public class HelmServlet extends BaseHelmServlet
{
    private static final boolean DEBUG = false;

    /**
     * The key to the property which specifies whether to automatically log in
     * clients as the anonymous user.
     */
    private static final String ALLOW_GUESTS = "ALLOW_GUESTS";

    /**
     * The context key containing the number of items per paginated page.
     */
    public static final String ITEMS_PER_PAGE_KEY = "itemsPerPage";

    /**
     * The context key containing the current page on a paginated list.
     */
    public static final String PAGINATED_PAGE_KEY = "paginated_page";

    /**
     * Context key for the current project.
     */
    private static final String CURRENT_PROJECT = "currentProject";

    /**
     * The key to the servlet property which specifies lists of
     * business objects to require.
     */
    private static final String REQUIRED_BUSINESS_OBJECTS_PROPERTY
        = "requiredBusinessObjects";

    /**
     * Handles session tracking and authentication tasks common to secure
     * servlets.  Subclasses should both override <i>and</i> invoke this 
     * method (via <code>super.processRequest(context)</code>).
     * <p>
     * See the
     * <a href="http://helm.tigris.org/docs/fieldguide-HelmServlet.html">field
     * guide</a> for more information.
     *
     * @@param context    The WebContext, partially populated by WMServlet.
     * @@param connection the JDBC database connection to use.
     * @@return           The name of the Template for formatting the 
     *                   Context data.
     *
     * @@exception HandlerException  Generic exception used for propogation.
     * @@exception RedirectException On any application-internal redirect
     *                              (<i>not</i> the same as a HTTP redirect).
     */
    protected String processRequest(Context context)
        throws NestableException, ACLException, RedirectException
    {
        // Get the default template to start with.
        String templateName = super.processRequest(context);

        // We should always get the SessionManager for the current request
        SessionManager sMgr = getSessionManager(context);
        HttpSession session = sMgr.getSession();
        User loginUser = null;

        try
        {
            HttpServletRequest request = ContextAPI.getRequest(context);

            loginAsGuestOrYourself(context);
            context.put("isLoggedIn", sMgr.isLoggedIn());

            // set up logging of user name in access_log
            HttpServletResponse response = ContextAPI.getResponse(context);
            response.setHeader("HelmLoginID", sMgr.getLoginID());
            
            //Populate the context with the appropriate host, domain,
            //and project objects.
            context.put("host", ProjectPeer.getHost());
            updateCurrentDomainAndProject(context, request);
            Domain currentDomain = getCurrentDomain(context);

            // User is logged in.  Build their business object and ACL.
            String loginUserID = sMgr.getUserID();
            //Log.debug("loginUserID=" + loginUserID);
            loginUser = (User)session.getValue("loginUser");

            //If the user who logged in changed their personal information
            //or anything which would affect their User object, get that
            //User object again.
            Boolean refreshLoginUser = (Boolean)session.getValue
                ("refreshLoginUser");
            session.removeValue("refreshLoginUser");            
            if (loginUserID != null &&
                (loginUser == null
                 || !loginUser.getID().equals(loginUserID) 
                 || (refreshLoginUser != null && 
                     refreshLoginUser.equals(Boolean.TRUE))));
            {                
                loginUser = UserPeer.getInstance(loginUserID);
                session.putValue("loginUser", loginUser);
            }

            // Check for additional ID crieteria if there are any and
            // apply them. Redirect to the login servlet if the tests fail
            if (loginUser != null && !loginUser.matchesIdentity(context)) {
                setAsDetour(context);
                context.put(ACTION_KEY, "none");
                redirectTo(myProperties.getProperty("loginServletName"));
            }

            context.put("loginUser", loginUser);
            
            AccessControlList acl = getACL(context, loginUserID);

            // If we've got a clickThroughPermission set up -- and if
            // they're not viewing the page showing it -- and if they don't
            // have the permission already -- then we'll need to redirect
            // them to the click through page.

            String clickThroughPermission = 
                myProperties.getProperty( "clickThroughPermission" );

            if (haveValue(clickThroughPermission))
            {
                String servlet = getServletName();
                String compulsoryClickThroughServlet =
                    myProperties.getProperty("compulsoryClickThrough");
                
                if (!servlet.equals(compulsoryClickThroughServlet))
                {
                    if (!acl.hasPermission(clickThroughPermission,
                                           currentDomain))
                    {
                        if (sMgr.detourTarget() == null)
                        {
                            setAsDetour(context);
                        }
                        redirectTo(compulsoryClickThroughServlet);
                    }
                }
            }
            else
            {
                //If no click-through permission is specified, give
                //them the role automatically. This needs to be
                //rethought; if you don't want click-through on your
                //site, the role shouldn't show up at all.
                User user = getLoginUser(context);
                if (!user.getACL().hasPermission("Click-through Page - Seen",
                                                 currentDomain))
                {
                    user.setClickThroughAsViewed(currentDomain);
                    acl = user.getACL();
                }
            }

            // Check the base permission needed to access the servlet.
            String requiredAction = null;
            requiredAction = myProperties.getProperty("permission");
            if (requiredAction != null)
            {
                Action action = ActionPeer.getInstanceByName(requiredAction);
                String type = action.getType();
                String requiredResource = (String) context.get("resource");
                if (requiredResource == null) 
                {
                    requiredResource = myProperties.getProperty("permission");
                    if (requiredResource == null) 
                    {
                        requiredResource = "not appliciable";
                    }
                }

                try 
                {
                    if (type.equals(Action.PROJECT_TYPE)) 
                    {
                        Project currentProject = getCurrentProject(context);
                        acl.assertPermission(requiredAction, requiredResource,
                                             currentProject);
                    }
                    else if (type.equals(Action.DOMAIN_TYPE)) 
                    {
                        acl.assertPermission(requiredAction, requiredResource,
                                             currentDomain);
                    }
                    else 
                    {
                        acl.assertPermission(requiredAction); 
                    }
                }
                catch (ACLException e) 
                {
                    throw e;
                }
            }

            //HACK: If the permission checked was to join the site,
            //and this site doesn't allow folks to join, then throw an
            //exception.
            if (requiredAction != null && requiredAction.equals("Domain - Join"))
            {
                String allowJoin = myProperties.getProperty("ALLOW_JOIN");
                if (!new Boolean(allowJoin).equals(Boolean.TRUE))
                {
                    throw new NestableException
                        ("This site does not allow users to self-register. Contact the site admin if you want an account.");
                }
            }

            populatePagination(myProperties.getProperty(ITEMS_PER_PAGE_KEY), 
                               context);
            populateFilter(context);

            populateBOs(request, context);
            String requiredBOs = myProperties.getProperty
                (REQUIRED_BUSINESS_OBJECTS_PROPERTY);
            if (requiredBOs != null)
            {
                assertBOs(context, requiredBOs);
            }
        }
        catch (ACLException aclEx)
        {
            try
            {
                if (!loginUser.isAnonymous())
                {
                    declareInsufficientPermission(context);
                }
            }
            catch (Exception e)
            {
                Log.error("Error handling ACLException user message: " +
                          e.getMessage());
            }
            setAsDetour(context);
            throw aclEx;
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (NestableException e)
        {
            //BaseHelmServlet will display the error message to the
            //user.
            throw e;
        }
        catch (Exception e)
        {
            Log.warn("Unhandled exception encountered by HelmServlet", 
                     e.getMessage());
            throw new NestableException(e);
        }

        context.put("pageTitle", getPageTitle(context));
        context.put("shortDisplayName", getShortDisplayName(context));
        context.put("servletHelp",
                    new ServletHelp(myProperties.getProperty("documentRoot")));
        context.put("servletTaskBar",
                    new ServletTaskBar(myProperties.getProperty("documentRoot")));

        // Put the template name into the session so that it will show
        // up on ListSessions.
        session.putValue("lastAction", getServletName());

        // Get the current date just before we return the template name.
        context.put("currentDate", new java.util.Date());

        //If something caused us to redirect, redirect instead of
        //continuing.
        String redirect = ContextAPI.getClientRedirect(context);
        if (redirect != null)
        {            
            if (DEBUG)
            {
                Log.debug("Performing client-side redirect to " + redirect);
            }
   
            try
            {
                ContextAPI.getResponse(context).sendRedirect(redirect);
                templateName = null;
            }
            catch (Exception e)
            {
                throw new NestableException(e);
            }
        }

        if (!ContextAPI.isValidUserInput(context, Boolean.FALSE))
        {
            redirectToError(context, "");
        }

        return templateName;
   }


    public void loginAsGuestOrYourself(Context context) 
        throws Exception
    {
        SessionManager sMgr = getSessionManager(context);

        // Make sure user is logged in. If they're not, redirect them
        // to the login servlet or log them in as guest (depending on
        // the site configuration).
        //
        // TODO: Add required login a flag, not based on inheritance 
        // structure (i.e. UnsecureServlet vs. SecureServlet subclass).
        if (!sMgr.isLoggedIn().booleanValue())
        {
            String allowGuests = myProperties.getProperty(ALLOW_GUESTS);
            if (DEBUG)
            {
                Log.debug(ALLOW_GUESTS + '=' + allowGuests);
            }
            if (allowGuests != null && allowGuests.equals("true"))
            {
                // Let the client attempt to view the screen.  If the user
                // does not have permission, redirect to the login screen. 
                // Display an informative message to non-guest users.
                if (DEBUG)
                {
                    Log.debug("Not logged in...logging in as guest");
                }
                User anon = UserPeer.getAnonymousUser();
                if (anon != null)
                {
                    sMgr.init(anon);
                }
            }
            else
            {
                setAsDetour(context);
                context.put(ACTION_KEY, "none");
                redirectTo(myProperties.getProperty("loginServletName"));
            }
        }
    }

    /**
     * Adds the text to display when a user does not have the requisite
     * permission to perform an activity to the user message.
     */
    protected final void declareInsufficientPermission(Context ctx)
    {
        ContextAPI.addError
            (ctx, "Your account does not have the necessary " +
             "<a href=\"/servlets/ACLDump\">permissions</a> to " +
             "access the page you requested.  Either request " +
             "more permission in project " +
             getCurrentProject(ctx).getWordMark() +
             ", or log in using a different account.");
    }


    //
    // Context population methods
    //

    /**
     * Populates the context with information about the current
     * pagination page.
     */
    private void populatePagination(String itemProp, Context context)
    {

        // If pagination information is provided for this servlet,
        // put the number of items desired per page into the context.
        Integer itemsPerPage;
        if (itemProp == null) 
        {
            itemsPerPage = new Integer(20);
        }
        else 
        {
            itemsPerPage = new Integer(Integer.parseInt(itemProp));
        }            
        context.put(ITEMS_PER_PAGE_KEY, itemsPerPage);

        String pageStr = null;
        try
        {
            pageStr = ContextAPI.getParameter(context, PAGINATED_PAGE_KEY);
            Integer page;
            if (pageStr == null) 
            {
                page = new Integer(1);
            } 
            else 
            {
                page = new Integer(Integer.parseInt(pageStr));
            }
            context.put(PAGINATED_PAGE_KEY, page);
        }
        catch (ClassCastException ignore)
        {
            //There was already an integer, we don't need to change it.
        }

    }

    /**
     * Populates the context with information about the current
     * filter settings.
     * TODO: Port this.
     */
    private void populateFilter(Context context)
    {
        // Put a reference to the context into the context--the
        // complex filter template needs this.
        context.put("context", context);

        Criteria filter = new Criteria();
        
        // Divine the filter criteria requested.

        //If they're using the simple form, make a trojan Criteria with
        //this information smuggled into it. PeerBackedList will expand
        //it into a properly ORed Criteria.
        context.put("simpleFilterValue", "");
        String simpleFilterValue = 
            ContextAPI.getParameter(context, 
                                    PeerBackedList.SIMPLE_FILTER_VALUE);
        if (simpleFilterValue != null && !simpleFilterValue.equals(""))
        {
            context.put("simpleFilterValue", simpleFilterValue);
            filter.add(PeerBackedList.SIMPLE_FILTER_VALUE, simpleFilterValue);
        }
        else if (ContextAPI.getParameter
                 (context, PeerBackedList.FILTER_CHECK) != null)
        {
            /*//They're using the big form--get parameter names. This is all TODO.
            Enumeration paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements ())
            {
                String paramName = (String)paramNames.nextElement();
                
                if (paramName.startsWith(PeerBackedList.FILTER_VALUE))
                {
                    StringTokenizer tok = 
                        new StringTokenizer(paramName, "/");
                    tok.nextToken();
                    String filterFieldName = tok.nextToken();
                    String filterValue = 
                        ContextAPI.getParameter(context, paramName);
                    if (!filterValue.equals(""))
                    {
                        context.put(paramName, filterValue);
                        String filterMatchType = 
                            context.getForm(PeerBackedList.cgiKey
                                            (PeerBackedList.FILTER_MATCHTYPE,
                                             filterFieldName));
                             criteria.add(newCrit);
                    }
                }
                }*/
        }
        context.put("filter", filter);
    }

    /**
     * Populate the context with whichever business objects are specified.
     */
    public void populateBOs(HttpServletRequest req, Context context)
        throws Exception
    {
        BOFactoryService.getService().processParameters(req, context);
    }

    /**
     * Asserts that the context contains current values for the
     * provided types of business objects.
     */
    private void assertBOs(Context context, String assertions)
        throws Exception
    {
        StringTokenizer tok = new StringTokenizer(assertions, ",");
        List missingBOs = new ArrayList(0);
        while (tok.hasMoreTokens())
        {
            String bo = tok.nextToken();
            String capBO = StringUtils.firstLetterCaps(bo);
            if (!context.containsKey("current" + capBO))
            {
                ContextAPI.addFatalError
                    (context, 
                     "You are missing the following required input: " 
                     + bo + "ID");
            }
        }
    }
    
    /** 
     * Update current domain and project in the context. These can be
     * specified in the following ways:
     * <ul>
     * <il>1. ID in the query string (e.g., passed from prev servlet)
     * <il>2. Project  or domain name in the query string (e.g., passed
     *     from a rewrite rule)
     * <il>3. Standard vhosting: project.domain
     * <il>4. Request server name matches project URL alias
     * <il>5. default to www project in domain matching request server name
     * </ul>
     *
     * @@param ctx  The context.
     * @@param req  The HTTP request.
     */
    protected void updateCurrentDomainAndProject(Context ctx,
                                                 HttpServletRequest req) 
        throws Exception
    {
        BitSet serverNameMatchedDomain = new BitSet(1);
        Domain reqDom = getRequestedDomain(ctx, req, serverNameMatchedDomain);
        Project reqProj = getRequestedProject(ctx, req, reqDom,
                                              serverNameMatchedDomain.get(0));
        boolean forceCurrentProjectChange = false;
            
        // See if domain changed.
        Domain curDomain = getCurrentDomain(ctx);
        if (curDomain == null || !reqDom.getID().equals(curDomain.getID())) 
        {
            curDomain = reqDom;
            ctx.put("currentDomain", curDomain);
            // Changing domains forces project change.
            forceCurrentProjectChange = true;
        }
        
        // See if project changed.
        Project curProj = getCurrentProject(ctx);
        if (forceCurrentProjectChange || curProj == null ||
            !reqProj.getID().equals(curProj.getID())) 
        {
            curProj = reqProj;
            ctx.put(CURRENT_PROJECT, curProj);
            if (curProj.isDeleted())
            {
                ContextAPI.addMessage
                    (ctx, "Project " + curProj.getName() 
                     + " has been deleted.");
            }

        }
    }

    //
    // Accessor methods; usually aliasing context.get().
    //

    /**
     * Checks first the context, then the HTML form and CGI query string 
     * values for the specified parameter whose value to retrieve.
     *
     * @@param context The context to check.
     * @@param key     The name of the parameter whose value to get.
     * @@return        The parameter value.
     */
    protected final String getServletParam (Context context, String key)
    {
        Object objVal = context.get(key);
        String strVal = (objVal != null ? objVal.toString() : "");
        if (strVal.equals(""))
        {
            strVal = ContextAPI.getParameter(context, key);
        }
        return strVal;
    }

    /**
     * Depends on the logged in user's database key having already been placed
     * into the context previously.
     *
     * @@see org.tigris.helm.security.HelmServlet#getACL(WebContext, String)
     */
    protected final AccessControlList getACL(Context ctx)
        throws Exception
    {
        return getACL(ctx, getSessionManager(ctx).getUserID());
    }

    /**
     * Gets the ACL of the current user from the ACL authority.
     * <p>
     * This probably really belongs in the SessionManager.
     *
     * @@param context The current WebContext. By the time this method is
     *                through, it will contain the user's ACL.
     * @@param userID  The database key of the user to get the ACL for.
     */
    protected AccessControlList getACL(Context ctx, String userID)
        throws Exception
    {
        AccessControlList acl =
            AccessControlList.getACL(UserPeer.getInstance(userID));
        ctx.put("acl", acl);
        return acl;
    }

    /**
     * Gets the host.
     *
     * @@param context The context to grab the host from
     * @@return a Host
     */
    protected final Host getHost (Context ctx)
    {
        return (Host) ctx.get("host");
    }

    /**
     * Gets the current domain.
     *
     * @@param context The context to grab the domain from
     * @@return a Domain
     */
    protected final Domain getCurrentDomain (Context context)
    {
        return (Domain) context.get("currentDomain");
    }

    /**
     * Gets the current project.
     *
     * @@param context The context to grab the project from
     * @@return a Project
     */
    protected final Project getCurrentProject (Context context)
    {
        return (Project) context.get(CURRENT_PROJECT);
    }

    /**
     * Gets the currently logged-in user.
     *
     * @@param context The context to grab the loginUser from
     * @@return a User
     */
    protected final User getLoginUser (Context context)
    {
        return (User) context.get("loginUser");
    }

    /**
     * Gets the user to be operated on.
     * 
     * Note, this is not the currently logged in user.  Use getLoginUser
     * for that.  getCurrentUser returns the user who has been
     * designated for manipulation in some way (eg. by UserEdit).
     * 
     * Just to confuse things more, this -does- return the logged in
     * user if no user is specified, since the logged-in user is
     * also the default action user.
     *
     * @@param context The context to grab the user from
     * @@return a User
     *
     * @@see org.tigris.helm.domain.UserEdit
     * @@see #getLoginUser
     */
    protected final User getCurrentUser (Context context)
    {
        return (User) context.get("currentUser");
    }

    /**
     * Gets the user group to be operated on.
     * 
     * @@param context The context to grab the user group from
     * @@return a UserGroup
     *
     */
    protected final UserGroup getCurrentUserGroup (Context context)
    {
        return (UserGroup) context.get("currentUserGroup");
    }

    /**
     * Gets the project group to be operated on.
     * 
     * @@param context The context to grab the project group from
     * @@return a ProjectGroup
     *
     */
    protected final ProjectGroup getCurrentProjectGroup (Context context)
    {
        return (ProjectGroup) context.get("currentProjectGroup");
    }

    /**
     * Gets the category to be operated on.
     * 
     * @@param context The context to grab the category from
     * @@return a Category
     *
     */
    protected final Category getCurrentCategory (Context context)
    {
        return (Category) context.get("currentCategory");
    }

    /**
     * Gets the license to be operated on.
     * 
     * @@param context The context to grab the license from
     * @@return a License
     *
     */
    protected final License getCurrentLicense (Context context)
    {
        return (License) context.get("currentLicense");
    }

    /**
     * Gets the current Role to be operated on.
     *
     * @@param context The context to grab the role from
     * @@return a Role
     */
    protected final Role getCurrentRole(Context context)
    {
        return (Role)context.get("currentRole");
    }

    /**
     * Gets the current Resource to be operated on.
     *
     * @@param context The context to grab the Resource from
     * @@return a Resource
     */
    protected final Resource getCurrentResource(Context context)
    {
        return (Resource)context.get("currentResource");
    }


    /**
     * Gets the current AuditLogEntry to be operated on.
     *
     * @@param context The context to grab the AuditLogEntry from
     * @@return an AuditLogEntry
     */
    protected final AuditLogEntry getCurrentAuditLogEntry(Context context)
    {
        return (AuditLogEntry)context.get("currentAuditLogEntry");
    }

    /** Show a useful title for this page.  
     *
     * Subclasses can override to show specific details like a user name or 
     * project name.   
     * <p>
     * Note, the super-class BaseHelmSerlvet has a mechanism for
     * setting the page HTML &lt?TITLE>.  If a servlet defines a property 
     * 'displayName' in its property file, BaseHelmSerlvet picks up this 
     * property and automatically adds it to the context for use by 
     * templates setting the HTML HEAD &lt;TITLE>.  The below method's default
     * behaviour is to use the displayName value put in the context by the 
     * parent BaseHelmSerlvet class.
     * 
     * @@param context The data in which to look for the page title.
     * @@return The value of the 'displayName' property from servlet property 
     * file.  If that is not present, returns the servletName property.
     */
    protected String getPageTitle(Context context)
    {
        String title = (String)context.get("displayName");
        if (title == null || title.equals(""))
        {
            title = (String)context.get("servletName");
        }
        return title;
    }

    /** The short name in the properties file
     *  Is the name that goes in the breadcrumbs in the 
     *  Project navigation.
     */
    protected String getShortDisplayName (Context context)
    {
        String shortDisplayName = (String)context.get("shortDisplayName");
        if (shortDisplayName == null || shortDisplayName.equals(""))
        {
            shortDisplayName = (String)context.get("displayName");
        }
        return shortDisplayName;
    }

    /**
     * Returns the requested domain.
     *
     * @@param ctx                     The context.
     * @@param req                     The HTTP request.
     * @@param serverNameMatchedDomain A boolean output parameter.
     */
    private Domain getRequestedDomain (Context ctx, HttpServletRequest req,
                                       BitSet serverNameMatchedDomain)
        throws Exception
    {
        Domain reqDom = null;
        String reqDomID = getServletParam(ctx, "domainID");
        if (reqDomID != null) 
        {
            reqDom = (Domain)ProjectPeer.getInstance(reqDomID);
        }
        else 
        {
            // Determine the name of the requested domain to infer its ID.
            String reqDomName = getServletParam(ctx, "domainName");
            if (reqDomName == null) 
            {
                reqDomName = req.getServerName();
            }

            int dot = reqDomName.indexOf('.');
            if (dot != -1) 
            {
                // Try using non-vhosted name.
                String domainNoVhost = reqDomName.substring(dot + 1);
                try 
                {
                    reqDom = ProjectPeer.getDomain(domainNoVhost);
                }
                catch (Exception noMatch)
                {
                    if (DEBUG)
                    {
                        Log.debug("Could not get domain from vhost-less name");
                    }
                }
            }
            else
            {
                if (DEBUG)
                {
                    Log.debug("Could not parse domain from vhost");
                }
            }

            // Try once more using vhosted name.
            if (reqDom == null)
            {
                try 
                {
                    reqDom = ProjectPeer.getDomain(reqDomName);
                    serverNameMatchedDomain.set(0);
                }
                catch (Exception noMatch)
                {
                    if (DEBUG)
                    {
                        Log.debug("Could not get domain from vhosted name");
                    }
                }
            }

            if (reqDom == null)
            {
                Log.error("Domain matching " + reqDomName +
                          " could not be resolved");
            }
        }
        return reqDom;
    }

    /**
     * Returns the requested project.
     *
     * @@param ctx                     The context.
     * @@param req                     The HTTP request.
     * @@param reqDom                  The requested domain.
     * @@param serverNameMatchedDomain Whether vhosted.
     */
    private Project getRequestedProject(Context ctx, 
                                        HttpServletRequest req, 
                                        Domain reqDom,
                                        boolean serverNameMatchedDomain)
        throws Exception
    {
        Project reqProj = null;
        String reqProjID = getServletParam(ctx, "projectID");
        if (!haveValue(reqProjID)) 
        {
            try 
            {
                String reqProjName = getServletParam(ctx, "projectName");
                if (reqProjName != null) 
                {
                    reqProj = ProjectPeer.getInstanceByName
                        (reqDom, reqProjName);
                }
            }
            catch (Exception e) 
            {
                reqProj = ProjectPeer.getInstanceByAliasURL
                    (reqDom, req.getServerName());
            }

            if (reqProj == null && !serverNameMatchedDomain) 
            {
                String vhost = req.getServerName();
                vhost = vhost.substring(0, vhost.indexOf('.'));
                try
                {
                    reqProj = ProjectPeer.getInstanceByName(reqDom, vhost);
                }
                catch (DoesNotExist e)
                {                    
                    StringBuffer url = URL.schemeAndServer(req);
                    String search = url.toString();
                    int end = search.indexOf('.');
                    String newURL = url.replace
                        (end-vhost.length(), end,
                         ProjectPeer.DEFAULT_PROJECT_NAME).toString();
                    ContextAPI.setClientRedirect(ctx, newURL);
                }
            }

            if (reqProj == null) 
            {
                reqProj = ProjectPeer.getInstanceByName
                    (reqDom, ProjectPeer.DEFAULT_PROJECT_NAME);
            }
        }
        else 
        {
            reqProj = ProjectPeer.getInstance(reqProjID);
        }
        return reqProj;
    }
}
@


1.134
log
@More methods migrated to ContextAPI.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.133 2001/08/24 22:39:03 leonardr Exp $
d106 5
d618 1
a618 1
            ctx.put("currentProject", curProj);
a628 1

d712 1
a712 1
        return (Project) context.get("currentProject");
@


1.133
log
@Factored code out of HelmServlet.populateBOs into BOFactoryService. Components can now specify the business objects they want populated in a TurbineResources.properties fragment.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.132 2001/08/22 15:42:34 leonardr Exp $
d462 1
a462 1
            pageStr = getParameter(context, PAGINATED_PAGE_KEY);
d501 2
a502 1
            getParameter(context, PeerBackedList.SIMPLE_FILTER_VALUE);        
d508 2
a509 1
        else if (getParameter(context, PeerBackedList.FILTER_CHECK) != null)
d524 1
a524 1
                        getParameter(context, paramName);
d643 1
a643 1
            strVal = getParameter(context, key);
@


1.132
log
@Made project deletions soft.
@
text
@d57 1
d64 1
d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.131 2001/08/11 09:08:08 dlr Exp $
d291 1
a291 1
            populateBOs(context);
d541 1
a541 1
    public void populateBOs(Context context)
d544 1
a544 98
        // The operative user (for this request). Defaults to the
        // logged-in user so that if you hit, eg. UserEdit without
        // specifying a user ID, it defaults to editing yourself.
        String currentUserID = getServletParam(context, "userID");
        if (haveValue(currentUserID)) 
        {
            User currentUser = UserPeer.getInstance(currentUserID);
            context.put("currentUser", currentUser);
            if (currentUser.isDeleted())
            {
                ContextAPI.addMessage
                    (context, 
                     "User " + currentUser.getLoginName() 
                     + " has been deleted.");
            }
        }
        else 
        {
            context.put("currentUser", getLoginUser(context));
        }
        
        String currentUserGroupID = 
            getServletParam(context, "userGroupID");
        if (haveValue(currentUserGroupID))
        {
            User u = UserPeer.getInstance(currentUserGroupID);
            if (!(u instanceof UserGroup))
            {
                throw new Exception("User with ID " + currentUserGroupID 
                                    + " is not a group.");
            }
            context.put("currentUserGroup", u);
        }            
        
        Project currentProject = getCurrentProject(context);

        String currentProjectGroupID = 
            getServletParam(context, "projectGroupID");
        if (haveValue(currentProjectGroupID))
        {                
            Project p = ProjectPeer.getInstance(currentProjectGroupID);
            if (!(p.isGroup()))
            {
                throw new Exception("Project with ID " + currentProjectGroupID
                                    + " is not a group.");
            }
            context.put("currentProjectGroup", p);
        }
        else if (currentProject.isGroup())
        {
            context.put("currentProjectGroup", currentProject);
        }
        
        String currentCategoryID = 
            getServletParam(context, "categoryID");
        if (haveValue(currentCategoryID))
        {                
            Project p = ProjectPeer.getInstance(currentCategoryID);
            if (!(p.isCategory()))
            {
                throw new Exception("Project with ID " + currentCategoryID
                                    + " is not a category.");
            }
            context.put("currentCategory", p);
        }
        else if (currentProject.isCategory())
        {
            context.put("currentCategory", currentProject);
        }

        String currentLicenseID = getServletParam(context, "licenseID");
        if (haveValue(currentLicenseID))
        {
            context.put("currentLicense",
                        LicensePeer.getInstance(currentLicenseID));
        }
        
        String currentRoleID = getServletParam(context, "roleID");
        if (haveValue(currentRoleID))
        {
            context.put("currentRole",
                        RolePeer.getInstance(currentRoleID));
        }
        
        String currentResourceID = getServletParam(context, "resourceID");
        if (haveValue(currentResourceID))
        {
            context.put("currentResource", 
                        ResourcePeer.getInstance(currentResourceID));
        }

        String currentAuditLogEntryID = getServletParam(context,
                                                        "auditLogEntryID");
        if (haveValue(currentAuditLogEntryID))
        {
            context.put("currentAuditLogEntry", 
                 AuditLogEntryPeer.getInstance(currentAuditLogEntryID));
        }
@


1.131
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.130 2001/08/06 23:09:54 dlr Exp $
d707 7
@


1.130
log
@Cleaned up JavaDoc.
@
text
@d53 1
a53 1
import org.apache.turbine.util.db.Criteria;
d55 2
a56 2
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.StringUtils;
d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.129 2001/08/06 22:00:05 dlr Exp $
d129 1
a129 1
        throws TurbineException, ACLException, RedirectException
d141 1
a141 1
            HttpServletRequest request = getRunData(context).getRequest();
d147 1
a147 1
            HttpServletResponse response = getRunData(context).getResponse();
d280 1
a280 1
                    throw new TurbineException
d318 1
a318 1
        catch (TurbineException e)
d328 1
a328 1
            throw new TurbineException(e);
d362 1
a362 1
                throw new TurbineException(e);
@


1.129
log
@Made use of SessionManager's new init(User) method.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.128 2001/08/03 18:43:40 leonardr Exp $
d925 1
a925 2
     * @@param context WebMacro context
     * 
d929 1
a929 1
    protected String getPageTitle (Context context)
@


1.128
log
@Turned off debug.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.127 2001/07/27 19:58:46 leonardr Exp $
d405 1
a405 5
                    sMgr.isLoggedIn(true);
                    sMgr.setUserID(anon.getID());
                    sMgr.setLoginID(anon.getLoginName());
                    sMgr.setEmail(anon.getEmail());
                    sMgr.setUserName(anon.getRealName());
@


1.127
log
@Got rid of phantom validation errors
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.126 2001/07/26 20:56:53 leonardr Exp $
d85 1
a85 1
    private static final boolean DEBUG = true;
@


1.126
log
@Actually, any fatal error shuold cause that.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.125 2001/07/26 20:54:52 leonardr Exp $
d366 1
a366 1
        if (!ContextAPI.isValidUserInput(context))
@


1.125
log
@Fatal errors at this stage should redirect to error.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.124 2001/07/26 01:46:51 dlr Exp $
d365 6
d372 1
a372 1
    }
a665 5
        }

        if (!ContextAPI.isValidUserInput(context))
        {
            redirectToError(context, "");
@


1.124
log
@Reduced accessibility of implementation method assertBOs() from public
to private.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.123 2001/07/25 20:01:59 leonardr Exp $
d661 5
d667 1
a667 1

@


1.123
log
@Canonicalized syntax expected by HelmServlet in reading requiredBusinessObjects property.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.122 2001/07/25 19:39:26 leonardr Exp $
d644 1
a644 1
    public void assertBOs(Context context, String assertions)
@


1.122
log
@User deletes are now soft deletes which change the user type to 'deleted' (a minimal type of user which has user information but is not allowed associations with roles or user groups). Includes some other miscellaneous bug fixes.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.121 2001/07/24 00:02:28 leonardr Exp $
d651 1
a651 1
            String bo = tok.nextToken().toLowerCase();
@


1.121
log
@The final pieces of the error handling revolution.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.120 2001/07/23 20:32:00 dlr Exp $
d546 9
a554 2
            context.put("currentUser", 
                        UserPeer.getInstance(currentUserID));
d641 1
a641 1
     * Asserts that the context contains current calues for the
@


1.120
log
@Removed Joist reference and made comment more specific.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.119 2001/07/20 00:23:00 dlr Exp $
d421 7
a427 6
        appendToMessage(ctx, "Your account does not have the necessary " +
                        "<a href=\"/servlets/ACLDump\">permissions</a> to " +
                        "access the page you requested.  Either request " +
                        "more permission in project " +
                        getCurrentProject(ctx).getWordMark() +
                        ", or log in using a different account.");
d648 4
a651 1
                alertToMissingInput(context, bo + "ID");
@


1.119
log
@Made formatting and spacing more uniform.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.118 2001/07/19 19:54:05 dlr Exp $
d125 2
a126 1
     * @@exception RedirectException On any Joist redirect.
@


1.118
log
@Removed Joist references.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.117 2001/07/19 19:08:43 dlr Exp $
d214 3
a216 1
            } else {
a229 1

a412 2


@


1.117
log
@Updated to use Helm URL class (just ported from Joist).
@
text
@a59 3
import org.joist.security.*;
import org.tigris.helm.util.URL;

d68 1
d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.116 2001/07/17 23:20:23 leonardr Exp $
@


1.116
log
@Added flag so that you can signal when missing fields are important errors and when they're not.
@
text
@d61 1
a61 1
import org.joist.util.URL;
d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.115 2001/07/17 16:00:43 leonardr Exp $
@


1.115
log
@Ported servlets over to the new error handling system.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.114 2001/07/16 03:18:07 jrobbins Exp $
d87 1
a87 1
    private static final boolean DEBUG = false;
@


1.114
log
@shifted code from helm to nidaba
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.113 2001/07/13 21:47:11 leonardr Exp $
a1083 111
    }


    /**
     * Search the form parameters for parameters that begin with a certain
     * prefix. Return the list of parameter values provided for that prefix.
     *
     * For instance, calling searchParamsForPrefix(context, "Add")
     * when "Add 4" and "Add 7" are form parameters will return a List
     * containing the Strings "4" and "7".
     */
    public List searchParamsForPrefix(Context context, String prefix)
        throws TurbineException
    {
        return searchParamsForPrefixAndTokenize(context, prefix, 1, false);
    }

    /**
     * Search the form parameters for parameters that begin with a certain
     * prefix. Return the list of parameter values provided for that prefix.
     *
     * For instance, calling searchParamsForPrefix(context, "Add"),
     * when "Add 4" and "Add 7" are form parameters mapping to "a" and
     * "b", will return a list containing the String arrays {"4" "a"}
     * and {"7" "b"}.  
     */
    public List searchParamsForPrefixIncludeValue
        (Context context, String prefix)
        throws TurbineException
    {
        return searchParamsForPrefixAndTokenize(context, prefix, 1, true);
    }

    /**
     * Search the form parameters for parameters that begin with a
     * certain prefix. Return the list of string arrays containing the
     * tokenized parameter values provided for that prefix.
     *
     * <p>Examples<br>
     * Assume the following parameters:
     * <li>"Add 4 7" => "a"
     * <li>"Add 10 4" => "b"
     *
     * <p>sPFPAT(context, "Add", 1, false) returns a List containing
     * the Strings "4 7" and "10 4".
     *
     * <p>sPFPAT(context, "Add", 2, false) returns a List containing
     * the String arrays {"4" "7"} and {"10" "4"}.
     *
     * <p>sPFPAT(context, "Add", 3, false) throws an exception
     * because there are not enough tokens in "Add 4 7".
     *
     * <p>sPFPAT(context, "Add", 2, true) returns a List containing
     * the String arrays {"4" "7" "a"} and {"10" "4" "b"}
     *
     * <p>sPFPAT(context, "Add", 1, true) returns a List containing
     * the String arrays {"4 7" "a"} and {"10 4" "b"}
     *
     * <p>sPFPAT(context, "Remove", 3, false) returns an empty List,
     * since there are no parameter values beginning with "Remove".
     */
    public List searchParamsForPrefixAndTokenize
        (Context context, String prefix, int tokens, boolean appendValue)
        throws TurbineException
    {
        List values = new ArrayList();
        Enumeration paramNames = getRequest(context).getParameterNames();
        while (paramNames.hasMoreElements())
        {
            String paramName = (String) paramNames.nextElement();
            if (paramName.startsWith(prefix))
            {
                StringTokenizer tok = new StringTokenizer (paramName);
                tok.nextToken();
                int size = tokens;
                if (appendValue)
                {
                    size++;
                }
                String[] theseValues = new String[size];
                for (int i = 0; i < tokens; i++)
                {
                    try
                    {                    
                        theseValues[i] = tok.nextToken();
                    }
                    catch (NoSuchElementException e)
                    {
                        throw new TurbineException
                            ("Attempt to tokenize \"" + paramName + "\" " 
                             + (tokens+1) 
                             + " times failed: not enough tokens.");
                    }
                    if (appendValue)
                    {
                        String value = processField(context, paramName, 
                                                    (String)null);
                        theseValues[theseValues.length-1] = value;
                    }
                }
                if (theseValues.length == 1) 
                {
                    values.add(theseValues[0]);
                }
                else
                {
                    values.add(theseValues);
                }
            }
        }    
        return values;
@


1.113
log
@Print stack traces along with errors instead of just the (often unhelpful) messages. Sticks with the messages, however unhelpful, in production environments.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.112 2001/07/13 21:39:29 leonardr Exp $
a624 7
        String currentSectionID = getServletParam(context, "sectionID");
        if (haveValue(currentSectionID))
        {
            context.put("currentSection", 
                        ProjectSectionPeer.getInstance(currentSectionID));
        }
        
a888 10
    /**
     * Gets the current ProjectSection to be operated on.
     *
     * @@param context The context to grab the ProjectSection from
     * @@return a ProjectSection
     */
    protected final ProjectSection getCurrentSection(Context context)
    {
        return (ProjectSection)context.get("currentSection");
    }
@


1.112
log
@BaseHelmServlet is going to print a stack trace; there's no need to do it twice.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.111 2001/07/13 19:47:34 leonardr Exp $
d318 6
a327 2
            // NOTE: BaseHelmServlet calls appendToError() to display a
            // reasonable description of the error message to the user.
@


1.111
log
@Minor new functionality avaliable to servlets to automatically check for the presence of 'current' values for business objects.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.110 2001/07/06 15:42:28 leonardr Exp $
d320 2
a321 1
            Log.warn("Unhandled exception encountered by HelmServlet", e);
@


1.110
log
@Integers in the context were causing ClassCastExceptions; trap them.
@
text
@d56 1
a56 1
import org.apache.turbine.util.TurbineException;
d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.109 2001/07/05 22:21:39 leonardr Exp $
d106 7
d290 6
d619 7
d631 1
a631 2
            context.put
                ("currentAuditLogEntry", 
d636 20
d889 11
@


1.109
log
@Licenses are now contained in a database-managed table rather than in a custom Java class (yay!)
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.108 2001/06/29 00:57:49 leonardr Exp $
d438 2
a439 3
        String pageStr = getParameter(context, PAGINATED_PAGE_KEY);
        Integer page;
        if (pageStr == null) 
d441 13
a453 3
            page = new Integer(1);
        } 
        else 
d455 3
a457 3
            page = new Integer(Integer.parseInt(pageStr));
        }           
        context.put(PAGINATED_PAGE_KEY, page);
@


1.108
log
@Implemented basic project group and category nesting.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.107 2001/06/20 21:32:25 leonardr Exp $
d576 7
a622 1

d807 12
@


1.107
log
@Added new methods for easily getting IDs from parameter names and values.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.106 2001/06/18 22:12:21 leonardr Exp $
d541 2
d548 1
a548 1
            if (!(p instanceof ProjectGroup))
d555 21
d789 12
@


1.106
log
@Huge patch of the day: Got rid of redundant HELM_DOMAIN table. The project representation of the domain and the host is now the canonical one. Host and Domain now subclass ProjectGroup. The canonical representation of a project's membership in a domain group is now the corresponding mapping in HELM_PROJECT_PROJECTGROUP. Schema changes: No more HELM_DOMAIN table (obviously); no more DOMAIN_ID in HELM_PROJECT; HELM_USER and HELM_VC_VIEW now have foreign keys in HELM_PROJECT instead of HELM_DOMAIN.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.105 2001/06/13 01:46:33 leonardr Exp $
d992 2
a993 2
     * when "Add 4" and "Add 7" are form parameters will return a list
     * containing the strings "4" and "7".
d996 52
d1051 1
a1051 1
        while (paramNames.hasMoreElements ())
d1058 34
a1091 1
                values.add(tok.nextToken());
@


1.105
log
@Do a client-side redirect to the defaulr project when a nonexistant project is accessed, rather than throwing an error.
@
text
@d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.104 2001/06/13 01:35:23 elicia Exp $
d146 1
a146 1
            context.put("host", new Host());
d858 1
a858 1
            reqDom = DomainPeer.getInstance(reqDomID);
d876 1
a876 1
                    reqDom = DomainPeer.getInstanceByName(domainNoVhost);
d899 1
a899 1
                    reqDom = DomainPeer.getInstanceByName(reqDomName);
@


1.104
log
@changed comments to read "BaseHelmServlet" as the superclass instead of "UnsecureServlet"
@
text
@d61 1
d66 1
d81 1
a81 1
 * @@version $Id: HelmServlet.java,v 1.103 2001/06/12 00:37:09 elicia Exp $
d326 21
d603 1
a603 1

d613 1
a613 1

d962 8
a969 2
                {
                    redirectToError(ctx, "No such project: " + vhost);
a1010 1

@


1.103
log
@made the servletDisplayName as the default for the shortDisplayName variable.

added a servletTaskBar to the context: this will be the servlet-specific list of tasks for project-level nav.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.102 2001/06/09 01:02:15 leonardr Exp $
d306 1
a306 1
            // NOTE: UnsecureServlet calls appendToError() to display a
d783 1
a783 1
     * Note, the super-class UnsecureServlet has a mechanism for
d785 1
a785 1
     * 'displayName' in its property file, UnsecureServlet picks up this 
d789 1
a789 1
     * parent UnsecureServlet class.
@


1.102
log
@Got rid of the ugly and unneccessary asGroup() and getGroupInstance() methods.
@
text
@d66 1
d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.101 2001/06/07 19:06:51 elicia Exp $
d315 2
d808 1
a808 1
     *  Project navigation
d815 1
a815 1
            shortDisplayName = (String)context.get("servletDisplayName");
@


1.101
log
@changed "shortName" to "shortDisplayName" for the context variable that the bread crumbs navigation on the Project_Nav. For example, for any of the ProjectDocuments page (Add, Edit, List) the shortDisplayName will be "Documents".
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.100 2001/06/07 03:07:20 elicia Exp $
d502 2
a503 2
        String currentUserGroupID = getServletParam(context, 
                                                    "userGroupID");
d506 7
a512 2
            context.put("currentUserGroup", 
                        UserPeer.getGroupInstance(currentUserGroupID));
d515 2
a516 2
        String currentProjectGroupID = getServletParam(context, 
                                                       "projectGroupID");
d519 7
a525 3
            context.put
                ("currentProjectGroup",
                 ProjectPeer.getGroupInstance(currentProjectGroupID));
@


1.100
log
@added shortName property to the context
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.99 2001/06/04 16:42:00 leonardr Exp $
d311 1
a311 1
        context.put("shortName", getShortName(context));
d798 1
a798 1
    protected String getShortName (Context context)
d800 2
a801 2
        String shortName = (String)context.get("shortName");
        if (shortName == null || shortName.equals(""))
d803 1
a803 1
            shortName = (String)context.get("servletName");
d805 1
a805 1
        return shortName;
@


1.99
log
@added useful code-factoring-out method
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.98 2001/06/01 20:13:52 leonardr Exp $
d311 1
d792 14
@


1.98
log
@Factored out context keys into constants.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.97 2001/05/25 21:05:26 leonardr Exp $
d929 27
@


1.97
log
@Redirect to an error if a project doesn't exist.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.96 2001/05/25 00:53:26 dlr Exp $
d93 10
d275 1
a275 1
            populatePagination(myProperties.getProperty("itemsPerPage"), 
d409 1
a409 1
        context.put("itemsPerPage", itemsPerPage);
d411 1
a411 1
        String pageStr = getParameter(context, "paginated_page");
d421 1
a421 1
        context.put("paginated_page", page);
@


1.96
log
@Instantiate ServletHelp instance as per its new API.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.95 2001/05/23 01:50:20 dlr Exp $
d897 8
a904 1
                reqProj = ProjectPeer.getInstanceByName(reqDom, vhost);
@


1.95
log
@Ported Helm from WebMacro to Velocity.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.94 2001/04/19 15:41:46 leonardr Exp $
d301 2
a302 1
        context.put("servletHelp", new ServletHelp());
@


1.94
log
@Refresh the ACL after granting a role to a user.
@
text
@d55 2
d58 1
a58 1
import org.webmacro.servlet.*;
a60 1
import org.joist.session.*;
d66 1
d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.93 2001/04/17 00:19:40 leonardr Exp $
d95 1
a95 1
     * method (via <code>super.processRequestion(connection, context)</code>).
d104 1
a104 1
     *                   WebContext data.
d109 2
a110 2
    protected String processRequest (Connection connection, WebContext context)
        throws HandlerException, ACLException, RedirectException
d113 1
a113 1
        String templateName = super.processRequest(connection, context);
d122 1
a122 1
            HttpServletRequest request = context.getRequest();
d128 1
a128 1
            HttpServletResponse response = context.getResponse();
d260 1
a260 1
                    throw new HandlerException
d297 1
a297 1
            throw new HandlerException(e.getMessage());
d313 1
a313 1
    public void loginAsGuestOrYourself(WebContext context) 
d318 18
a335 9
            // Make sure user is logged in. If they're not, redirect them
            // to the login servlet or log them in as guest (depending on
            // the site configuration).
            //
            // TODO: Add required login a flag, not based on inheritance 
            // structure (i.e. UnsecureServlet vs. SecureServlet subclass).
            if (!sMgr.isLoggedIn().booleanValue())
            {
                String allowGuests = myProperties.getProperty(ALLOW_GUESTS);
d338 1
a338 1
                    Log.debug(ALLOW_GUESTS + '=' + allowGuests);
d340 2
a341 1
                if (allowGuests != null && allowGuests.equals("true"))
d343 5
a347 22
                    // Let the client attempt to view the screen.  If the user
                    // does not have permission, redirect to the login screen. 
                    // Display an informative message to non-guest users.
                    if (DEBUG)
                    {
                        Log.debug("Not logged in...logging in as guest");
                    }
                    User anon = UserPeer.getAnonymousUser();
                    if (anon != null)
                    {
                        sMgr.isLoggedIn(true);
                        sMgr.setUserID(anon.getID());
                        sMgr.setLoginID(anon.getLoginName());
                        sMgr.setEmail(anon.getEmail());
                        sMgr.setUserName(anon.getRealName());
                    }
                }
                else
                {
                    setAsDetour(context);
                    context.put(ACTION_KEY, "none");
                    redirectTo(myProperties.getProperty("loginServletName"));
d350 7
d365 1
a365 1
    protected final void declareInsufficientPermission(WebContext ctx)
d384 1
a384 1
    private void populatePagination(String itemProp, WebContext context)
d400 1
a400 1
        String pageStr = context.getForm("paginated_page");
d418 1
a418 1
    private void populateFilter(WebContext context)
d433 1
a433 1
            context.getForm(PeerBackedList.SIMPLE_FILTER_VALUE);        
d438 3
a440 1
        } else if (context.getForm(PeerBackedList.FILTER_CHECK) != null) {
d454 1
a454 1
                        context.getForm(paramName);
d473 1
a473 1
    public void populateBOs(WebContext context)
d547 1
a547 1
    protected void updateCurrentDomainAndProject(WebContext ctx,
d590 1
a590 1
    protected final String getServletParam (WebContext context, String key)
d596 1
a596 1
            strVal = context.getForm(key);
d607 1
a607 1
    protected final AccessControlList getACL(WebContext ctx)
a613 19
     * @@deprecated Use getACL(WebContext ctx) instead.
     */
    protected final AccessControlList getACL(WebContext ctx, Connection conn)
        throws Exception
    {
        return getACL(ctx);
    }

    /**
     * @@deprecated Use getACL(WebContext ctx, String userID) instead.
     */
    protected AccessControlList getACL(WebContext ctx, Connection c,
                                       String userID)
        throws Exception
    {
        return getACL(ctx, userID);
    }

    /**
d616 1
a616 2
     * This probably really belongs in the SessionManager, but we don't want 
     * to change Joist (yet).
d622 1
a622 1
    protected AccessControlList getACL(WebContext ctx, String userID)
d637 1
a637 1
    protected final Host getHost (WebContext ctx)
d648 1
a648 1
    protected final Domain getCurrentDomain (WebContext context)
d659 1
a659 1
    protected final Project getCurrentProject (WebContext context)
d670 1
a670 1
    protected final User getLoginUser (WebContext context)
d692 1
a692 1
    protected final User getCurrentUser (WebContext context)
d704 1
a704 1
    protected final UserGroup getCurrentUserGroup (WebContext context)
d716 1
a716 1
    protected final ProjectGroup getCurrentProjectGroup (WebContext context)
d727 1
a727 1
    protected final Role getCurrentRole(WebContext context)
d738 1
a738 1
    protected final Resource getCurrentResource(WebContext context)
d749 1
a749 1
    protected final AuditLogEntry getCurrentAuditLogEntry(WebContext context)
d772 1
a772 1
    protected String getPageTitle (WebContext context)
d789 1
a789 1
    private Domain getRequestedDomain (WebContext ctx, HttpServletRequest req,
d867 1
a867 1
    private Project getRequestedProject(WebContext ctx, 
@


1.93
log
@Moved from Message, the last of the Joist tables, to HELM_MESSAGE. A few minor problems with Joist servlets remain.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.92 2001/04/16 19:52:42 dlr Exp $
d204 1
@


1.92
log
@Refactored getRequestedDomain() to check non-vhosted domain names
before vhosted.  This saves on database hits, because non-vhosted is
the common case (and should thus be checked first).  Also added better
debugging information (turned off for now).
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.91 2001/04/16 18:05:09 dlr Exp $
d80 1
a80 1
public class HelmServlet extends UnsecureServlet
a463 1
    
@


1.91
log
@Renamed a couple Exception variables to better indicate what they
represent.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.90 2001/04/16 17:06:57 leonardr Exp $
d824 2
a825 1
            try 
d827 20
a846 2
                reqDom = DomainPeer.getInstanceByName(reqDomName);
                serverNameMatchedDomain.set(0);
d848 3
a850 1
            catch (Exception noMatch)
d852 6
a857 2
                int dot = reqDomName.indexOf('.');
                if (dot != -1) 
d859 1
a859 7
                    // Try once more using non-vhosted name.
                    String domainNoVhost = reqDomName.substring(dot + 1);
                    try 
                    {
                        reqDom = DomainPeer.getInstanceByName(domainNoVhost);
                    }
                    catch (Exception e)
d861 1
a861 1
                        Log.error("Could not get domain via URL alias.", e);
d864 6
a869 4
                else
                {
                    Log.error("Could not parse domain from vhost");
                }
@


1.90
log
@Cleanup. Also, check alias URL after project.domain so that someone
can't create an alias URL that trumps someone else's project.domain.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.89 2001/04/05 07:07:36 manoj Exp $
d829 1
a829 1
            catch (Exception e) 
d840 1
a840 1
                    catch (Exception f) 
d842 1
a842 1
                        Log.error("Could not get domain via URL alias.", f);
@


1.89
log
@Add use of the new User.matchesIdentity() method that takes advantage
of the IdentityVerificationService.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.88 2001/04/04 00:24:53 jrobbins Exp $
d534 2
a535 2
     * <il>3. Request server name matches project URL alias
     * <il>4. Standard vhosting: project.domain
d555 2
a556 1
        if (curDomain == null || !reqDom.getID().equals(curDomain.getID())) {
d566 2
a567 1
            !reqProj.getID().equals(curProj.getID())) {
a569 7

            //TODO: Set the project's skin as well.
//             Skin skin = curProj.getSkin();
//             if (skin != null)
//             {
//                 ctx.put("skin", skin);
//             }
d819 2
a820 1
            if (reqDomName == null) {
a873 5
                reqProj = ProjectPeer.getInstanceByAliasURL
                    (reqDom, req.getServerName());
            }
            catch (Exception e) 
            {
d877 2
a878 1
                    reqProj = getProjectByName(reqProjName, reqDom);
d881 5
d891 1
a891 1
                reqProj = getProjectByName(vhost, reqDom);
d896 2
a897 2
                reqProj = getProjectByName(ProjectPeer.DEFAULT_PROJECT_NAME, 
                                           reqDom);
a905 19

    /**
     * Returns the named project in the specified domain.
     */
    private Project getProjectByName (String projectName, Domain domain)
    {
        // TODO: cache this info
        Project project = null;
        try 
        {
            project = ProjectPeer.getInstanceByName(domain, projectName);
        }
        catch (Exception e) 
        {
            Log.error("Project not found: projectName=" + projectName, e);
        }
        return project;
    }

@


1.88
log
@PR: 3412. Since ContentHelmNoodle does specific resource permission checking before hitting the actual page, it needs to do some more of what HelmServlet does. Broke out the guest login and/or redirect login as a method I can call.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.87 2001/03/27 06:57:53 jrobbins Exp $
a139 5
            // TODO: Check loginUser.matchesIdentity(Object ident)
            // here.  Leonard suggests that this may have some effect
            // on login (i.e. might replace it).  Leaving it to the
            // domain experts to decide (i.e. Manoj, Niels)

d155 9
@


1.87
log
@made this method public because I need it in content helm noodle
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.86 2001/03/26 18:49:54 dlr Exp $
d122 1
a122 39
            // Make sure user is logged in. If they're not, redirect them
            // to the login servlet or log them in as guest (depending on
            // the site configuration).
            //
            // TODO: Add required login a flag, not based on inheritance 
            // structure (i.e. UnsecureServlet vs. SecureServlet subclass).
            if (!sMgr.isLoggedIn().booleanValue())
            {
                String allowGuests = myProperties.getProperty(ALLOW_GUESTS);
                if (DEBUG)
                {
                    Log.debug(ALLOW_GUESTS + '=' + allowGuests);
                }
                if (allowGuests != null && allowGuests.equals("true"))
                {
                    // Let the client attempt to view the screen.  If the user
                    // does not have permission, redirect to the login screen. 
                    // Display an informative message to non-guest users.
                    if (DEBUG)
                    {
                        Log.debug("Not logged in...logging in as guest");
                    }
                    User anon = UserPeer.getAnonymousUser();
                    if (anon != null)
                    {
                        sMgr.isLoggedIn(true);
                        sMgr.setUserID(anon.getID());
                        sMgr.setLoginID(anon.getLoginName());
                        sMgr.setEmail(anon.getEmail());
                        sMgr.setUserName(anon.getRealName());
                    }
                }
                else
                {
                    setAsDetour(context);
                    context.put(ACTION_KEY, "none");
                    redirectTo(myProperties.getProperty("loginServletName"));
                }
            }
d304 49
@


1.87.2.1
log
@Merging in Jason's bug fix to the HEAD:

PR: 3412. Since ContentHelmNoodle does specific resource permission
checking before hitting the actual page, it needs to do some more of
what HelmServlet does. Broke out the guest login and/or redirect login
as a method I can call.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.88 2001/04/04 00:24:53 jrobbins Exp $
d122 39
a160 1
            loginAsGuestOrYourself(context);
a341 49


    public void loginAsGuestOrYourself(WebContext context) 
        throws Exception
    {
        SessionManager sMgr = getSessionManager(context);

            // Make sure user is logged in. If they're not, redirect them
            // to the login servlet or log them in as guest (depending on
            // the site configuration).
            //
            // TODO: Add required login a flag, not based on inheritance 
            // structure (i.e. UnsecureServlet vs. SecureServlet subclass).
            if (!sMgr.isLoggedIn().booleanValue())
            {
                String allowGuests = myProperties.getProperty(ALLOW_GUESTS);
                if (DEBUG)
                {
                    Log.debug(ALLOW_GUESTS + '=' + allowGuests);
                }
                if (allowGuests != null && allowGuests.equals("true"))
                {
                    // Let the client attempt to view the screen.  If the user
                    // does not have permission, redirect to the login screen. 
                    // Display an informative message to non-guest users.
                    if (DEBUG)
                    {
                        Log.debug("Not logged in...logging in as guest");
                    }
                    User anon = UserPeer.getAnonymousUser();
                    if (anon != null)
                    {
                        sMgr.isLoggedIn(true);
                        sMgr.setUserID(anon.getID());
                        sMgr.setLoginID(anon.getLoginName());
                        sMgr.setEmail(anon.getEmail());
                        sMgr.setUserName(anon.getRealName());
                    }
                }
                else
                {
                    setAsDetour(context);
                    context.put(ACTION_KEY, "none");
                    redirectTo(myProperties.getProperty("loginServletName"));
                }
            }
    }


@


1.87.2.2
log
@Merged in Manoj's activation of IdentityVerificationService from the
HEAD.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.87.2.1 2001/04/04 20:50:47 dlr Exp $
d140 5
a159 9

            // Check for additional ID crieteria if there are any and
            // apply them. Redirect to the login servlet if the tests fail
            if (loginUser != null && !loginUser.matchesIdentity(context)) {
                setAsDetour(context);
                context.put(ACTION_KEY, "none");
                redirectTo(myProperties.getProperty("loginServletName"));
            }

@


1.87.2.2.4.1
log
@Extended new BaseHelmServlet class (which is used to override
functionality from Joist's UnsecureServlet, its base class).
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.87.2.2 2001/04/05 22:02:55 dlr Exp $
d80 1
a80 1
public class HelmServlet extends BaseHelmServlet
@


1.87.2.2.4.2
log
@Ported over client-side redirects to DEFAULT_PROJECT when an invalid project name is specified.
@
text
@a59 1
import org.joist.util.URL;
a63 1
import org.tigris.helm.tool.ContextAPI;
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.87.2.2.4.1 2001/04/25 23:52:16 dlr Exp $
a117 1
        HttpServletResponse response = context.getResponse();
d126 1
a305 23

        //If something caused us to redirect, redirect instead of
        //continuing.
        String redirect = ContextAPI.getClientRedirect(context);
        if (redirect != null)
        {            
            if (DEBUG)
            {
                Log.debug("Performing client-side redirect to " + redirect);
            }
   
            try
            {
                response.sendRedirect(redirect);
            }
            catch (java.io.IOException e)
            {
                throw new HandlerException(e.getMessage());
            }
            templateName = null;

        }

d894 1
a894 14
                try
                {
                    reqProj = ProjectPeer.getInstanceByName(reqDom, vhost);
                }
                catch (DoesNotExist e)
                {                    
                    StringBuffer url = URL.schemeAndServer(ctx);
                    String search = url.toString();
                    int end = search.indexOf('.');
                    String newURL = url.replace
                        (end-vhost.length(), end,
                         ProjectPeer.DEFAULT_PROJECT_NAME).toString();
                    ContextAPI.setClientRedirect(ctx, newURL);
                }
@


1.86
log
@Anonymous user error logging is handled at a lower level API,
specifically by UserPeer's static initializer block.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.85 2001/03/23 23:10:58 leonardr Exp $
d347 1
a347 1
    private final void declareInsufficientPermission(WebContext ctx)
@


1.85
log
@Always set the detour on ACLException.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.84 2001/03/23 19:25:22 leonardr Exp $
a151 4
                    }
                    else
                    {
                        Log.error("Could not get anonymous user");
@


1.84
log
@Don't overwrite an existing detour.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.83 2001/03/23 03:49:35 leonardr Exp $
d245 1
a282 1
                    setAsDetour(context);
d320 1
@


1.83
log
@This actually doesn't go here.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.82 2001/03/23 02:45:37 leonardr Exp $
d225 4
a228 1
                        setAsDetour(context);
@


1.82
log
@Added redirectOnTicket method.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.81 2001/03/22 01:13:56 dlr Exp $
a912 18
    /**
     * See if the session contains a ticket.  If so, redirect the user
     * to the specified servlet. This should be called in servlets
     * like Join and TLogin after they do their processing.  
     */
    public void redirectOnTicket(HttpSession session, 
                                 String ticketFieldName,
                                 String servlet)
        throws RedirectException, Exception
    {
        if (haveValue(ticketFieldName))
        {
            String ticket = (String)session.getValue(ticketFieldName);
            Invitation invite = InvitationPeer.getInstance(ticket);
            Project project = invite.getProject();            
            throw new RedirectException(project.getProjectPageURL(servlet));
        }
    }
@


1.81
log
@Added TODO note regarding User's matchesIdentity(Object ident) method.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.80 2001/03/15 19:58:35 leonardr Exp $
d911 19
@


1.80
log
@Prevent NPEs.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.79 2001/03/15 19:19:28 leonardr Exp $
d181 5
@


1.79
log
@Implemented access control based on ALLOW_JOIN.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.78 2001/03/09 20:06:42 dlr Exp $
d282 1
a282 1
            if (requiredAction.equals("Domain - Join"))
@


1.78
log
@Added a link to the HelmServlet field guide from the processRequest()
and header doc.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.77 2001/03/09 19:32:05 leonardr Exp $
d245 2
a246 1
                if (requiredResource == null) {
d248 2
a249 1
                    if (requiredResource == null) {
d256 2
a257 1
                    if (type.equals(Action.PROJECT_TYPE)) {
d262 2
a263 1
                    else if (type.equals(Action.DOMAIN_TYPE)) {
d267 2
a268 1
                    else {
d272 2
a273 1
                catch (ACLException e) {
d276 13
@


1.77
log
@Misc. cleanup.
@
text
@d69 3
a71 1
 * servlets.
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.76 2001/03/09 01:59:38 leonardr Exp $
d94 4
@


1.76
log
@Only you can prevent log bloat.
@
text
@d74 1
a74 1
 * @@version $Id: HelmServlet.java,v 1.75 2001/03/08 01:00:54 dlr Exp $
a163 1

d219 5
a223 1
                User user = getLoginUser( context );
d227 1
a227 1
                    user.setClickThroughAsViewed( currentDomain );
d342 2
a343 1
        if (itemProp == null) {
d346 2
a347 1
        else {
d357 3
a359 1
        } else {
d431 2
a432 1
        if (haveValue(currentUserID)) {
a729 16
    /**
     *  Determines whether the user has the required access permission.
     *  For secured servlets, check if the permission is in the permissionSet
     *
     * @@param    permissionName    The name of the required permission.
     * @@param    userPermissions   The set of permissions possessed by the user.
     * @@return                      Whether the accessing user is allowed access.
     */
    protected boolean accessAllowed (String permissionName, 
                                     PermissionSet userPermissions)
    {
        return (userPermissions != null ? 
                userPermissions.accessAllowed(permissionName) : 
                false);
    }

d771 2
a772 1
        if (reqDomID != null) {
d775 2
a776 1
        else {
d783 2
a784 1
            try {
d788 2
a789 1
            catch (Exception e) {
d791 2
a792 1
                if (dot != -1) {
d795 2
a796 1
                    try {
d804 2
a805 1
                else {
d829 4
a832 2
        if (!haveValue(reqProjID)) {
            try {
d836 2
a837 1
            catch (Exception e) {
d839 2
a840 1
                if (reqProjName != null) {
d845 2
a846 1
            if (reqProj == null && !serverNameMatchedDomain) {
d852 2
a853 1
            if (reqProj == null) {
d858 2
a859 1
        else {
d872 2
a873 1
        try {
d876 2
a877 1
        catch (Exception e) {
@


1.75
log
@Make use of UnsecureServlet constant.
@
text
@d74 1
a74 1
 * @@version $Id: HelmServlet.java,v 1.74 2001/03/08 00:52:48 dlr Exp $
d80 2
d125 4
a128 1
                Log.debug(ALLOW_GUESTS + '=' + allowGuests);
d134 4
a137 1
                    Log.debug("Not logged in...logging in as guest");
a214 1
                        Log.debug("Redirecting to CompulsoryClickThrough");
a246 2
                        Log.debug("Checking project permission: " +
                                  requiredAction);
a250 2
                        Log.debug("Checking domain permission: " +
                                  requiredAction);
a254 1
                        Log.debug("Checking permission: " + requiredAction);
a303 1
        Log.debug("Lastaction: " + session.getValue("lastAction"));
a342 1
            Log.debug("itemProp: " + itemProp);
a504 1
            Log.debug("Setting current domain: " + curDomain.getName());
a513 1
            Log.debug("Setting current project: " + curProj.getName());
a791 2
                Log.debug("serverNameMatchedDomain.get(0)=" +
                          serverNameMatchedDomain.get(0));
a793 1
                Log.debug("Not a match: reqDomName=" + reqDomName);
a797 2
                    Log.debug("Trying URL alias: domainNoVhost=" +
                              domainNoVhost);
a827 1
        Log.debug("Calling getRequestedProject()");
a831 1
                Log.debug("Trying URL alias...");
a833 1
                Log.debug("Using URL alias");
a835 1
                Log.debug("Trying projectName...");
a841 1
            Log.debug("serverNameMatchedDomain=" + serverNameMatchedDomain);
a842 1
                Log.debug("Assuming vhosted...");
a844 1
                Log.debug("vhost=" + vhost);
a848 2
                Log.debug("Using default project: " +
                          ProjectPeer.DEFAULT_PROJECT_NAME);
a866 2
            Log.debug("Looking up project: Project named " + projectName + 
                      " and domain named " + domain.getName());
@


1.74
log
@* Saved one check for requiredResource.
* Cleaned up surrounding log trace.
@
text
@d74 1
a74 1
 * @@version $Id: HelmServlet.java,v 1.73 2001/03/07 01:53:27 lucas Exp $
d147 1
a147 1
                    context.put("action", "none");
@


1.73
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d74 1
a74 1
 * @@version $Id: HelmServlet.java,v 1.72 2001/03/05 02:35:26 jrobbins Exp $
d231 3
a234 6
                if (requiredResource == null) {
                    requiredResource = "not appliciable";
                }
                Log.debug("Checking permission for action:" + requiredAction);
                Log.debug("Checking permission for domain: " + currentDomain);
                Log.debug("Checking permission for resource: " + requiredResource);
d240 2
a241 2
                        Log.debug("Checking permission for project: " + currentProject);
                        Log.debug("one more line");
d246 2
d252 1
@


1.72
log
@added checking of permission resources
@
text
@a62 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
d74 1
a74 1
 * @@version $Id: HelmServlet.java,v 1.71 2001/02/27 04:25:49 dlr Exp $
@


1.71
log
@This permission reporting snippet is cleaner as a macro.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.70 2001/02/27 01:32:22 dlr Exp $
d230 10
d245 3
a247 2
                        Log.debug("Checking permission for " + requiredAction);
                        acl.assertPermission(requiredAction,
d251 1
a251 1
                        acl.assertPermission(requiredAction, 
@


1.70
log
@Improving exception handling.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.69 2001/02/27 00:48:35 leonardr Exp $
d265 1
a265 6
                    appendToMessage
                        (context, "Your account does not have the necessary " +
                         "<a href=\"/servlets/ACLDump\">permissions</a> to access the page you requested. " +
                         "Either request more permission in project " +
                         getCurrentProject(context).getWordMark() +
                         ", or log in using a different account.");
d299 15
@


1.69
log
@Got rid of unneccessary debug messages.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.68 2001/02/23 23:56:57 leonardr Exp $
d246 2
a247 1
                } catch (ACLException e) {
d287 2
@


1.68
log
@Redirect to CCT now that it's ported.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.67 2001/02/23 19:04:11 stack Exp $
a346 2
        Log.debug("In populateFilter.");
                
a387 1
        Log.info("Initial filter: " + filter);
@


1.67
log
@Fix getACL javadoc 'see' in overrides
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.66 2001/02/22 23:56:33 leonardr Exp $
a194 3
            /**
             * FIXME: There's a reason this is commented out--we don't have the
             * click through permission servlet ported yet.             
a205 1
                    Log.debug("Click through check.");
d207 1
a207 1
                                                    currentDomain))
d217 1
a217 1
                currentDomain))
a221 2
            */

@


1.66
log
@WOOHOO! Once again you hit a servlet, log in, and have it redirect you to the servlet you wanted to go to in the first place instead of your startpage!
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.65 2001/02/22 18:08:52 leonardr Exp $
d542 1
a542 1
     * @@see org.tigris.helm.security.HelmServlet#getACL(WebContext, User)
@


1.65
log
@Put the simple filter value into the context so that Filter.wm doesn't have to know what the Peer calls it.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.64 2001/02/22 09:20:14 dlr Exp $
d237 18
a254 12
                if (type.equals(Action.PROJECT_TYPE)) {
                    Project currentProject = getCurrentProject(context);
                    Log.debug("Checking permission for " + requiredAction);
                    acl.assertPermission(requiredAction,
                                                   currentProject);
                }
                else if (type.equals(Action.DOMAIN_TYPE)) {
                    acl.assertPermission(requiredAction, 
                                                  currentDomain);
                }
                else {
                    acl.assertPermission(requiredAction); 
@


1.64
log
@Corrected insidious bug where the anonymous user was not set as logged
in on first hit to processRequest().
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.63 2001/02/21 01:08:25 dlr Exp $
d356 1
d361 1
@


1.63
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60.2.21 2001/02/17 20:33:41 leonardr Exp $
d122 1
a122 2
            Boolean isLoggedIn = sMgr.isLoggedIn();            
            if (!isLoggedIn.booleanValue())
d153 1
a153 1
            context.put("isLoggedIn", isLoggedIn);
@


1.62
log
@added support for logging user info in access_log
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by CollabNet (http://www.Collab.Net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d53 2
a54 1
import com.workingdogs.village.*;
a55 1
import org.webmacro.util.*;
a57 1
import org.joist.database.*;
d62 3
a64 2
import org.tigris.helm.business.*;
import org.tigris.helm.database.*;
a65 1
import org.tigris.helm.project.Project;
d67 1
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.61 2001/01/29 23:55:11 leonardr Exp $
a82 10
     * Open up the log.
     */
    private static Log log = new Log("helm", "HelmServlet");

    /**
     * Turn debug log output on/off.
     */
    private static final boolean debug = true;

    /**
d84 1
a84 1
     * clients as the guest user.
a88 5
     * The servlet's DataManager.
     */
    protected DataManager dMgr;

    /**
d102 1
a102 1
        throws HandlerException, RedirectException, ACLException
d110 1
d116 4
a119 9
            if (dMgr == null)
            {
                dMgr = sMgr.getDataManager();
            }            

            // Put a reference to the context into the context.
            context.put("context", context);

            // Make sure user is logged in.
d122 1
a122 1
            Boolean isLoggedIn = sMgr.isLoggedIn();
d126 1
a126 1
                if (debug) log.info(ALLOW_GUESTS + '=' + allowGuests);
d132 3
a134 3
                    if (debug) log.info("Not logged in...logging in as guest");
                    User guest = User.getGuest();
                    if (guest != null)
d137 4
a140 4
                        sMgr.setUserID(guest.getID());
                        sMgr.setLoginID(guest.getLoginID());
                        sMgr.setEmail(guest.getEmail());
                        sMgr.setUserName(guest.getName());
d144 1
a144 1
                        log.error("Could not get guest user");
d161 4
a164 3
            // The current host and domain.
            context.put("host", new Host(connection, dMgr));
            updateCurrentDomainAndProject(connection, context, request);
d167 1
a167 1
            // User is logged in.  Build their application object and ACL.
d169 6
a174 1
            User loginUser = (User)session.getValue("loginUser");
d184 1
a184 1
                loginUser = User.getInstance(connection, dMgr, loginUserID);
d188 2
d191 1
a191 4
            AccessControlList acl = getACL(context, connection,
                                           loginUserID);

            // if we've got a clickThroughPermission set up -- and if
d194 5
a198 1
            // them.
d201 1
a201 1
            
d210 3
a212 2
                    if(!acl.hasPermissionForDomain (clickThroughPermission,
                                                    currentDomain.getID()))
d214 1
a214 1
                        log.info("Redirecting CompulsoryClickThrough");
d219 1
a219 3
            }
            else
            {
d221 2
a222 1
                if (!user.getACL().hasPermissionForDomain("Click-through Page - Seen", currentDomain.getID()))
a223 1
                    log.info( "CCT Feature is off. Granting CCT permission." );
d227 2
d230 1
a230 1
            // Check for permission to access the servlet.
d235 4
a238 8
                ActionManager aMgr = (ActionManager)dMgr.getManager
                    ("org.tigris.helm.database.ActionManager");
                Record action = aMgr.getActionForName(requiredAction);
                String type = action.getValue(ActionManager.ACTION_TYPE)
                    .toString();
                
                if (type.equals("Project"))
                {
d240 3
a242 8
                    log.info("Checking permission for " + requiredAction);
                    acl.assertPermissionForProject(requiredAction, 
                                                   currentProject.getID());
                } else if (type.equals("Domain")) {
                    acl.assertPermissionForDomain(requiredAction,
                                                  currentDomain.getID());
                } else {
                    acl.assertPermissionForHost(requiredAction); 
d244 6
a249 76
            }
            
            // If pagination information is provided for this servlet,
            // put the number of items desired per page into the context.
            String itemProp = myProperties.getProperty("itemsPerPage");
            Integer itemsPerPage;
            if (itemProp == null) 
            {
                itemsPerPage = new Integer(20);
            } else {
                log.info("itemProp: " + itemProp);
                itemsPerPage = new Integer(Integer.parseInt(itemProp));
            }            
            context.put("itemsPerPage", itemsPerPage);

            /*
             * Pagination and search fields.
             */
            String pageStr = context.getForm("paginated_page");
            Integer page;
            if (pageStr == null) 
            {
                page = new Integer(1);
            } else {
                page = new Integer(Integer.parseInt(pageStr));
            }           
            context.put("paginated_page", page);
            
            // Divine the filter criteria requested.
            Criterion criterion = null;

            //If they're using the simple form, make a big or-ed
            //Criterion.
            if (haveValue(Criterion.SIMPLE_FILTER_VALUE))
            {
                String simpleFilter = 
                    context.getForm(Criterion.SIMPLE_FILTER_VALUE);
                context.put(Criterion.SIMPLE_FILTER_VALUE, simpleFilter);
                criterion = new Criterion
                    ("", Criterion.SPECIAL_MATCH, simpleFilter);
            } else if (context.getForm(Criterion.FILTER_CHECK) != null) {
                //They're using the big form--get parameter names.
                Enumeration paramNames = request.getParameterNames();
                while (paramNames.hasMoreElements ())
                {
                    String paramName = (String)paramNames.nextElement();
                    
                    if (paramName.startsWith(Criterion.FILTER_VALUE))
                    {
                        StringTokenizer tok = 
                            new StringTokenizer(paramName, "/");
                        tok.nextToken();
                        String filterFieldName = tok.nextToken();
                        String filterValue = 
                            context.getForm(paramName);
                        if (!filterValue.equals(""))
                        {
                            if (debug)
                                log.info("Value \"" + filterValue +
                                         " provided for " + filterFieldName);
                            context.put(paramName, filterValue);
                            String filterMatchType = 
                                context.getForm(Criterion.cgiKey
                                                (Criterion.FILTER_MATCHTYPE,
                                                 filterFieldName));
                            Criterion newCrit = new Criterion
                                (filterFieldName, filterMatchType,
                                 filterValue);
                            if (criterion == null)
                            {
                                criterion = newCrit;
                            } else {
                                criterion.and(newCrit);
                            }
                        }
                    }
a251 34
            if (criterion == null)
            {
                criterion = new Criterion(null, null);
            }
            context.put("criterion", criterion);

            // -------------------------------------------------------
            // The current user (for this request).
            String currentUserID = getServletParam(context, "userID");
            if (haveValue(currentUserID))
            {
                context.put("currentUser", 
                            User.getInstance(connection, dMgr, currentUserID));
            } else {
                context.put("currentUser", getLoginUser(context));
            }

            String currentUserGroupID = getServletParam(context, 
                                                        "userGroupID");
            if (haveValue(currentUserGroupID))
            {
                context.put("currentUserGroup", 
                            new UserGroup
                                (connection, dMgr, currentUserGroupID));
            }            

            String currentProjectGroupID = getServletParam(context, 
                                                           "projectGroupID");
            if (haveValue(currentProjectGroupID))
            {                
                ProjectGroup g = new ProjectGroup
                    (connection, dMgr, currentProjectGroupID);
                context.put("currentProjectGroup", g);
            }            
d253 3
a255 6
            String currentRoleID = getServletParam(context, "roleID");
            if (haveValue(currentRoleID))
            {
                context.put("currentRole", 
                            new Role(connection, dMgr, currentRoleID));
            } 
d257 1
a257 15
            String currentResourceID = getServletParam(context, "resourceID");
            if (haveValue(currentResourceID))
            {
                context.put("currentResource", 
                            new Resource(connection, dMgr, currentResourceID));
            }

            String currentAuditLogEntryID = getServletParam(context,
                                                            "auditLogEntryID");
            if (haveValue(currentAuditLogEntryID))
            {
                context.put("currentAuditLogEntry", 
                            new AuditLogEntry(connection, dMgr,
                                              currentAuditLogEntryID));
            }
d259 1
a259 1
        catch (ACLException e)
d263 1
a263 1
                if (!sMgr.getUserID().equals(User.getGuest().getID()))
d265 6
a270 1
                    appendToMessage(context, "Your account does not have the necessary permissions to access the page you requested. Either request more permission in project " + getCurrentProject(context).getWordMark() + ", or log in using a different account.");
d273 1
a273 1
            catch (DataSetException dse)
d275 2
a276 2
                log.error("Error handling ACLException user message: " +
                          dse.getMessage());
d278 1
a278 1
            throw e;
d286 1
a286 1
            log.exception(e);
d296 1
a296 1
        log.info("Lastaction: " + (String)session.getValue("lastAction"));
d303 209
d535 10
a544 1
     * @@see org.tigris.helm.security.HelmServlet#getACL()
d546 2
a547 2
    protected AccessControlList getACL (WebContext ctx, Connection conn)
        throws SQLException, DataSetException, JoistDatabaseException
d549 11
a559 1
        return getACL(ctx, conn, getSessionManager(ctx).getUserID());
a567 1
     * @@param conn    A JDBC connection.
d570 1
d572 6
a577 8
    protected AccessControlList getACL (WebContext context, 
                                        Connection connection, 
                                        String userID)
        throws SQLException, DataSetException, JoistDatabaseException
    {
        AccessControlList acl = AccessControlList.getACL(connection, dMgr,
                                                         userID);
        context.put("acl", acl);
a580 1

d587 1
a587 1
    protected final Host getHost (WebContext context)
d589 1
a589 1
        return (Host) context.get("host");
a747 59

    /** 
     * Update current domain and project in the context. These can be
     * specified in the following ways:
     * <ul>
     * <il>1. ID in the query string (e.g., passed from prev servlet)
     * <il>2. Project  or domain name in the query string (e.g., passed
     *     from a rewrite rule)
     * <il>3. Request server name matches project URL alias
     * <il>4. Standard vhosting: project.domain
     * <il>5. default to www project in domain matching request server name
     * </ul>
     *
     * @@param conn The JDBC database connection.
     * @@param ctx  The context.
     * @@param req  The HTTP request.
     */

    protected void updateCurrentDomainAndProject (Connection conn,
                                                  WebContext ctx,
                                                  HttpServletRequest req) 
        throws SQLException, DataSetException, Exception
    {
        BitSet serverNameMatchedDomain = new BitSet(1);
        Domain reqDom = getRequestedDomain(conn, ctx, req,
                                           serverNameMatchedDomain);
        Project reqProj = getRequestedProject(conn, ctx, req, reqDom,
                                              serverNameMatchedDomain.get(0));
        boolean forceCurrentProjectChange = false;

        // See if domain changed.
        Domain curDomain = getCurrentDomain(ctx);
        if (curDomain == null || !reqDom.getID().equals(curDomain.getID())) {
            curDomain = reqDom;
            ctx.put("currentDomain", curDomain);
            if (debug) log.info("setting current domain: " +
                                curDomain.getName());
            // Changing domains forces project change.
            forceCurrentProjectChange = true;
        }

        // See if project changed.
        Project curProj = getCurrentProject(ctx);
        if (forceCurrentProjectChange || curProj == null ||
            !reqProj.getID().equals(curProj.getID())) {
            curProj = reqProj;
            if (debug) log.info("setting current project: " +
                                curProj.getName());
            ctx.put("currentProject", curProj);

            //Set the project's skin as well.
            Skin skin = curProj.getSkin();
            if (skin != null)
            {
                ctx.put("skin", skin);
            }
        }
    }

a750 1
     * @@param conn                    The JDBC database connection.
d755 1
a755 2
    private Domain getRequestedDomain (Connection conn, WebContext ctx, 
                                       HttpServletRequest req,
d757 1
a757 1
        throws JoistDatabaseException, DataSetException, DoesNotExist
d762 1
a762 1
            reqDom = new Domain(conn, dMgr, reqDomID);
d772 1
a772 1
                reqDom = new Domain(conn, reqDomName, dMgr);
d774 2
a775 3
                if (debug) log.info("serverNameMatchedDomain.get(0)=" +
                                    serverNameMatchedDomain.get(0));

d777 2
a778 3
            catch (JoistDatabaseException e) {
                if (debug) log.info("Not a match: reqDomName=" +
                                    reqDomName);
d783 2
a784 2
                    if (debug) log.info("Trying URL alias: domainNoVhost=" +
                                        domainNoVhost);
d786 5
a790 1
                        reqDom = new Domain(conn, domainNoVhost, dMgr);
a791 1
                    catch (Exception ignored) {}
d794 1
a794 1
                    log.error("Could not parse domain from vhost");
a803 1
     * @@param conn                    The JDBC database connection.
d809 3
a811 2
    private Project getRequestedProject(Connection conn, WebContext ctx,
                                        HttpServletRequest req, Domain reqDom,
d813 1
a813 1
        throws SQLException, DataSetException, DoesNotExist
d815 1
a815 1
        if (debug) log.info("Calling getRequestedProject()");
d818 1
a818 2
        if (reqProjID == null) {
            String reqDomID = reqDom.getID();
d820 4
a823 4
                if (debug) log.info("Trying URL alias...");
                reqProj = new Project(conn, dMgr, reqDomID,
                                      req.getServerName(), true);
                if (debug) log.info("Using URL alias");
d826 1
a826 1
                if (debug) log.info("Trying projectName...");
d829 1
a829 2
                    reqProj = getProjectByName(conn, reqProjName,
                                               reqDomID);
d833 1
a833 2
            if (debug) log.info("serverNameMatchedDomain=" +
                                serverNameMatchedDomain);
d835 1
a835 1
                if (debug) log.info("Assuming vhosted...");
d838 2
a839 3
                if (debug) log.info("vhost=" + vhost);
                reqProj = getProjectByName(conn, vhost, reqDomID);

d843 4
a846 4
                if (debug) log.info("Using default project: " +
                                    Project.DEFAULT_NAME);
                reqProj = getProjectByName(conn, Project.DEFAULT_NAME, 
                                           reqDomID);
d850 1
a850 1
            reqProj = new Project(conn, dMgr, reqProjID);
d858 1
a858 2
    private Project getProjectByName (Connection conn, String projectName, 
                                      String domainID)
d863 3
a865 3
            if (debug) log.info("Looking up project: projectName=" +
                                projectName + " and domainID=" + domainID);
            project = new Project(conn, dMgr, domainID, projectName);
d868 1
a868 1
            log.info("Project not found: projectName=" + projectName);
@


1.61
log
@Only grant click-through permission if they don't already have it.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60 2001/01/26 23:38:44 stack Exp $
d174 5
@


1.60
log
@Give the user CCT permission whether they were forced through the CCT servlet or not.  Previous, if CCT facility was turned off, the user would be logged in but wouldn't have been granted the CCT permission.  Certain pages require the CCT permission.  Rather than go through the site changing base permissions on pages that require CCT, grant CCT permission.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.59 2001/01/26 18:29:08 edk Exp $
a225 1
                log.info( "Granting CCT permission" );
d227 5
a231 1
                user.setClickThroughAsViewed( currentDomain );
@


1.60.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60 2001/01/26 23:38:44 stack Exp $
@


1.60.2.2
log
@Started porting.
@
text
@d63 2
a64 2
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
d66 1
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.57 2001/01/17 21:56:13 leonardr Exp $
d117 1
a117 1
        throws HandlerException, ACLException, RedirectException
d152 1
a152 1
                    User guest = UserPeer.getGuestUser();
d157 1
a157 1
                        sMgr.setLoginID(guest.getLoginName());
d159 1
a159 1
                        sMgr.setUserName(guest.getRealName());
d176 2
a177 2
            context.put("host", new Host());
            updateCurrentDomainAndProject(context, request);
d192 1
a192 1
                loginUser = UserPeer.getInstance(loginUserID);
d197 2
a198 1
            AccessControlList acl = getACL(context, loginUserID);
d215 2
a216 2
                    if(!acl.hasPermissionForDomain(clickThroughPermission,
                                                   currentDomain))
d224 6
d236 8
a243 4
                Action action = ActionPeer.getInstanceByName(requiredAction);
                String type = action.getType();

                if (type.equals(Action.PROJECT_TYPE)) {
d246 3
a248 4
                    acl.assertPermissionForProject(requiredAction,
                                                   currentProject);
                }
                else if (type.equals(Action.DOMAIN_TYPE)) {
d250 2
a251 3
                                                  currentDomain);
                }
                else {
d341 2
a342 1
            if (haveValue(currentUserID)) {
d344 2
a345 3
                            UserPeer.getInstance(currentUserID));
            }
            else {
d354 2
a355 1
                            UserPeer.getGroupInstance(currentUserGroupID));
d362 4
a365 4
                context.put
                    ("currentProjectGroup",
                     ProjectPeer.getGroupInstance(currentProjectGroupID));
            }
d370 3
a372 3
                context.put("currentRole",
                            RolePeer.getInstance(currentRoleID));
            }
d378 1
a378 1
                            ResourcePeer.getInstance(currentResourceID));
d385 3
a387 3
                context.put
                    ("currentAuditLogEntry", 
                     AuditLogEntryPeer.getInstance(currentAuditLogEntryID));
d390 1
a390 1
        catch (ACLException aclEx)
d394 1
a394 1
                if (!sMgr.getUserID().equals(UserPeer.getGuestUser().getID()))
d396 1
a396 6
                    appendToMessage
                        (context, "Your account does not have the necessary " +
                         "permissions to access the page you requested. " +
                         "Either request more permission in project " +
                         getCurrentProject(context).getWordMark() +
                         ", or log in using a different account.");
d399 1
a399 1
            catch (Exception e)
d402 1
a402 1
                          e.getMessage());
d404 1
a404 1
            throw aclEx;
d454 2
a455 21
    protected final AccessControlList getACL(WebContext ctx)
        throws Exception
    {
        return getACL(ctx, getSessionManager(ctx).getUserID());
    }

    /**
     * @@deprecated Use getACL(WebContext ctx) instead.
     */
    protected final AccessControlList getACL(WebContext ctx, Connection conn)
        throws Exception
    {
        return getACL(ctx);
    }

    /**
     * @@deprecated Use getACL(WebContext ctx, String userID) instead.
     */
    protected AccessControlList getACL(WebContext ctx, Connection c,
                                       String userID)
        throws Exception
d457 1
a457 1
        return getACL(ctx, userID);
d466 1
a468 1
     * @@param userID  The database key of the user to get the ACL for.
d470 8
a477 6
    protected AccessControlList getACL(WebContext ctx, String userID)
        throws Exception
    {
        AccessControlList acl =
            AccessControlList.getACL(UserPeer.getInstance(userID));
        ctx.put("acl", acl);
d481 1
d488 1
a488 1
    protected final Host getHost (WebContext ctx)
d490 1
a490 1
        return (Host) ctx.get("host");
d662 1
d667 2
a668 1
    protected void updateCurrentDomainAndProject (WebContext ctx,
d673 3
a675 2
        Domain reqDom = getRequestedDomain(ctx, req, serverNameMatchedDomain);
        Project reqProj = getRequestedProject(ctx, req, reqDom,
d711 1
d716 2
a717 1
    private Domain getRequestedDomain (WebContext ctx, HttpServletRequest req,
d719 1
a719 1
        throws DoesNotExist, Exception
d724 1
a724 1
            reqDom = DomainPeer.getInstance(reqDomID);
d734 1
a734 1
                reqDom = DomainPeer.getInstanceByName(reqDomName);
d750 1
a750 1
                        reqDom = DomainPeer.getInstanceByName(domainNoVhost);
d765 1
d771 2
a772 2
    private Project getRequestedProject(WebContext ctx, HttpServletRequest req, 
                                        Domain reqDom,
d774 1
a774 1
        throws DoesNotExist, Exception
d780 1
d783 2
a784 3
                // TODO: FIXME!
//                 reqProj = new Project(conn, dMgr, reqDom.getID(),
//                                       req.getServerName(), true);
d791 2
a792 1
                    reqProj = getProjectByName(reqProjName, reqDom);
d803 2
a804 1
                reqProj = getProjectByName(vhost, reqDom);
d809 3
a811 3
                                    ProjectPeer.DEFAULT_PROJECT_NAME);
                reqProj = getProjectByName(ProjectPeer.DEFAULT_PROJECT_NAME, 
                                           reqDom);
d815 1
a815 1
            reqProj = ProjectPeer.getInstance(reqProjID);
d823 2
a824 1
    private Project getProjectByName (String projectName, Domain domain)
d829 3
a831 4
            if (debug) log.info("Looking up project: Project named " +
                                projectName + " and domain named " +
                                domain.getName());
            project = ProjectPeer.getInstanceByName(domain, projectName);
@


1.60.2.3
log
@* Swapped crappy WM logging for superior Turbine logging.
* Ported project instantiation by alias URL.
@
text
@a52 2
import org.apache.turbine.util.Log;

d55 1
d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.2 2001/01/31 02:54:24 dlr Exp $
d82 10
d144 1
a144 1
                Log.debug(ALLOW_GUESTS + '=' + allowGuests);
d150 1
a150 1
                    Log.debug("Not logged in...logging in as guest");
d162 1
a162 1
                        Log.error("Could not get guest user");
d213 2
a214 2
                    if (!acl.hasPermissionForDomain(clickThroughPermission,
                                                    currentDomain))
d216 1
a216 1
                        Log.debug("Redirecting CompulsoryClickThrough");
d233 1
a233 1
                    Log.debug("Checking permission for " + requiredAction);
d250 2
a251 1
            if (itemProp == null) {
d253 2
a254 3
            }
            else {
                Log.debug("itemProp: " + itemProp);
d301 3
a303 2
                            Log.debug("Value '" + filterValue +
                                      "' provided for " + filterFieldName);
d395 1
a395 1
                Log.error("Error handling ACLException user message: " +
d406 1
a406 1
            Log.warn("Unhandled exception encountered by HelmServlet", e);
d416 1
a416 1
        Log.debug("Lastaction: " + session.getValue("lastAction"));
d691 2
a692 1
            Log.debug("Setting current domain: " + curDomain.getName());
d702 2
a703 1
            Log.debug("Setting current project: " + curProj.getName());
d741 3
a743 2
                Log.debug("serverNameMatchedDomain.get(0)=" +
                          serverNameMatchedDomain.get(0));
d746 2
a747 1
                Log.debug("Not a match: reqDomName=" + reqDomName);
d752 2
a753 2
                    Log.debug("Trying URL alias: domainNoVhost=" +
                              domainNoVhost);
d760 1
a760 1
                    Log.error("Could not parse domain from vhost");
d780 1
a780 1
        Log.debug("Calling getRequestedProject()");
d785 5
a789 4
                Log.debug("Trying URL alias...");
                reqProj = ProjectPeer.getInstanceByAliasURL
                    (reqDom, req.getServerName());
                Log.debug("Using URL alias");
d792 1
a792 1
                Log.debug("Trying projectName...");
d799 2
a800 1
            Log.debug("serverNameMatchedDomain=" + serverNameMatchedDomain);
d802 1
a802 1
                Log.debug("Assuming vhosted...");
d805 1
a805 1
                Log.debug("vhost=" + vhost);
d810 2
a811 2
                Log.debug("Using default project: " +
                          ProjectPeer.DEFAULT_PROJECT_NAME);
d830 3
a832 2
            Log.debug("Looking up project: Project named " + projectName + 
                      " and domain named " + domain.getName());
d836 1
a836 1
            Log.debug("Project not found: projectName=" + projectName);
@


1.60.2.4
log
@* Removed DataManager.
* Commented out use of unfinished Skin business objects.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60.2.3 2001/01/31 03:11:53 dlr Exp $
d89 5
d120 5
d170 1
a170 1
            // User is logged in.  Build their business object and ACL.
d436 1
a436 1
     * @@see org.tigris.helm.security.HelmServlet#getACL(WebContext, User)
d694 6
a699 6
            //TODO: Set the project's skin as well.
//             Skin skin = curProj.getSkin();
//             if (skin != null)
//             {
//                 ctx.put("skin", skin);
//             }
@


1.60.2.5
log
@Big patch to make access control work.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60.2.4 2001/01/31 20:52:30 leonardr Exp $
a135 1
                        Log.debug("guest.getID()=" + guest.getID());
a161 1
            Log.debug("loginUserID=" + loginUserID);
d183 8
a190 8
//             String clickThroughPermission = 
//                 myProperties.getProperty( "clickThroughPermission" );

//             if (haveValue(clickThroughPermission))
//             {
//                 String servlet = getServletName();
//                 String compulsoryClickThroughServlet =
//                     myProperties.getProperty("compulsoryClickThrough");
d192 11
a202 12
//                 if (!servlet.equals(compulsoryClickThroughServlet))
//                 {
//                     Log.debug("Click through check.");
//                     if (!acl.hasPermissionForDomain(clickThroughPermission,
//                                                     currentDomain))
//                     {
//                         Log.debug("Redirecting CompulsoryClickThrough");
//                         setAsDetour(context);
//                         redirectTo(compulsoryClickThroughServlet);
//                     }
//                 }
//             }
a206 1
            Log.debug("Required action begin.");
d226 1
a226 1

a306 2

            Log.debug("Getting stuff.");            
@


1.60.2.6
log
@Misc. changes to support PermissionDump.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60.2.5 2001/02/01 02:57:47 leonardr Exp $
d121 1
a121 1
            Boolean isLoggedIn = sMgr.isLoggedIn();            
@


1.60.2.7
log
@More fixes for ACL and ACLDump.
@
text
@d17 1
a17 1
 * software developed by CollabNet (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60.2.6 2001/02/01 18:03:00 leonardr Exp $
d321 1
a321 2
            else 
            {
@


1.60.2.8
log
@Commented out pagination stuff until it gets ported.
@
text
@d55 2
d59 1
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60.2.7 2001/02/01 20:40:24 leonardr Exp $
a246 1
            /*
d258 1
a258 1
            Criterion criteria = null;
d311 1
a311 1
            */
d665 1
a665 1
        throws Exception
d709 1
a709 1
        throws Exception
d729 1
a729 1
            catch (Exception e) {
d758 1
a758 2
    private Project getRequestedProject(WebContext ctx, 
                                        HttpServletRequest req, 
d761 1
a761 1
        throws Exception
@


1.60.2.9
log
@Cleaned and polished HelmServlet. Filtering stuff still needs to be implemented.
@
text
@a52 1
import org.apache.turbine.util.db.Criteria;
a65 1

d73 1
a73 1
 * @@version $Id: HelmServlet.java,v 1.60.2.8 2001/02/05 22:53:18 leonardr Exp $
d112 4
a115 4
            // Make sure user is logged in. If they're not, redirect them
            // to the login servlet or log them in as guest (depending on
            // the site configuration).
            //
d133 1
d153 1
a153 2
            //Populate the context with the appropriate host, domain,
            //and project objects.
a161 4

            //If the user who logged in changed their personal information
            //or anything which would affect their User object, get that
            //User object again.
d175 1
a175 1
            
d178 1
a178 1
            // If we've got a clickThroughPermission set up -- and if
d181 9
a189 9
            // them to the click through page.
            String clickThroughPermission = 
                myProperties.getProperty( "clickThroughPermission" );

            if (haveValue(clickThroughPermission))
            {
                String servlet = getServletName();
                String compulsoryClickThroughServlet =
                    myProperties.getProperty("compulsoryClickThrough");
d191 12
a202 12
                if (!servlet.equals(compulsoryClickThroughServlet))
                {
                    Log.debug("Click through check.");
                    if (!acl.hasPermissionForDomain(clickThroughPermission,
                                                    currentDomain))
                    {
                        Log.debug("Redirecting to CompulsoryClickThrough");
                        setAsDetour(context);
                        redirectTo(compulsoryClickThroughServlet);
                    }
                }
            }
d204 1
a204 1
            // Check the base permission needed to access the servlet.
d207 1
d220 1
a220 1
                    acl.assertPermissionForDomain(requiredAction, 
d228 29
a256 3
            populatePagination(myProperties.getProperty("itemsPerPage"), 
                               context);
            populateFilter(context);
d258 105
a362 1
            populateBOs(context);
a407 218
    //
    // Context population methods
    //

    /**
     * Populates the context with information about the current
     * pagination page.
     */
    private void populatePagination(String itemProp, WebContext context)
    {

        // If pagination information is provided for this servlet,
        // put the number of items desired per page into the context.
        Integer itemsPerPage;
        if (itemProp == null) {
            itemsPerPage = new Integer(20);
        }
        else {
            Log.debug("itemProp: " + itemProp);
            itemsPerPage = new Integer(Integer.parseInt(itemProp));
        }            
        context.put("itemsPerPage", itemsPerPage);

        String pageStr = context.getForm("paginated_page");
        Integer page;
        if (pageStr == null) 
        {
            page = new Integer(1);
        } else {
            page = new Integer(Integer.parseInt(pageStr));
        }           
        context.put("paginated_page", page);
    }

    /**
     * Populates the context with information about the current
     * filter settings.
     * TODO: Port this.
     */
    private void populateFilter(WebContext context)
    {
        // Put a reference to the context into the context--the
        // complex filter template needs this.
        context.put("context", context);
                
        Criteria criteria = new Criteria();
        
        // Divine the filter criteria requested.

        //If they're using the simple form, make a big or-ed
        //Criterion. This can't be ported until Criteria supports
        //an or system.       
        /*
        if (haveValue(Criterion.SIMPLE_FILTER_VALUE))
        {
            String simpleFilter = 
                context.getForm(Criterion.SIMPLE_FILTER_VALUE);
            context.put(Criterion.SIMPLE_FILTER_VALUE, simpleFilter);
            criterion = new Criterion
                ("", Criterion.SPECIAL_MATCH, simpleFilter);
        } else if (context.getForm(Criterion.FILTER_CHECK) != null) {
            //They're using the big form--get parameter names.
            Enumeration paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements ())
            {
                String paramName = (String)paramNames.nextElement();
                
                if (paramName.startsWith(Criterion.FILTER_VALUE))
                {
                    StringTokenizer tok = 
                        new StringTokenizer(paramName, "/");
                    tok.nextToken();
                    String filterFieldName = tok.nextToken();
                    String filterValue = 
                        context.getForm(paramName);
                    if (!filterValue.equals(""))
                    {
                        context.put(paramName, filterValue);
                        String filterMatchType = 
                            context.getForm(Criterion.cgiKey
                                            (Criterion.FILTER_MATCHTYPE,
                                             filterFieldName));
                        Criterion newCrit = new Criterion
                            (filterFieldName, filterMatchType,
                             filterValue);
                        if (criteria == null)
                        {
                            criteria = newCrit;
                        } else {
                            criteria.add(newCrit);
                        }
                    }
                }
            }
            }*/

        context.put("criteria", criteria);
    }
    

    /**
     * Populate the context with whichever business objects are specified.
     */
    public void populateBOs(WebContext context)
        throws Exception
    {
        // The operative user (for this request). Defaults to the
        // logged-in user so that if you hit, eg. UserEdit without
        // specifying a user ID, it defaults to editing yourself.
        String currentUserID = getServletParam(context, "userID");
        if (haveValue(currentUserID)) {
            context.put("currentUser", 
                        UserPeer.getInstance(currentUserID));
        }
        else 
        {
            context.put("currentUser", getLoginUser(context));
        }
        
        String currentUserGroupID = getServletParam(context, 
                                                    "userGroupID");
        if (haveValue(currentUserGroupID))
        {
            context.put("currentUserGroup", 
                        UserPeer.getGroupInstance(currentUserGroupID));
        }            
        
        String currentProjectGroupID = getServletParam(context, 
                                                       "projectGroupID");
        if (haveValue(currentProjectGroupID))
        {                
            context.put
                ("currentProjectGroup",
                 ProjectPeer.getGroupInstance(currentProjectGroupID));
        }
        
        String currentRoleID = getServletParam(context, "roleID");
        if (haveValue(currentRoleID))
        {
            context.put("currentRole",
                        RolePeer.getInstance(currentRoleID));
        }
        
        String currentResourceID = getServletParam(context, "resourceID");
        if (haveValue(currentResourceID))
        {
            context.put("currentResource", 
                        ResourcePeer.getInstance(currentResourceID));
        }
        
        String currentAuditLogEntryID = getServletParam(context,
                                                        "auditLogEntryID");
        if (haveValue(currentAuditLogEntryID))
        {
            context.put
                ("currentAuditLogEntry", 
                 AuditLogEntryPeer.getInstance(currentAuditLogEntryID));
        }
    }

    /** 
     * Update current domain and project in the context. These can be
     * specified in the following ways:
     * <ul>
     * <il>1. ID in the query string (e.g., passed from prev servlet)
     * <il>2. Project  or domain name in the query string (e.g., passed
     *     from a rewrite rule)
     * <il>3. Request server name matches project URL alias
     * <il>4. Standard vhosting: project.domain
     * <il>5. default to www project in domain matching request server name
     * </ul>
     *
     * @@param ctx  The context.
     * @@param req  The HTTP request.
     */

    protected void updateCurrentDomainAndProject (WebContext ctx,
                                                  HttpServletRequest req) 
        throws Exception
    {
        BitSet serverNameMatchedDomain = new BitSet(1);
        Domain reqDom = getRequestedDomain(ctx, req, serverNameMatchedDomain);
        Project reqProj = getRequestedProject(ctx, req, reqDom,
                                              serverNameMatchedDomain.get(0));
        boolean forceCurrentProjectChange = false;

        // See if domain changed.
        Domain curDomain = getCurrentDomain(ctx);
        if (curDomain == null || !reqDom.getID().equals(curDomain.getID())) {
            curDomain = reqDom;
            ctx.put("currentDomain", curDomain);
            Log.debug("Setting current domain: " + curDomain.getName());
            // Changing domains forces project change.
            forceCurrentProjectChange = true;
        }

        // See if project changed.
        Project curProj = getCurrentProject(ctx);
        if (forceCurrentProjectChange || curProj == null ||
            !reqProj.getID().equals(curProj.getID())) {
            curProj = reqProj;
            Log.debug("Setting current project: " + curProj.getName());
            ctx.put("currentProject", curProj);

            //TODO: Set the project's skin as well.
//             Skin skin = curProj.getSkin();
//             if (skin != null)
//             {
//                 ctx.put("skin", skin);
//             }
        }
    }


    //
    // Accessor methods; usually aliasing context.get().
    //

d642 54
@


1.60.2.10
log
@That code is commented out for a reason.
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.9 2001/02/06 01:06:39 leonardr Exp $
a187 4

            /**
             * There's a reason this is commented out--we don't have the
             * click through permission servlet ported yet.             
a208 1
            */
@


1.60.2.11
log
@Ported UserAdd servlet.
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.10 2001/02/06 01:49:06 leonardr Exp $
a331 2

        Log.debug("In populateFilter.");
a384 2
        if (criteria == null) Log.debug("Criteria is null!"); else Log.debug("Criteria is not null!");
        Log.debug("Done.");
@


1.60.2.12
log
@Changes to support toolbar guides and filtering on paginated lists. Note that filtering does not yet actually work.
@
text
@d66 1
a66 1
import org.tigris.helm.tool.paginate.PeerBackedList;
d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.11 2001/02/07 02:23:55 leonardr Exp $
d335 1
a335 1
        Criteria filter = new Criteria();
d339 5
a343 6
        //If they're using the simple form, make a trojan Criteria with
        //this information smuggled into it. PeerBackedList will expand
        //it into a properly ORed Criteria.
        String simpleFilterValue = 
            context.getForm(PeerBackedList.SIMPLE_FILTER_VALUE);        
        if (simpleFilterValue != null && !simpleFilterValue.equals(""))
d345 7
a351 3
            filter.add(PeerBackedList.SIMPLE_FILTER_VALUE, simpleFilterValue);
        } else if (context.getForm(PeerBackedList.FILTER_CHECK) != null) {
            /*//They're using the big form--get parameter names. This is all TODO.
d357 1
a357 1
                if (paramName.startsWith(PeerBackedList.FILTER_VALUE))
d369 2
a370 2
                            context.getForm(PeerBackedList.cgiKey
                                            (PeerBackedList.FILTER_MATCHTYPE,
d372 9
a380 1
                             criteria.add(newCrit);
d383 6
a388 4
                }*/
        }
        Log.info("Initial filter: " + filter);
        context.put("filter", filter);
@


1.60.2.13
log
@Don't need to see our login user's id every time.
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.12 2001/02/07 19:49:07 leonardr Exp $
d162 1
a162 1
            //Log.debug("loginUserID=" + loginUserID);
@


1.60.2.14
log
@Concept of the "guest" user renamed to "anonymous".
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.13 2001/02/07 23:07:31 dlr Exp $
d83 1
a83 1
     * clients as the anonymous user.
a108 1
        User loginUser = null;
d131 2
a132 2
                    User anon = UserPeer.getAnonymousUser();
                    if (anon != null)
d135 4
a138 4
                        sMgr.setUserID(anon.getID());
                        sMgr.setLoginID(anon.getLoginName());
                        sMgr.setEmail(anon.getEmail());
                        sMgr.setUserName(anon.getRealName());
d142 1
a142 1
                        Log.error("Could not get anonymous user");
d163 1
a163 1
            loginUser = (User)session.getValue("loginUser");
d248 1
a248 1
                if (!loginUser.isAnonymous())
@


1.60.2.15
log
@Changed code to no longer use deprecated methods.
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.14 2001/02/09 03:06:48 dlr Exp $
d205 1
a205 1
                    if (!acl.hasPermission(clickThroughPermission,
d227 1
a227 1
                    acl.assertPermission(requiredAction,
d231 1
a231 1
                    acl.assertPermission(requiredAction, 
d235 1
a235 1
                    acl.assertPermission(requiredAction); 
@


1.60.2.16
log
@* Changed formatting.
* Corrected bug in getRequestedProject() where reqProjID was assumed
  to be valid if not null, when the empty string needed to be checked
  for as well.  Changed to use of !haveValue() instead.
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.15 2001/02/12 16:24:32 leonardr Exp $
d456 2
a457 2
    protected void updateCurrentDomainAndProject(WebContext ctx,
                                                 HttpServletRequest req) 
d801 1
a801 1
        if (!haveValue(reqProjID)) {
@


1.60.2.17
log
@Big wide-ranging patch being committed all at once due to network downness. Features of this patch include: lots of added and updated JavaDoc, conversion of emails to use TemplateInterpolator and HelmEmailer, rearrangement of methods, changing code that gets mappings and loops over them to code that just gets the appropriate objects from the peer using AddJoin.
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.16 2001/02/12 21:35:45 dlr Exp $
d774 1
a774 4
                    catch (Exception f) 
                    {
                        Log.error("Could not get domain via URL alias.", f);
                    }
d851 1
a851 1
            Log.error("Project not found: projectName=" + projectName, e);
@


1.60.2.18
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.17 2001/02/14 23:20:30 leonardr Exp $
@


1.60.2.19
log
@Added link to ACLDump so that the user can see what permissions they do have.
@
text
@d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.18 2001/02/15 20:50:43 leonardr Exp $
d253 1
a253 1
                         "<a href=\"/servlets/ACLDump\">permissions</a> to access the page you requested. " +
@


1.60.2.20
log
@Added new imports necessitated by Torque.
@
text
@a63 1
import org.tigris.helm.om.base.*;
d75 1
a75 1
 * @@version $Id: HelmServlet.java,v 1.60.2.19 2001/02/16 02:43:35 leonardr Exp $
@


1.60.2.21
log
@Ported changes from head.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.60.2.20 2001/02/16 03:01:35 dlr Exp $
a154 5

            // set up logging of user name in access_log
            HttpServletResponse response = context.getResponse();
            response.setHeader("HelmLoginID", sMgr.getLoginID());

d192 1
a192 1
             * FIXME: There's a reason this is commented out--we don't have the
a213 7
            } else {
                User user = getLoginUser( context );
                if (!user.getACL().hasPermission("Click-through Page - Seen",
                currentDomain))
                {
                    user.setClickThroughAsViewed( currentDomain );
                }
a215 1

@


1.59
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.57 2001/01/17 21:56:13 leonardr Exp $
d223 6
@


1.58
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.57
log
@When putting a project in the context, also supply that project's skin.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.56 2001/01/17 18:35:36 dlr Exp $
@


1.57.2.1
log
@Give the user CCT permission whether they were forced through the CCT servlet or not.  Previous, if CCT facility was turned off, the user would be logged in but wouldn't have been granted the CCT permission.  Certain pages require the CCT permission.  Rather than go through the site changing base permissions on pages that require CCT, grant CCT permission.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.57 2001/01/17 21:56:13 leonardr Exp $
a223 7
            else
            {
                log.info( "CCT Feature is off. Granting CCT permission." );
                User user = getLoginUser( context );
                user.setClickThroughAsViewed( currentDomain );
            }
                
@


1.57.2.2
log
@Porting changes from HEAD into branch.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.57.2.1 2001/01/26 23:36:52 stack Exp $
d226 1
d228 1
a228 5
                if (!user.getACL().hasPermissionForDomain("Click-through Page - Seen", currentDomain.getID()))
                {
                    log.info( "CCT Feature is off. Granting CCT permission." );
                    user.setClickThroughAsViewed( currentDomain );
                }
d230 1
@


1.57.2.3
log
@copied helm loginID logging from HEAD
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.62 2001/02/07 08:56:23 jrobbins Exp $
a173 5

            // set up logging of user name in access_log
            HttpServletResponse response = context.getResponse();
            response.setHeader("HelmLoginID", sMgr.getLoginID());

@


1.56
log
@Properly aligned JavaDoc.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.55 2001/01/12 22:54:27 dlr Exp $
d692 7
@


1.55
log
@Added debugging trace.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.54 2001/01/11 20:20:07 dlr Exp $
d110 1
a110 1
     * @@return             The name of the Template for formatting the 
@


1.54
log
@Removed unused trace.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.53 2001/01/11 19:53:23 dlr Exp $
d78 1
a78 1
 * Copyright (c) 2000 CollabNet, Inc.
d145 1
@


1.53
log
@* Moved update of current host, domain, and project towards beginning
  of processRequest.
* Finally managed to migrate to business objects only in servlets,
  removing the need for all those TableManager instance variables.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.52 2001/01/11 03:03:38 dlr Exp $
a171 1
            if (debug) log.debug("logged in");
@


1.52
log
@Use the ALLOW_GUESTS initArg to determine whether to automatically log
in clients as the guest user.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.51 2001/01/10 01:52:19 leonardr Exp $
a103 30
     * The servlet's DomainManager.
     */
    protected DomainManager domMgr;

    /**
     * The servlet's ProjectManager.
     */
    protected ProjectManager projMgr;

    /**
     * The servlet's UserManager.
     */
    protected UserManager userMgr;

    /**
     * The servlet's UserUserGroupManager.
     */
    protected UserUserGroupManager uugMgr;

    /**
     * The servlet's RoleManager.
     */
    protected RoleManager roleMgr;

    /**
     * The servlet's UserRoleProjectManager.
     */
    protected UserRoleProjectManager urpMgr;

    /**
a133 1
            initTableManagers(dMgr);
d173 6
a180 2
            context.put("isLoggedIn", isLoggedIn);
            
d192 1
a192 3
                loginUser = 
                    new User(connection, dMgr,
                             userMgr.getUser(connection, loginUserID));
a196 8
            context.put("host", new Host(connection, dMgr));

            // The current domain.
            updateCurrentDomainAndProject(connection, context, request);

            // -------------------------------------------------------
                   
            Domain currentDomain = getCurrentDomain(context);
a203 1

a823 42
    }

    /**
     * Initialize the TableManagers (if necessary).
     */
    private void initTableManagers (DataManager dMgr)
    {
        if (domMgr == null)
        {
            domMgr = (DomainManager) dMgr
                .getManager("org.tigris.helm.database.DomainManager");
        }            

        if (projMgr == null)
        {
            projMgr = (ProjectManager) dMgr
                .getManager("org.tigris.helm.database.ProjectManager");
        }            

        if (userMgr == null)
        {
            userMgr = (UserManager) dMgr
                .getManager("org.joist.database.UserManager");
        }            

        if (uugMgr == null)
        {
            uugMgr = (UserUserGroupManager) dMgr.getManager
                ("org.tigris.helm.database.UserUserGroupManager");
        }            

        if (roleMgr == null)
        {
            roleMgr = (RoleManager) dMgr
                .getManager("org.joist.database.RoleManager");
        }            

        if (urpMgr == null)
        {
            urpMgr = (UserRoleProjectManager) dMgr.getManager
                ("org.tigris.helm.database.UserRoleProjectManager");
        }
@


1.51
log
@Filter interface is much simpler now. The more complicated interface is commented out in case we need it again.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.50 2001/01/09 07:52:59 dlr Exp $
d93 6
d175 2
a176 3
                if (debug) log.info("Not logged in...logging in as guest");
                User guest = User.getGuest();
                if (guest != null)
d178 17
a194 5
                    sMgr.isLoggedIn(true);
                    sMgr.setUserID(guest.getID());
                    sMgr.setLoginID(guest.getLoginID());
                    sMgr.setEmail(guest.getEmail());
                    sMgr.setUserName(guest.getName());
d198 3
a200 1
                    log.error("Could not get guest user");
a201 4

                // Let the client attempt to view the screen.  If the user does
                // not have permission, redirect to the login screen.  Display
                // an informative message to non-guest users.
@


1.50
log
@Handle ACLExceptions via redirect to TLogin with informative message rather
than through redirect to UnauthorizedAccess.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.49 2001/01/08 23:25:03 dlr Exp $
d301 4
a304 1
            if (context.getForm(Criterion.FILTER_CHECK) != null)
d306 7
a312 2
                if (debug) log.info("Checking for filter fields.");
                // Get parameter names
d336 3
a338 3
                            Criterion newCrit = 
                                new Criterion(filterFieldName, filterMatchType,
                                              filterValue);
d347 1
a347 1
                }                
@


1.49
log
@Corrected a bunch of regressions to previous User instantion method.  Deprecated User's getUserID() method in favor of getID() for better conformance with BusinessObject interface and orthoginality with other business objects.  Added a guest user and interface.  Added some JavaDoc to User.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.48 2001/01/05 15:44:13 leonardr Exp $
d184 3
a186 12
                // Let the client attempt to view the screen.  If guest does
                // not have permission, redirect to the login screen.

                // TODO: Rework the login screen to replace UnauthorizedAccess.
                // If the client is logged in as the guest user, just display
                // the login screen as if they weren't logged in at all.
                // Otherwise, display an additional message saying that they
                // didn't have access to view the page they'd requested.

                //setAsDetour(context);
                //context.put("action", "none");
                //redirectTo(myProperties.getProperty("loginServletName"));
d227 2
a228 2
            String clickThroughPermission
                = myProperties.getProperty( "clickThroughPermission" );
d398 16
@


1.48
log
@Always check clickthrough permission (if enabled), not only if there's a base permission.
@
text
@a66 1
import org.tigris.helm.security.ACLException;
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.47 2001/01/03 22:32:55 dlr Exp $
a153 1
            // Initialize the TableManagers, if necessary.
d158 1
a158 36

            if (domMgr == null)
            {
                domMgr = (DomainManager) dMgr
                    .getManager("org.tigris.helm.database.DomainManager");
            }            

            if (projMgr == null)
            {
                projMgr = (ProjectManager) dMgr
                    .getManager("org.tigris.helm.database.ProjectManager");
            }            

            if (userMgr == null)
            {
                userMgr = (UserManager) dMgr
                    .getManager("org.joist.database.UserManager");
            }            

            if (uugMgr == null)
            {
                uugMgr = (UserUserGroupManager) dMgr.getManager
                    ("org.tigris.helm.database.UserUserGroupManager");
            }            

            if (roleMgr == null)
            {
                roleMgr = (RoleManager) dMgr
                    .getManager("org.joist.database.RoleManager");
            }            

            if (urpMgr == null)
            {
                urpMgr = (UserRoleProjectManager) dMgr.getManager
                    ("org.tigris.helm.database.UserRoleProjectManager");
            }
d165 1
a165 1
            // structure.
d169 27
a195 4
                if (debug) log.debug("NOT logged in");
                setAsDetour(context);
                context.put("action", "none");
                redirectTo(myProperties.getProperty("loginServletName"));
d209 1
a209 1
                 || !loginUser.getUserID().equals(loginUserID) 
d399 2
a400 1
            String currentAuditLogEntryID = getServletParam(context, "auditLogEntryID");
d404 2
a405 1
                            new AuditLogEntry(connection, dMgr, currentAuditLogEntryID));
a406 1

d832 42
@


1.47
log
@Moved addBooleanToContext to UnsecureServlet.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.46 2000/12/30 00:34:35 dlr Exp $
d241 30
a273 2
            AccessControlList acl = getACL(context, connection,
                                           loginUserID);
a275 1
                Domain currentDomain = getCurrentDomain(context);
a280 25

                // if we've got a clickThroughPermission set up -- and if
                // they're not viewing the page showing it -- and if they don't
                // have the permission already -- then we'll need to redirect
                // them.
                String clickThroughPermission
                    = myProperties.getProperty( "clickThroughPermission" );

                if (haveValue(clickThroughPermission))
                {
                    String servlet = getServletName();
                    String compulsoryClickThroughServlet =
                        myProperties.getProperty("compulsoryClickThrough");

                    if (!servlet.equals(compulsoryClickThroughServlet))
                    {
                        if(!acl.hasPermissionForDomain (clickThroughPermission,
                                                        currentDomain.getID()))
                        {
                            log.info("Redirecting CompulsoryClickThrough");
                            setAsDetour(context);
                            redirectTo(compulsoryClickThroughServlet);
                        }
                    }
                }
@


1.46
log
@Made use of new Criterion constants and macro.  Clearly defined
interfaces are great.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.45 2000/12/23 00:48:19 dlr Exp $
a842 13
    }

    /**
     * Adds a boolean value to the context.
     *
     * @@param ctx  The context to add to.
     * @@param key  The key name of the value in the context.
     * @@param bool The boolean primitive whose object equivalent to add.
     */
    protected final void addBooleanToContext (WebContext ctx, String key, 
                                              boolean bool)
    {
        ctx.put(key, (bool ? Boolean.TRUE : Boolean.FALSE));
@


1.45
log
@Removed unnecessary getCache() implementations in BusinessObject subclasses and migrated to a factory method for User's primary database key ctor.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.44 2000/12/20 23:05:27 kmaples Exp $
d322 1
a322 1
            if (context.getForm("FILTER CHECK") != null)
d324 1
a324 1
                log.info("Checking for filter fields.");
d331 1
a331 1
                    if (paramName.startsWith("FILTER VALUE"))
d341 3
a343 1
                            log.info("Value \"" + filterValue + " provided for " + filterFieldName);
d346 3
a348 2
                                context.getForm("FILTER MATCHTYPE/" 
                                                + filterFieldName);
@


1.44
log
@Changed pagination 'page' key to be 'paginated_page so it would stop clashing w/ noodle use of 'page'
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.43 2000/12/20 18:39:55 leonardr Exp $
d371 1
a371 1
                            new User(connection, dMgr, currentUserID));
@


1.44.2.1
log
@If CCT is turned off, grant the CCT permission w/o going to the CCT servlet
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.44 2000/12/20 23:05:27 kmaples Exp $
d258 1
a258 2
                // them.  Else just grant the click-through permission.
                //
a278 7
                else
                {
		    log.info( "Granting CCT permission" );
                    User user = getLoginUser( context ); 
                    user.setClickThroughAsViewed( currentDomain );
                }
		
@


1.44.2.2
log
@moved userID logging from HEAD
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.44.2.1 2001/01/13 02:53:08 stack Exp $
a215 4
            // set up logging of user name in access_log
            HttpServletResponse response = context.getResponse();
            response.setHeader("HelmLoginID", sMgr.getLoginID());

@


1.43
log
@First tenative steps towards the new pagination/filtering regime.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.42 2000/12/19 00:14:30 leonardr Exp $
d310 1
a310 1
            String pageStr = context.getForm("page");
d318 1
a318 1
            context.put("page", page);
@


1.42
log
@SessionList changes.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.41 2000/12/15 04:37:57 leonardr Exp $
d294 71
@


1.41
log
@Big patch whose main effect is to make dynamic the list of roles on UserEdit.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.40 2000/12/14 03:04:17 edk Exp $
d147 4
a154 3
            // We should always get the SessionManager for the current request
            SessionManager sMgr = getSessionManager(context);

a196 2
            HttpSession session = sMgr.getSession();

d357 5
@


1.40
log
@* adjust for corrections to Role constructor
* correct another Role constructor which listed the DataManager before
  the Connection
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.39 2000/12/13 22:05:13 leonardr Exp $
d416 11
@


1.39
log
@More work on AuditEventDetail.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.38 2000/12/13 19:37:04 leonardr Exp $
d328 1
a328 1
                            new Role(dMgr, connection, currentRoleID));
@


1.38
log
@New servlet: AuditEventDetail
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.37 2000/12/13 18:59:06 leonardr Exp $
d342 1
a342 1
                            new Resource(connection, dMgr, currentAuditLogEntryID));
@


1.37
log
@Fixed broken ProjectDelete redirect.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.36 2000/12/13 18:23:53 leonardr Exp $
d516 11
@


1.36
log
@Added logging to project deletion.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.35 2000/12/13 02:00:41 leonardr Exp $
d337 8
d685 1
a685 1
        if (reqProjID == null || reqProjID == "") {
@


1.35
log
@Put host in context.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.34 2000/12/11 18:26:34 leonardr Exp $
d677 1
a677 1
        if (reqProjID == null) {
@


1.34
log
@Doh, how about changing the method name when I copy and paste.
@
text
@d63 1
d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.33 2000/12/11 18:23:35 leonardr Exp $
d234 2
@


1.33
log
@More of the same.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.32 2000/12/11 18:19:36 leonardr Exp $
d502 1
a502 1
    protected final Resource getCurrentRole(WebContext context)
@


1.32
log
@Added support for servlets that act on a Resource.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.31 2000/12/09 02:13:37 leonardr Exp $
d494 11
@


1.31
log
@More role support.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.30 2000/12/06 23:04:47 leonardr Exp $
d328 6
@


1.30
log
@Added ACL dump servlet.
@
text
@d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.29 2000/12/06 20:49:04 dlr Exp $
d477 11
@


1.29
log
@Corrected possible NPE from getRequestedProject.  Found by Kevin and
diagnosed by Ed.
@
text
@d41 1
a41 2
 * ====================================================================
 * 
d76 1
a76 1
 * @@version $Id: HelmServlet.java,v 1.28 2000/12/06 20:45:41 leonardr Exp $
d242 2
a245 2
                AccessControlList acl = getACL(context, connection,
                                               loginUserID);
@


1.28
log
@Added support for role-manipulating servlets.
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.27 2000/12/06 19:03:13 dlr Exp $
d642 1
d681 3
@


1.27
log
@Reorganized updateCurrentDomainAndProject() and its helper methods.
@
text
@d65 1
a65 4
import org.tigris.helm.domain.Domain;
import org.tigris.helm.domain.User;
import org.tigris.helm.domain.UserGroup;
import org.tigris.helm.domain.ProjectGroup;
d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.26 2000/12/05 21:28:52 dlr Exp $
d321 8
a328 1
            context.put("pageTitle", getPageTitle(context));
d340 1
@


1.26
log
@Removed unnecessary local variable.
@
text
@d63 1
a64 1

d80 1
a80 1
 * @@version $Id: HelmServlet.java,v 1.25 2000/12/04 06:25:28 edk Exp $
a244 6






d249 1
a249 1
                        loginUserID);
d262 1
a262 1
                        = myProperties.getProperty( "clickThroughPermission" );
d317 1
a317 1
                                                        "projectGroupID");
d522 1
a522 1
     * specified in the following ways (in order of precedence): 
d531 4
d537 3
a539 3
    protected void updateCurrentDomainAndProject(Connection conn,
                                                 WebContext context,
                                                 HttpServletRequest req) 
d542 26
a567 33
        SessionManager sMgr = getSessionManager(context);
        HttpSession session = sMgr.getSession();
        boolean serverNameMatchedDomain = false;

        String reqDomainName = getServletParam(context, "domainName"); //2
        if (reqDomainName == null) 
            reqDomainName = req.getServerName(); // 3,4,5

        // figure out requested domain ID
        String reqDomainID = getServletParam(context, "domainID"); //1
        if (reqDomainID == null) {
            reqDomainID = findDomainIDByName(conn, reqDomainName); //2,3
            if (reqDomainID != null) serverNameMatchedDomain = true;
        }
        if (reqDomainID == null) {
            int dot = reqDomainName.indexOf('.');
            String domainNoVhost = reqDomainName.substring(dot+1);
            log.info("domainNoVhost: " + domainNoVhost);
            reqDomainID = findDomainIDByName(conn, domainNoVhost);
        }

        log.info("reqDomainID=" + reqDomainID);

        // figure out requested project ID
        String reqProjectID = getServletParam(context, "projectID"); //1
        if (reqProjectID == null) {
            reqProjectID =
                findProjectIDByURLAlias(conn, req.getServerName()); //3
            if (reqProjectID != null) {
                Project reqProj = new Project(conn, dMgr, reqProjectID);
                reqDomainID = reqProj.getDomainID();
            }
            
d569 25
a593 5
        if (reqProjectID == null) {
            String reqProjectName = getServletParam(context, "projectName");
            if (reqProjectName != null) {
                reqProjectID = findProjectIDByName(conn, reqProjectName,
                                                   reqDomainID); //2
a594 12
        }
        log.info("initially, reqProjectID=" + reqProjectID);
        if (reqProjectID == null && !serverNameMatchedDomain) {
            String vhost = req.getServerName();
            vhost = vhost.substring(0, vhost.indexOf('.'));
            log.info("trying vhost: " + vhost);
            reqProjectID = findProjectIDByName(conn, vhost, reqDomainID); // 4
        }
        if (reqProjectID == null) {
            reqProjectID = findProjectIDByName(conn, "www", reqDomainID); // 5
        }
        log.info("later, reqProjectID=" + reqProjectID);
d596 5
a600 8
        // get current domain and project IDs
        Domain currentDomain = getCurrentDomain(context);
        String curDomainID = null;
        if (currentDomain != null) curDomainID = currentDomain.getID();
        Project currentProject = getCurrentProject(context);
        String curProjectID = null;
        if (currentProject != null) curProjectID = currentProject.getID();
        
d602 19
a620 6
        // see if domain changed
        if (currentDomain == null || !reqDomainID.equals(curDomainID)) {
            currentDomain = new Domain(conn, dMgr, reqDomainID);
            context.put("currentDomain", currentDomain);
            log.info("setting current domain: " + currentDomain.getName( ) );
            curProjectID = "Changing domain forces project change";
d622 2
d625 41
a666 7
        // see if project changed
        if (currentProject == null || !reqProjectID.equals(curProjectID)) {
            currentProject = new Project(conn, dMgr, reqProjectID);
            if (currentProject.exists()) {
                if (debug) log.info("setting current project: " +
                                    currentProject.getName());
                context.put("currentProject", currentProject);
a667 2
        }
    }
d669 6
a674 7
    
    protected String findDomainIDByName(Connection conn, String domainName) 
        throws DataSetException
    {
        String domainID = null;
        try {
            domainID = domMgr.getDomainID(domainName).toString();
d676 1
a676 4
        catch (org.joist.database.JoistDatabaseException e) {
            log.info("domainName " + domainName + " not a match. try URL alias");
        }
        return domainID;
d679 5
a683 17
    protected String findProjectIDByName(Connection conn, String
                                         projectName, String domainID) 
    {
        // TODO: cache this info
        String projectID = null;
        try {
            log.info("looking up projectName: " + projectName + 
                     " in domainID " + domainID);
            projectID = projMgr.getProjectID(conn, domainID, projectName);
        }
        catch (Exception e) {
            log.info("projectName " + projectName + " not a match. try URL alias");
        }
        return projectID;
    }

    protected String findProjectIDByURLAlias(Connection conn, String fqdn) 
d686 1
a686 1
        log.info("trying URL alias: " + fqdn);
d688 3
a690 3
            Record rec = projMgr.getProjectForAliasURL(conn, null, fqdn);
            String projectID = 
                rec.getValue(ProjectManager.PROJECT_ALIAS_URL).toString();
d693 1
a693 1
            log.info("project URL " + fqdn + " not a match.");
d695 1
a695 1
        return null;
@


1.25
log
@remove incomplete breadcrumb which prevented this from building
@
text
@d80 1
a80 1
 * @@version $Id: HelmServlet.java,v 1.24 2000/12/04 06:16:16 edk Exp $
d574 1
a574 2
                String d = reqProj.getDomainID();
                reqDomainID = d;
@


1.24
log
@* make compulsory click through compulsory -- it should be applied on
  any page which has any base permission checking
* make the redirect be to the home page -- generally this sends the
  visitor to /, which is reasonable
@
text
@d80 1
a80 1
 * @@version $Id: HelmServlet.java,v 1.23 2000/12/01 08:35:42 dlr Exp $
a274 1
                            compulsoryClickThroughServlet);
@


1.23
log
@Moved some functionality into UnsecureServlet.
@
text
@d80 1
a80 1
 * @@version $Id: HelmServlet.java,v 1.22 2000/11/29 23:57:51 leonardr Exp $
d246 5
d254 3
d262 26
a287 2
                AccessControlList acl = getACL(context, connection, 
                                               loginUserID);
a295 26
                    Domain currentDomain = getCurrentDomain(context);
                    
                    // Insert compulsory click-through check if the 
                    // clickThroughPermission property is non-null.  The way 
                    // i'm doing it is a little awkward because
                    // alternative is catching the exception thrown by 
                    // assertPermission and then rethrowing -- which i think 
                    // uglier.
                    // 
                    String clickThroughPermission
                        = myProperties.getProperty( "clickThroughPermission" );
                    if( haveValue( clickThroughPermission ) )
                    {
                        if(!acl.hasPermissionForDomain (requiredAction,
                                                        currentDomain.getID()))
                        {
                            if(requiredAction.equals(clickThroughPermission))
                            {                            
                                log.info("Redirecting CompulsoryClickThrough");
                                setAsDetour(context);
                                redirectTo(myProperties.getProperty(
                                                                    "compulsoryClickThrough"));
                            }
                        }
                    }
                   
a298 1
                    
@


1.22
log
@Added project group edit and delete.
@
text
@d80 1
a80 1
 * @@version $Id: HelmServlet.java,v 1.21 2000/11/27 21:30:27 leonardr Exp $
a474 154
    }

    /**
     * @@see org.tigris.helm.security.HelmServlet#processField
     */
    protected final String processField (WebContext context, String key)
    {
        return processField(context, key, (String)null);
    }

    /**
     * @@see org.tigris.helm.security.HelmServlet#processField
     */
    protected final String processField (WebContext context, 
                                         String key, String description, 
                                         List missingFields)
    {
        return processField(context, key, (String)null, description,
                            missingFields);
    }

    /**
     * @@see org.tigris.helm.security.HelmServlet#processField
     */
    protected final String processField (WebContext context, 
                                         String key, String defaultValue)
    {
        return processField(context, key, defaultValue, null, null);
    }

    /**
     * @@see org.tigris.helm.security.HelmServlet#processField
     */
    protected final String processField (WebContext context, String key,
                                         HttpSession session)
    {
        return processField(context, key, session, null, null);
    }

    /**
     * Attempts to get <code>defaultValue</code> from the 
     * <code>HttpSession</code> object, keyed by <code>key</code>.
     *
     * @@see org.tigris.helm.security.HelmServlet#processField
     */
    protected final String processField (WebContext context, String key,
                                         HttpSession session,
                                         String description,
                                         List missingFields)
    {
        return processField(context, key, (String)session.getValue(key), 
                            description, missingFields);
    }

    /**
     * Retrieves HTML form and/or CGI query string data, both adding the data 
     * to the context and returning it.  If the form field contains no data, 
     * the provided <code>description</code> is noted in the 
     * <code>missingFields</code> list (if provided).
     * <p>
     * The name of this method is, unfortunately, ambiguous (because it does 
     * so many things).  It may not be a cohesive, but it sure is useful!
     *
     * @@param context       The WebContext to add the param to.
     * @@param key           The name of the form field and context key.
     * @@param defaultValue  The default value to use if there is nothing in 
     *                      the form (if <code>null</code>, defaults to the
     *                      empty string).
     * @@param description   The description to put into the 
     *                      <code>missingFields</code> list if the the form 
     *                      field has no value (or <code>null</code>).
     * @@param missingFields The list of missing fields (or <code>null</code> 
     *                      if you do not care if the field is missing).
     * @@return The form value retrieved.
     */
    protected String processField (WebContext context, String key, 
                                   String defaultValue, String description, 
                                   List missingFields)
    {
        String value = context.getForm(key);
        if (!haveValue(value))
        {
            if (missingFields != null)
            {
                missingFields.add(description);
            }
            value = (defaultValue != null ? defaultValue : "");
        }
        context.put(key, value);
        if (debug) log.info("Processing field: " + key + '=' + value);
        return value;
    }

    /**
     * Requires that a value is provided, adding it to the list of missing 
     * fields if it is not there.  This method is convenient to call in 
     * conjunction with the processField() variants which do not take a list 
     * of missing fields.
     *
     * @@param value         The value to check.
     * @@param description   The description to use to describe a missing value.
     * @@param missingFields The list of missing fields to add to.
     */
    protected void requireValue (String value, String description, 
                                 List missingFields)
    {
        if (!haveValue(value))
        {
            if (missingFields != null)
            {
                missingFields.add(description);
            }
        }
    }

    /**
     * Checks whether the user inputs are valid.  Examines 
     * <code>missingFields</code> and <code>validationErrors</code> for listed 
     * fields.
     *
     * @@param missingFields    The missing fields.
     * @@param validationErrors The field validaiton errors.
     * @@return                 The validity of the user input.
     */
    protected final boolean isValidUserInput (List missingFields, 
                                              List validationErrors)
    {
        return ((missingFields == null || missingFields.isEmpty()) && 
                (validationErrors == null || validationErrors.isEmpty()));
    }

    /**
     * Reports missing fields and data validation errors.  Examines 
     * <code>missingFields</code> and <code>validationErrors</code> for listed 
     * fields.
     *
     * @@param context          The WebContext to report errors in.
     * @@param missingFields    The missing fields.
     * @@param validationErrors The field validaiton errors.
     */
    protected final void reportInvalidUserInput (WebContext context, 
                                                 List missingFields, 
                                                 List validationErrors)
    {
        if (missingFields != null && !missingFields.isEmpty())
        {
            appendToMessage(context, "Required information missing", 
                            missingFields);
        }
        if (validationErrors != null && !validationErrors.isEmpty())
        {
            appendToMessage(context, "Invalid information entered", 
                            validationErrors);
        }
@


1.21
log
@Started work on paginating ProjectList.
@
text
@d68 1
d80 1
a80 1
 * @@version $Id: HelmServlet.java,v 1.20 2000/11/23 09:45:05 dlr Exp $
a312 1
                log.info("Making usergroup for " + currentUserGroupID);
d318 8
d463 12
@


1.20
log
@Resolve ambiguous method calls.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.19 2000/11/23 09:42:22 dlr Exp $
d199 3
@


1.19
log
@Invoke the right method.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.18 2000/11/23 09:40:19 dlr Exp $
d459 1
a459 1
        return processField(context, key, null, null, null);
d469 2
a470 1
        return processField(context, key, null, description, missingFields);
@


1.18
log
@Added some wrapper methods for getting default values for
processField() from a HttpSession.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.17 2000/11/23 08:42:05 dlr Exp $
d501 2
a502 2
        return processField(context, key, session.getValue(key), description,
                            missingFields);
@


1.17
log
@More bullet-proof behavior for processField() when a null String is
passed for the defaultValue parameter.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.16 2000/11/22 21:16:14 leonardr Exp $
d479 24
@


1.16
log
@User group descriptions can now be changed.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.15 2000/11/21 22:07:54 leonardr Exp $
d459 1
a459 1
        return processField(context, key, "", null, null);
d469 1
a469 1
        return processField(context, key, "", description, missingFields);
d493 2
a494 1
     *                      the form.
d513 1
a513 1
            value = defaultValue;
@


1.15
log
@Got rid of unneeded code.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.14 2000/11/21 22:07:12 leonardr Exp $
d309 1
d449 1
a449 1
    protected final User getCurrentUserGroup (WebContext context)
d451 1
a451 1
        return (User) context.get("currentUserGroup");
@


1.14
log
@Automatically grab the current UserGroup, if applicable.
@
text
@d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.13 2000/11/20 10:04:47 dlr Exp $
d312 1
a312 5

            } else {
                context.put("currentUser", getLoginUser(context));
            }
            
@


1.13
log
@detabify++...I need a macro
@
text
@d67 1
d79 1
a79 1
 * @@version $Id: HelmServlet.java,v 1.12 2000/11/19 22:34:32 dlr Exp $
d300 13
a312 3
                            new User(connection, dMgr,
                                     userMgr.getUser
                                     (connection, currentUserID)));
d317 1
a317 6
            // NOTE: There is already a displayName variable added to the 
            // context in UnsecureServlet.  Is this different?
            //
            // ANSWER: Yes. It's different.  See javadoc for getPageTitle 
            // method  St.Ack 11/13/2000.
            //
d443 12
@


1.12
log
@HttpServletRequest instance variable.  Since servlet instances are
used accross requests, instance variables MUST be thread-safe.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.11 2000/11/16 18:54:55 leonardr Exp $
a127 1
    
d136 1
a136 1
     * @@return	         The name of the Template for formatting the 
d143 1
a143 1
	throws HandlerException, RedirectException, ACLException
d145 2
a146 2
	// Get the default template to start with.
	String templateName = super.processRequest(connection, context);
d237 1
a237 1
            	   
d280 1
a280 1
                                    "compulsoryClickThrough"));
d286 1
a286 1
                                                    currentDomain.getID());
d288 1
a288 1
					
d312 1
a312 1
	    context.put("pageTitle", getPageTitle(context));
d324 3
a326 1
        // Get the current date just before we return the template.
d328 1
a328 2
        context.put("servletHelp", new ServletHelp());
	return templateName;
d571 3
a573 3
     * @@param	permissionName    The name of the required permission.
     * @@param	userPermissions   The set of permissions possessed by the user.
     * @@return	                  Whether the accessing user is allowed access.
d578 1
a578 1
	return (userPermissions != null ? 
d715 1
a715 1
    throws DataSetException
@


1.11
log
@Accessing a servlet that requires a user without specifying a user will now be equivalent to specifying yourself as the user.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.10 2000/11/16 01:43:59 stack Exp $
a93 2
    protected HttpServletRequest request;

d151 1
a151 1
            request = context.getRequest();
d651 1
a651 1
        log.info("reqDomainID = " + reqDomainID);
d676 1
a676 1
            log.info("trying vhost:"+ vhost);
@


1.10
log
@Add redirect to CompulsoryClickThrough. Can be turned off when we don't need it.  See http://projects.collab.net/project/eng/stack/projects/clickthroughlicense/ for how it works as well as how to turn it on and off
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.9 2000/11/15 21:57:34 leonardr Exp $
d305 2
d308 1
a308 1

d421 8
a428 4
	 * 
	 * Note, this is not the currently logged in user.  Use getLoginUser
	 * for that.  getCurrentUser is the user in context when doing 
	 * edits on a list of multiple users
d432 3
a434 3
	 *
	 * @@see org.tigris.helm.domain.UserEdit
	 * @@see #getLoginUser
@


1.9
log
@Moved getAction to Joist.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.8 2000/11/15 19:20:50 stack Exp $
d263 25
d289 1
a289 1
                                                  currentDomain.getID());
d291 1
d382 1
@


1.8
log
@Added javadoc on getCurrentUser tightening up description of what it actually does.  Forsecond time i've attempted to get the logged in user using getCurrentUser when i should be using getLoginUser
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.7 2000/11/15 17:18:57 leonardr Exp $
a354 11
    }

    /**
     * Gets the action specified by the last button pushed.
     *
     * @@param context The context to grab the action from
     * @@return a String containing the action
     */
    protected final String getAction (WebContext context)
    {
        return (String) context.get("action");
@


1.7
log
@Added getAction method.
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.6 2000/11/15 03:50:07 dlr Exp $
d403 4
d410 3
@


1.6
log
@that line was distracting me ;P
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.5 2000/11/15 01:38:10 susank Exp $
d243 1
d355 11
@


1.5
log
@added ServletHelp to check existence of context help file (don't worry, it wasn't me alone, dlr did it)
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.4 2000/11/13 22:39:52 leonardr Exp $
d629 2
a630 1
                reqProjectID = findProjectIDByName(conn, reqProjectName, reqDomainID); //2
d633 1
a633 1
        log.info("========= reqProjectID = " + reqProjectID);
d643 1
a643 1
        log.info("reqProjectID = " + reqProjectID);
@


1.4
log
@Permission checking bugfixes; one more big one on the way.
@
text
@d69 1
d78 1
a78 1
 * @@version $Id: HelmServlet.java,v 1.3 2000/11/13 22:17:37 stack Exp $
d300 1
@


1.3
log
@Added javadoc around getPageTitle explaining how it relates to the UnsecureServlet displayName mechanism for getting the HTML page TITLE
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.2 2000/11/13 19:51:49 stack Exp $
d252 1
a252 1

d256 1
@


1.2
log
@Took out the start method i'd added previously to start up the single instance of MemorySentinel class.  Moved it instead ot joist at davidp prompting
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.1.1.1 2000/11/12 21:16:41 dlr Exp $
d280 4
d541 17
a557 3
    /**
     * Show a useful title for this page.  Subclasses can override to
     * show specific details like a user name or project name.
@


1.1
log
@Initial revision
@
text
@d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.90 2000/11/11 20:58:41 dlr Exp $
a128 31
    
    
    /**
     * Helm servlet start.
     * Calls the super class start, then adds Helm start items.
     * Implemented mostly because St.Ack is afraid to touch 
     * UnsecureServlet.
     *
     * @@exception ServletException
     */
    public void start ()
        throws ServletException
    {
        super.start();
        
        // Get instance of MemorySentinel running in current Heap.  It writes 
        // memory total and free to webmacro log.  It's singleton, so only
        // ever one instance per heap. Reads properties from
        // 30joist.zone.properties.
        //
        // Not a tragedy if we MemorySentinel fails to run but the fact that
        // it failed is worthy of mention.
        try 
        {
            org.joist.util.MemorySentinel.getInstance();
        }
        catch (Exception e)
        {
            log.warning("Failed starting memory sentinel: " + e);
        }
    }
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by CollabNet (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d41 2
a42 1
 * ================================================================
d54 1
a54 2
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.Log;
d56 1
d59 1
d63 6
a68 7
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.domain.*;
import org.tigris.helm.tool.ServletHelp;
import org.tigris.helm.tool.paginate.PeerBackedList;
d77 1
a77 1
 * @@version $Id: HelmServlet.java,v 1.60.2.21 2001/02/17 20:33:41 leonardr Exp $
d79 1
a79 1
 * Copyright (c) 2000-2001 CollabNet, Inc.
d84 54
a137 2
     * The key to the property which specifies whether to automatically log in
     * clients as the anonymous user.
d139 22
a160 1
    private static final String ALLOW_GUESTS = "ALLOW_GUESTS";
d169 1
a169 1
     * @@return           The name of the Template for formatting the 
d176 1
a176 1
        throws HandlerException, ACLException, RedirectException
d178 2
a179 7
        // Get the default template to start with.
        String templateName = super.processRequest(connection, context);

        // We should always get the SessionManager for the current request
        SessionManager sMgr = getSessionManager(context);
        HttpSession session = sMgr.getSession();
        User loginUser = null;
d183 46
a228 1
            HttpServletRequest request = context.getRequest();
d230 3
a232 4
            // Make sure user is logged in. If they're not, redirect them
            // to the login servlet or log them in as guest (depending on
            // the site configuration).
            //
d234 2
a235 2
            // structure (i.e. UnsecureServlet vs. SecureServlet subclass).
            Boolean isLoggedIn = sMgr.isLoggedIn();            
d238 4
a241 28
                String allowGuests = myProperties.getProperty(ALLOW_GUESTS);
                Log.debug(ALLOW_GUESTS + '=' + allowGuests);
                if (allowGuests != null && allowGuests.equals("true"))
                {
                    // Let the client attempt to view the screen.  If the user
                    // does not have permission, redirect to the login screen. 
                    // Display an informative message to non-guest users.
                    Log.debug("Not logged in...logging in as guest");
                    User anon = UserPeer.getAnonymousUser();
                    if (anon != null)
                    {
                        sMgr.isLoggedIn(true);
                        sMgr.setUserID(anon.getID());
                        sMgr.setLoginID(anon.getLoginName());
                        sMgr.setEmail(anon.getEmail());
                        sMgr.setUserName(anon.getRealName());
                    }
                    else
                    {
                        Log.error("Could not get anonymous user");
                    }
                }
                else
                {
                    setAsDetour(context);
                    context.put("action", "none");
                    redirectTo(myProperties.getProperty("loginServletName"));
                }
d243 3
a246 5

            // set up logging of user name in access_log
            HttpServletResponse response = context.getResponse();
            response.setHeader("HelmLoginID", sMgr.getLoginID());

a247 7
            //Populate the context with the appropriate host, domain,
            //and project objects.
            context.put("host", new Host());
            updateCurrentDomainAndProject(context, request);
            Domain currentDomain = getCurrentDomain(context);

            // User is logged in.  Build their business object and ACL.
d249 1
a249 6
            //Log.debug("loginUserID=" + loginUserID);
            loginUser = (User)session.getValue("loginUser");

            //If the user who logged in changed their personal information
            //or anything which would affect their User object, get that
            //User object again.
d255 1
a255 1
                 || !loginUser.getID().equals(loginUserID) 
d259 3
a261 1
                loginUser = UserPeer.getInstance(loginUserID);
a264 40
            
            AccessControlList acl = getACL(context, loginUserID);

            // If we've got a clickThroughPermission set up -- and if
            // they're not viewing the page showing it -- and if they don't
            // have the permission already -- then we'll need to redirect
            // them to the click through page.

            /**
             * FIXME: There's a reason this is commented out--we don't have the
             * click through permission servlet ported yet.             
            String clickThroughPermission = 
                myProperties.getProperty( "clickThroughPermission" );

            if (haveValue(clickThroughPermission))
            {
                String servlet = getServletName();
                String compulsoryClickThroughServlet =
                    myProperties.getProperty("compulsoryClickThrough");
                
                if (!servlet.equals(compulsoryClickThroughServlet))
                {
                    Log.debug("Click through check.");
                    if (!acl.hasPermission(clickThroughPermission,
                                                    currentDomain))
                    {
                        Log.debug("Redirecting to CompulsoryClickThrough");
                        setAsDetour(context);
                        redirectTo(compulsoryClickThroughServlet);
                    }
                }
            } else {
                User user = getLoginUser( context );
                if (!user.getACL().hasPermission("Click-through Page - Seen",
                currentDomain))
                {
                    user.setClickThroughAsViewed( currentDomain );
                }
            }
            */
d266 2
d269 3
a271 1
            // Check the base permission needed to access the servlet.
d276 7
a282 2
                Action action = ActionPeer.getInstanceByName(requiredAction);
                String type = action.getType();
d284 2
a285 1
                if (type.equals(Action.PROJECT_TYPE)) {
d287 8
a294 10
                    Log.debug("Checking permission for " + requiredAction);
                    acl.assertPermission(requiredAction,
                                                   currentProject);
                }
                else if (type.equals(Action.DOMAIN_TYPE)) {
                    acl.assertPermission(requiredAction, 
                                                  currentDomain);
                }
                else {
                    acl.assertPermission(requiredAction); 
d297 5
a301 10

            populatePagination(myProperties.getProperty("itemsPerPage"), 
                               context);
            populateFilter(context);

            populateBOs(context);
        }
        catch (ACLException aclEx)
        {
            try
d303 4
a306 9
                if (!loginUser.isAnonymous())
                {
                    appendToMessage
                        (context, "Your account does not have the necessary " +
                         "<a href=\"/servlets/ACLDump\">permissions</a> to access the page you requested. " +
                         "Either request more permission in project " +
                         getCurrentProject(context).getWordMark() +
                         ", or log in using a different account.");
                }
d308 4
a311 6
            catch (Exception e)
            {
                Log.error("Error handling ACLException user message: " +
                          e.getMessage());
            }
            throw aclEx;
d319 1
a319 1
            Log.warn("Unhandled exception encountered by HelmServlet", e);
d323 1
a323 9
        context.put("pageTitle", getPageTitle(context));
        context.put("servletHelp", new ServletHelp());

        // Put the template name into the session so that it will show
        // up on ListSessions.
        session.putValue("lastAction", getServletName());
        Log.debug("Lastaction: " + session.getValue("lastAction"));

        // Get the current date just before we return the template name.
d325 1
a325 205
        return templateName;
    }

    //
    // Context population methods
    //

    /**
     * Populates the context with information about the current
     * pagination page.
     */
    private void populatePagination(String itemProp, WebContext context)
    {

        // If pagination information is provided for this servlet,
        // put the number of items desired per page into the context.
        Integer itemsPerPage;
        if (itemProp == null) {
            itemsPerPage = new Integer(20);
        }
        else {
            Log.debug("itemProp: " + itemProp);
            itemsPerPage = new Integer(Integer.parseInt(itemProp));
        }            
        context.put("itemsPerPage", itemsPerPage);

        String pageStr = context.getForm("paginated_page");
        Integer page;
        if (pageStr == null) 
        {
            page = new Integer(1);
        } else {
            page = new Integer(Integer.parseInt(pageStr));
        }           
        context.put("paginated_page", page);
    }

    /**
     * Populates the context with information about the current
     * filter settings.
     * TODO: Port this.
     */
    private void populateFilter(WebContext context)
    {
        // Put a reference to the context into the context--the
        // complex filter template needs this.
        context.put("context", context);

        Log.debug("In populateFilter.");
                
        Criteria filter = new Criteria();
        
        // Divine the filter criteria requested.

        //If they're using the simple form, make a trojan Criteria with
        //this information smuggled into it. PeerBackedList will expand
        //it into a properly ORed Criteria.
        String simpleFilterValue = 
            context.getForm(PeerBackedList.SIMPLE_FILTER_VALUE);        
        if (simpleFilterValue != null && !simpleFilterValue.equals(""))
        {
            filter.add(PeerBackedList.SIMPLE_FILTER_VALUE, simpleFilterValue);
        } else if (context.getForm(PeerBackedList.FILTER_CHECK) != null) {
            /*//They're using the big form--get parameter names. This is all TODO.
            Enumeration paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements ())
            {
                String paramName = (String)paramNames.nextElement();
                
                if (paramName.startsWith(PeerBackedList.FILTER_VALUE))
                {
                    StringTokenizer tok = 
                        new StringTokenizer(paramName, "/");
                    tok.nextToken();
                    String filterFieldName = tok.nextToken();
                    String filterValue = 
                        context.getForm(paramName);
                    if (!filterValue.equals(""))
                    {
                        context.put(paramName, filterValue);
                        String filterMatchType = 
                            context.getForm(PeerBackedList.cgiKey
                                            (PeerBackedList.FILTER_MATCHTYPE,
                                             filterFieldName));
                             criteria.add(newCrit);
                    }
                }
                }*/
        }
        Log.info("Initial filter: " + filter);
        context.put("filter", filter);
    }
    

    /**
     * Populate the context with whichever business objects are specified.
     */
    public void populateBOs(WebContext context)
        throws Exception
    {
        // The operative user (for this request). Defaults to the
        // logged-in user so that if you hit, eg. UserEdit without
        // specifying a user ID, it defaults to editing yourself.
        String currentUserID = getServletParam(context, "userID");
        if (haveValue(currentUserID)) {
            context.put("currentUser", 
                        UserPeer.getInstance(currentUserID));
        }
        else 
        {
            context.put("currentUser", getLoginUser(context));
        }
        
        String currentUserGroupID = getServletParam(context, 
                                                    "userGroupID");
        if (haveValue(currentUserGroupID))
        {
            context.put("currentUserGroup", 
                        UserPeer.getGroupInstance(currentUserGroupID));
        }            
        
        String currentProjectGroupID = getServletParam(context, 
                                                       "projectGroupID");
        if (haveValue(currentProjectGroupID))
        {                
            context.put
                ("currentProjectGroup",
                 ProjectPeer.getGroupInstance(currentProjectGroupID));
        }
        
        String currentRoleID = getServletParam(context, "roleID");
        if (haveValue(currentRoleID))
        {
            context.put("currentRole",
                        RolePeer.getInstance(currentRoleID));
        }
        
        String currentResourceID = getServletParam(context, "resourceID");
        if (haveValue(currentResourceID))
        {
            context.put("currentResource", 
                        ResourcePeer.getInstance(currentResourceID));
        }
        
        String currentAuditLogEntryID = getServletParam(context,
                                                        "auditLogEntryID");
        if (haveValue(currentAuditLogEntryID))
        {
            context.put
                ("currentAuditLogEntry", 
                 AuditLogEntryPeer.getInstance(currentAuditLogEntryID));
        }
    }

    /** 
     * Update current domain and project in the context. These can be
     * specified in the following ways:
     * <ul>
     * <il>1. ID in the query string (e.g., passed from prev servlet)
     * <il>2. Project  or domain name in the query string (e.g., passed
     *     from a rewrite rule)
     * <il>3. Request server name matches project URL alias
     * <il>4. Standard vhosting: project.domain
     * <il>5. default to www project in domain matching request server name
     * </ul>
     *
     * @@param ctx  The context.
     * @@param req  The HTTP request.
     */

    protected void updateCurrentDomainAndProject(WebContext ctx,
                                                 HttpServletRequest req) 
        throws Exception
    {
        BitSet serverNameMatchedDomain = new BitSet(1);
        Domain reqDom = getRequestedDomain(ctx, req, serverNameMatchedDomain);
        Project reqProj = getRequestedProject(ctx, req, reqDom,
                                              serverNameMatchedDomain.get(0));
        boolean forceCurrentProjectChange = false;

        // See if domain changed.
        Domain curDomain = getCurrentDomain(ctx);
        if (curDomain == null || !reqDom.getID().equals(curDomain.getID())) {
            curDomain = reqDom;
            ctx.put("currentDomain", curDomain);
            Log.debug("Setting current domain: " + curDomain.getName());
            // Changing domains forces project change.
            forceCurrentProjectChange = true;
        }

        // See if project changed.
        Project curProj = getCurrentProject(ctx);
        if (forceCurrentProjectChange || curProj == null ||
            !reqProj.getID().equals(curProj.getID())) {
            curProj = reqProj;
            Log.debug("Setting current project: " + curProj.getName());
            ctx.put("currentProject", curProj);

            //TODO: Set the project's skin as well.
//             Skin skin = curProj.getSkin();
//             if (skin != null)
//             {
//                 ctx.put("skin", skin);
//             }
        }
a327 5

    //
    // Accessor methods; usually aliasing context.get().
    //

d351 1
a351 19
     * @@see org.tigris.helm.security.HelmServlet#getACL(WebContext, User)
     */
    protected final AccessControlList getACL(WebContext ctx)
        throws Exception
    {
        return getACL(ctx, getSessionManager(ctx).getUserID());
    }

    /**
     * @@deprecated Use getACL(WebContext ctx) instead.
     */
    protected final AccessControlList getACL(WebContext ctx, Connection conn)
        throws Exception
    {
        return getACL(ctx);
    }

    /**
     * @@deprecated Use getACL(WebContext ctx, String userID) instead.
d353 2
a354 3
    protected AccessControlList getACL(WebContext ctx, Connection c,
                                       String userID)
        throws Exception
d356 1
a356 1
        return getACL(ctx, userID);
d365 1
a367 1
     * @@param userID  The database key of the user to get the ACL for.
d369 8
a376 6
    protected AccessControlList getACL(WebContext ctx, String userID)
        throws Exception
    {
        AccessControlList acl =
            AccessControlList.getACL(UserPeer.getInstance(userID));
        ctx.put("acl", acl);
a380 11
     * Gets the host.
     *
     * @@param context The context to grab the host from
     * @@return a Host
     */
    protected final Host getHost (WebContext ctx)
    {
        return (Host) ctx.get("host");
    }

    /**
a414 8
     * 
     * Note, this is not the currently logged in user.  Use getLoginUser
     * for that.  getCurrentUser returns the user who has been
     * designated for manipulation in some way (eg. by UserEdit).
     * 
     * Just to confuse things more, this -does- return the logged in
     * user if no user is specified, since the logged-in user is
     * also the default action user.
a417 3
     *
     * @@see org.tigris.helm.domain.UserEdit
     * @@see #getLoginUser
d425 19
a443 5
     * Gets the user group to be operated on.
     * 
     * @@param context The context to grab the user group from
     * @@return a UserGroup
     *
d445 2
a446 1
    protected final UserGroup getCurrentUserGroup (WebContext context)
d448 1
a448 1
        return (UserGroup) context.get("currentUserGroup");
d452 7
a458 4
     * Gets the project group to be operated on.
     * 
     * @@param context The context to grab the project group from
     * @@return a ProjectGroup
d460 14
a473 2
     */
    protected final ProjectGroup getCurrentProjectGroup (WebContext context)
d475 12
a486 1
        return (ProjectGroup) context.get("currentProjectGroup");
d490 4
a493 1
     * Gets the current Role to be operated on.
d495 3
a497 2
     * @@param context The context to grab the role from
     * @@return a Role
d499 2
a500 1
    protected final Role getCurrentRole(WebContext context)
d502 7
a508 1
        return (Role)context.get("currentRole");
d512 3
a514 1
     * Gets the current Resource to be operated on.
d516 3
a518 2
     * @@param context The context to grab the Resource from
     * @@return a Resource
d520 2
a521 1
    protected final Resource getCurrentResource(WebContext context)
d523 2
a524 1
        return (Resource)context.get("currentResource");
d528 3
a530 1
     * Gets the current AuditLogEntry to be operated on.
d532 3
a534 2
     * @@param context The context to grab the AuditLogEntry from
     * @@return an AuditLogEntry
d536 3
a538 1
    protected final AuditLogEntry getCurrentAuditLogEntry(WebContext context)
d540 10
a549 1
        return (AuditLogEntry)context.get("currentAuditLogEntry");
d556 3
a558 3
     * @@param    permissionName    The name of the required permission.
     * @@param    userPermissions   The set of permissions possessed by the user.
     * @@return                      Whether the accessing user is allowed access.
d563 1
a563 1
        return (userPermissions != null ? 
d568 3
a570 17
    /** Show a useful title for this page.  
     *
     * Subclasses can override to show specific details like a user name or 
     * project name.   
     * <p>
     * Note, the super-class UnsecureServlet has a mechanism for
     * setting the page HTML &lt?TITLE>.  If a servlet defines a property 
     * 'displayName' in its property file, UnsecureServlet picks up this 
     * property and automatically adds it to the context for use by 
     * templates setting the HTML HEAD &lt;TITLE>.  The below method's default
     * behaviour is to use the displayName value put in the context by the 
     * parent UnsecureServlet class.
     * 
     * @@param context WebMacro context
     * 
     * @@return The value of the 'displayName' property from servlet property 
     * file.  If that is not present, returns the servletName property.
d582 51
a632 21
    /**
     * Returns the requested domain.
     *
     * @@param ctx                     The context.
     * @@param req                     The HTTP request.
     * @@param serverNameMatchedDomain A boolean output parameter.
     */
    private Domain getRequestedDomain (WebContext ctx, HttpServletRequest req,
                                       BitSet serverNameMatchedDomain)
        throws Exception
    {
        Domain reqDom = null;
        String reqDomID = getServletParam(ctx, "domainID");
        if (reqDomID != null) {
            reqDom = DomainPeer.getInstance(reqDomID);
        }
        else {
            // Determine the name of the requested domain to infer its ID.
            String reqDomName = getServletParam(ctx, "domainName");
            if (reqDomName == null) {
                reqDomName = req.getServerName();
d634 28
d663 16
a678 25
            try {
                reqDom = DomainPeer.getInstanceByName(reqDomName);
                serverNameMatchedDomain.set(0);
                Log.debug("serverNameMatchedDomain.get(0)=" +
                          serverNameMatchedDomain.get(0));
            }
            catch (Exception e) {
                Log.debug("Not a match: reqDomName=" + reqDomName);
                int dot = reqDomName.indexOf('.');
                if (dot != -1) {
                    // Try once more using non-vhosted name.
                    String domainNoVhost = reqDomName.substring(dot + 1);
                    Log.debug("Trying URL alias: domainNoVhost=" +
                              domainNoVhost);
                    try {
                        reqDom = DomainPeer.getInstanceByName(domainNoVhost);
                    }
                    catch (Exception f) 
                    {
                        Log.error("Could not get domain via URL alias.", f);
                    }
                }
                else {
                    Log.error("Could not parse domain from vhost");
                }
a680 1
        return reqDom;
d683 13
a695 31
    /**
     * Returns the requested project.
     *
     * @@param ctx                     The context.
     * @@param req                     The HTTP request.
     * @@param reqDom                  The requested domain.
     * @@param serverNameMatchedDomain Whether vhosted.
     */
    private Project getRequestedProject(WebContext ctx, 
                                        HttpServletRequest req, 
                                        Domain reqDom,
                                        boolean serverNameMatchedDomain)
        throws Exception
    {
        Log.debug("Calling getRequestedProject()");
        Project reqProj = null;
        String reqProjID = getServletParam(ctx, "projectID");
        if (!haveValue(reqProjID)) {
            try {
                Log.debug("Trying URL alias...");
                reqProj = ProjectPeer.getInstanceByAliasURL
                    (reqDom, req.getServerName());
                Log.debug("Using URL alias");
            }
            catch (Exception e) {
                Log.debug("Trying projectName...");
                String reqProjName = getServletParam(ctx, "projectName");
                if (reqProjName != null) {
                    reqProj = getProjectByName(reqProjName, reqDom);
                }
            }
d697 9
a705 15
            Log.debug("serverNameMatchedDomain=" + serverNameMatchedDomain);
            if (reqProj == null && !serverNameMatchedDomain) {
                Log.debug("Assuming vhosted...");
                String vhost = req.getServerName();
                vhost = vhost.substring(0, vhost.indexOf('.'));
                Log.debug("vhost=" + vhost);
                reqProj = getProjectByName(vhost, reqDom);
            }

            if (reqProj == null) {
                Log.debug("Using default project: " +
                          ProjectPeer.DEFAULT_PROJECT_NAME);
                reqProj = getProjectByName(ProjectPeer.DEFAULT_PROJECT_NAME, 
                                           reqDom);
            }
d707 2
a708 2
        else {
            reqProj = ProjectPeer.getInstance(reqProjID);
d710 1
a710 1
        return reqProj;
d713 1
a713 4
    /**
     * Returns the named project in the specified domain.
     */
    private Project getProjectByName (String projectName, Domain domain)
d716 1
a716 1
        Project project = null;
d718 3
a720 3
            Log.debug("Looking up project: Project named " + projectName + 
                      " and domain named " + domain.getName());
            project = ProjectPeer.getInstanceByName(domain, projectName);
d723 1
a723 1
            Log.error("Project not found: projectName=" + projectName, e);
d725 14
a738 1
        return project;
@

