public WSAuthorizationManager(String serverUrl, String cookie, ConfigurationContext configCtxt) throws UserStoreException { try { stub = new RemoteAuthorizationManagerServiceStub(configCtxt, serverUrl + SERVICE_NAME); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault e) { throw new UserStoreException("Axis error occurred while creating service client stub", e); } }
public WSAuthorizationManager(String serverUrl, String cookie, ConfigurationContext configCtxt) throws UserStoreException { try { stub = new RemoteAuthorizationManagerServiceStub(configCtxt, serverUrl + "RemoteAuthorizationManagerService"); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault e) { throw new UserStoreException(); } }
/** * Query the remote user manager to find out whether the specified user has the * specified permission. * * @param user Username * @param permission A valid Carbon permission * @return true if the user has the specified permission and false otherwise * @throws org.wso2.carbon.appmgt.api.AppManagementException If and error occurs while accessing the admin service */ public boolean isUserAuthorized(String user, String permission) throws AppManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, authorizationManager._getServiceClient()); if (cookie != null) { authorizationManager._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie); } try { boolean authorized = authorizationManager.isUserAuthorized(user, permission, CarbonConstants.UI_PERMISSION_ACTION); ServiceContext serviceContext = authorizationManager. _getServiceClient().getLastOperationContext().getServiceContext(); cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return authorized; } catch (Exception e) { throw new AppManagementException("Error while accessing backend services for " + "user permission validation", e); } }
public RemoteAuthorizationManagerClient() throws AppManagementException { AppManagerConfiguration config = ServiceReferenceHolder.getInstance(). getAPIManagerConfigurationService().getAPIManagerConfiguration(); String serviceURL = config.getFirstProperty(AppMConstants.AUTH_MANAGER_URL); username = config.getFirstProperty(AppMConstants.AUTH_MANAGER_USERNAME); password = config.getFirstProperty(AppMConstants.AUTH_MANAGER_PASSWORD); if (serviceURL == null || username == null || password == null) { throw new AppManagementException("Required connection details for authentication " + "manager not provided"); } try { authorizationManager = new RemoteAuthorizationManagerServiceStub(null, serviceURL + "RemoteAuthorizationManagerService"); userStoreManager = new RemoteUserStoreManagerServiceStub(null, serviceURL + "RemoteUserStoreManagerService"); for (ServiceClient client : new ServiceClient[] { authorizationManager._getServiceClient(), userStoreManager._getServiceClient()}) { Options options = client.getOptions(); options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS); options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS); options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS); options.setCallTransportCleanup(true); options.setManageSession(true); } } catch (AxisFault axisFault) { throw new AppManagementException("Error while initializing the user management stubs", axisFault); } }