本文整理汇总了Java中jcifs.ntlmssp.Type3Message类的典型用法代码示例。如果您正苦于以下问题:Java Type3Message类的具体用法?Java Type3Message怎么用?Java Type3Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Type3Message类属于jcifs.ntlmssp包,在下文中一共展示了Type3Message类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAuthentication
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
@Override
protected final HandlerResult doAuthentication(
final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential ntlmCredential = (SpnegoCredential) credential;
final byte[] src = ntlmCredential.getInitToken();
UniAddress dc = null;
boolean success = false;
try {
if (this.loadBalance) {
// find the first dc that matches the includepattern
if (StringUtils.isNotBlank(this.includePattern)) {
final NbtAddress[] dcs = NbtAddress.getAllByName(this.domainController, NBT_ADDRESS_TYPE, null, null);
for (final NbtAddress dc2 : dcs) {
if(dc2.getHostAddress().matches(this.includePattern)){
dc = new UniAddress(dc2);
break;
}
}
} else {
dc = new UniAddress(NbtAddress.getByName(this.domainController, NBT_ADDRESS_TYPE, null));
}
} else {
dc = UniAddress.getByName(this.domainController, true);
}
final byte[] challenge = SmbSession.getChallenge(dc);
switch (src[NTLM_TOKEN_TYPE_FIELD_INDEX]) {
case NTLM_TOKEN_TYPE_ONE:
logger.debug("Type 1 received");
final Type1Message type1 = new Type1Message(src);
final Type2Message type2 = new Type2Message(type1,
challenge, null);
logger.debug("Type 2 returned. Setting next token.");
ntlmCredential.setNextToken(type2.toByteArray());
break;
case NTLM_TOKEN_TYPE_THREE:
logger.debug("Type 3 received");
final Type3Message type3 = new Type3Message(src);
final byte[] lmResponse = type3.getLMResponse() == null ? new byte[0] : type3.getLMResponse();
final byte[] ntResponse = type3.getNTResponse() == null ? new byte[0] : type3.getNTResponse();
final NtlmPasswordAuthentication ntlm = new NtlmPasswordAuthentication(
type3.getDomain(), type3.getUser(), challenge,
lmResponse, ntResponse);
logger.debug("Trying to authenticate {} with domain controller", type3.getUser());
try {
SmbSession.logon(dc, ntlm);
ntlmCredential.setPrincipal(this.principalFactory.createPrincipal(type3.getUser()));
success = true;
} catch (final SmbAuthException sae) {
throw new FailedLoginException(sae.getMessage());
}
break;
default:
logger.debug("Unknown type: {}", src[NTLM_TOKEN_TYPE_FIELD_INDEX]);
}
} catch (final Exception e) {
throw new FailedLoginException(e.getMessage());
}
if (!success) {
throw new FailedLoginException();
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
示例2: getNTLMString
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
public String getNTLMString(String challangeString) throws IOException {
if (challangeString == null) {
Type1Message m1 = new Type1Message();
m1.setSuppliedDomain(this.ntDomain);
return Base64.encode(m1.toByteArray());
} else {
byte[] challange = Base64.decode(challangeString);
Type2Message m2 = new Type2Message(challange);
Type3Message m3 = new Type3Message(m2, ntPass, ntDomain, ntUser,
InetAddress.getLocalHost().getHostName());
return Base64.encode(m3.toByteArray());
}
}
示例3: authenticate
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
/**
* Performs NTLM authentication for the servlet request.
*
* @param req The request being serviced.
* @param resp The response.
* @param challenge The domain controller challenge.
* @throws IOException If an IO error occurs.
* @throws ServletException If an error occurs.
*/
public static NtlmPasswordAuthentication authenticate(
HttpServletRequest req, HttpServletResponse resp, byte[] challenge)
throws IOException, ServletException {
String msg = req.getHeader("Authorization");
if (msg != null && msg.startsWith("NTLM ")) {
byte[] src = Base64.decode(msg.substring(5));
if (src[8] == 1) {
Type1Message type1 = new Type1Message(src);
Type2Message type2 = new Type2Message(type1, challenge, null);
msg = Base64.encode(type2.toByteArray());
resp.setHeader( "WWW-Authenticate", "NTLM " + msg );
} else if (src[8] == 3) {
Type3Message type3 = new Type3Message(src);
byte[] lmResponse = type3.getLMResponse();
if (lmResponse == null) lmResponse = new byte[0];
byte[] ntResponse = type3.getNTResponse();
if (ntResponse == null) ntResponse = new byte[0];
return new NtlmPasswordAuthentication(type3.getDomain(),
type3.getUser(), challenge, lmResponse, ntResponse);
}
} else {
resp.setHeader("WWW-Authenticate", "NTLM");
}
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
resp.setContentLength(0);
resp.flushBuffer();
return null;
}
示例4: authenticate
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
/**
* Performs NTLM authentication for the servlet request.
*
* @param tc
* context to use
*
* @param req
* The request being serviced.
* @param resp
* The response.
* @param challenge
* The domain controller challenge.
* @return credentials passed in the servlet request
* @throws IOException
* If an IO error occurs.
*/
public static NtlmPasswordAuthentication authenticate ( CIFSContext tc, HttpServletRequest req, HttpServletResponse resp, byte[] challenge )
throws IOException {
String msg = req.getHeader("Authorization");
if ( msg != null && msg.startsWith("NTLM ") ) {
byte[] src = Base64.decode(msg.substring(5));
if ( src[ 8 ] == 1 ) {
Type1Message type1 = new Type1Message(src);
Type2Message type2 = new Type2Message(tc, type1, challenge, null);
msg = new String(Base64.encode(type2.toByteArray()), "US-ASCII");
resp.setHeader("WWW-Authenticate", "NTLM " + msg);
}
else if ( src[ 8 ] == 3 ) {
Type3Message type3 = new Type3Message(src);
byte[] lmResponse = type3.getLMResponse();
if ( lmResponse == null )
lmResponse = new byte[0];
byte[] ntResponse = type3.getNTResponse();
if ( ntResponse == null )
ntResponse = new byte[0];
return new NtlmPasswordAuthentication(type3.getDomain(), type3.getUser(), challenge, lmResponse, ntResponse);
}
}
else {
resp.setHeader("WWW-Authenticate", "NTLM");
}
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
resp.setContentLength(0);
resp.flushBuffer();
return null;
}
示例5: getNTLMString
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
public String getNTLMString(String challangeString) throws IOException {
if(challangeString == null) {
Type1Message challange1 = new Type1Message();
challange1.setSuppliedDomain(this.ntDomain);
return Base64.encode(challange1.toByteArray());
} else {
byte[] challange = Base64.decode(challangeString);
Type2Message m2 = new Type2Message(challange);
Type3Message m3 = new Type3Message(m2, this.ntPass, this.ntDomain, this.ntUser, InetAddress.getLocalHost().getHostName());
return Base64.encode(m3.toByteArray());
}
}
示例6: performNtlmAuthentication
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
protected String performNtlmAuthentication(InetSocketAddress target,
String challenge) throws IOException {
if (challenge.length() == 4) {
NtlmMessage type1 = new Type1Message(NTLMV2_FLAGS, null, null);
return "NTLM "
+ Base64
.encodeBytes(type1.toByteArray(), Base64.NO_OPTIONS);
} else {
challenge = challenge.substring(5); // "NTLM "
Type2Message type2 = new Type2Message(Base64.decode(challenge,
Base64.NO_OPTIONS));
String domain = type2.getTarget();
String hostname = target.getHostName();
InetAddress addr = target.isUnresolved() ? null : target
.getAddress();
PasswordAuthentication pa = Authenticator
.requestPasswordAuthentication(hostname, addr, target
.getPort(), "HTTP", domain, "NTLM");
if (pa == null)
return null;
String username = pa.getUserName();
String password = new String(pa.getPassword());
int slash = username.indexOf('\\');
if (slash > -1) {
domain = username.substring(0, slash);
username = username.substring(slash + 1);
}
Type3Message type3 = new Type3Message(type2, password, domain,
username, null, NTLMV2_FLAGS_TYPE3);
return "NTLM "
+ Base64
.encodeBytes(type3.toByteArray(), Base64.NO_OPTIONS);
}
}
示例7: ntlmAuthenticate
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
private void ntlmAuthenticate(HttpRequest modifiedRequest, HttpRequest finalRequest, HttpByteSink sink, CapturingHandler handler,
BufferProcessor<HttpInput, HttpByteSink> processor) throws IOException {
Type1Message message1 = new Type1Message(TYPE_1_FLAGS, null, null);
modifiedRequest.setHeader("PROXY-AUTHORIZATION", "NTLM " + Base64.encode(message1.toByteArray()));
if (HttpUtils.sendHeader(modifiedRequest, channel) >= 0) {
if (readResponse(handler, sink, processor) >= 0) {
switch (handler.getResponse().getCode()) {
case 407:
String authenticate = handler.getResponse().getHeader("PROXY-AUTHENTICATE");
if (authenticate != null) {
if (authenticate.startsWith("NTLM ")) {
String base64 = authenticate.substring(5);
Type2Message message2 = new Type2Message(Base64.decode(base64));
Type3Message message3 = new Type3Message(message2, password, domain, username, null,
message2.getFlags());
finalRequest.setHeader("PROXY-AUTHORIZATION",
"NTLM " + Base64.encode(message3.toByteArray()));
HttpUtils.sendHeader(finalRequest, channel);
authenticated = true;
prepareChannel(factory, sourceChannel, calledAddress);
}
}
break;
case 200:
authenticated = true;
prepareChannel(factory, sourceChannel, calledAddress);
break;
default:
// this happens only in HTTP with disallowed connections.
channel.close();
}
}
}
}
示例8: generateType3Msg
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
public String generateType3Msg(String username, String password, String domain, String workstation, String challenge) throws NTLMEngineException {
Type2Message type2Message = decodeType2Message(challenge);
Type3Message type3Message = new Type3Message(type2Message, password, domain, username, workstation, Type3Message.getDefaultFlags());
return Base64.encode(type3Message.toByteArray());
}
示例9: doAuthentication
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
@Override
protected final HandlerResult doAuthentication(
final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential ntlmCredential = (SpnegoCredential) credential;
final byte[] src = ntlmCredential.getInitToken();
UniAddress dc = null;
boolean success = false;
try {
if (this.loadBalance) {
// find the first dc that matches the includepattern
if (this.includePattern != null) {
final NbtAddress[] dcs= NbtAddress.getAllByName(this.domainController, NBT_ADDRESS_TYPE, null, null);
for (final NbtAddress dc2 : dcs) {
if(dc2.getHostAddress().matches(this.includePattern)){
dc = new UniAddress(dc2);
break;
}
}
} else {
dc = new UniAddress(NbtAddress.getByName(this.domainController, NBT_ADDRESS_TYPE, null));
}
} else {
dc = UniAddress.getByName(this.domainController, true);
}
final byte[] challenge = SmbSession.getChallenge(dc);
switch (src[NTLM_TOKEN_TYPE_FIELD_INDEX]) {
case NTLM_TOKEN_TYPE_ONE:
logger.debug("Type 1 received");
final Type1Message type1 = new Type1Message(src);
final Type2Message type2 = new Type2Message(type1,
challenge, null);
logger.debug("Type 2 returned. Setting next token.");
ntlmCredential.setNextToken(type2.toByteArray());
break;
case NTLM_TOKEN_TYPE_THREE:
logger.debug("Type 3 received");
final Type3Message type3 = new Type3Message(src);
final byte[] lmResponse = type3.getLMResponse() == null ? new byte[0] : type3.getLMResponse();
final byte[] ntResponse = type3.getNTResponse() == null ? new byte[0] : type3.getNTResponse();
final NtlmPasswordAuthentication ntlm = new NtlmPasswordAuthentication(
type3.getDomain(), type3.getUser(), challenge,
lmResponse, ntResponse);
logger.debug("Trying to authenticate {} with domain controller", type3.getUser());
try {
SmbSession.logon(dc, ntlm);
ntlmCredential.setPrincipal(this.principalFactory.createPrincipal(type3.getUser()));
success = true;
} catch (final SmbAuthException sae) {
throw new FailedLoginException(sae.getMessage());
}
break;
default:
logger.debug("Unknown type: {}", src[NTLM_TOKEN_TYPE_FIELD_INDEX]);
}
} catch (final Exception e) {
throw new FailedLoginException(e.getMessage());
}
if (!success) {
throw new FailedLoginException();
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
示例10: doAuthentication
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
@Override
protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential ntlmCredential = (SpnegoCredential) credential;
final byte[] src = ntlmCredential.getInitToken();
final UniAddress dc;
boolean success = false;
try {
if (this.loadBalance) {
// find the first dc that matches the includepattern
if (StringUtils.isNotBlank(this.includePattern)) {
final NbtAddress[] dcs = NbtAddress.getAllByName(this.domainController, NBT_ADDRESS_TYPE, null, null);
dc = Arrays.stream(dcs).filter(dc2 -> dc2.getHostAddress().matches(this.includePattern)).findFirst().map(UniAddress::new).orElse(null);
} else {
dc = new UniAddress(NbtAddress.getByName(this.domainController, NBT_ADDRESS_TYPE, null));
}
} else {
dc = UniAddress.getByName(this.domainController, true);
}
final byte[] challenge = SmbSession.getChallenge(dc);
switch (src[NTLM_TOKEN_TYPE_FIELD_INDEX]) {
case NTLM_TOKEN_TYPE_ONE:
LOGGER.debug("Type 1 received");
final Type1Message type1 = new Type1Message(src);
final Type2Message type2 = new Type2Message(type1,
challenge, null);
LOGGER.debug("Type 2 returned. Setting next token.");
ntlmCredential.setNextToken(type2.toByteArray());
break;
case NTLM_TOKEN_TYPE_THREE:
LOGGER.debug("Type 3 received");
final Type3Message type3 = new Type3Message(src);
final byte[] lmResponse = type3.getLMResponse() == null ? new byte[0] : type3.getLMResponse();
final byte[] ntResponse = type3.getNTResponse() == null ? new byte[0] : type3.getNTResponse();
final NtlmPasswordAuthentication ntlm = new NtlmPasswordAuthentication(
type3.getDomain(), type3.getUser(), challenge,
lmResponse, ntResponse);
LOGGER.debug("Trying to authenticate [{}] with domain controller", type3.getUser());
try {
SmbSession.logon(dc, ntlm);
ntlmCredential.setPrincipal(this.principalFactory.createPrincipal(type3.getUser()));
success = true;
} catch (final SmbAuthException sae) {
throw new FailedLoginException(sae.getMessage());
}
break;
default:
LOGGER.debug("Unknown type: [{}]", src[NTLM_TOKEN_TYPE_FIELD_INDEX]);
}
} catch (final Exception e) {
throw new FailedLoginException(e.getMessage());
}
if (!success) {
throw new FailedLoginException();
}
return new DefaultHandlerResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
示例11: doAuthentication
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
@Override
protected final HandlerResult doAuthentication(
final Credential credential) throws GeneralSecurityException, PreventedException {
final SpnegoCredential ntlmCredential = (SpnegoCredential) credential;
final byte[] src = ntlmCredential.getInitToken();
UniAddress dc = null;
boolean success = false;
try {
if (this.loadBalance) {
// find the first dc that matches the includepattern
if(this.includePattern != null){
NbtAddress [] dcs = NbtAddress.getAllByName(this.domainController, 0x1C, null, null);
for (NbtAddress dc2 : dcs) {
if(dc2.getHostAddress().matches(this.includePattern)){
dc = new UniAddress(dc2);
break;
}
}
} else {
dc = new UniAddress(NbtAddress.getByName(this.domainController,
0x1C, null));
}
} else {
dc = UniAddress.getByName(this.domainController, true);
}
final byte[] challenge = SmbSession.getChallenge(dc);
switch (src[8]) {
case 1:
logger.debug("Type 1 received");
final Type1Message type1 = new Type1Message(src);
final Type2Message type2 = new Type2Message(type1,
challenge, null);
logger.debug("Type 2 returned. Setting next token.");
ntlmCredential.setNextToken(type2.toByteArray());
case 3:
logger.debug("Type 3 received");
final Type3Message type3 = new Type3Message(src);
final byte[] lmResponse = type3.getLMResponse() == null ? new byte[0] : type3.getLMResponse();
byte[] ntResponse = type3.getNTResponse() == null ? new byte[0] : type3.getNTResponse();
final NtlmPasswordAuthentication ntlm = new NtlmPasswordAuthentication(
type3.getDomain(), type3.getUser(), challenge,
lmResponse, ntResponse);
logger.debug("Trying to authenticate {} with domain controller", type3.getUser());
try {
SmbSession.logon(dc, ntlm);
ntlmCredential.setPrincipal(new SimplePrincipal(type3.getUser()));
success = true;
} catch (final SmbAuthException sae) {
throw new FailedLoginException(sae.getMessage());
}
default:
logger.debug("Unknown type: {}", src[8]);
}
} catch (final Exception e) {
throw new FailedLoginException(e.getMessage());
}
if (!success) {
throw new FailedLoginException();
}
return new HandlerResult(this, new BasicCredentialMetaData(ntlmCredential), ntlmCredential.getPrincipal());
}
示例12: doHandshake
import jcifs.ntlmssp.Type3Message; //导入依赖的package包/类
private void doHandshake() throws IOException {
connect();
try {
int response = parseResponseCode();
if (response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH) {
return;
}
Type1Message type1 = (Type1Message) attemptNegotiation(response);
if (type1 == null) return; // no NTLM
int attempt = 0;
while (attempt < MAX_REDIRECTS) {
connection.setRequestProperty(authProperty, authMethod + ' ' +
Base64.encode(type1.toByteArray()));
connection.connect(); // send type 1
response = parseResponseCode();
if (response != HTTP_UNAUTHORIZED &&
response != HTTP_PROXY_AUTH) {
return;
}
Type3Message type3 = (Type3Message)
attemptNegotiation(response);
if (type3 == null) return;
connection.setRequestProperty(authProperty, authMethod + ' ' +
Base64.encode(type3.toByteArray()));
connection.connect(); // send type 3
if (cachedOutput != null && doOutput) {
OutputStream output = connection.getOutputStream();
cachedOutput.writeTo(output);
output.flush();
}
response = parseResponseCode();
if (response != HTTP_UNAUTHORIZED &&
response != HTTP_PROXY_AUTH) {
return;
}
attempt++;
if (allowUserInteraction && attempt < MAX_REDIRECTS) {
reconnect();
} else {
break;
}
}
throw new IOException("Unable to negotiate NTLM authentication.");
} finally {
cachedOutput = null;
}
}