use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class AuthenticationUtils method loginOnBehalf.
public static void loginOnBehalf(SsoContext ssoContext, HttpServletRequest request, String username) throws Exception {
log.debug("Entered AuthenticationUtils.loginOnBehalf");
int index = username.lastIndexOf("@");
String profile = null;
if (index != -1) {
profile = username.substring(index + 1);
username = username.substring(0, index);
}
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(profile)) {
throw new AuthenticationException(ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_PROVIDE_USERNAME_AND_PROFILE, (Locale) request.getAttribute(SsoConstants.LOCALE)));
}
ObjectMapper mapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false).enableDefaultTyping(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE);
mapper.getDeserializationConfig().addMixInAnnotations(ExtMap.class, JsonExtMapMixIn.class);
String authRecordJson = SsoUtils.getRequestParameter(request, SsoConstants.HTTP_PARAM_AUTH_RECORD, "");
ExtMap authRecord;
if (StringUtils.isNotEmpty(authRecordJson)) {
authRecord = mapper.readValue(authRecordJson, ExtMap.class);
} else {
authRecord = new ExtMap().mput(Authn.AuthRecord.PRINCIPAL, username);
}
SsoSession ssoSession = login(ssoContext, request, new Credentials(username, null, profile, SsoUtils.getSsoContext(request).getSsoProfiles().contains(profile)), authRecord, false);
log.info("User {}@{} successfully logged in using login-on-behalf with client id : {} and scopes : {}", username, profile, ssoSession.getClientId(), ssoSession.getScope());
}
use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class AuthenticationUtils method login.
private static SsoSession login(SsoContext ssoContext, HttpServletRequest request, Credentials credentials, ExtMap authRecord, boolean interactive) throws Exception {
ExtensionProfile profile = getExtensionProfile(ssoContext, credentials.getProfile());
String user = mapUser(profile, credentials);
if (authRecord == null) {
log.debug("AuthenticationUtils.handleCredentials invoking AUTHENTICATE_CREDENTIALS on authn");
ExtMap outputMap = profile.authn.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Authn.InvokeCommands.AUTHENTICATE_CREDENTIALS).mput(Authn.InvokeKeys.USER, user).mput(Authn.InvokeKeys.CREDENTIALS, credentials.getPassword()));
if (outputMap.<Integer>get(Base.InvokeKeys.RESULT) != Base.InvokeResult.SUCCESS || outputMap.<Integer>get(Authn.InvokeKeys.RESULT) != Authn.AuthResult.SUCCESS) {
if (interactive) {
SsoUtils.getSsoSession(request).setChangePasswdCredentials(credentials);
}
log.debug("AuthenticationUtils.handleCredentials AUTHENTICATE_CREDENTIALS on authn failed");
throw new AuthenticationException(AuthnMessageMapper.mapMessageErrorCode(ssoContext, request, credentials.getProfile(), outputMap));
}
log.debug("AuthenticationUtils.handleCredentials AUTHENTICATE_CREDENTIALS on authn succeeded");
authRecord = outputMap.get(Authn.InvokeKeys.AUTH_RECORD);
}
if (profile.mapper != null) {
log.debug("AuthenticationUtils.handleCredentials invoking MAP_AUTH_RECORD on mapper");
authRecord = profile.mapper.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Mapping.InvokeCommands.MAP_AUTH_RECORD).mput(Authn.InvokeKeys.AUTH_RECORD, authRecord), true).get(Authn.InvokeKeys.AUTH_RECORD, authRecord);
}
log.debug("AuthenticationUtils.handleCredentials invoking FETCH_PRINCIPAL_RECORD on authz");
ExtMap output = profile.authz.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Authz.InvokeCommands.FETCH_PRINCIPAL_RECORD).mput(Authn.InvokeKeys.AUTH_RECORD, authRecord).mput(Authz.InvokeKeys.QUERY_FLAGS, Authz.QueryFlags.RESOLVE_GROUPS | Authz.QueryFlags.RESOLVE_GROUPS_RECURSIVE));
log.debug("AuthenticationUtils.handleCredentials saving data in session data");
return SsoUtils.persistAuthInfoInContextWithToken(request, credentials.getPassword(), credentials.getProfile(), authRecord, output.get(Authz.InvokeKeys.PRINCIPAL_RECORD));
}
use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class AuthenticationUtils method mapUser.
private static String mapUser(ExtensionProfile profile, Credentials credentials) {
String user = credentials.getUsername();
if (profile.mapper != null) {
log.debug("AuthenticationUtils.handleCredentials invoking MAP_USER on mapper");
user = profile.mapper.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Mapping.InvokeCommands.MAP_USER).mput(Mapping.InvokeKeys.USER, user), true).get(Mapping.InvokeKeys.USER, user);
}
return user;
}
use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class CreateUserSessionCommand method flatGroups.
private static void flatGroups(ExtMap entity, ExtKey key, Map<String, ExtMap> accumulator) {
for (ExtMap group : entity.<Collection<ExtMap>>get(key, Collections.<ExtMap>emptyList())) {
if (!accumulator.containsKey(group.<String>get(Authz.GroupRecord.ID))) {
accumulator.put(group.get(Authz.GroupRecord.ID), group);
flatGroups(group, Authz.GroupRecord.GROUPS, accumulator);
}
}
}
use of org.ovirt.engine.api.extensions.ExtMap in project ovirt-engine by oVirt.
the class CreateUserSessionCommand method buildUser.
private DbUser buildUser(T params, String authzName) {
DbUser dbUser = dbUserDao.getByExternalId(authzName, params.getPrincipalId());
DbUser user = new DbUser(dbUser);
user.setId(dbUser == null ? Guid.newGuid() : dbUser.getId());
user.setExternalId(params.getPrincipalId());
user.setDomain(authzName);
user.setEmail(params.getEmail());
user.setFirstName(params.getFirstName());
user.setLastName(params.getLastName());
user.setNamespace(params.getNamespace());
user.setLoginName(params.getPrincipalName());
List<Guid> groupIds = new ArrayList<>();
Map<String, ExtMap> groupRecords = new HashMap<>();
flatGroups((Collection<ExtMap>) params.getGroupIds(), groupRecords);
for (Map.Entry<String, ExtMap> group : groupRecords.entrySet()) {
DbGroup dbGroup = dbGroupDao.getByExternalId(authzName, group.getKey());
if (dbGroup != null) {
dbGroup.setName(group.getValue().get(Authz.GroupRecord.NAME));
dbGroupDao.update(dbGroup);
groupIds.add(dbGroup.getId());
}
}
user.setGroupIds(groupIds);
user.setAdmin(!roleDao.getAnyAdminRoleForUserAndGroups(user.getId(), StringUtils.join(user.getGroupIds(), ",")).isEmpty());
if (dbUser == null) {
dbUserDao.save(user);
} else if (!dbUser.equals(user)) {
dbUserDao.update(user);
}
return user;
}
Aggregations