use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.
the class TestAuthentication method testSimpleAuth.
/**
* test detault auth request with login/password
* @throws Exception
*/
public void testSimpleAuth() throws Exception {
//regular auth request
Account a = TestUtil.getAccount(USER_NAME);
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, a.getName());
AuthRequest req = new AuthRequest(acctSel, "test123");
Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
String newAuthToken = authResp.getAuthToken();
assertNotNull("should have received a new authtoken", newAuthToken);
AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
assertTrue("new auth token should be registered", at.isRegistered());
assertFalse("new auth token should not be expired yet", at.isExpired());
}
use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.
the class AddGalSyncDataSource method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
AddGalSyncDataSourceRequest dsRequest = JaxbUtil.elementToJaxb(request);
String name = dsRequest.getName();
String domainStr = dsRequest.getDomain();
GalMode type = dsRequest.getType();
AccountSelector acctSelector = dsRequest.getAccount();
AccountBy acctBy = acctSelector.getBy();
String acctValue = acctSelector.getKey();
String folder = dsRequest.getFolder();
Domain domain = prov.getDomainByName(domainStr);
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
}
Account account = null;
try {
account = prov.get(acctBy.toKeyAccountBy(), acctValue, zsc.getAuthToken());
} catch (ServiceException se) {
ZimbraLog.gal.warn("error checking GalSyncAccount", se);
}
if (account == null) {
throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
}
if (!Provisioning.onLocalServer(account)) {
String host = account.getMailHost();
Server server = prov.getServerByName(host);
return proxyRequest(request, context, server);
}
CreateGalSyncAccount.addDataSource(request, zsc, account, domain, folder, name, type);
Element response = zsc.createElement(AdminConstants.ADD_GAL_SYNC_DATASOURCE_RESPONSE);
ToXML.encodeAccount(response, account, false, emptySet, null);
return response;
}
use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.
the class GetShareInfo method doGetShareInfo.
/**
* @param zsc
* @param targetAcct
* @param request
* @param response
*/
private void doGetShareInfo(ZimbraSoapContext zsc, Map<String, Object> context, Account targetAcct, Element request, GetShareInfoResponse response) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
GetShareInfoRequest req = JaxbUtil.elementToJaxb(request);
GranteeChooser granteeChooser = req.getGrantee();
byte granteeType = getGranteeType(granteeChooser);
String granteeId = granteeChooser == null ? null : granteeChooser.getId();
String granteeName = granteeChooser == null ? null : granteeChooser.getName();
Account owner = null;
AccountSelector ownerSelector = req.getOwner();
if (ownerSelector != null) {
owner = prov.get(ownerSelector);
// when an invalid user name/id is used.
if ((owner == null) || (owner.isAccountExternal())) {
return;
} else {
AccountStatus status = owner.getAccountStatus();
if (status != null && status.isClosed()) {
return;
}
}
}
OperationContext octxt = getOperationContext(zsc, context);
ShareInfo.MountedFolders mountedFolders = null;
if (!Boolean.TRUE.equals(req.getInternal())) {
// this (new ShareInfo.MountedFolders) should be executed on the requested
// account's home server.
// If we get here, we should be proxied to the right server naturally by the framework.
mountedFolders = new ShareInfo.MountedFolders(octxt, targetAcct);
}
ResultFilter resultFilter;
if (Boolean.FALSE.equals(req.getIncludeSelf())) {
resultFilter = new ResultFilterByTargetExcludeSelf(granteeId, granteeName, targetAcct);
} else {
resultFilter = new ResultFilterByTarget(granteeId, granteeName);
}
String filterDomain = null;
if (LC.PUBLIC_SHARE_VISIBILITY.samePrimaryDomain.equals(LC.getPublicShareAdvertisingScope())) {
filterDomain = targetAcct.getDomainName();
}
ResultFilter resultFilter2 = new ResultFilterForPublicShares(filterDomain);
ShareInfoVisitor visitor = new ShareInfoVisitor(prov, response, mountedFolders, resultFilter, resultFilter2);
if (owner == null) {
// retrieve from published share info
ShareInfo.Published.get(prov, targetAcct, granteeType, owner, visitor);
} else {
if (targetAcct.getId().equals(owner.getId()))
throw ServiceException.INVALID_REQUEST("cannot discover shares on self", null);
if (Provisioning.onLocalServer(owner))
ShareInfo.Discover.discover(octxt, prov, targetAcct, granteeType, owner, visitor);
else {
// issue an GetShareInfoRequest to the home server of the owner, and tell it *not*
// to proxy to the requesting account's mailbox server.
fetchRemoteShareInfo(context, request, owner.getId(), visitor);
}
}
visitor.finish();
}
use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.
the class GetAccount method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetAccountRequest req = JaxbUtil.elementToJaxb(request);
AccountSelector acctSel = req.getAccount();
if (acctSel == null) {
throw ServiceException.INVALID_REQUEST(String.format("missing <%s>", AdminConstants.E_ACCOUNT), null);
}
String accountSelectorKey = acctSel.getKey();
AccountBy by = acctSel.getBy().toKeyAccountBy();
Account account = prov.get(by, accountSelectorKey, zsc.getAuthToken());
defendAgainstAccountHarvesting(account, by, accountSelectorKey, zsc, Admin.R_getAccountInfo);
AdminAccessControl aac = checkAccountRight(zsc, account, AdminRight.PR_ALWAYS_ALLOW);
Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_RESPONSE);
boolean applyCos = !Boolean.FALSE.equals(req.isApplyCos());
Set<String> reqAttrs = getReqAttrs(req.getAttrs(), AttributeClass.account);
ToXML.encodeAccount(response, account, applyCos, reqAttrs, aac.getAttrRightChecker(account));
return response;
}
Aggregations