use of org.wso2.ballerinalang.compiler.parser.Parser in project carbon-apimgt by wso2.
the class DefaultIdentityProviderImpl method getIdOfUser.
@Override
public String getIdOfUser(String userName) throws IdentityProviderException {
// should not user id outside this domain and should not log that id.
try {
userName = userNameMapper.getLoggedInUserIDFromPseudoName(userName);
} catch (APIManagementException e) {
throw new IdentityProviderException(e.getMessage(), ExceptionCodes.USER_MAPPING_RETRIEVAL_FAILED);
}
Response userResponse = scimServiceStub.searchUsers(FILTER_PREFIX_USER + userName);
String userId;
if (userResponse == null) {
String errorMessage = "Error occurred while retrieving Id of user " + userName + ". Error : Response is null.";
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
if (userResponse.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
String responseBody = userResponse.body().toString();
JsonParser parser = new JsonParser();
JsonObject parsedResponseBody = (JsonObject) parser.parse(responseBody);
JsonArray user = (JsonArray) parsedResponseBody.get(RESOURCES);
JsonObject scimUser = (JsonObject) user.get(0);
userId = scimUser.get(ID).getAsString();
String message = "Id " + userId + " of user " + scimUser.get(USERNAME).getAsString() + " is successfully retrieved from SCIM endpoint.";
if (log.isDebugEnabled()) {
log.debug(message);
}
} else {
String errorMessage = "Error occurred while retrieving Id of user " + userName + ". Error : " + getErrorMessage(userResponse);
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
return userId;
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project carbon-apimgt by wso2.
the class DefaultIdentityProviderImpl method getRoleId.
@Override
public String getRoleId(String roleName) throws IdentityProviderException {
Response roleResponse = scimServiceStub.searchGroups(FILTER_PREFIX_ROLE + roleName);
String roleId;
if (roleResponse == null) {
String errorMessage = "Error occurred while retrieving Id of role " + roleName + ". Error : Response is null.";
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
if (roleResponse.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
String responseBody = roleResponse.body().toString();
JsonParser parser = new JsonParser();
JsonObject parsedResponseBody = (JsonObject) parser.parse(responseBody);
JsonArray role = (JsonArray) parsedResponseBody.get(RESOURCES);
JsonObject scimGroup = (JsonObject) role.get(0);
roleId = scimGroup.get(ID).getAsString();
String message = "Id " + roleId + " of role " + scimGroup.get(GROUPNAME).getAsString() + " is successfully retrieved from SCIM endpoint.";
if (log.isDebugEnabled()) {
log.debug(message);
}
} else {
String errorMessage = "Error occurred while retrieving Id of role " + roleName + ". Error : " + getErrorMessage(roleResponse);
log.error(errorMessage);
throw new IdentityProviderException(errorMessage, ExceptionCodes.RESOURCE_RETRIEVAL_FAILED);
}
return roleId;
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project ballerina by ballerina-lang.
the class LSCustomErrorStrategy method setContextException.
@Override
protected void setContextException(Parser parser) {
// Here the type of the exception is not important.
InputMismatchException e = new InputMismatchException(parser);
ParserRuleContext context = parser.getContext();
// the run time
if (context instanceof BallerinaParser.CallableUnitBodyContext) {
context.exception = null;
return;
}
context.exception = e;
// We need to set the error for the variable definition as well.
if (context.getParent() instanceof BallerinaParser.VariableDefinitionStatementContext) {
context.getParent().exception = e;
return;
}
if (context instanceof BallerinaParser.NameReferenceContext) {
setContextIfConnectorInit(context, e);
} else if (context instanceof BallerinaParser.ExpressionContext) {
setContextIfConditionalStatement(context, e);
}
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project ballerina by ballerina-lang.
the class Parser method generateCompilationUnit.
private CompilationUnitNode generateCompilationUnit(PackageSourceEntry sourceEntry) {
try {
int prevErrCount = dlog.errorCount;
BDiagnosticSource diagnosticSrc = getDiagnosticSource(sourceEntry);
String entryName = sourceEntry.getEntryName();
BLangCompilationUnit compUnit = (BLangCompilationUnit) TreeBuilder.createCompilationUnit();
compUnit.setName(sourceEntry.getEntryName());
compUnit.pos = new DiagnosticPos(diagnosticSrc, 1, 1, 1, 1);
ANTLRInputStream ais = new ANTLRInputStream(new ByteArrayInputStream(sourceEntry.getCode()));
ais.name = entryName;
BallerinaLexer lexer = new BallerinaLexer(ais);
lexer.removeErrorListeners();
lexer.addErrorListener(new BallerinaParserErrorListener(context, diagnosticSrc));
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
BallerinaParser parser = new BallerinaParser(tokenStream);
parser.setErrorHandler(getErrorStrategy(diagnosticSrc));
parser.addParseListener(newListener(tokenStream, compUnit, diagnosticSrc));
parser.compilationUnit();
return compUnit;
} catch (IOException e) {
throw new RuntimeException("Error in populating package model: " + e.getMessage(), e);
}
}
use of org.wso2.ballerinalang.compiler.parser.Parser in project ballerina by ballerina-lang.
the class BallerinaParserErrorStrategy method reportUnwantedToken.
@Override
public void reportUnwantedToken(Parser parser) {
if (parser.getContext().exception != null || inErrorRecoveryMode(parser)) {
return;
}
beginErrorCondition(parser);
setContextException(parser);
Token token = parser.getCurrentToken();
DiagnosticPos pos = getPosition(getMissingSymbol(parser));
dlog.error(pos, DiagnosticCode.EXTRANEOUS_INPUT, getTokenErrorDisplay(token));
}
Aggregations