use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class AuthorizationApiImpl method createAuthorizationPkgRule.
@Override
public CreateAuthorizationPkgRuleResult createAuthorizationPkgRule(CreateAuthorizationPkgRuleRequest request) throws AuthorizationRuleConflictException {
Preconditions.checkNotNull(request);
Preconditions.checkState(!Strings.isNullOrEmpty(request.permissionCode), "the permission code is required");
Preconditions.checkState(org.haiku.haikudepotserver.security.model.Permission.valueOf(request.permissionCode.toUpperCase()).getRequiredTargetType() == TargetType.PKG, "the permission should have a target type of; " + TargetType.PKG);
Preconditions.checkState(!Strings.isNullOrEmpty(request.userNickname), "the user nickname must be supplied");
ensureCanAuthorizationManipulate();
ObjectContext context = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Permission permission = ensurePermission(context, request.permissionCode);
User user = ensureUser(context, request.userNickname);
if (user.getIsRoot()) {
throw new ValidationException(new ValidationFailure("user", "root"));
}
Pkg pkg = null;
if (null != request.pkgName) {
pkg = ensurePkg(context, request.pkgName);
}
if (authorizationPkgRulesService.wouldConflict(context, user, permission, pkg)) {
throw new AuthorizationRuleConflictException();
}
authorizationPkgRulesService.create(context, user, permission, pkg);
context.commitChanges();
return new CreateAuthorizationPkgRuleResult();
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class AuthorizationApiImpl method removeAuthorizationPkgRule.
@Override
public RemoveAuthorizationPkgRuleResult removeAuthorizationPkgRule(RemoveAuthorizationPkgRuleRequest request) {
Preconditions.checkNotNull(request);
Preconditions.checkState(!Strings.isNullOrEmpty(request.permissionCode), "the permission code is required");
Preconditions.checkState(!Strings.isNullOrEmpty(request.userNickname), "the user nickname is required");
ensureCanAuthorizationManipulate();
ObjectContext context = serverRuntime.newContext();
org.haiku.haikudepotserver.dataobjects.Permission permission = ensurePermission(context, request.permissionCode);
User user = null;
if (null != request.userNickname) {
user = ensureUser(context, request.userNickname);
}
Pkg pkg = null;
if (!Strings.isNullOrEmpty(request.pkgName)) {
pkg = ensurePkg(context, request.pkgName);
}
authorizationPkgRulesService.remove(context, user, permission, pkg);
context.commitChanges();
return new RemoveAuthorizationPkgRuleResult();
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class AuthorizationJobApiImpl method queueAuthorizationRulesSpreadsheet.
@Override
public QueueAuthorizationRulesSpreadsheetResult queueAuthorizationRulesSpreadsheet(QueueAuthorizationRulesSpreadsheetRequest request) {
Preconditions.checkArgument(null != request, "a request objects is required");
final ObjectContext context = serverRuntime.newContext();
User user = obtainAuthenticatedUser(context);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.AUTHORIZATION_CONFIGURE)) {
String msg = "attempt to queue authorization spreadsheet without sufficient authorization";
LOGGER.warn(msg);
throw new AccessDeniedException(msg);
}
QueueAuthorizationRulesSpreadsheetResult result = new QueueAuthorizationRulesSpreadsheetResult();
result.guid = jobService.submit(new AuthorizationRulesSpreadsheetJobSpecification(), JobSnapshot.COALESCE_STATUSES_QUEUED_STARTED);
return result;
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class UserApiIT method testCreateUser.
@Test
public void testCreateUser() {
Captcha captcha = captchaService.generate();
CreateUserRequest request = new CreateUserRequest();
request.captchaToken = captcha.getToken();
request.captchaResponse = captcha.getResponse();
request.nickname = "testuser";
request.passwordClear = "Ue4nI92Rw";
request.naturalLanguageCode = "en";
request.userUsageConditionsCode = "UUC2021V01";
// ------------------------------------
CreateUserResult result = userApi.createUser(request);
// ------------------------------------
Assertions.assertThat(result).isNotNull();
ObjectContext context = serverRuntime.newContext();
Optional<User> userOptional = User.tryGetByNickname(context, "testuser");
Assertions.assertThat(userOptional.isPresent()).isTrue();
User user = userOptional.get();
Assertions.assertThat(user.getActive()).isTrue();
Assertions.assertThat(user.getIsRoot()).isFalse();
Assertions.assertThat(user.getNickname()).isEqualTo("testuser");
Assertions.assertThat(user.getNaturalLanguage().getCode()).isEqualTo("en");
Assertions.assertThat(user.getLastAuthenticationTimestamp()).isNull();
Assertions.assertThat(user.tryGetUserUsageConditionsAgreement().get().getUserUsageConditions().getCode()).isEqualTo("UUC2021V01");
Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "Ue4nI92Rw").get()).isEqualTo(userOptional.get().getObjectId());
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class UserApiIT method testRenewToken.
@Test
public void testRenewToken() {
String token;
ObjectId userOid;
{
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
userOid = user.getObjectId();
token = userAuthenticationService.generateToken(user);
}
RenewTokenRequest renewTokenRequest = new RenewTokenRequest();
renewTokenRequest.token = token;
// ------------------------------------
RenewTokenResult result = userApi.renewToken(renewTokenRequest);
// ------------------------------------
{
Optional<ObjectId> afterUserObjectId = userAuthenticationService.authenticateByToken(result.token);
Assertions.assertThat(userOid).isEqualTo(afterUserObjectId.get());
}
}
Aggregations