зеркало из https://github.com/mozilla/pjs.git
OJI part of bug 60304 "Basic Auth doesn't work for Java"
r = peterlubczynski; sr = darin patch = joshua.xia@sun.com
This commit is contained in:
Родитель
d48c2c89f7
Коммит
a510419b9d
|
@ -32,6 +32,7 @@ GRE_MODULE = 1
|
|||
XPIDLSRCS = \
|
||||
nsIJVMManager.idl \
|
||||
nsIJVMPluginInstance.idl \
|
||||
nsIJVMAuthTools.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystem.
|
||||
* Portions created by Sun Microsystem are Copyright (C) 2003
|
||||
* by Sun Microsystem. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Joshua Xia <joshua.xia@sun.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_JVMAUTHTOOLS_CID \
|
||||
{ /* d8e716f9-c96e-4e84-ab12-980f5567e2a4 */ \
|
||||
0xd8e716f9, \
|
||||
0xc96e, \
|
||||
0x4e84, \
|
||||
{0xab, 0x12, 0x98, 0x0f, 0x55, 0x67, 0xe2, 0xa4} \
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
[noscript, uuid(078a1b99-6be2-4a57-a749-378f4a506097)]
|
||||
interface nsIAuthenticationInfo : nsISupports
|
||||
{
|
||||
/**
|
||||
* AuthenticationInfo (username/password pair)
|
||||
*/
|
||||
|
||||
readonly attribute string username;
|
||||
readonly attribute string password;
|
||||
};
|
||||
|
||||
[noscript, uuid(82274a32-a196-42ee-8e3b-fcb73e339518)]
|
||||
interface nsIJVMAuthTools : nsISupports
|
||||
{
|
||||
/**
|
||||
* Export AuthenticationInfo interface to JPI.
|
||||
*
|
||||
* @param protocol the protocol that support (http/https)
|
||||
* @param host host name
|
||||
* @param port port number
|
||||
* @param scheme scheme
|
||||
* @param realm realm
|
||||
* @param nsIAuthenticationInfo the AuthenticationInfo interface
|
||||
* that export
|
||||
*
|
||||
* @return NS_OK if success, other if fail
|
||||
*/
|
||||
|
||||
nsIAuthenticationInfo GetAuthenticationInfo(in string protocol,
|
||||
in string host,
|
||||
in PRInt32 port,
|
||||
in string scheme,
|
||||
in string realm);
|
||||
|
||||
/**
|
||||
* Import username/password pair from JPI.
|
||||
*
|
||||
* @param protocol the protocol that support (http/https)
|
||||
* @param host host name
|
||||
* @param port port number
|
||||
* @param scheme scheme
|
||||
* @param realm realm
|
||||
* @param username user name
|
||||
* @param password password
|
||||
*
|
||||
* @return NS_OK if success, other if fail
|
||||
*/
|
||||
|
||||
void SetAuthenticationInfo(in string protocol,
|
||||
in string host,
|
||||
in PRInt32 port,
|
||||
in string scheme,
|
||||
in string realm,
|
||||
in string username,
|
||||
in string password);
|
||||
|
||||
};
|
|
@ -72,6 +72,7 @@ CPPSRCS = \
|
|||
nsCSecurityContext.cpp \
|
||||
nsCJVMManagerFactory.cpp \
|
||||
lcglue.cpp \
|
||||
nsJVMAuthTools.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsJVMAuthTools.h"
|
||||
#include "nsJVMManager.h"
|
||||
|
||||
/*
|
||||
|
@ -54,6 +55,12 @@ static const nsModuleComponentInfo components[] =
|
|||
"@mozilla.org/oji/jvm-mgr;1",
|
||||
nsJVMManager::Create
|
||||
},
|
||||
|
||||
{ "JVM Authentication Service",
|
||||
NS_JVMAUTHTOOLS_CID,
|
||||
"@mozilla.org/oji/jvm-auth-tools;1",
|
||||
nsJVMAuthTools::Create
|
||||
},
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(nsCJVMManagerModule, components);
|
||||
|
|
|
@ -0,0 +1,212 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystem.
|
||||
* Portions created by Sun Microsystem are Copyright (C) 2003 by
|
||||
* Sun Microsystem. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Joshua Xia <joshua.xia@sun.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "plstr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsJVMAuthTools.h"
|
||||
#include "nsIHttpAuthManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIJVMAUTHTOOLSIID, NS_IJVMAUTHTOOLS_IID);
|
||||
static NS_DEFINE_CID(kHttpAuthManagerCID, NS_HTTPAUTHMANAGER_CID);
|
||||
|
||||
//---------------------------------------------------
|
||||
// implementation of interface nsIAuthenticationInfo
|
||||
// --------------------------------------------------
|
||||
NS_IMPL_ISUPPORTS1(nsAuthenticationInfoImp, nsIAuthenticationInfo)
|
||||
|
||||
nsAuthenticationInfoImp::nsAuthenticationInfoImp(char* username,
|
||||
char* password)
|
||||
{
|
||||
mUserName = username;
|
||||
mPassWord = password;
|
||||
}
|
||||
|
||||
nsAuthenticationInfoImp::~nsAuthenticationInfoImp()
|
||||
{
|
||||
if (mUserName)
|
||||
nsMemory::Free(mUserName);
|
||||
|
||||
if (mPassWord)
|
||||
nsMemory::Free(mPassWord);
|
||||
}
|
||||
|
||||
/* readonly attribute string username; */
|
||||
NS_IMETHODIMP nsAuthenticationInfoImp::GetUsername(char * *aUsername)
|
||||
{
|
||||
*aUsername = mUserName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute string password; */
|
||||
NS_IMETHODIMP nsAuthenticationInfoImp::GetPassword(char * *aPassword)
|
||||
{
|
||||
*aPassword = mPassWord;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------
|
||||
// implementation of interface nsIJVMAuthTools
|
||||
// --------------------------------------------------
|
||||
NS_IMPL_AGGREGATED(nsJVMAuthTools);
|
||||
|
||||
nsJVMAuthTools::nsJVMAuthTools(nsISupports* outer)
|
||||
{
|
||||
NS_INIT_AGGREGATED(outer);
|
||||
}
|
||||
|
||||
nsJVMAuthTools::~nsJVMAuthTools(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsJVMAuthTools::Create(nsISupports* outer,
|
||||
const nsIID& aIID,
|
||||
void* *aInstancePtr)
|
||||
{
|
||||
if (!aInstancePtr)
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
*aInstancePtr = nsnull;
|
||||
|
||||
if (outer && !aIID.Equals(kISupportsIID))
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsJVMAuthTools* authtools = new nsJVMAuthTools(outer);
|
||||
if (authtools == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = authtools->AggregatedQueryInterface(aIID, aInstancePtr);
|
||||
if(NS_FAILED(rv))
|
||||
delete authtools;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsJVMAuthTools::AggregatedQueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
if (aIID.Equals(kIJVMAUTHTOOLSIID)) {
|
||||
*aInstancePtr = this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = GetInner();
|
||||
NS_ADDREF((nsISupports*)*aInstancePtr);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsJVMAuthTools::GetAuthenticationInfo(const char* protocol,
|
||||
const char* host,
|
||||
PRInt32 port,
|
||||
const char* scheme,
|
||||
const char* realm,
|
||||
nsIAuthenticationInfo **_retval)
|
||||
{
|
||||
if (!protocol || !host || !realm)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (!PL_strcasecmp(protocol, "HTTP") && !PL_strcasecmp(protocol, "HTTPS"))
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<nsIHttpAuthManager> authManager = do_GetService(kHttpAuthManagerCID);
|
||||
if (!authManager)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsDependentCString hostString(host);
|
||||
nsDependentCString realmString(realm);
|
||||
nsAutoString domainString, username, password;
|
||||
|
||||
nsresult rv = authManager->GetAuthIdentity(hostString,
|
||||
port,
|
||||
realmString,
|
||||
nsCString(),
|
||||
domainString,
|
||||
username,
|
||||
password);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
else {
|
||||
nsAuthenticationInfoImp* authInfo = new nsAuthenticationInfoImp(
|
||||
ToNewUTF8String(username),
|
||||
ToNewUTF8String(password));
|
||||
NS_ENSURE_TRUE(authInfo, NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ADDREF(authInfo);
|
||||
*_retval = authInfo;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsJVMAuthTools::SetAuthenticationInfo(const char* protocol,
|
||||
const char* host,
|
||||
PRInt32 port,
|
||||
const char* scheme,
|
||||
const char* realm,
|
||||
const char *username,
|
||||
const char *password)
|
||||
{
|
||||
if (!protocol || !host || !realm)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (!PL_strcasecmp(protocol, "HTTP") && !PL_strcasecmp(protocol, "HTTPS"))
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsCOMPtr<nsIHttpAuthManager> authManager = do_GetService(kHttpAuthManagerCID);
|
||||
if (!authManager)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsDependentCString hostString(host);
|
||||
nsDependentCString realmString(realm);
|
||||
|
||||
nsresult rv = authManager->SetAuthIdentity(hostString,
|
||||
port,
|
||||
realmString,
|
||||
nsCString(),
|
||||
nsString(),
|
||||
NS_ConvertUTF8toUCS2(username),
|
||||
NS_ConvertUTF8toUCS2(password));
|
||||
return rv;
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystem.
|
||||
* Portions created by Sun Microsystem are Copyright (C) 2003 by
|
||||
* Sun Microsystem. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Joshua Xia <joshua.xia@sun.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsJVMAuthTools_h___
|
||||
#define nsJVMAuthTools_h___
|
||||
|
||||
#include "nsAgg.h"
|
||||
#include "nsIJVMAuthTools.h"
|
||||
|
||||
class nsAuthenticationInfoImp : public nsIAuthenticationInfo
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAUTHENTICATIONINFO
|
||||
|
||||
nsAuthenticationInfoImp(char* aUsername, char* aPassword);
|
||||
virtual ~nsAuthenticationInfoImp();
|
||||
|
||||
protected:
|
||||
char* mUserName;
|
||||
char* mPassWord;
|
||||
|
||||
};
|
||||
|
||||
class nsJVMAuthTools : public nsIJVMAuthTools
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_AGGREGATED
|
||||
NS_DECL_NSIJVMAUTHTOOLS
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
|
||||
nsJVMAuthTools(nsISupports* outer);
|
||||
virtual ~nsJVMAuthTools(void);
|
||||
};
|
||||
|
||||
#endif // nsJVMAuthTools_h___
|
Загрузка…
Ссылка в новой задаче