use of com.haulmont.cuba.portal.sys.exceptions.NoMiddlewareConnectionException in project cuba by cuba-platform.
the class AnonymousSessionHolder method loginAsAnonymous.
protected UserSession loginAsAnonymous() {
String login = portalConfig.getAnonymousUserLogin();
String password = portalConfig.getTrustedClientPassword();
UserSession userSession;
try {
String portalLocationString = getPortalNetworkLocation();
String portalClientInfo = "Portal Anonymous Session";
if (StringUtils.isNotBlank(portalLocationString)) {
portalClientInfo += " (" + portalLocationString + ")";
}
TrustedClientCredentials credentials = new TrustedClientCredentials(login, password, messagesTools.getDefaultLocale());
credentials.setClientType(ClientType.PORTAL);
credentials.setClientInfo(portalClientInfo);
credentials.setParams(ParamsMap.of(ClientType.class.getName(), AppContext.getProperty("cuba.clientType"), SessionParams.CLIENT_INFO.getId(), portalClientInfo));
userSession = authenticationService.login(credentials).getSession();
} catch (LoginException e) {
throw new NoMiddlewareConnectionException("Unable to login as anonymous portal user", e);
} catch (Exception e) {
throw new NoMiddlewareConnectionException("Unable to connect to middleware services", e);
}
return userSession;
}
Aggregations