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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations