def try_auth(self, username, password): if self.interface == 'admin-console': # We need to retrieve ViewState value r = Requester.get(self.interface_url) m = re.search('<input type="hidden" name="javax\.faces\.ViewState" ' \ 'id="javax\.faces\.ViewState" value="(?P<viewstate>.*?)"', r.text) if not m: raise RequestException( 'Unable to retrieve ViewState from {}'.format( self.interface_url)) data = OrderedDict([ ("login_form", "login_form"), ("login_form:name", username), ("login_form:password", password), ("login_form:submit", "Login"), ("javax.faces.ViewState", m.group('viewstate')), ]) # We also need to retrieve JSESSIONID value m = re.search( r'JSESSIONID=(?P<jsessionid>.*); Path=\/admin-console', r.headers['Set-Cookie']) if not m: raise RequestException('Unable to retrieve JSESSIONID value ' \ 'from {}'.format(self.interface_url)) r = Requester.post(self.interface_url, data, headers={ 'Cookie': 'JSESSIONID={}'.format( m.group('jsessionid')) }, allow_redirects=False) status = ('name="login_form:password"' not in r.text \ and 'Not logged in' not in r.text) return status elif self.interface == 'jmx-console': r = Requester.http_auth(self.interface_url, self.http_auth_type, username, password) return (r.status_code != 401) elif self.interface == 'management': r = Requester.http_auth(self.interface_url, self.http_auth_type, username, password) return (r.status_code != 401) elif self.interface == 'web-console': r = Requester.http_auth(self.interface_url, self.http_auth_type, username, password) return (r.status_code != 401) else: raise AuthException( 'No auth interface found during initialization')
def try_auth(self, username, password): if self.interface == 'htaccess': r = Requester.http_auth(self.interface_url, self.http_auth_type, username, password) return (r.status_code != 401) else: raise AuthException('No auth interface found during initialization')