use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class Mailbox method getAuthToken.
private AuthToken getAuthToken(OperationContext octxt) throws ServiceException {
AuthToken authToken = octxt == null ? null : octxt.getAuthToken();
if (authToken == null) {
Account authuser = octxt == null ? getAccount() : octxt.getAuthenticatedUser();
boolean isAdminRequest = octxt == null ? false : octxt.isUsingAdminPrivileges();
authToken = AuthProvider.getAuthToken(authuser, isAdminRequest);
}
return authToken;
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class Mailbox method refreshMountpoint.
/**
* Updates the remote owner and item id stored in the mountpoint to match the current location of the
* target folder. The target folder is identified by the remote UUID stored in the mountpoint's metadata.
* @param octxt
* @param mountpointId item id of the Mountpoint
* @return
* @throws ServiceException
*/
public Mountpoint refreshMountpoint(OperationContext octxt, int mountpointId) throws ServiceException {
Mountpoint mp = getMountpointById(octxt, mountpointId);
Provisioning prov = Provisioning.getInstance();
ShareLocator shloc = prov.getShareLocatorById(mp.getRemoteUuid());
if (shloc == null || mp.getOwnerId().equalsIgnoreCase(shloc.getShareOwnerAccountId())) {
// Share apparently did not move.
return mp;
}
// Look up remote folder by UUID to discover the new numeric id.
Account shareOwner = Provisioning.getInstance().get(Key.AccountBy.id, shloc.getShareOwnerAccountId());
AuthToken at = AuthToken.getCsrfUnsecuredAuthToken(octxt.getAuthToken());
String pxyAuthToken = Provisioning.onLocalServer(shareOwner) ? null : at.getProxyAuthToken();
ZAuthToken zat = null;
if (pxyAuthToken == null) {
zat = at.toZAuthToken();
zat.resetProxyAuthToken();
} else {
zat = new ZAuthToken(pxyAuthToken);
}
ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(shareOwner));
zoptions.setNoSession(true);
zoptions.setTargetAccount(shareOwner.getId());
zoptions.setTargetAccountBy(Key.AccountBy.id);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
ZFolder zfolder = zmbx.getFolderByUuid(shloc.getUuid());
if (zfolder != null) {
ItemId fid = new ItemId(zfolder.getId(), shareOwner.getId());
return refreshMountpoint(octxt, mountpointId, shareOwner.getId(), fid.getId());
} else {
return null;
}
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class AuthProvider method getAuthToken.
public static AuthToken getAuthToken(Account acct, long expires) throws AuthProviderException {
List<AuthProvider> providers = getProviders();
AuthProviderException authProviderExp = null;
for (AuthProvider ap : providers) {
try {
AuthToken at = ap.authToken(acct, expires);
if (at == null) {
authProviderExp = AuthProviderException.FAILURE("auth provider " + ap.getName() + " returned null");
} else {
return at;
}
} catch (AuthProviderException e) {
if (e.canIgnore()) {
logger().debug(ap.getName() + ":" + e.getMessage());
} else {
authProviderExp = e;
}
}
}
if (null != authProviderExp) {
throw authProviderExp;
}
throw AuthProviderException.FAILURE("cannot get authtoken from account " + acct.getName());
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class AuthProvider method getAuthToken.
public static AuthToken getAuthToken(Element authTokenElem, Account acct) throws AuthTokenException {
AuthToken at = null;
List<AuthProvider> providers = getProviders();
AuthTokenException authTokenExp = null;
for (AuthProvider ap : providers) {
try {
at = ap.authToken(authTokenElem, acct);
if (at == null) {
authTokenExp = new AuthTokenException("auth provider " + ap.getName() + " returned null");
} else {
return at;
}
} catch (AuthProviderException e) {
// if there is no auth data for this provider, log and continue with next provider
if (e.canIgnore()) {
logger().debug(ap.getName() + ":" + e.getMessage());
} else {
authTokenExp = new AuthTokenException("auth provider error", e);
}
} catch (AuthTokenException e) {
//log and store exception reference
authTokenExp = e;
logger().debug("getAuthToken error: provider=" + ap.getName() + ", err=" + e.getMessage(), e);
}
}
//If multiple auth providers caused AuthTokenException, then last exception is rethrown from here.
if (null != authTokenExp) {
throw authTokenExp;
}
// there is no auth data for any of the enabled providers
return null;
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class AuthProvider method getAuthToken.
/**
* The static getAuthToken methods go through all the providers, trying them in order
* until one returns an AuthToken.
*
* If any provider in the chain throws AuthTokenException,
* it will be stored and re-thrown to caller at the end.
*
* If more than one provider throws AuthTokenException then exception reported
* by last provider will be thrown to caller.
*
* If AuthProviderException is thrown by provider then-
* - For AuthProviderException that is ignorable(AuthProviderException.NO_AUTH_TOKEN, AuthProviderException.NOT_SUPPORTED),
* it will be logged and next provider will be tried.
* - For AuthProviderExceptions that is not ignorable, AuthTokenException is generated and stored,
* thrown at the end if all provider fails.
*
* Return null when all providers fails to get AuthToken and no exception thrown by any provider.
*/
/**
* @param req http request
* @return an AuthToken object, or null if auth data is not present for any of the enabled providers
* @throws ServiceException
*/
public static AuthToken getAuthToken(HttpServletRequest req, boolean isAdminReq) throws AuthTokenException {
AuthToken at = null;
List<AuthProvider> providers = getProviders();
AuthTokenException authTokenExp = null;
for (AuthProvider ap : providers) {
try {
at = ap.authToken(req, isAdminReq);
if (at == null) {
authTokenExp = new AuthTokenException("auth provider " + ap.getName() + " returned null");
} else {
return at;
}
} catch (AuthProviderException e) {
// if there is no auth data for this provider, log and continue with next provider
if (e.canIgnore()) {
logger().debug(ap.getName() + ":" + e.getMessage());
} else {
authTokenExp = new AuthTokenException("auth provider error", e);
}
} catch (AuthTokenException e) {
//log and store exception reference
authTokenExp = e;
logger().debug("getAuthToken error: provider=" + ap.getName() + ", err=" + e.getMessage(), e);
}
}
//If multiple auth providers caused AuthTokenException, then last exception is rethrown from here.
if (null != authTokenExp) {
throw authTokenExp;
}
// there is no auth data for any of the enabled providers
return null;
}
Aggregations