Search in sources :

Example 1 with IdpSession

use of com.haulmont.cuba.security.global.IdpSession in project cuba by cuba-platform.

the class IdpServiceController method getSession.

@RequestMapping(value = "get", method = RequestMethod.GET)
public IdpSession getSession(@RequestParam("idpSessionId") String idpSessionId, @RequestParam("trustedServicePassword") String trustedServicePassword, HttpServletResponse response) {
    if (!Objects.equals(idpConfig.getTrustedServicePassword(), trustedServicePassword)) {
        response.setStatus(HttpStatus.UNAUTHORIZED.value());
        log.warn("Incorrect trusted client password has been passed {}", trustedServicePassword);
        return null;
    }
    log.debug("Get IDP session {}", idpSessionId);
    IdpSession idpSession = idpService.getSession(idpSessionId);
    if (idpSession == null) {
        log.debug("IDP Session not found for id {}", idpSessionId);
        response.setStatus(HttpStatus.GONE.value());
        return null;
    }
    log.debug("IDP session {} obtained", idpSession);
    return idpSession;
}
Also used : IdpSession(com.haulmont.cuba.security.global.IdpSession) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with IdpSession

use of com.haulmont.cuba.security.global.IdpSession in project cuba by cuba-platform.

the class IdpServiceController method activateServiceProviderTicket.

@RequestMapping(value = "activate", method = RequestMethod.POST)
public IdpSession activateServiceProviderTicket(@RequestParam("serviceProviderTicket") String serviceProviderTicket, @RequestParam("trustedServicePassword") String trustedServicePassword, HttpServletResponse response) {
    if (!Objects.equals(idpConfig.getTrustedServicePassword(), trustedServicePassword)) {
        response.setStatus(HttpStatus.UNAUTHORIZED.value());
        log.warn("Incorrect trusted client password has been passed {}", trustedServicePassword);
        return null;
    }
    log.debug("Activate service provider ticket {}", serviceProviderTicket);
    IdpSession idpSession = idpService.activateServiceProviderTicket(serviceProviderTicket);
    if (idpSession == null) {
        log.debug("IDP Session not found for ticket {}", serviceProviderTicket);
        response.setStatus(HttpStatus.GONE.value());
        return null;
    }
    log.debug("IDP ticket {} activated for session {}", serviceProviderTicket, idpSession);
    return idpSession;
}
Also used : IdpSession(com.haulmont.cuba.security.global.IdpSession) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with IdpSession

use of com.haulmont.cuba.security.global.IdpSession in project cuba by cuba-platform.

the class IdpSessionJsonTest method idpSessionFromJson.

@Test
public void idpSessionFromJson() {
    String sessionJson = "{\"id\":\"ba8693d910404111b3eac8636192d1ff\"," + "\"attributes\":{\"demo3\":2.2,\"demo1\":1,\"demo2\":\"test\"}}";
    IdpSession session = new Gson().fromJson(sessionJson, IdpSession.class);
    assertNotNull(session);
}
Also used : IdpSession(com.haulmont.cuba.security.global.IdpSession) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 4 with IdpSession

use of com.haulmont.cuba.security.global.IdpSession in project cuba by cuba-platform.

the class IdpSessionJsonTest method idpSessionToJson.

@Test
public void idpSessionToJson() {
    IdpSession session = new IdpSession(UUID.randomUUID().toString().replace("-", ""));
    session.setAttributes(new HashMap<>());
    session.getAttributes().put("demo1", 1);
    session.getAttributes().put("demo2", "test");
    session.getAttributes().put("demo3", 2.2);
    String json = new Gson().toJson(session);
    assertNotNull(json);
}
Also used : IdpSession(com.haulmont.cuba.security.global.IdpSession) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 5 with IdpSession

use of com.haulmont.cuba.security.global.IdpSession in project cuba by cuba-platform.

the class IdpServiceBean method login.

@Nonnull
@Override
public IdpLoginResult login(String login, String password, Locale locale, @Nullable Map<String, Object> parameters) throws LoginException {
    log.debug("Authenticating CUBA user for IDP");
    LoginPasswordCredentials credentials = new LoginPasswordCredentials(login, password, locale, parameters);
    AuthenticationDetails sessionDetails = authenticationManager.authenticate(credentials);
    User user = sessionDetails.getSession().getUser();
    IdpSession session = new IdpSession(createIdpSessionId());
    session.setLogin(user.getLogin());
    session.setEmail(user.getEmail());
    Locale userLocale = locale;
    if (user.getLanguage() != null && !globalConfig.getLocaleSelectVisible()) {
        userLocale = LocaleUtils.toLocale(user.getLanguage());
    }
    session.setLocale(userLocale.toLanguageTag());
    String serviceProviderTicket = sessionStore.putSession(session);
    return new IdpLoginResult(session.getId(), serviceProviderTicket);
}
Also used : User(com.haulmont.cuba.security.entity.User) LoginPasswordCredentials(com.haulmont.cuba.security.auth.LoginPasswordCredentials) IdpSession(com.haulmont.cuba.security.global.IdpSession) AuthenticationDetails(com.haulmont.cuba.security.auth.AuthenticationDetails) Nonnull(javax.annotation.Nonnull)

Aggregations

IdpSession (com.haulmont.cuba.security.global.IdpSession)18 Gson (com.google.gson.Gson)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 VaadinRequest (com.vaadin.server.VaadinRequest)2 IOException (java.io.IOException)2 Principal (java.security.Principal)2 Nullable (javax.annotation.Nullable)2 HttpResponse (org.apache.http.HttpResponse)2 HttpClient (org.apache.http.client.HttpClient)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpClientConnectionManager (org.apache.http.conn.HttpClientConnectionManager)2 BasicResponseHandler (org.apache.http.impl.client.BasicResponseHandler)2 BasicHttpClientConnectionManager (org.apache.http.impl.conn.BasicHttpClientConnectionManager)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 Test (org.junit.Test)2 AuthenticationDetails (com.haulmont.cuba.security.auth.AuthenticationDetails)1 LoginPasswordCredentials (com.haulmont.cuba.security.auth.LoginPasswordCredentials)1 User (com.haulmont.cuba.security.entity.User)1