private void setAdminCookie(boolean result) { if (result) { String cookie = (String) stub._getServiceClient().getServiceContext().getProperty( HTTPConstants.COOKIE_STRING); if (cookie == null) { // For local transport - the cookie will be null. // This generated cookie cannot be used for any form authentication with the backend. // This is done to be backward compatible. cookie = UUID.randomUUID().toString(); } session.setAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN, cookie); } }
/** * Returns an object stored in the session with the given name. */ private static Object getSessionObject(String name) { MessageContext messageContext = MessageContext.getCurrentMessageContext(); if (messageContext != null) { ServiceContext serviceContext = messageContext.getServiceContext(); if (serviceContext != null) { return serviceContext.getProperty(name); } } else { return threadLocalSession.get().get(name); } return null; }
private String login() throws AxisFault { if (parameters.get(SERVER_URL) == null || parameters.get(USERNAME) == null || parameters.get(PASSWORD) == null) { throw new AxisFault("SSO Configurator authentication details unspecified"); } String host; try { host = new URL(parameters.get(SERVER_URL)).getHost(); } catch (MalformedURLException e) { throw new AxisFault("SSO Configurator provider URL is malformed", e); } AuthenticationAdminStub authAdminStub = new AuthenticationAdminStub(null, parameters.get(SERVER_URL) + "/services/AuthenticationAdmin"); ServiceClient client = authAdminStub._getServiceClient(); Options options = client.getOptions(); options.setManageSession(true); try { authAdminStub.login(parameters.get(USERNAME), parameters.get(PASSWORD), host); ServiceContext serviceContext = authAdminStub. _getServiceClient().getLastOperationContext().getServiceContext(); String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return sessionCookie; } catch (RemoteException e) { throw new AxisFault("Error while contacting the authentication admin services", e); } catch (LoginAuthenticationExceptionException e) { throw new AxisFault("Error while authenticating against the SSO IDP admin", e); } }
public String login(String username, char[] password, String backendURL) throws MalformedURLException, RemoteException, LoginAuthenticationExceptionException { String authenticationServiceURL = backendURL + "AuthenticationAdmin"; AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(authenticationServiceURL); ServiceClient client = authenticationAdminStub._getServiceClient(); String hostName = new URL(backendURL).getHost(); Options options = client.getOptions(); options.setManageSession(true); if (log.isDebugEnabled()) { log.debug("UserName : " + username + " Password : " + String.valueOf(password) + " HostName : " + hostName); } boolean isLoggedIn = authenticationAdminStub.login(username, String.valueOf(password), hostName); assert isLoggedIn : "Login failed!"; log.debug("getting sessionCookie"); ServiceContext serviceContext = authenticationAdminStub._getServiceClient().getLastOperationContext().getServiceContext(); sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); assert sessionCookie != null : "Logged in session cookie is null"; if (log.isDebugEnabled()) { log.debug("sessionCookie : " + sessionCookie); } log.info("Successfully logged in : " + sessionCookie); return sessionCookie; }
public String login(String userName, String password, String host) throws LoginAuthenticationExceptionException, RemoteException { Boolean loginStatus; ServiceContext serviceContext; String sessionCookie; loginStatus = authenticationAdminStub.login(userName, password, host); if (!loginStatus) { throw new LoginAuthenticationExceptionException("Login Unsuccessful. Return false as a login status by Server"); } log.info("Login Successful"); serviceContext = authenticationAdminStub._getServiceClient().getLastOperationContext().getServiceContext(); sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); if (log.isDebugEnabled()) { log.debug("SessionCookie :" + sessionCookie); } return sessionCookie; }
private String login() throws AxisFault { if (backendServerURL == null || user == null || pass == null) { throw new AxisFault("SSO Configurator authentication details unspecified"); } String host; try { host = new URL(backendServerURL).getHost(); } catch (MalformedURLException e) { throw new AxisFault("SSO Configurator provider URL is malformed", e); } AuthenticationAdminStub authAdminStub = new AuthenticationAdminStub(null, backendServerURL + "/services/AuthenticationAdmin"); ServiceClient client = authAdminStub._getServiceClient(); Options options = client.getOptions(); options.setManageSession(true); try { authAdminStub.login(user, pass, host); ServiceContext serviceContext = authAdminStub. _getServiceClient().getLastOperationContext().getServiceContext(); String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return sessionCookie; } catch (RemoteException e) { throw new AxisFault("Error while contacting the authentication admin services", e); } catch (LoginAuthenticationExceptionException e) { throw new AxisFault("Error while authenticating against the SSO IDP admin", e); } }
public static String login(String hostName, String userName, String password) throws Exception { authenticationAdminStub.login(userName, password, hostName); // authenticationAdminStub.login(userName, password, hostName); ServiceContext serviceContext = authenticationAdminStub. _getServiceClient().getLastOperationContext().getServiceContext(); String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return sessionCookie; }
public boolean authenticate(ConfigurationContext ctx, String serverURL, String username, String password) throws AxisFault, AuthenticationException { String serviceEPR = serverURL + "AuthenticationAdmin"; authenticationAdminStub = new AuthenticationAdminStub(ctx, serviceEPR); ServiceClient client = authenticationAdminStub._getServiceClient(); Options options = client.getOptions(); options.setManageSession(true); try { boolean result = authenticationAdminStub.login(username, password, new URL(serviceEPR).getHost()); if (result){ setCookie((String) authenticationAdminStub._getServiceClient().getServiceContext(). getProperty(HTTPConstants.COOKIE_STRING)); } return result; } catch (Exception e) { String msg = "Error occurred while logging in"; throw new AuthenticationException(msg, e); } }
public boolean authenticate(String username, String password) throws RemoteException, SocketException, AuthenticationExceptionException { boolean loginResponse; loginResponse = stub.login(username, password, NetworkUtils.getLocalHostname()); this.sessionCookie = (String) stub._getServiceClient().getLastOperationContext().getServiceContext() .getProperty(HTTPConstants.COOKIE_STRING); return loginResponse; }
public boolean authenticate(String username, String password) throws Exception { boolean loginResponse; loginResponse = stub.login(username, password, NetworkUtils.getLocalHostname()); this.sessionCookie = (String) stub._getServiceClient().getLastOperationContext().getServiceContext() .getProperty(HTTPConstants.COOKIE_STRING); return loginResponse; }
public boolean authenticate(String username, String password) throws RemoteException, SocketException, AuthenticationExceptionException { boolean loginResponse; loginResponse = stub.login(username, password, NetworkUtils.getLocalHostname()); this.sessionCookie = (String)stub._getServiceClient().getLastOperationContext().getServiceContext() .getProperty(HTTPConstants.COOKIE_STRING); return loginResponse; }
public boolean authenticate(String userName, String password) throws RemoteException, SocketException, AuthenticationExceptionException { boolean logInResponse = false; try { logInResponse = stub.login(userName, password, NetworkUtils.getLocalHostname()); this.sessionCookie = (String) stub._getServiceClient().getLastOperationContext().getServiceContext() .getProperty(HTTPConstants.COOKIE_STRING); } catch (org.wso2.carbon.bam.services.stub.authenticationadmin_3_1_0.AuthenticationExceptionException e) { e.printStackTrace(); } return logInResponse; }
private boolean authenticate() throws Exception { ConfigurationContext configurationContext; configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext(); Map<String, TransportOutDescription> transportsOut = configurationContext .getAxisConfiguration().getTransportsOut(); for (TransportOutDescription transportOutDescription : transportsOut.values()) { transportOutDescription.getSender().init(configurationContext, transportOutDescription); } boolean isAuthenticated = false; if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) { //if authorized cookie is not available authorize using credentials AuthenticationAdminStub authAdmin = new AuthenticationAdminStub(configurationContext, serverUrl); isAuthenticated = authAdmin.login(userName, password, "localhost"); cookie = (String) authAdmin._getServiceClient().getServiceContext() .getProperty(HTTPConstants.COOKIE_STRING); authAdmin._getServiceClient().cleanupTransport(); } else if (StringUtils.isNotEmpty(authorizedCookie)) { //when authorized cookie is available assign it to local variable isAuthenticated = true; cookie = authorizedCookie; } return isAuthenticated; }
private boolean authenticate() throws Exception { ConfigurationContext configurationContext; configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext(); Map<String, TransportOutDescription> transportsOut = configurationContext .getAxisConfiguration().getTransportsOut(); for (TransportOutDescription transportOutDescription : transportsOut.values()) { transportOutDescription.getSender().init(configurationContext, transportOutDescription); } boolean isAuthenticated = false; if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) { //if authorized cookie is not available authorize using credentials AuthenticationAdminStub authAdmin = new AuthenticationAdminStub(configurationContext, serverUrl); isAuthenticated = authAdmin.login(userName, password, "localhost"); cookie = (String) authAdmin._getServiceClient().getServiceContext() .getProperty(HTTPConstants.COOKIE_STRING); authAdmin._getServiceClient().cleanupTransport(); } else if (StringUtils.isNotEmpty(authorizedCookie)) { //when authorized cookie is available assign it to local variable isAuthenticated = true; cookie = authorizedCookie; } return isAuthenticated; }
/** * Query the remote user manager and retrieve the list of role names in users-store * * * @return the list of roles * @throws org.wso2.carbon.appmgt.api.AppManagementException If and error occurs while accessing the admin service */ public String[] getRoleNames() throws AppManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, userStoreManager._getServiceClient()); if (cookie != null) { userStoreManager._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie); } try { String[] roles = userStoreManager.getRoleNames(); ServiceContext serviceContext = userStoreManager. _getServiceClient().getLastOperationContext().getServiceContext(); cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return roles; } catch (Exception e) { throw new AppManagementException("Error while accessing backend services for " + "getting list of all the roles.", e); } } }
/** * Query the remote user manager and retrieve the list of role names associated for the given * user name. This is used when authorization for certain actions are appropriately delegated * to other components (ex:- Lifecycle Management). * * @param user Username * @return the list of roles to which the user belongs to. * @throws org.wso2.carbon.appmgt.api.AppManagementException If and error occurs while accessing the admin service */ public String[] getRolesOfUser(String user) throws AppManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, true, userStoreManager._getServiceClient()); if (cookie != null) { userStoreManager._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie); } try { String[] roles = userStoreManager.getRoleListOfUser(user); ServiceContext serviceContext = userStoreManager. _getServiceClient().getLastOperationContext().getServiceContext(); cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); return roles; } catch (Exception e) { throw new AppManagementException("Error while accessing backend services for " + "user role list", e); } }
/** * 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); } }
/** * Retrieve the implementation object. This will either return a cached * object if present in the ServiceContext, or create a new one via * makeNewServiceObject() (and then cache that). * * @param msgContext the active MessageContext * @return the appropriate back-end service object. * @throws AxisFault if there's a problem */ protected Object getTheImplementationObject(MessageContext msgContext) throws AxisFault { ServiceContext serviceContext = msgContext.getServiceContext(); Object serviceimpl = serviceContext.getProperty(ServiceContext.SERVICE_OBJECT); if (serviceimpl != null) { // since service impl is there in service context , take that from there return serviceimpl; } else { // create a new service impl class for that service serviceimpl = makeNewServiceObject(msgContext); //Service initialization DependencyManager.initServiceObject(serviceimpl, msgContext.getServiceContext()); serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, serviceimpl); return serviceimpl; } }
/** * Retrieve the implementation object. This will either return a cached * object if present in the ServiceContext, or create a new one via * makeNewServiceObject() (and then cache that). * * @param msgContext the active MessageContext * @return the appropriate back-end service object. * @throws AxisFault if there's a problem */ protected Object getTheImplementationObject(MessageContext msgContext) throws AxisFault { ServiceContext serviceContext = msgContext.getServiceContext(); Object serviceimpl = serviceContext.getProperty(ServiceContext.SERVICE_OBJECT); if (serviceimpl != null) { // since service impl is there in service context , take that from there return serviceimpl; } else { // create a new service impl class for that service serviceimpl = makeNewServiceObject(msgContext); //Service initialization DependencyManager.initServiceObject(serviceimpl, msgContext.getServiceContext()); serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, serviceimpl); return serviceimpl; } }
public boolean authenticate(String username, String password) throws AuthenticationExceptionException, RemoteException { try { boolean isAuthenticated = stub.login(username,password,NetworkUtils.getLocalHostname()); if(isAuthenticated){ ServiceContext serviceContext; serviceContext = stub._getServiceClient().getLastOperationContext().getServiceContext(); String sessionCookie; sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); this.sessionCookie = sessionCookie; }else{ throw new AuthenticationExceptionException("Authentication Failed"); } return isAuthenticated; } catch (SocketException e) { throw new AuthenticationExceptionException(e); } }