List of usage examples for org.apache.commons.httpclient.auth AuthenticationException AuthenticationException
public AuthenticationException(String paramString)
From source file:org.vosao.rest.RestManager.java
private String runService(String serviceKey, List<String> path, Map<String, String> params) throws Throwable { Object restService = services.get(serviceKey); if (restService != null) { // check Authorized if (restService.getClass().getAnnotation(Authorized.class) != null) { if (VosaoContext.getInstance().getUser() == null) { throw new AuthenticationException("User is not authenticated."); }//from ww w .j a v a2 s . co m } MatchResult result = matchMethod(restService, path, params); if (result != null) { try { // check Authorized if (result.method.getAnnotation(Authorized.class) != null) { if (VosaoContext.getInstance().getUser() == null) { throw new AuthenticationException("User is not authenticated."); } } Object invokeResult = result.method.invoke(restService, result.args); if (invokeResult instanceof String) return (String) invokeResult; else return new JSONObject(invokeResult).toString(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { if (e.getCause() != null) throw e.getCause(); e.printStackTrace(); } } } return null; }
From source file:org.zaproxy.zap.network.ZapNTLMEngineImpl.java
private static int readULong(final byte[] src, final int index) throws AuthenticationException { if (src.length < index + 4) throw new AuthenticationException("NTLM authentication - buffer too small for DWORD"); return (src[index] & 0xff) | ((src[index + 1] & 0xff) << 8) | ((src[index + 2] & 0xff) << 16) | ((src[index + 3] & 0xff) << 24); }
From source file:org.zaproxy.zap.network.ZapNTLMEngineImpl.java
private static int readUShort(final byte[] src, final int index) throws AuthenticationException { if (src.length < index + 2) throw new AuthenticationException("NTLM authentication - buffer too small for WORD"); return (src[index] & 0xff) | ((src[index + 1] & 0xff) << 8); }
From source file:org.zaproxy.zap.network.ZapNTLMEngineImpl.java
private static byte[] readSecurityBuffer(final byte[] src, final int index) throws AuthenticationException { final int length = readUShort(src, index); final int offset = readULong(src, index + 4); if (src.length < offset + length) throw new AuthenticationException("NTLM authentication - buffer too small for data item"); final byte[] buffer = new byte[length]; System.arraycopy(src, offset, buffer, 0, length); return buffer; }
From source file:org.zaproxy.zap.network.ZapNTLMEngineImpl.java
/** Calculate a challenge block */ private static byte[] makeRandomChallenge() throws AuthenticationException { if (RND_GEN == null) { throw new AuthenticationException("Random generator not available"); }/*from ww w . jav a 2 s.c om*/ final byte[] rval = new byte[8]; synchronized (RND_GEN) { RND_GEN.nextBytes(rval); } return rval; }
From source file:org.zaproxy.zap.network.ZapNTLMEngineImpl.java
/** Calculate a 16-byte secondary key */ private static byte[] makeSecondaryKey() throws AuthenticationException { if (RND_GEN == null) { throw new AuthenticationException("Random generator not available"); }// w w w. j a v a2s . c o m final byte[] rval = new byte[16]; synchronized (RND_GEN) { RND_GEN.nextBytes(rval); } return rval; }
From source file:org.zaproxy.zap.network.ZapNTLMScheme.java
@Override public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { NTCredentials ntcredentials = null;/*from www. j a v a2s .c o m*/ try { ntcredentials = (NTCredentials) credentials; } catch (final ClassCastException e) { throw new AuthenticationException( "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName()); } String response = null; if (this.state == State.FAILED) { throw new AuthenticationException("NTLM authentication failed"); } else if (this.state == State.CHALLENGE_RECEIVED) { response = this.engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getHost()); this.state = State.MSG_TYPE1_GENERATED; } else if (this.state == State.MSG_TYPE2_RECEVIED) { response = this.engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getHost(), this.challenge); this.state = State.MSG_TYPE3_GENERATED; } else { throw new AuthenticationException("Unexpected state: " + this.state); } return "NTLM " + response; }