Use Case: a remote app (CAS for SSO) to authenticate against Liferay Portal
Out of box, Liferay does not expose authentication methods so this is what I did to expose one of their methods in Extension Environment.
1. edit service.xml to include the following
<entity name="MyUser" local-service="true" remote-service="true"></entity>
2. build service, add a method in MyUserServiceImpl, and rebuild service
public int authenticateByEmailAddress(
long companyId, String emailAddress, String password)
throws PortalException, SystemException {
Map headerMap = null;
Map parameterMap = null;
int isAuthenticated = UserLocalServiceUtil.authenticateByEmailAddress(companyId, emailAddress, password, headerMap, parameterMap);
return isAuthenticated;
}
3. "ant build-wsdd" in ext-impl/ to generate /ext-web/docroot/WEB-INF/server-config.wsdd for SOAP calls
4. ant clean deploy and you are done exposing a method. Check it out at /tunnel-web/secure/axis.

To consume the newly exposed method, I wanted to generate ext-client.jar just like Liferay did with portal-client.jar so I did the following.
1. create ext-client/
2. copy over build.xml from portal-client/ and edit to use ext-client instead of portal-ext and to pass in server-config.wsdd from ext-web instead of tunnel-web
3. create namespaceMapping.properties and put in a mapping (package=namespace). Hint: use namespace from the value of wsdlTargetNamespace in server-config.wsdd
com.company.portal.service.http=http.service.portal.company.com
4. While localhost is up and running, run "ant build-client" to generate ext-client.jar
5. Test consuming with ext-client.jar
import java.net.URL;
import com.company.portal.service.http.MyUserServiceSoap;
import com.company.portal.service.http.MyUserServiceSoapServiceLocator;
public class LiferayClient {
public static void main(String [] args) {
long userId = 54321L;
long companyId = 12345L;
String email = "me@company.com";
String password = "notTellingYou";
try {
MyUserServiceSoapServiceLocator locator = new MyUserServiceSoapServiceLocator();
MyUserServiceSoap soap = locator.getPortal_MyUserService(_getURL(Long.toString(userId), "Portal_MyUserService"));
int isAuthenticated = soap.authenticateByEmailAddress(companyId, email, password);
System.out.println("is user authenticated? " + isAuthenticated);
} catch (Exception e) {
System.err.println(e.toString());
}
}
private static URL _getURL(String remoteUser, String serviceName) throws Exception {
String password = "secret";
url = "http://" + remoteUser + ":" + password + "@localhost:8080/tunnel-web/secure/axis/" + serviceName;
return new URL(url);
}
}
Hope this help. If it does, we could turn this thread into a wiki post.
Please sign in to flag this as inappropriate.