org.apache.axis2.context.ServiceContext Java Examples
The following examples show how to use
org.apache.axis2.context.ServiceContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthenticatorClient.java From product-ei with Apache License 2.0 | 6 votes |
public String login(String userName, String password, String host) throws Exception { Boolean loginStatus; ServiceContext serviceContext; String sessionCookie; loginStatus = authenticationAdminStub.login(userName, password, host); if (!loginStatus) { throw new Exception("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; }
Example #2
Source File: AuthenticatorClient.java From product-es with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: AuthenticationClient.java From carbon-commons with Apache License 2.0 | 6 votes |
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); } }
Example #4
Source File: APIGatewayAdminClientTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { environment = new Environment(); environment.setName(ENV_NAME); environment.setPassword(PASSWORD); environment.setUserName(USERNAME); environment.setServerURL(SERVER_URL); apiGatewayAdminStub = Mockito.mock(APIGatewayAdminStub.class); Options options = new Options(); ServiceContext serviceContext = new ServiceContext(); OperationContext operationContext = Mockito.mock(OperationContext.class); serviceContext.setProperty(HTTPConstants.COOKIE_STRING, ""); ServiceClient serviceClient = Mockito.mock(ServiceClient.class); AuthenticationAdminStub authAdminStub = Mockito.mock(AuthenticationAdminStub.class); Mockito.doReturn(true).when(authAdminStub).login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); Mockito.when(authAdminStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getLastOperationContext()).thenReturn(operationContext); Mockito.when(operationContext.getServiceContext()).thenReturn(serviceContext); Mockito.when(apiGatewayAdminStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getOptions()).thenReturn(options); PowerMockito.whenNew(AuthenticationAdminStub.class) .withArguments(Mockito.any(ConfigurationContext.class), Mockito.anyString()).thenReturn(authAdminStub); }
Example #5
Source File: RemoteAuthorizationManagerClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Query the remote user manager and retrieve the list of role names in users-store * * * @return the list of roles * @throws APIManagementException If and error occurs while accessing the admin service */ public String[] getRoleNames() throws APIManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, 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 APIManagementException("Error while accessing backend services for " + "getting list of all the roles.", e); } }
Example #6
Source File: RemoteAuthorizationManagerClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * 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 APIManagementException If and error occurs while accessing the admin service */ public String[] getRolesOfUser(String user) throws APIManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, 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 APIManagementException("Error while accessing backend services for " + "user role list", e); } }
Example #7
Source File: RemoteAuthorizationManagerClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * 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 APIManagementException If and error occurs while accessing the admin service */ public boolean isUserAuthorized(String user, String permission) throws APIManagementException { CarbonUtils.setBasicAccessSecurityHeaders(username, password, 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 APIManagementException("Error while accessing backend services for " + "user permission validation", e); } }
Example #8
Source File: HelloService.java From product-ei with Apache License 2.0 | 6 votes |
public String greet(String name) { ServiceContext serviceContext = MessageContext.getCurrentMessageContext().getServiceContext(); serviceContext.setProperty(HELLO_SERVICE_NAME, name); try { Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME}); } catch (ClusteringFault clusteringFault) { clusteringFault.printStackTrace(); } if (name != null) { return "Hello World, " + name + " !!!"; } else { return "Hello World !!!"; } }
Example #9
Source File: JMSTestsUtils.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Create a empty message context. * * @return A context with empty message * @throws AxisFault on an error creating a context */ public static org.apache.synapse.MessageContext createMessageContext() throws AxisFault { Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration()); org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext(); axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration())); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MC.setServiceContext(svcCtx); axis2MC.setOperationContext(opCtx); org.apache.synapse.MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(), synapseEnvironment); mc.setMessageID(UIDGenerator.generateURNString()); SOAPEnvelope env = OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope(); OMNamespace namespace = OMAbstractFactory.getSOAP11Factory() .createOMNamespace("http://ws.apache.org/commons/ns/payload", "text"); env.declareNamespace(namespace); mc.setEnvelope(env); SOAPBody body = OMAbstractFactory.getSOAP11Factory().createSOAPBody(); OMElement element = OMAbstractFactory.getSOAP11Factory().createOMElement("TestElement", namespace); element.setText("This is a test!!"); body.addChild(element); mc.getEnvelope().addChild(body); return mc; }
Example #10
Source File: HelloService.java From micro-integrator with Apache License 2.0 | 6 votes |
public String greet(String name) { ServiceContext serviceContext = MessageContext.getCurrentMessageContext().getServiceContext(); serviceContext.setProperty(HELLO_SERVICE_NAME, name); try { Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME}); } catch (ClusteringFault clusteringFault) { clusteringFault.printStackTrace(); } if (name != null) { return "Hello World, " + name + " !!!"; } else { return "Hello World !!!"; } }
Example #11
Source File: AuthenticatorClient.java From micro-integrator with Apache License 2.0 | 6 votes |
public String login(String userName, String password, String host) throws Exception { Boolean loginStatus; ServiceContext serviceContext; String sessionCookie; loginStatus = authenticationAdminStub.login(userName, password, host); if (!loginStatus) { throw new Exception("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; }
Example #12
Source File: HelloService.java From micro-integrator with Apache License 2.0 | 6 votes |
public String greet(String name) { ServiceContext serviceContext = MessageContext.getCurrentMessageContext().getServiceContext(); serviceContext.setProperty(HELLO_SERVICE_NAME, name); try { Replicator.replicate(serviceContext, new String[]{HELLO_SERVICE_NAME}); } catch (ClusteringFault clusteringFault) { clusteringFault.printStackTrace(); } if (name != null) { return "Hello World, " + name + " !!!"; } else { return "Hello World !!!"; } }
Example #13
Source File: InboundWebsocketSourceHandler.java From micro-integrator with Apache License 2.0 | 5 votes |
private static org.apache.synapse.MessageContext createSynapseMessageContext(String tenantDomain) throws AxisFault { org.apache.axis2.context.MessageContext axis2MsgCtx = createAxis2MessageContext(); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MsgCtx.setServiceContext(svcCtx); axis2MsgCtx.setOperationContext(opCtx); axis2MsgCtx.setProperty(TENANT_DOMAIN, SUPER_TENANT_DOMAIN_NAME); SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = fac.getDefaultEnvelope(); axis2MsgCtx.setEnvelope(envelope); return MessageContextCreatorForAxis2.getSynapseMessageContext(axis2MsgCtx); }
Example #14
Source File: InboundHttpServerWorker.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Updates additional properties in Axis2 Message Context from Synapse Message Context * * @param synCtx Synapse Message Context * @return Updated Axis2 Message Context * @throws AxisFault */ private org.apache.synapse.MessageContext updateAxis2MessageContextForSynapse( org.apache.synapse.MessageContext synCtx) throws AxisFault { ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); ((Axis2MessageContext) synCtx).getAxis2MessageContext().setServiceContext(svcCtx); ((Axis2MessageContext) synCtx).getAxis2MessageContext().setOperationContext(opCtx); return synCtx; }
Example #15
Source File: HL7MessageUtils.java From micro-integrator with Apache License 2.0 | 5 votes |
private static org.apache.synapse.MessageContext createSynapseMessageContext(String tenantDomain) throws AxisFault { // Create super tenant message context org.apache.axis2.context.MessageContext axis2MsgCtx = createAxis2MessageContext(); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MsgCtx.setServiceContext(svcCtx); axis2MsgCtx.setOperationContext(opCtx); return MessageContextCreatorForAxis2.getSynapseMessageContext(axis2MsgCtx); }
Example #16
Source File: DSSessionManager.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Save the given object in the session with the given name. */ private static void setSessionObject(String name, Object obj) { MessageContext messageContext = MessageContext.getCurrentMessageContext(); if (messageContext != null) { ServiceContext serviceContext = messageContext.getServiceContext(); if (serviceContext != null) { serviceContext.setProperty(name, obj); } } else { threadLocalSession.get().put(name, obj); } }
Example #17
Source File: WebSocketClientHandler.java From micro-integrator with Apache License 2.0 | 5 votes |
private static org.apache.synapse.MessageContext createSynapseMessageContext(String tenantDomain) throws AxisFault { org.apache.axis2.context.MessageContext axis2MsgCtx = createAxis2MessageContext(); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MsgCtx.setServiceContext(svcCtx); axis2MsgCtx.setOperationContext(opCtx); SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); SOAPEnvelope envelope = fac.getDefaultEnvelope(); axis2MsgCtx.setEnvelope(envelope); return MessageContextCreatorForAxis2.getSynapseMessageContext(axis2MsgCtx); }
Example #18
Source File: HelloService.java From micro-integrator with Apache License 2.0 | 5 votes |
public String greet(String name) { ServiceContext serviceContext = MessageContext.getCurrentMessageContext().getServiceContext(); serviceContext.setProperty(HELLO_SERVICE_NAME, name); try { Replicator.replicate(serviceContext, new String[] { HELLO_SERVICE_NAME }); } catch (ClusteringFault clusteringFault) { clusteringFault.printStackTrace(); } if (name != null) { return "Hello World, " + name + " !!!"; } else { return "Hello World !!!"; } }
Example #19
Source File: DSSessionManager.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * 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; }
Example #20
Source File: CacheMediatorTest.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Create Synapse Context. * * @return mc created message context. * @throws AxisFault when exception happens on message context creation. */ private MessageContext createSynapseMessageContext() throws AxisFault { org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext(); axis2MC.setConfigurationContext(this.configContext); ServiceContext svcCtx = new ServiceContext(); OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx); axis2MC.setServiceContext(svcCtx); axis2MC.setOperationContext(opCtx); Axis2MessageContext mc = new Axis2MessageContext(axis2MC, this.synapseConfig, null); mc.setMessageID(UIDGenerator.generateURNString()); mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope()); mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody()); return mc; }
Example #21
Source File: APIAuthenticationServiceClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public APIAuthenticationServiceClient(String backendServerURL, String username, String password) throws Exception { try { AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(null, backendServerURL + "AuthenticationAdmin"); ServiceClient authAdminServiceClient = authenticationAdminStub._getServiceClient(); authAdminServiceClient.getOptions().setManageSession(true); authenticationAdminStub.login(username, password, new URL(backendServerURL).getHost()); ServiceContext serviceContext = authenticationAdminStub. _getServiceClient().getLastOperationContext().getServiceContext(); String authenticatedCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); if (log.isDebugEnabled()) { log.debug("Authentication Successful with AuthenticationAdmin. " + "Authenticated Cookie ID : " + authenticatedCookie); } stub = new APIAuthenticationServiceStub( null, backendServerURL + "APIAuthenticationService"); ServiceClient client = stub._getServiceClient(); Options options = client.getOptions(); options.setManageSession(true); options.setProperty(HTTPConstants.COOKIE_STRING, authenticatedCookie); } catch (Exception e) { String errorMsg = "Error when instantiating APIAuthenticationServiceClient."; log.error(errorMsg, e); throw e; } }
Example #22
Source File: RegistryCacheInvalidationClientTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws APIManagementException, RemoteException { PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(ConfigurationContextFactory.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class); amConfig = Mockito.mock(APIManagerConfiguration.class); configFactory = Mockito.mock(ConfigurationContextFactory.class); configurationContext = Mockito.mock(ConfigurationContext.class); serviceClient = Mockito.mock(ServiceClient.class); authStub = Mockito.mock(AuthenticationAdminStub.class); cacheStub = Mockito.mock(RegistryCacheInvalidationServiceStub.class); OperationContext opContext = Mockito.mock(OperationContext.class); ServiceContext serviceContext = Mockito.mock(ServiceContext.class); Environment environment = new Environment(); environment.setServerURL(SERVER_URL); environment.setUserName(USERNAME); environment.setPassword(PASSWORD); validEnvironments = new HashMap<String, Environment>(); validEnvironments.put(ENV_NAME, environment); Mockito.when(opContext.getServiceContext()).thenReturn(serviceContext); Mockito.when(serviceContext.getProperty(Mockito.anyString())).thenReturn("cookie"); Mockito.when(authStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(cacheStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getLastOperationContext()).thenReturn(opContext); Mockito.when(serviceClient.getOptions()).thenReturn(new Options()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(amConfigService); Mockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig); Mockito.when(configFactory.createConfigurationContextFromFileSystem(null, null)) .thenReturn(configurationContext); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); }
Example #23
Source File: GlobalThrottleEngineClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private String login() throws RemoteException, LoginAuthenticationExceptionException, MalformedURLException { authenticationAdminStub = getAuthenticationAdminStub(); String sessionCookie = null; if (authenticationAdminStub.login(getPolicyDeployer().getUsername(), getPolicyDeployer().getPassword(), getHost())) { ServiceContext serviceContext = authenticationAdminStub._getServiceClient().getLastOperationContext() .getServiceContext(); sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); } return sessionCookie; }
Example #24
Source File: TierCacheInvalidationClientTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws APIManagementException, RemoteException { PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(ConfigurationContextFactory.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class); amConfig = Mockito.mock(APIManagerConfiguration.class); configFactory = Mockito.mock(ConfigurationContextFactory.class); configurationContext = Mockito.mock(ConfigurationContext.class); serviceClient = Mockito.mock(ServiceClient.class); authStub = Mockito.mock(AuthenticationAdminStub.class); cacheStub = Mockito.mock(TierCacheServiceStub.class); OperationContext opContext = Mockito.mock(OperationContext.class); ServiceContext serviceContext = Mockito.mock(ServiceContext.class); Mockito.when(opContext.getServiceContext()).thenReturn(serviceContext); Mockito.when(serviceContext.getProperty(Mockito.anyString())).thenReturn("cookie"); Mockito.when(authStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(cacheStub._getServiceClient()).thenReturn(serviceClient); Mockito.when(serviceClient.getLastOperationContext()).thenReturn(opContext); Mockito.when(serviceClient.getOptions()).thenReturn(new Options()); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(amConfigService); Mockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig); Mockito.when(configFactory.createConfigurationContextFromFileSystem(null, null)) .thenReturn(configurationContext); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); }
Example #25
Source File: LBService2.java From micro-integrator with Apache License 2.0 | 4 votes |
public void init(ServiceContext serviceContext) { this.serviceContext = serviceContext; }
Example #26
Source File: LBService2.java From micro-integrator with Apache License 2.0 | 4 votes |
public void init(ServiceContext serviceContext) { this.serviceContext = serviceContext; }
Example #27
Source File: LBService2.java From micro-integrator with Apache License 2.0 | 4 votes |
public void init(ServiceContext serviceContext) { this.serviceContext = serviceContext; }
Example #28
Source File: OAuthService.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Unless otherwise specified by the Service Provider, the time-stamp is expressed in the number * of seconds since January 1, 1970 00:00:00 GMT. The time-stamp value MUST be a positive * integer and MUST be equal or greater than the time-stamp used in previous requests. The * Consumer SHALL then generate a Nonce value that is unique for all requests with that * timestamp. A nonce is a random string, uniquely generated for each request. The nonce allows * the Service Provider to verify that a request has never been made before and helps prevent * replay attacks when requests are made over a non-secure channel (such as HTTP). * * @param timestamp * @param nonce * @throws Exception */ private void validateTimestampAndNonce(String timestamp, String nonce) throws AuthenticationException { if (timestamp == null || nonce == null || nonce.trim().length() == 0) { // We are not going to give out the exact error why the request failed. throw new AuthenticationException("Invalid request for OAuth access token"); } long time = Long.parseLong(timestamp); synchronized (this) { long latestTimeStamp = 0; String strTimestamp; ServiceContext context = MessageContext.getCurrentMessageContext().getServiceContext(); if ((strTimestamp = (String) context.getProperty(OAUTH_LATEST_TIMESTAMP)) != null) { latestTimeStamp = Long.parseLong(strTimestamp); } if (time < 0 || time < latestTimeStamp) { // The time-stamp value MUST be a positive integer and MUST be equal or greater than // the time-stamp used in previous requests throw new AuthenticationException("Invalid timestamp"); } context.setProperty(OAUTH_LATEST_TIMESTAMP, String.valueOf(time)); List<String> nonceStore = null; if ((nonceStore = (List<String>) context.getProperty(OAUTH_NONCE_STORE)) != null) { if (nonceStore.contains(nonce)) { // We are not going to give out the exact error why the request failed. throw new AuthenticationException("Invalid request for OAuth access token"); } else { nonceStore.add(nonce); } } else { nonceStore = new ArrayList<String>(); nonceStore.add(nonce); context.setProperty(OAUTH_NONCE_STORE, nonceStore); } } }
Example #29
Source File: LoginManager.java From product-ei with Apache License 2.0 | 4 votes |
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String userName = null, userPassword = null; ServletContext servletContext = this.getServletContext(); String backendServerURL = servletContext.getInitParameter(HumanTaskSampleConstants.BACKEND_SERVER_URL); // set the required system properties System.setProperty("javax.net.ssl.trustStore", servletContext .getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PATH).trim()); System.setProperty("javax.net.ssl.trustStorePassword", servletContext .getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_PASSWORD).trim()); System.setProperty("javax.net.ssl.trustStoreType", servletContext .getInitParameter(HumanTaskSampleConstants.CLIENT_TRUST_STORE_TYPE).trim()); try { AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(backendServerURL + HumanTaskSampleConstants .SERVICE_URL + HumanTaskSampleConstants .AUTHENTICATION_ADMIN_SERVICE_URL); // handles logout String logout = req.getParameter("logout"); if (logout != null) { authenticationAdminStub.logout(); req.getRequestDispatcher("/Login.jsp").forward(req, resp); return; } if (req.getParameter("userName") != null) { userName = req.getParameter("userName").trim(); } if (req.getParameter("userPassword") != null) { userPassword = req.getParameter("userPassword").trim(); } // login to server with given user name and password if (authenticationAdminStub.login(userName, userPassword, HumanTaskSampleConstants.HOSTNAME)) { ServiceContext serviceContext = authenticationAdminStub._getServiceClient().getLastOperationContext() .getServiceContext(); String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING); HttpSession session = req.getSession(); session.setAttribute(HumanTaskSampleConstants.USERNAME, userName); session.setAttribute(HumanTaskSampleConstants.SESSION_COOKIE, sessionCookie); req.getRequestDispatcher("/Home.jsp?queryType=assignedToMe&pageNumber=0").forward(req, resp); } else { log.warn(userName + " login failed."); req.setAttribute("message", "Please enter a valid user name and a password."); req.getRequestDispatcher("/Login.jsp").forward(req, resp); } } catch (Exception e) { log.error("Failed to retrieve the user session ", e); req.setAttribute(HumanTaskSampleConstants.MESSAGE, e); req.getRequestDispatcher("/Login.jsp").forward(req, resp); } }
Example #30
Source File: LBService2.java From product-ei with Apache License 2.0 | 4 votes |
public void init(ServiceContext serviceContext) { this.serviceContext = serviceContext; }