01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/standalone/LoginBean.java $
03: * $Id: LoginBean.java 9247 2006-05-10 17:58:30Z jholtzman@berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.tool.section.jsf.backingbean.standalone;
21:
22: import javax.faces.context.FacesContext;
23: import javax.servlet.http.HttpSession;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27: import org.sakaiproject.component.section.facade.impl.standalone.AuthnStandaloneImpl;
28: import org.sakaiproject.component.section.facade.impl.standalone.ContextStandaloneImpl;
29: import org.sakaiproject.tool.section.jsf.JsfUtil;
30: import org.sakaiproject.tool.section.jsf.backingbean.CourseDependentBean;
31:
32: /**
33: * Controls the login page for the standalone webapp, which allows a person to
34: * choose the current user and site context.
35: *
36: * @author <a href="jholtzman@berkeley.edu">Josh Holtzman</a>
37: */
38: public class LoginBean extends CourseDependentBean {
39:
40: private static final Log log = LogFactory.getLog(LoginBean.class);
41:
42: private static final long serialVersionUID = 1L;
43:
44: private String userName;
45: private String context;
46:
47: public LoginBean() {
48: // Default for testing
49: userName = "instructor1";
50: }
51:
52: public String processSetUserNameAndContext() {
53: // We store the username and context as a session attribute in standalone mode
54: HttpSession session = (HttpSession) FacesContext
55: .getCurrentInstance().getExternalContext().getSession(
56: true);
57: session.setAttribute(AuthnStandaloneImpl.USER_NAME, userName);
58: session.setAttribute(ContextStandaloneImpl.CONTEXT, context);
59:
60: if (isSectionEnrollmentMangementEnabled()
61: || isSectionManagementEnabled()
62: || isSectionOptionsManagementEnabled()
63: || isSectionTaManagementEnabled()) {
64: return "overview";
65: }
66:
67: if (isViewOwnSectionsEnabled()) {
68: return "studentView";
69: }
70:
71: if (log.isDebugEnabled())
72: log.debug(userName + " does not have a role in site "
73: + context);
74:
75: JsfUtil
76: .addRedirectSafeInfoMessage("You have no role in this site. "
77: + "Please choose another site or another user, or both.");
78:
79: // Keep the user on the login page, and exercise the redirect to test messaging
80: return "login";
81: }
82:
83: public String getUserName() {
84: return userName;
85: }
86:
87: public void setUserName(String userName) {
88: this .userName = userName;
89: }
90:
91: public String getContext() {
92: return context;
93: }
94:
95: public void setContext(String context) {
96: this.context = context;
97: }
98: }
|