apache sling service user mapper service amendment ---> I have provided the details in service mapping ....and saved it.. where we can see our newly created or added configuration ?
I am adding but I its nt getting saved ...
I have given all permission to newly created system user.
Solved! Go to Solution.
Any changes/additions of configurations from the web console will be saved under /apps/system/config
So, for your case, service user mapping should be saved under:/apps/system/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl*******
Attaching a screenshot for reference below where I tried to create a test config:
Have you checked the relevant .config file in CRX/DE ?
/libs/system/config/
Views
Replies
Total Likes
Any changes/additions of configurations from the web console will be saved under /apps/system/config
So, for your case, service user mapping should be saved under:/apps/system/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl*******
Attaching a screenshot for reference below where I tried to create a test config:
You should also see your mapping (mapping:) at http://localhost:port/system/console/configMgr
Thanks @Vish.dhaliwal and @JaideepBrar
and @hamidk92094312
Please help me out on this.
Actually I am facing the issue with usermapper service configuration....
Below underlined code is not working properly .not able to create .xlsi file isnide /content/dam ,WHEN i am hitting the servlet localhost:4503/bin/excel.....
Note:
1)system user : amit which I have created having all permission .
2)workbook.close()and closing and all is not main problems .
@SlingServlet(paths = "/bin/excel")
//@Model(adaptables={ Resource.class, SlingHttpServletRequest.class})
public class ExcelReading extends SlingAllMethodsServlet {
@Reference
ResourceResolverFactory resourceResolverFactory;
//private String filename="C:/Users/amipande5/Desktop/AEM_Docx/planetexcelfile.xlsx";
private String filename="/content/dam/amitsample/planetexcelfile.xlsx";
@Override
public void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException {
Logger logger = LoggerFactory.getLogger(ExcelReading.class);
String[] headerlist={"Planet_name","diameter","gravity","Surface_water","rotation_period","orbital_period"};
Map<String, Object> usermap = new HashMap<String, Object>();
usermap.put(ResourceResolverFactory.SUBSERVICE,"anyname");
Apireading apireading=new Apireading();
try {
apireading.activate();
} catch (Exception e) {
e.printStackTrace();
}
int rowcount= apireading.getResultsObjlist().size();
ArrayList<Results> resultsObjlist = apireading.getResultsObjlist();
//planetsheet.createRow(rowcount);
Workbook workbook = new XSSFWorkbook();
Sheet planetsheet = workbook.createSheet("planet");
Row headerrow=planetsheet.createRow(0);
for (int i=0;i<headerlist.length;i++) {
Cell cell = headerrow.createCell(i);
cell.setCellValue(headerlist[i]);
}
for(int m=1;m<rowcount+1;m++) {
Row otherRows = planetsheet.createRow(m);
Cell cellOne = otherRows.createCell(0);
cellOne.setCellValue(resultsObjlist.get(m-1).getName());
Cell cellTwo = otherRows.createCell(1);
cellTwo.setCellValue(resultsObjlist.get(m-1).getDiameter());
Cell cellThree = otherRows.createCell(2);
cellThree.setCellValue(resultsObjlist.get(m-1).getGravity());
Cell cellfourth = otherRows.createCell(3);
cellfourth.setCellValue(resultsObjlist.get(m-1).getSurface_water());
Cell cellfifth = otherRows.createCell(4);
cellfifth.setCellValue(resultsObjlist.get(m-1).getRotation_period());
Cell cellSixth = otherRows.createCell(5);
cellSixth.setCellValue(resultsObjlist.get(m-1).getOrbital_period());
ByteArrayOutputStream baos=new ByteArrayOutputStream();
workbook.write(baos);
ByteArrayInputStream bais=new ByteArrayInputStream(baos.toByteArray());
try {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(usermap);
AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
String filename1="planet.xlsx";
Asset asset = assetManager.createAsset("/content/dam/amit/" + filename1, bais, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", true);
//application/vnd.ms-excel
}
catch (LoginException e){
logger.info("Error obtaining the admin resource resolver.", e);
}
response.getWriter().print("anything");
//workbook.close();
}
}
it would be good if i get to know how i can verify that my system user has been mapped to service and I am getting the session ?
becasue i debuuged but didnt get anything .
Views
Replies
Total Likes
What's the exception you see in the logs?
Views
Replies
Total Likes
I am not getting any exception in log file ......
but my /content/dam/amit ....is not updating not creating any file ..nothing is happening inside /content/dam/ no new node is created nothing ....code is running if I put log even on this position "after creating resourceresolver" so without any error
it is printing that in log files
try {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(usermap);
AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
String filename1="planet.xlsx";
logger.info("after creating resourceresolver ");
Asset asset = assetManager.createAsset("/content/dam/amit/" + filename1, bais, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", true);
//application/vnd.ms-excel
}
FYI my servlet information
Views
Replies
Total Likes
The issue could be you are not saving created asset
e.g
String newFile = "/content/dam/AEM63App/"+fileName;
Session session = request.getResourceResolver().adaptTo(Session.class);
assetMgr.createAsset(newFile, is, mimeType, true);
session.save();
session.logout();
aem63app-repo/UploadAssets.java at master · arunpatidar02/aem63app-repo · GitHub
Views
Replies
Total Likes
Map<String, Object> usermap = new HashMap<String, Object>();
usermap.put(ResourceResolverFactory.SUBSERVICE,"anyname");
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(usermap);
AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
String filename1="planet.xlsx";
Session session=resourceResolver.adaptTo(Session.class);
Asset asset = assetManager.createAsset("/content/dam/amit/" + filename1, bais, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", true);
session.save();
session.logout();
After chnaging as per above as well, still not able to create any file inside /content/dam
Views
Replies
Total Likes
AssetManager assetManager= request.getResourceResolver().adaptTo(AssetManager.class);
String filename1="planet.xlsx";
Session session=request.getResourceResolver().adaptTo(Session.class);
//Session session=resourceResolver.adaptTo(Session.class);
Asset asset = assetManager.createAsset("/content/dam/" + filename1, bais, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", true);
session.save();
session.logout();
//application/vnd.ms-excel
if I take session from request object I can see my excel file has been created inside /content/dam.........whats the problem with taking session through resourceresolverfactory and syste user method ?
Views
Replies
Total Likes
resourceResolver = resourceResolverFactory.getResourceResolver(usermap);--------->> This doesnt work
07.09.2019 12:55:55.228 *INFO* [0:0:0:0:0:0:0:1 [1567841153722] GET /bin/excel HTTP/1.1] amitsample.core.models.ExcelReading Resolved user: anonymous
resourceResolver = resourceResolverFactory.getServiceResourceResolver(usermap);---------->> This works
07.09.2019 13:14:12.993 *INFO* [0:0:0:0:0:0:0:1 [1567842251453] GET /bin/excel HTTP/1.1] amitsample.core.models.ExcelReading Resolved user: amitpandey
with 2nd one my file has been created . wats the reason behind it ?
Views
Replies
Total Likes
Because the second method is the correct method which allows you to get sub-service session
Sling offers a Service User Mapping service, which allows configuring a bundle-to-user mapping and two corresponding API methods: SlingRepository.loginService() and ResourceResolverFactory.getServiceResourceResolver() which return a session/resource resolver with the privileges of a configured user only.
Views
Like
Replies
Views
Likes
Replies