jcifs.netbios.NbtAddress Java Examples
The following examples show how to use
jcifs.netbios.NbtAddress.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubnetScanner.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
public Computer call() throws Exception { try { NbtAddress[] allByAddress = NbtAddress.getAllByAddress(this.addr); if (allByAddress == null || allByAddress.length <= 0) { return new Computer(null, this.addr); } return new Computer(allByAddress[0].getHostName(), this.addr); } catch (UnknownHostException e) { return new Computer(null, this.addr); } }
Example #2
Source File: NtlmAuthenticationHandler.java From springboot-shiro-cas-mybatis with MIT License | 4 votes |
@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()); }
Example #3
Source File: NtlmAuthenticationHandler.java From cas4.0.x-server-wechat with Apache License 2.0 | 4 votes |
@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()); }
Example #4
Source File: SmbResourceLocatorImpl.java From jcifs with GNU Lesser General Public License v2.1 | 4 votes |
Address getFirstAddress () throws CIFSException { this.addressIndex = 0; if ( this.addresses == null ) { String host = this.url.getHost(); String path = this.url.getPath(); String query = this.url.getQuery(); try { if ( query != null ) { String server = queryLookup(query, "server"); if ( server != null && server.length() > 0 ) { this.addresses = new UniAddress[1]; this.addresses[ 0 ] = this.ctx.getNameServiceClient().getByName(server); } String address = queryLookup(query, "address"); if ( address != null && address.length() > 0 ) { byte[] ip = java.net.InetAddress.getByName(address).getAddress(); this.addresses = new UniAddress[1]; this.addresses[ 0 ] = new UniAddress(java.net.InetAddress.getByAddress(host, ip)); } } else if ( host.length() == 0 ) { try { Address addr = this.ctx.getNameServiceClient().getNbtByName(NbtAddress.MASTER_BROWSER_NAME, 0x01, null); this.addresses = new UniAddress[1]; this.addresses[ 0 ] = this.ctx.getNameServiceClient().getByName(addr.getHostAddress()); } catch ( UnknownHostException uhe ) { log.debug("Unknown host", uhe); if ( this.ctx.getConfig().getDefaultDomain() == null ) { throw uhe; } this.addresses = this.ctx.getNameServiceClient().getAllByName(this.ctx.getConfig().getDefaultDomain(), true); } } else if ( path.length() == 0 || path.equals("/") ) { this.addresses = this.ctx.getNameServiceClient().getAllByName(host, true); } else { this.addresses = this.ctx.getNameServiceClient().getAllByName(host, false); } } catch ( UnknownHostException e ) { throw new CIFSException("Failed to lookup address for name " + host, e); } } return getNextAddress(); }
Example #5
Source File: SmbResourceLocatorImpl.java From jcifs-ng with GNU Lesser General Public License v2.1 | 4 votes |
Address getFirstAddress () throws CIFSException { this.addressIndex = 0; if ( this.addresses == null ) { String host = this.url.getHost(); String path = this.url.getPath(); String query = this.url.getQuery(); try { if ( query != null ) { String server = queryLookup(query, "server"); if ( server != null && server.length() > 0 ) { this.addresses = new UniAddress[1]; this.addresses[ 0 ] = this.ctx.getNameServiceClient().getByName(server); } String address = queryLookup(query, "address"); if ( address != null && address.length() > 0 ) { byte[] ip = java.net.InetAddress.getByName(address).getAddress(); this.addresses = new UniAddress[1]; this.addresses[ 0 ] = new UniAddress(java.net.InetAddress.getByAddress(host, ip)); } } else if ( host.length() == 0 ) { try { Address addr = this.ctx.getNameServiceClient().getNbtByName(NbtAddress.MASTER_BROWSER_NAME, 0x01, null); this.addresses = new UniAddress[1]; this.addresses[ 0 ] = this.ctx.getNameServiceClient().getByName(addr.getHostAddress()); } catch ( UnknownHostException uhe ) { log.debug("Unknown host", uhe); if ( this.ctx.getConfig().getDefaultDomain() == null ) { throw uhe; } this.addresses = this.ctx.getNameServiceClient().getAllByName(this.ctx.getConfig().getDefaultDomain(), true); } } else if ( path.length() == 0 || path.equals("/") ) { this.addresses = this.ctx.getNameServiceClient().getAllByName(host, true); } else { this.addresses = this.ctx.getNameServiceClient().getAllByName(host, false); } } catch ( UnknownHostException e ) { throw new CIFSException("Failed to lookup address for name " + host, e); } } return getNextAddress(); }