Search in sources :

Example 11 with ZAuthToken

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);
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) XMLElement(com.zimbra.common.soap.Element.XMLElement) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 12 with ZAuthToken

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);
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) HttpState(org.apache.commons.httpclient.HttpState) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ZAuthToken(com.zimbra.common.auth.ZAuthToken) URI(java.net.URI) Test(org.junit.Test)

Example 13 with ZAuthToken

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);
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) HttpState(org.apache.commons.httpclient.HttpState) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ZAuthToken(com.zimbra.common.auth.ZAuthToken) URI(java.net.URI) Test(org.junit.Test)

Example 14 with ZAuthToken

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;
}
Also used : Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 15 with ZAuthToken

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);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Aggregations

ZAuthToken (com.zimbra.common.auth.ZAuthToken)36 ZMailbox (com.zimbra.client.ZMailbox)14 Element (com.zimbra.common.soap.Element)11 AuthToken (com.zimbra.cs.account.AuthToken)7 ZFolder (com.zimbra.client.ZFolder)6 ServiceException (com.zimbra.common.service.ServiceException)6 XMLElement (com.zimbra.common.soap.Element.XMLElement)6 Account (com.zimbra.cs.account.Account)6 IOException (java.io.IOException)6 HttpClient (org.apache.commons.httpclient.HttpClient)6 HttpState (org.apache.commons.httpclient.HttpState)6 Test (org.junit.Test)6 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)5 ItemId (com.zimbra.cs.service.util.ItemId)5 URI (java.net.URI)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 Folder (com.zimbra.cs.mailbox.Folder)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Options (com.zimbra.client.ZMailbox.Options)2 ZMountpoint (com.zimbra.client.ZMountpoint)2