Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

user mapper service amendment

AdobeID24
Level 6
Level 6

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.

1825357_pastedImage_0.png

1 Accepted Solution
jbrar
Correct answer by
Employee
Employee

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:

Screen Shot 2019-09-02 at 7.16.52 PM.png

View solution in original post

11 Replies
hamidk92094312
Employee
Employee

Have you checked the relevant .config file in CRX/DE ?

/libs/system/config/

jbrar
Correct answer by
Employee
Employee

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:

Screen Shot 2019-09-02 at 7.16.52 PM.png

View solution in original post

AdobeID24
Level 6
Level 6

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 .

1826737_pastedImage_3.png

1826736_pastedImage_2.png

1826741_pastedImage_4.png

@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 .

Chase_Turner1
Level 1
Level 1

What's the exception you see in the logs?

AdobeID24
Level 6
Level 6

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

1826993_pastedImage_0.png

Arun_Patidar
Community Advisor
Community Advisor

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

AdobeID24
Level 6
Level 6

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

AdobeID24
Level 6
Level 6

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 ?

AdobeID24
Level 6
Level 6

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 ?

Arun_Patidar
Community Advisor
Community Advisor

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.

Service Users in AEM