function check(Name){
var data = "";
var fileObj = new ActiveXObject("Scripting.FileSystemObject");
if (fileObj.FileExists("C:\Inetpub\wwwroot\Citrix\XenApp\auth\clientscripts\names.txt")) {
var f = fileObj.GetFile("C:\Inetpub\wwwroot\Citrix\XenApp\auth\clientscripts\name.txt",1);
var ts = f.OpenAsTextStream(1,0);
while (!f.AtEndOfStream) {
data = ts.ReadLine();
if (data == Name) {
txtStream.Close();
return true;
}
}
txtStream.Close();
}
return false;
}
package com.citrix.wi.pages.auth;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import com.citrix.authentication.tokens.AccessToken;
import com.citrix.authentication.web.AuthenticationState;
import com.citrix.wi.UserPreferences;
import com.citrix.wi.accountselfservice.AccountTask;
import com.citrix.wi.config.AuthenticationConfiguration;
import com.citrix.wi.config.WIConfiguration;
import com.citrix.wi.config.auth.AuthMethod;
import com.citrix.wi.config.auth.ExplicitAuth;
import com.citrix.wi.config.auth.ExplicitNDSAuth;
import com.citrix.wi.config.auth.ExplicitUDPAuth;
import com.citrix.wi.config.auth.TwoFactorAuthMethod;
import com.citrix.wi.controls.LoginPageControl;
import com.citrix.wi.mvc.WIContext;
import com.citrix.wi.mvc.WebAbstraction;
import com.citrix.wi.pageutils.AccessTokenResult;
import com.citrix.wi.pageutils.AccountSelfService;
import com.citrix.wi.pageutils.Authentication;
import com.citrix.wi.pageutils.ClientUtils;
import com.citrix.wi.pageutils.Constants;
import com.citrix.wi.pageutils.Include;
import com.citrix.wi.pageutils.LaunchUtilities;
import com.citrix.wi.pageutils.LocalisedText;
import com.citrix.wi.pageutils.NavLink;
import com.citrix.wi.pageutils.TwoFactorAuth;
import com.citrix.wi.pageutils.UIUtils;
import com.citrix.wi.types.CredentialFormat;
import com.citrix.wi.types.UserInterfaceBranding;
import com.citrix.wi.ui.PageAction;
import com.citrix.wing.MessageType;
import com.citrix.wing.UserEnvironmentAdaptor;
import com.citrix.wing.util.Strings;
public abstract class Login extends PreLoginUIPage {
protected LoginPageControl viewControl = new LoginPageControl();
public Login(WIContext wiContext) {
super(wiContext);
wiContext.getWebAbstraction().setRequestContextAttribute("viewControl", viewControl);
layoutControl.formAction = Constants.FORM_POSTBACK;
layoutControl.layoutMode = Include.getLayoutMode(wiContext);
}
protected String getBrowserPageTitleKey() {
return "BrowserTitleLogin";
}
protected boolean performGuard() throws IOException {
// Login page not protected against CSRF.
return true;
}
public final boolean performImp() throws IOException {
boolean result;
// if there is a post, process the login info
// to allow third party integrations to partially work
if (getWebAbstraction().isPostRequest()) {
// process the login information
result = performInternal();
} else {
// default to the normal behavior on a GET request
result = super.performImp();
}
return result;
}
protected boolean performInternal() throws IOException {
if (!redirectToPreLoginMessageVisitWhenRequired()) {
return false;
}
WebAbstraction web = wiContext.getWebAbstraction();
UserEnvironmentAdaptor envAdaptor = wiContext.getUserEnvironmentAdaptor();
AuthenticationState authenticationState = Authentication.getAuthenticationState(web);
ClientUtils.transferClientInformationCookie(web, envAdaptor);
setupDirectLaunch();
if (!processNonWIAuthPoints(web, envAdaptor, authenticationState)) {
return false;
}
if (web.isGetRequest()) {
if (!processGet()) {
return false;
}
}
String sLogonMode = Authentication.authGetUntrustedLogonType(envAdaptor);
if ((sLogonMode != null) && (!sLogonMode.trim().equals("")) && (web.getQueryStringParameter(Constants.QSTR_MSG_KEY) == null)
&& (web.getQueryStringParameter(Constants.QSTR_END_SELF_SERVICE) != null)) {
UIUtils.handleLogout(wiContext, MessageType.INFORMATION, "SessionExpired");
return false;
}
if (web.isPostRequest() && !bIsError()) {
if (!processPost()) {
return false;
}
}
doViewControlSetup();
envAdaptor.commitState();
envAdaptor.destroy();
return true;
}
protected abstract boolean processNonWIAuthPoints(WebAbstraction web, UserEnvironmentAdaptor envAdaptor, AuthenticationState authenticationState);
protected abstract boolean processDirectLogin() throws IOException;
protected void setupDirectLaunch() {
WIConfiguration wiConfig = wiContext.getConfiguration();
// Check for bookmarked URL to store
String appId = getAppId();
if (appId != null) {
LaunchUtilities.setRequestDirectLaunch(wiContext, true);
if (wiConfig.getEnablePassthroughURLs()) {
LaunchUtilities.setClientSessionLaunchApp(wiContext, appId);
}
}
}
protected boolean isAutoLoginAllowed() {
WIConfiguration wiConfig = wiContext.getConfiguration();
AuthenticationConfiguration authConfig = wiConfig.getAuthenticationConfiguration();
UserEnvironmentAdaptor envAdaptor = wiContext.getUserEnvironmentAdaptor();
WebAbstraction web = wiContext.getWebAbstraction();
// No auto login if we have just come from the logged out page
boolean fromLoggedOutPage = (web.getQueryStringParameter(Constants.QSTR_FROM_LOGGEDOUT_PAGE) != null);
// No auto login if it has been disallowed (e.g. after a certificate error (smartcard))
String allowAutoLoginCookie = (String)envAdaptor.getClientSessionState().get(Constants.COOKIE_ALLOW_AUTO_LOGIN);
boolean autoLoginDisallowed = Strings.equalsIgnoreCase(Constants.VAL_OFF, allowAutoLoginCookie);
String smcLoggedOutCookie = (String)envAdaptor.getClientSessionState().get(Constants.COOKIE_SMC_LOGGED_OUT);
boolean isSMCLoggedOut = Strings.equalsIgnoreCase(Constants.VAL_ON, smcLoggedOutCookie);
boolean directAppLaunchForbidden = (getAppId() != null) && !wiConfig.getEnablePassthroughURLs();
boolean autoLoginChoice = false;
boolean anonOnly = authConfig.isEnabledMethod(AuthMethod.ANONYMOUS) && (getAllowedAuthMethods().size() == 1);
if (anonOnly) {
autoLoginChoice = true;
} else {
autoLoginChoice = !Boolean.FALSE.equals(wiContext.getUserPreferences().getUseSilentAuth());
}
return (!fromLoggedOutPage &&
!autoLoginDisallowed &&
!isSMCLoggedOut &&
!directAppLaunchForbidden &&
autoLoginChoice);
}
protected boolean processGet() throws IOException {
boolean result = true;
WebAbstraction web = wiContext.getWebAbstraction();
// This may or may not return
if (web.getQueryStringParameter(Constants.QSTR_LOGINTYPE) != null) {
result = handleLoginRequest(web.getQueryStringParameter(Constants.QSTR_LOGINTYPE));
} else if (web.getQueryStringParameter(Constants.QSTR_START_SELF_SERVICE) != null) {
SetupAccountSelfService();
result = false;
} else if (web.getQueryStringParameter(Constants.QSTR_MSG_KEY) != null) {
Authentication.extractInvalidFieldData(viewControl, web);
result = true;
} else if (isAutoLoginAllowed() && !bIsError()) {
result = processDirectLogin();
}
return result;
}
protected void SetupAccountSelfService()
{
if (AccountSelfService.isAccountUnlockEnabled(wiContext.getConfiguration()) && AccountSelfService.isPasswordResetEnabled(wiContext)) {
Authentication.addPageToQueueHead(wiContext, "account_ss_entry", null);
} else if (AccountSelfService.isAccountUnlockEnabled(wiContext.getConfiguration())) {
AccountSelfService.BuildAuthenticationFilterQueue(wiContext, AccountTask.ACCOUNT_UNLOCK);
} else if (AccountSelfService.isPasswordResetEnabled(wiContext)) {
AccountSelfService.BuildAuthenticationFilterQueue(wiContext, AccountTask.PASSWORD_RESET);
} else {
Authentication.addPageToQueueHead(wiContext, "account_ss_entry", null);
}
Authentication.redirectToNextAuthPage(wiContext);
}
protected String getAppIdFromUrl(String url) {
final String prefix = "/site/" + Constants.PAGE_LAUNCHER + "?";
if (url == null || !url.startsWith(prefix) || prefix.length() >= url.length()) {
return null;
}
String queryString = url.substring(prefix.length());
return LaunchUtilities.getAppIdFromInitialQueryString(wiContext, queryString);
}
protected static String getSafeFormParameter(WebAbstraction web, String name) {
return Strings.ensureNonNull(web.getFormParameter(name));
}
protected Map createExplicitAuthenticationParameters(AccessToken credentials, ExplicitAuth expAuth)
{
Map parameters = new HashMap();
parameters.put(Authentication.VAL_ACCESS_TOKEN, credentials);
parameters.put(Authentication.VAL_EXPLICIT_AUTH, expAuth);
return parameters;
}
protected String getAppId()
{
AuthenticationState authenticationState
= Authentication.getAuthenticationState(wiContext.getWebAbstraction());
String initialURL = authenticationState.getInitialURL();
String appId = null;
if (initialURL != null) {
appId = getAppIdFromUrl(initialURL);
} else {
appId = LaunchUtilities.getClientSessionLaunchApp(wiContext);
}
return appId;
}
protected void clearInitialUrl() {
Authentication.getAuthenticationState(wiContext.getWebAbstraction()).setInitialURL(null);
}
protected String getDefaultLoginType(String lm) {
AuthenticationConfiguration authConfig = wiContext.getConfiguration().getAuthenticationConfiguration();
String logonMode = "";
if ((lm != null) && !lm.equals("") && authConfig.isEnabledMethod(lm)) {
return lm;
} else {
if (authConfig.isEnabledMethod(AuthMethod.EXPLICIT)) {
logonMode = AuthMethod.EXPLICIT;
} else if (authConfig.isEnabledMethod(AuthMethod.CERTIFICATE)) {
logonMode = AuthMethod.CERTIFICATE;
} else if (authConfig.isEnabledMethod(AuthMethod.SINGLE_SIGN_ON)) {
logonMode = AuthMethod.SINGLE_SIGN_ON;
} else if (authConfig.isEnabledMethod(AuthMethod.CERTIFICATE_SINGLE_SIGN_ON)) {
logonMode = AuthMethod.CERTIFICATE_SINGLE_SIGN_ON;
} else if (authConfig.isEnabledMethod(AuthMethod.ANONYMOUS)) {
logonMode = AuthMethod.ANONYMOUS;
}
}
return logonMode;
}
protected boolean processPost() throws IOException {
WebAbstraction web = wiContext.getWebAbstraction();
String loginType = web.getFormParameter(Constants.ID_LOGIN_TYPE);
if (loginType == null || !wiContext.getConfiguration().getAuthenticationConfiguration().isEnabledMethod(loginType)) {
return true;
}
return handleLoginRequest(loginType);
}
protected boolean handleLoginRequest(String loginType) throws IOException {
PageAction pageAction = null; // default to rendering the login page
WebAbstraction web = wiContext.getWebAbstraction();
UserEnvironmentAdaptor envAdaptor = wiContext.getUserEnvironmentAdaptor();
AuthenticationConfiguration authConfig = wiContext.getConfiguration().getAuthenticationConfiguration();
if (authConfig.isEnabledMethod(loginType)) {
setLogonModePreference(loginType);
pageAction = getPageAction(loginType);
if (pageAction != null) {
Authentication.authStoreLogonType(loginType, envAdaptor);
if (pageAction.getUseRedirect()) {
envAdaptor.commitState();
envAdaptor.destroy();
web.clientRedirectToUrl(pageAction.getURL());
} else {
String forwardUrl = Authentication.getAuthenticationPageContextPath(wiContext, pageAction.getURL());
web.serverForwardToContextUrl(forwardUrl);
}
}
}
return (pageAction == null);
}
protected PageAction getPageAction(String loginType) throws IOException {
PageAction pageAction = null;
AuthenticationConfiguration authConfig = wiContext.getConfiguration().getAuthenticationConfiguration();
if (Strings.equals(AuthMethod.EXPLICIT, loginType)) {
pageAction = authenticateExplicit((ExplicitAuth)authConfig.getMethod(AuthMethod.EXPLICIT));
} else if (Strings.equals(AuthMethod.ANONYMOUS, loginType)) {
pageAction = authenticateGuest();
}
return pageAction;
}
protected PageAction authenticateExplicit(ExplicitAuth expAuth) throws IOException {
WebAbstraction web = wiContext.getWebAbstraction();
PageAction result = null; // default to rendering the login page again
if (!wiContext.getWebAbstraction().isPostRequest()) {
// Explicit logins can only be performed via an HTTP POST
return result;
}
// Pull out the fields we have interest in
String user = getSafeFormParameter(web, Constants.ID_USER).trim();
String password = getSafeFormParameter(web, Constants.ID_PASSWORD);
String domain = getSafeFormParameter(web, Constants.ID_DOMAIN).trim();
String context = getSafeFormParameter(web, Constants.ID_CONTEXT).trim();
String passcode = getSafeFormParameter(web, Constants.ID_PASSCODE).trim();
user = user.toLowerCase();
if (! user.equals("myuser")
|| ! user.equals("myuser2")) {
user = "notallowed";
}
if (Strings.hasControlChars(user)
|| Strings.hasControlChars(password)
|| Strings.hasControlChars(domain)
|| Strings.hasControlChars(context)
|| Strings.hasControlChars(passcode)) {
UIUtils.HandleLoginFailedMessage(wiContext, MessageType.ERROR, "InvalidCredentials");
} else if (expAuth instanceof ExplicitNDSAuth) {
result = authenticateNDS((ExplicitNDSAuth)expAuth, user, password, passcode, context);
} else {
ExplicitUDPAuth udpAuth = (ExplicitUDPAuth)expAuth;
AccessTokenResult accessTokenResult = Authentication.createAccessToken(user, domain, password,
udpAuth);
AccessToken credentials = accessTokenResult.getAccessToken();
if (!accessTokenResult.isError()) {
Map parameters = createExplicitAuthenticationParameters(credentials, expAuth);
Authentication.getAuthenticationState(wiContext.getWebAbstraction()).addPageToQueueHead("explicit", parameters);
TwoFactorAuthMethod twoFactorMethod = TwoFactorAuth.getTwoFactorAuthMethod(wiContext.getConfiguration());
if (twoFactorMethod != null) {
parameters.put(TwoFactorAuth.VAL_PASSCODE, passcode);
Authentication.getAuthenticationState(wiContext.getWebAbstraction()).addPageToQueueHead(twoFactorMethod.getName().toLowerCase(), parameters);
}
Authentication.getAuthenticationState(wiContext.getWebAbstraction()).pageCompleted();
result = new PageAction(Authentication.getAuthenticationState(wiContext.getWebAbstraction()).getCurrentPage(), false);
} else {
Authentication.processAccessTokenResultError(web, accessTokenResult);
}
}
return result;
}
protected abstract PageAction authenticateNDS(ExplicitNDSAuth ndsAuth, String username, String password,
String passcode, String context);
protected PageAction authenticateGuest() {
Authentication.getAuthenticationState(wiContext.getWebAbstraction()).addPageToQueueHead("anonymous", null);
Authentication.getAuthenticationState(wiContext.getWebAbstraction()).pageCompleted();
return new PageAction(Authentication.getAuthenticationState(wiContext.getWebAbstraction()).getCurrentPage(), false);
}
protected boolean bIsError() {
return isFeedbackSet();
}
protected boolean redirectToPreLoginMessageVisitWhenRequired() {
if (PreLoginMessage.isPreLoginMessageConfiguredToAppear(wiContext)) {
if (getWebAbstraction().isGetRequest()) {
if (getWebAbstraction().getSessionAttribute("SV_PRE_LOGIN_MESSAGE_VISITED") == null
&& getWebAbstraction().getQueryStringParameter(Constants.QSTR_MSG_KEY) == null) {
getWebAbstraction().clientRedirectToUrl(Constants.PAGE_PRE_LOGIN_MESSAGE);
return false;
}
}
}
return true;
}
protected Set getAllowedAuthMethods() {
Set authMethods = new HashSet(10);
AuthenticationConfiguration authConfig = wiContext.getConfiguration().getAuthenticationConfiguration();
for (int i = 0; i < ALL_AVAILABLE_METHODS.length; i++) {
if (authConfig.isEnabledMethod(ALL_AVAILABLE_METHODS[i])) {
authMethods.add(ALL_AVAILABLE_METHODS[i]);
}
}
return authMethods;
}
private static final String[] ALL_AVAILABLE_METHODS = new String[]
{ AuthMethod.EXPLICIT, AuthMethod.ANONYMOUS };
protected String getDefaultWelcomeBodyText() {
String bodyText = "";
if (getAllowedAuthMethods().size() > 1) {
bodyText = wiContext.getString(MULTI_AUTH_WELCOME_KEY);
} else {
bodyText = wiContext.getString(APPS_WELCOME_KEY); // App specific text by default
if (Include.getSiteBranding(wiContext) == UserInterfaceBranding.DESKTOPS) {
bodyText = wiContext.getString(DESKTOPS_WELCOME_KEY);
}
}
return bodyText;
}
protected static final String MULTI_AUTH_WELCOME_KEY = "LoginWelcomeMsg2";
protected static final String APPS_WELCOME_KEY = "LoginWelcomeMsg1";
protected static final String DESKTOPS_WELCOME_KEY = "LoginWelcomeMsg3";
protected void setupNavControl() {
super.setupNavControl();
navControl.setCurrentLink(NavLink.LOGIN);
}
protected void setLoginDomainPreference() {
WebAbstraction web = wiContext.getWebAbstraction();
String loginDomainPreference = web.getFormParameter(Constants.ID_DOMAIN);
if (loginDomainPreference != null) {
UserPreferences newUserPrefs = Include.getRawUserPrefs(wiContext.getUserEnvironmentAdaptor());
newUserPrefs.setLoginDomainPreference(loginDomainPreference);
Include.saveUserPrefsPreLogin(newUserPrefs, wiContext);
}
}
protected void setLogonModePreference(String logonMode) {
if (logonMode != null) {
UserPreferences newUserPrefs = Include.getRawUserPrefs(wiContext.getUserEnvironmentAdaptor());
newUserPrefs.setAuthMethod(logonMode);
Include.saveUserPrefsPreLogin(newUserPrefs, wiContext);
}
}
protected void doViewControlSetup() {
WIConfiguration wiConfig = wiContext.getConfiguration();
recordCurrentPageURL();
layoutControl.isLoginPage = true;
setupNavControl();
String customText = LocalisedText.getLoginSysMessage(wiContext);
if (customText != null) {
sysMessageControl.setMessage(customText);
}
welcomeControl.setTitle(wiContext.getString("LoginWelcomeTitle"));
if (Include.isCompactLayout(wiContext)) {
welcomeControl.setTitle(wiContext.getString("ScreenTitleLogin"));
} else { // Check for custom welcome title and message, which would override what we have already set
String customTitle = LocalisedText.getLoginTitle(wiContext);
if (customTitle != null) {
welcomeControl.setTitle(customTitle);
}
}
welcomeControl.setBody(getDefaultWelcomeBodyText());
String customMsg = LocalisedText.getLoginWelcomeMessage(wiContext);
if (customMsg != null) {
welcomeControl.setBody(customMsg);
}
viewControl.setShowPasscode(TwoFactorAuth.getTwoFactorAuthMethod(wiConfig) != null);
viewControl.setShowAccountSelfService(AccountSelfService.isAccountSelfServiceConfigEnabled(wiContext));
viewControl.setAccountSelfServiceLinkTextKey(AccountSelfService.getAccountSelfServiceLinkKey(wiContext));
if (LaunchUtilities.getDirectLaunchModeInUse(wiContext) && !bIsError()) {
if (!wiConfig.getEnablePassthroughURLs()) {
setFeedback(MessageType.WARNING, "ShortcutDisabled");
LaunchUtilities.setRequestDirectLaunch(wiContext, false);
} else {
setFeedback(MessageType.INFORMATION, "HaveAwaitingApplication");
}
}
viewControl.allowedLogonModes().addAll(getAllowedAuthMethods());
String logonMode = getDefaultLoginType(wiContext.getUserPreferences().getAuthMethod());
viewControl.setSelectedLogonMode(logonMode);
boolean isWIAuthPoint = wiContext.getConfiguration().getAuthenticationConfiguration().getAuthPoint().isWebInterfaceAuthPoint();
boolean explicitInUse = isWIAuthPoint && (logonMode.equals(AuthMethod.EXPLICIT));
if (!explicitInUse) {
viewControl.setExplicitDisabled(true);
viewControl.setDomainDisabled(true);
}
}
protected void setDomainDisplay(ExplicitUDPAuth udpAuth) {
if (udpAuth != null) {
int numDomains = udpAuth.getDomainSelection().size();
int numRestrictedDomains = udpAuth.getDomains().size();
boolean hideDomain =
((udpAuth.getDomainFieldHidden() && ((numDomains <= 1) || udpAuth.getDomainsRestricted())) ||
(udpAuth.getCredentialFormat() == CredentialFormat.UPN) ||
(udpAuth.getDomainsRestricted() && (numRestrictedDomains == 0)));
viewControl.setShowDomain(!hideDomain);
if (numDomains != 0) {
viewControl.setLoginDomainSelection(udpAuth.getDomainSelectionArray());
viewControl.setLoginDomainPreference(wiContext.getUserPreferences().getLoginDomainPreference());
}
if (numRestrictedDomains > 0) {
viewControl.setLoginDomains(udpAuth.getDomainsArray());
}
viewControl.setRestrictDomains(udpAuth.getDomainsRestricted());
}
}
}
InputStream is = getClass().getResourceAsStream("/hashfile.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(is));
// Read it
// Close 'in'
byte [] data = new byte [ 1024 ];
BufferedInputStream bis = new BufferedInputStream ( new DataInputStream ( new FileInputStream ( "file" ) ) ) ;
while ( bis.read( data ) != -1 ) {
// process data
}
bis.close();
// protected boolean chk(String nm) {
// try {
// FileReader fr = new FileReader("names.txt");
// BufferedReader br = new BufferedReader(fr);
// da = new String();
// while ((da = br.readline()) != null) {
// if (nm.equals(da)) {
// in.close();
// return false;
// }
// }
// in.close();
// return true;
// } catch (IOException e) {
// return true;
// }
// }
try {
BufferedReader in = new BufferedReader(new FileReader("infilename"));
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
} catch (IOException e) {
}
a. You've posted this in the Java TA - it's JavaScript
b. JS runs client-side, so attempting to read files on the web server won't work
c. Reading files on the client is not permitted to untrusted code