use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class RoleUITest method execute.
@Override
public void execute(StandaloneSupport conquery) throws Exception {
MetaStorage storage = conquery.getMetaStorage();
Role mandator = new Role("testMandatorName", "testMandatorLabel", storage);
RoleId mandatorId = mandator.getId();
User user = new User("testUser@test.de", "testUserName", storage);
UserId userId = user.getId();
try {
ConqueryPermission permission = DatasetPermission.onInstance(Ability.READ.asSet(), new DatasetId("testDatasetId"));
storage.addRole(mandator);
storage.addUser(user);
// override permission object, because it might have changed by the subject
// owning the permission
mandator.addPermission(permission);
user.addRole(mandator);
URI classBase = HierarchyHelper.hierarchicalPath(conquery.defaultAdminURIBuilder(), RoleUIResource.class, "getRole").buildFromMap(Map.of(ROLE_ID, mandatorId.toString()));
Response response = conquery.getClient().target(classBase).request().get();
assertThat(response.getStatus()).isEqualTo(200);
// Check for Freemarker Errors
assertThat(response.readEntity(String.class).toLowerCase()).doesNotContain(List.of("freemarker", "debug"));
} finally {
storage.removeRole(mandatorId);
storage.removeUser(userId);
}
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class UserAuthenticationManagementProcessor method tryRegister.
public boolean tryRegister(ProtoUser pUser) {
final UserId id = pUser.createId();
User user = storage.getUser(id);
if (user == null) {
log.warn("Unable to add new user {}. Probably already existed.", pUser);
return false;
}
log.trace("Added the user {} to the authorization storage", id);
if (AuthorizationHelper.registerForAuthentication(realm, user, pUser.getCredentials(), false)) {
log.trace("Added the user {} to the realm {}", id, realm.getName());
return true;
}
log.trace("Failed to add added the user {} to the realm {}", id, realm.getName());
return false;
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class IntrospectionDelegatingRealm method doGetAuthenticationInfo.
@Override
@SneakyThrows
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
if (!(TOKEN_CLASS.isAssignableFrom(token.getClass()))) {
log.trace("Incompatible token. Expected {}, got {}", TOKEN_CLASS, token.getClass());
return null;
}
log.trace("Token has expected format!");
TokenIntrospectionSuccessResponse successResponse = tokenCache.get((BearerToken) token);
log.trace("Got an successful token introspection response.");
UserId userId = extractId(successResponse);
User user = getUserOrThrowUnknownAccount(storage, userId);
return new ConqueryAuthenticationInfo(user, token, this, true);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class ConqueryTokenRealm method doGetAuthenticationInfo.
@Override
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
if (!(TOKEN_CLASS.isAssignableFrom(token.getClass()))) {
log.trace("Incompatible token. Expected {}, got {}", TOKEN_CLASS, token.getClass());
return null;
}
log.trace("Token has expected format: {}\tWas: {} ", TOKEN_CLASS, token.getClass());
DecodedJWT decodedToken = null;
try {
decodedToken = jwtConfig.getTokenVerifier(this).verify((String) token.getCredentials());
} catch (TokenExpiredException e) {
log.trace("The provided token is expired.");
throw new ExpiredCredentialsException(e);
} catch (SignatureVerificationException | InvalidClaimException e) {
log.trace("The provided token was not successfully verified against its signature or claims.");
throw new IncorrectCredentialsException(e);
} catch (JWTVerificationException e) {
log.trace("The provided token could not be verified.", e);
throw new AuthenticationException(e);
} catch (Exception e) {
log.trace("Unable to decode token", e);
throw new AuthenticationException(e);
}
log.trace("Received valid token.");
String username = decodedToken.getSubject();
UserId userId = UserId.Parser.INSTANCE.parse(username);
final User user = getUserOrThrowUnknownAccount(storage, userId);
return new ConqueryAuthenticationInfo(user, token, this, true);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class UserIdTokenExtractor method apply.
/**
* Tries to extract a plain {@link UserId} from the request to submit it for the authentication process.
*/
@Override
public AuthenticationToken apply(ContainerRequestContext requestContext) {
// Check if the developer passed a UserId under whose the Request should be
// executed
// Check the Authorization header for a String which can be parsed as a UserId
String uid = requestContext.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
if (uid != null) {
uid = uid.replaceFirst("^Bearer ", "");
} else {
// Check also the query parameter "access_token" for a UserId
uid = requestContext.getUriInfo().getQueryParameters().getFirst(UID_QUERY_STRING_PARAMETER);
}
UserId userId = null;
if (StringUtils.isEmpty(uid)) {
// If nothing was found execute the request as the default user
userId = defaultUser.getId();
return new DevelopmentToken(userId, uid);
}
try {
userId = UserId.Parser.INSTANCE.parse(uid);
log.trace("Parsed UserId: {}", userId);
return new DevelopmentToken(userId, uid);
} catch (Exception e) {
log.trace("Unable to extract a valid user id.");
return null;
}
}
Aggregations