use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class AuthProvider method getAuthToken.
/**
* Creates an AuthToken object from token string.
*
* @param encoded
* @return
* @throws AuthTokenException
* @see #authToken(String)
*/
public static AuthToken getAuthToken(String encoded) throws AuthTokenException {
AuthToken at = null;
List<AuthProvider> providers = getProviders();
AuthTokenException authTokenExp = null;
for (AuthProvider ap : providers) {
try {
at = ap.authToken(encoded);
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().warn(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
logger().error("unable to get AuthToken from encoded " + encoded);
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 account, Usage usage) throws AuthProviderException {
List<AuthProvider> providers = getProviders();
AuthProviderException authProviderExp = null;
for (AuthProvider ap : providers) {
try {
AuthToken at = ap.authToken(account, usage);
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 " + account.getName());
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class AuthProvider method getAuthToken.
public static AuthToken getAuthToken(Account acct, boolean isAdmin, AuthMech authMech) throws AuthProviderException {
List<AuthProvider> providers = getProviders();
AuthProviderException authProviderExp = null;
for (AuthProvider ap : providers) {
try {
AuthToken at = ap.authToken(acct, isAdmin, authMech);
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;
}
}
}
String acctName = acct != null ? acct.getName() : "null";
if (null != authProviderExp) {
throw authProviderExp;
}
throw AuthProviderException.FAILURE("cannot get authtoken from account " + acctName);
}
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, boolean isAdmin, Account adminAcct) throws AuthProviderException {
List<AuthProvider> providers = getProviders();
AuthProviderException authProviderExp = null;
for (AuthProvider ap : providers) {
try {
AuthToken at = ap.authToken(acct, expires, isAdmin, adminAcct);
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 UserServlet method getExternalRestUrl.
/**
* Constructs the exteral url for a mount point. This gets the link back to the correct server without need for proxying it
* @param authToken
* @param mpt The mount point to create the url for
* @return The url for the mountpoint/share that goes back to the original user/share/server
* @throws ServiceException
*/
public static String getExternalRestUrl(OperationContext octxt, Mountpoint mpt) throws ServiceException {
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(octxt.getAuthToken());
// no need to do anything
if (mpt.isLocal()) {
return null;
}
String folderPath = null;
// Figure out the target server from the target user's account.
// This will let us get the correct server/port
Provisioning prov = Provisioning.getInstance();
Account targetAccount = prov.get(AccountBy.id, mpt.getOwnerId());
if (targetAccount == null) {
// Remote owner account has been deleted.
return null;
}
Server targetServer = prov.getServer(targetAccount);
// Avoid the soap call if its a local mailbox
if (Provisioning.onLocalServer(targetAccount)) {
Mailbox mailbox = MailboxManager.getInstance().getMailboxByAccountId(targetAccount.getId());
if (mailbox == null) {
// no mailbox (shouldn't happen normally)
return null;
}
// Get the folder from the mailbox
Folder folder = mailbox.getFolderById(octxt, mpt.getRemoteId());
if (folder == null) {
return null;
}
folderPath = folder.getPath();
} else {
// The remote server case
// Get the target user's mailbox..
ZMailbox.Options zoptions = new ZMailbox.Options(authToken.toZAuthToken(), AccountUtil.getSoapUri(targetAccount));
zoptions.setTargetAccount(mpt.getOwnerId());
zoptions.setTargetAccountBy(AccountBy.id);
zoptions.setNoSession(true);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
if (zmbx == null) {
// we didn't manage to get a mailbox
return null;
}
// Get an instance of their folder so we can build the path correctly
ZFolder folder = zmbx.getFolderById(mpt.getTarget().toString(authToken.getAccount().getId()));
// if for some reason we can't find the folder, return null
if (folder == null) {
return null;
}
folderPath = folder.getPath();
}
// For now we'll always use SSL
return URLUtil.getServiceURL(targetServer, SERVLET_PATH + HttpUtil.urlEscape(getAccountPath(targetAccount) + folderPath), true);
}
Aggregations