Search in sources :

Example 36 with AuthTokenException

use of com.zimbra.cs.account.AuthTokenException in project zm-mailbox by Zimbra.

the class ZimbraAuthenticator method authenticate.

@Override
public Account authenticate(String username, String authenticateId, String authtoken, AuthContext.Protocol protocol, String origRemoteIp, String remoteIp, String userAgent) throws ServiceException {
    if (authenticateId == null || authenticateId.equals(""))
        return null;
    // validate the auth token
    Provisioning prov = Provisioning.getInstance();
    AuthToken at;
    try {
        at = ZimbraAuthToken.getAuthToken(authtoken);
    } catch (AuthTokenException e) {
        return null;
    }
    try {
        AuthProvider.validateAuthToken(prov, at, false);
    } catch (ServiceException e) {
        return null;
    }
    // make sure that the authentication account is valid
    Account authAccount = prov.get(Key.AccountBy.name, authenticateId, at);
    if (authAccount == null)
        return null;
    // make sure the auth token belongs to authenticatedId
    if (!at.getAccountId().equalsIgnoreCase(authAccount.getId()))
        return null;
    // make sure the protocol is enabled for the user
    if (!isProtocolEnabled(authAccount, protocol)) {
        ZimbraLog.account.info("Authentication failed - %s not enabled for %s", protocol, authAccount.getName());
        return null;
    }
    // if necessary, check that the authenticated user can authorize as the target user
    Account targetAcct = authorize(authAccount, username, AuthToken.isAnyAdmin(at));
    if (targetAcct != null)
        prov.accountAuthed(authAccount);
    return targetAcct;
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) AuthTokenException(com.zimbra.cs.account.AuthTokenException) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) Provisioning(com.zimbra.cs.account.Provisioning)

Example 37 with AuthTokenException

use of com.zimbra.cs.account.AuthTokenException in project zm-mailbox by Zimbra.

the class CsrfUtil method getAuthTokenFromReq.

/**
   *
   * @param req
   * @return
   */
public static AuthToken getAuthTokenFromReq(HttpServletRequest req) {
    AuthToken at = null;
    try {
        boolean isAdminRequest = AuthUtil.isAdminRequest(req);
        at = AuthProvider.getAuthToken(req, isAdminRequest);
    } catch (ServiceException | AuthTokenException e) {
        ZimbraLog.security.info("Error extracting auth token from the request. " + e.getMessage());
    }
    return at;
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) AuthTokenException(com.zimbra.cs.account.AuthTokenException) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken)

Aggregations

AuthTokenException (com.zimbra.cs.account.AuthTokenException)37 AuthToken (com.zimbra.cs.account.AuthToken)25 ServiceException (com.zimbra.common.service.ServiceException)24 Account (com.zimbra.cs.account.Account)20 Provisioning (com.zimbra.cs.account.Provisioning)8 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)7 IOException (java.io.IOException)7 HttpClient (org.apache.commons.httpclient.HttpClient)7 GetMethod (org.apache.commons.httpclient.methods.GetMethod)7 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)6 ServletException (javax.servlet.ServletException)6 Element (com.zimbra.common.soap.Element)5 Server (com.zimbra.cs.account.Server)5 HttpMethod (org.apache.commons.httpclient.HttpMethod)5 Domain (com.zimbra.cs.account.Domain)4 GuestAccount (com.zimbra.cs.account.GuestAccount)4 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ZMailbox (com.zimbra.client.ZMailbox)3 AccountBy (com.zimbra.common.account.Key.AccountBy)3