how to check for authentication of users login in custom application using CMIS in alfresco?

593 views Asked by At

I have made custom webapp using CMIS with which I am able to get the document from repository of alfresco and also able to upload document from my webapp into the repository of alfresco. But it is not checking for user authentication, if I try to login with random user who doesn't have access to the alfresco repository he/she is also able to login.

I am using below code:

    public Session getSession() {

    Properties prop = new Properties();

    try {



        prop.load(getClass().getClassLoader().getResourceAsStream("config.properties"));

        ALFRSCO_ATOMPUB_URL = "http://" + prop.getProperty("url") + ":"
                + prop.getProperty("port") + "/alfresco/service/cmis";

        System.out.println(ALFRSCO_ATOMPUB_URL);
        parameter.put(SessionParameter.USER, prop.getProperty("USER"));

        parameter.put(SessionParameter.PASSWORD,
                prop.getProperty("PASSWORD"));

        // Specify the connection settings

        parameter.put(SessionParameter.ATOMPUB_URL, ALFRSCO_ATOMPUB_URL);

        parameter.put(SessionParameter.BINDING_TYPE,
                BindingType.ATOMPUB.value());

        parameter.put(SessionParameter.REPOSITORY_ID,
                prop.getProperty("REPOSITORY_ID"));

        SessionFactory factory = SessionFactoryImpl.newInstance();

        session = factory.getRepositories(parameter).get(0).createSession();

        return session;
    } catch (CmisUnauthorizedException ex) {

        System.out.println("you are unauthorized ");
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return session;
}
    public boolean validateUser() {
    Session session = getSession();
    System.out.println("session " + session);
    if (session != null) {
        FolderBean.cmisSession = session;
        return true;
    }
    return false;
}

Any advice would be appreciated!!!

1

There are 1 answers

0
Krutik Jayswal On

You are reading username and password from config.properties file.You should change that with the username and password which are entered in your webapp.

Below line in your code reads property file.

prop.load(getClass().getClassLoader().getResourceAsStream("config.properties"));

Below is reading username and password from property file.

parameter.put(SessionParameter.USER, prop.getProperty("USER"));
parameter.put(SessionParameter.PASSWORD,prop.getProperty("PASSWORD"));

Instead of that put here username and password of webapp which you are entering.