@Override public CouchContext createSession(String userName, String password) throws Exception { Map<String,String> form = new HashMap<String,String>(); form.put("name", userName); form.put("password", password); // Create a context to receive the cookie for authentication CouchContextCookie context = new CouchContextCookie(); // POST _session JSONObject jsonUserCtx = ConnectionUtils.postForm(context, url, form); ConnectionUtils.captureReponseErrors(jsonUserCtx, "Error while creating session context: "); // Parse response CouchUtils.authenticationContextFromDocument(jsonUserCtx); return context; }
private CouchDb getUserCouchDbFromCookies(Cookie[] cookies) throws Exception { CouchContextCookie contextCookie = new CouchContextCookie(); for(Cookie cookie : cookies){ contextCookie.setCookie(cookie.getName(), cookie.getValue()); } CouchFactory factory = new CouchFactory(); return factory.getDb(contextCookie, dd.getDatabase()); }
@Override public CouchAuthenticationContext getRolesFromAuthentication(Cookie[] cookies) throws Exception { CouchContextCookie contextCookie = new CouchContextCookie(); for(Cookie cookie : cookies){ contextCookie.setCookie(cookie.getName(), cookie.getValue()); } CouchFactory factory = new CouchFactory(); CouchDb couchDb = factory.getDb(contextCookie, userDb); CouchSession session = couchDb.getClient().getSession(); CouchAuthenticationContext userContext = session.getAuthenticationContext(); return userContext; }
private CouchAuthenticationContext getAuthenticationContextFromCookies(Cookie[] cookies) throws Exception { CouchContextCookie contextCookie = new CouchContextCookie(); if( null != cookies ) { for(Cookie cookie : cookies){ contextCookie.setCookie(cookie.getName(), cookie.getValue()); } } CouchClient client = documentDesign.getDatabase().getClient(); CouchFactory factory = new CouchFactory(); CouchClient userClient = factory.getClient(contextCookie, client); CouchSession session = userClient.getSession(); CouchAuthenticationContext authContext = session.getAuthenticationContext(); return authContext; }