Search in sources :

Example 1 with NoMiddlewareConnectionException

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;
}
Also used : NoMiddlewareConnectionException(com.haulmont.cuba.portal.sys.exceptions.NoMiddlewareConnectionException) UserSession(com.haulmont.cuba.security.global.UserSession) LoginException(com.haulmont.cuba.security.global.LoginException) TrustedClientCredentials(com.haulmont.cuba.security.auth.TrustedClientCredentials) NoMiddlewareConnectionException(com.haulmont.cuba.portal.sys.exceptions.NoMiddlewareConnectionException) LoginException(com.haulmont.cuba.security.global.LoginException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Aggregations

NoMiddlewareConnectionException (com.haulmont.cuba.portal.sys.exceptions.NoMiddlewareConnectionException)1 TrustedClientCredentials (com.haulmont.cuba.security.auth.TrustedClientCredentials)1 LoginException (com.haulmont.cuba.security.global.LoginException)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1