use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.
the class WaitSetValidator method soapAdminAuthenticate.
/**
* used to authenticate via admin AuthRequest. can only be called after setting the URI with setURI.
*
* @param name
* @param password
* @throws ServiceException
* @throws IOException
*/
public void soapAdminAuthenticate(String name, String password) throws ServiceException {
if (mTransport == null)
throw ZClientException.CLIENT_ERROR("must call setURI before calling adminAuthenticate", null);
XMLElement req = new XMLElement(AdminConstants.AUTH_REQUEST);
req.addElement(AdminConstants.E_NAME).setText(name);
req.addElement(AdminConstants.E_PASSWORD).setText(password);
Element response = invoke(req);
mAuthToken = new ZAuthToken(response.getElement(AdminConstants.E_AUTH_TOKEN), true);
mAuthTokenLifetime = response.getAttributeLong(AdminConstants.E_LIFETIME);
mAuthTokenExpiration = System.currentTimeMillis() + mAuthTokenLifetime;
mTransport.setAuthToken(mAuthToken);
}
use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.
the class TestCollectConfigServletsAccess method testLDAPConfigDelegatedAdmin.
/**
* Verify that global admin can access servlet at /service/collectldapconfig/
* @throws Exception
*/
/* @Test
public void testLDAPConfigGlobalAdmin() throws Exception {
ZAuthToken at = TestUtil.getAdminSoapTransport().getAuthToken();
URI servletURI = new URI(getLDAPConfigServletUrl());
HttpState initialState = HttpClientUtil.newHttpState(at, servletURI.getHost(), true);
HttpClient restClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
restClient.setState(initialState);
restClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
GetMethod get = new GetMethod(servletURI.toString());
int statusCode = HttpClientUtil.executeMethod(restClient, get);
if(statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
fail("collectldapconfig servlet is failing. Likely Zimbra SSH access is not properly configured. " + get.getResponseHeader("X-Zimbra-Fault-Message").getValue());
} else {
assertEquals("This request should succeed. Getting status code " + statusCode, HttpStatus.SC_OK,statusCode);
}
}*/
/**
* Verify that delegated admin canNOT access servlet at /service/collectldapconfig/
* @throws Exception
*/
@Test
public void testLDAPConfigDelegatedAdmin() throws Exception {
ZAuthToken at = TestUtil.getAdminSoapTransport(TEST_ADMIN_NAME, PASSWORD).getAuthToken();
URI servletURI = new URI(getLDAPConfigServletUrl());
HttpState initialState = HttpClientUtil.newHttpState(at, servletURI.getHost(), true);
HttpClient restClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
restClient.setState(initialState);
restClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
GetMethod get = new GetMethod(servletURI.toString());
int statusCode = HttpClientUtil.executeMethod(restClient, get);
assertEquals("This request should NOT succeed. Getting status code " + statusCode, HttpStatus.SC_UNAUTHORIZED, statusCode);
}
use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.
the class TestCollectConfigServletsAccess method testConfigDelegatedAdmin.
/**
* Verify that global admin can access servlet at /service/collectconfig/
* @throws Exception
*/
/* @Test
public void testConfigGlobalAdmin() throws Exception {
ZAuthToken at = TestUtil.getAdminSoapTransport().getAuthToken();
URI servletURI = new URI(getConfigServletUrl());
HttpState initialState = HttpClientUtil.newHttpState(at, servletURI.getHost(), true);
HttpClient restClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
restClient.setState(initialState);
restClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
GetMethod get = new GetMethod(servletURI.toString());
int statusCode = HttpClientUtil.executeMethod(restClient, get);
if(statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
fail("collectconfig servlet is failing. Likely Zimbra SSH access is not properly configured. " + get.getResponseHeader("X-Zimbra-Fault-Message").getValue());
} else {
assertEquals("This request should succeed. Getting status code " + statusCode, HttpStatus.SC_OK,statusCode);
}
}*/
/**
* Verify that delegated admin canNOT access servlet at /service/collectconfig/
* @throws Exception
*/
@Test
public void testConfigDelegatedAdmin() throws Exception {
ZAuthToken at = TestUtil.getAdminSoapTransport(TEST_ADMIN_NAME, PASSWORD).getAuthToken();
URI servletURI = new URI(getConfigServletUrl());
HttpState initialState = HttpClientUtil.newHttpState(at, servletURI.getHost(), true);
HttpClient restClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
restClient.setState(initialState);
restClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
GetMethod get = new GetMethod(servletURI.toString());
int statusCode = HttpClientUtil.executeMethod(restClient, get);
assertEquals("This request should NOT succeed. Getting status code " + statusCode, HttpStatus.SC_UNAUTHORIZED, statusCode);
}
use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.
the class UndeployZimlet method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
String name = request.getAttribute(AdminConstants.A_NAME);
String action = request.getAttribute(AdminConstants.A_ACTION, null);
ZAuthToken auth = null;
if (action == null) {
auth = zsc.getRawAuthToken();
}
Element response = zsc.createElement(AdminConstants.UNDEPLOY_ZIMLET_RESPONSE);
//undeploy on local server and LDAP anyway
ZimletUtil.undeployZimletLocally(name);
if (AdminConstants.A_DEPLOYALL.equals(action)) {
//undeploy on remote servers
for (Server server : Provisioning.getInstance().getAllServers()) {
if (!server.isLocalServer()) {
checkRight(zsc, context, server, Admin.R_deployZimlet);
new Thread(new UndeployThread(server, name, auth)).start();
}
}
}
return response;
}
use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.
the class TestAccessKeyGrant method getZMailboxByKey.
private ZMailbox getZMailboxByKey() throws Exception {
Map<String, String> authAttrs = new HashMap<String, String>();
authAttrs.put(AUTH_K_ATTR, ACCESS_KEY);
authAttrs.put(AUTH_H_ATTR, getAccountId(OWNER_NAME));
ZAuthToken zat = new ZAuthToken(DUMMY_AUTH_PROVIDER, null, authAttrs);
ZMailbox.Options options = new ZMailbox.Options(zat, TestUtil.getSoapUrl());
return ZMailbox.getMailbox(options);
}
Aggregations