package com.mobius.livecycle;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;
import com.adobe.idp.um.api.UMException;
import com.adobe.idp.um.api.infomodel.AuthResult;
import com.adobe.livecycle.usermanager.client.AuthenticationManagerServiceClient;
import com.mobius.utils.ResourceManager;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
/**
* Created with IntelliJ IDEA.
* User: Pawel
* Date: 17.12.13
* Time: 15:57
* To change this template use File | Settings | File Templates.
*/
public class LiveCycleService {
private Properties connectionProperties;
private ServiceClientFactory serviceClientFactory;
private AuthenticationManagerServiceClient authClient;
private ResourceManager resourceManager;
public LiveCycleService(ResourceManager resourceManager) {
this.resourceManager = resourceManager;
}
public ServiceClientFactory getServiceClientFactory() {
return serviceClientFactory;
}
public boolean authorize(String login,String password) {
initServiceClientFactory();
initAuthenticationManagerServicesClient();
try {
AuthResult authResult = authClient.authenticate(login, password.getBytes("UTF-8"));
return true;
} catch (UMException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return false;
}
private void initServiceClientFactory()
{
connectionProperties = new Properties();
connectionProperties.setProperty(
ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT,
resourceManager.getPropValue(ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT));
connectionProperties.setProperty(
ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT,
resourceManager.getPropValue(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT));
String endpointProtocol = resourceManager.getPropValue(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL);
connectionProperties.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL, endpointProtocol);
connectionProperties.setProperty(
ServiceClientFactoryProperties.DSC_SERVER_TYPE,
ServiceClientFactoryProperties.DSC_JBOSS_SERVER_TYPE);
connectionProperties.setProperty(
ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME,
resourceManager.getPropValue(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME));
connectionProperties.setProperty(
ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD,
resourceManager.getPropValue(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD));
//ServiceClientFactory.installThrowHandler(new ServiceFactoryThrowHandler(this));
serviceClientFactory = ServiceClientFactory.createInstance(connectionProperties);
}
private void initAuthenticationManagerServicesClient()
{
authClient = new AuthenticationManagerServiceClient(getServiceClientFactory());
}
}