test_class.file: modules/security/security-client/src/test/java/org/openiot/security/client/rest/RestfulOAuthServiceTest.java
test_class.identifier: RestfulOAuthServiceTest
test_case.body: @Test
  	public void testGetAccessToken() {
  		String casOAuthUrl = "https://localhost:8443/openiot-cas/openiot1/tickets";
  		RestfulOAuthService service = new RestfulOAuthService(casOAuthUrl);
  
  		OAuthCredentialsRest credentials = new OAuthCredentialsRest("admin", "secret", "dummyClientName", "testservice1", "testsecret1");
  		Token accessToken = service.getAccessToken(credentials);
  
  		assertNotNull(accessToken);
  	}
test_case.class_method_signature: RestfulOAuthServiceTest.testGetAccessToken()
test_case.full_signature: @Test public void testGetAccessToken()
test_case.identifier: testGetAccessToken
test_case.invocations: getAccessToken assertNotNull
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetAccessToken()
focal_class.declarator: log = LoggerFactory.getLogger(RestfulOAuthService.class)
focal_class.modifier: private static
focal_class.original_string: private static Logger log = LoggerFactory.getLogger(RestfulOAuthService.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: STATUS_SUCCESS = 201
focal_class.modifier: private static final
focal_class.original_string: private static final int STATUS_SUCCESS = 201;
focal_class.type: int
focal_class.var_name: STATUS_SUCCESS
focal_class.declarator: STATUS_DELETE_SUCCESS = 200
focal_class.modifier: private static final
focal_class.original_string: private static final int STATUS_DELETE_SUCCESS = 200;
focal_class.type: int
focal_class.var_name: STATUS_DELETE_SUCCESS
focal_class.declarator: casOAuthURL
focal_class.modifier: private
focal_class.original_string: private String casOAuthURL;
focal_class.type: String
focal_class.var_name: casOAuthURL
focal_class.file: modules/security/security-client/src/main/java/org/openiot/security/client/rest/RestfulOAuthService.java
focal_class.identifier: RestfulOAuthService
focal_class.class_method_signature: RestfulOAuthService.RestfulOAuthService(String casOAuthUrl)
focal_class.full_signature: public  RestfulOAuthService(String casOAuthUrl)
focal_class.identifier: RestfulOAuthService
focal_class.modifiers: public
focal_class.parameters: (String casOAuthUrl)
focal_class.signature:  RestfulOAuthService(String casOAuthUrl)
focal_class.class_method_signature: RestfulOAuthService.getAccessToken(OAuthCredentialsRest credentials)
focal_class.full_signature: public Token getAccessToken(OAuthCredentialsRest credentials)
focal_class.identifier: getAccessToken
focal_class.modifiers: public
focal_class.parameters: (OAuthCredentialsRest credentials)
focal_class.return: Token
focal_class.signature: Token getAccessToken(OAuthCredentialsRest credentials)
focal_class.class_method_signature: RestfulOAuthService.removeAccessToken(String token)
focal_class.full_signature: public boolean removeAccessToken(String token)
focal_class.identifier: removeAccessToken
focal_class.modifiers: public
focal_class.parameters: (String token)
focal_class.return: boolean
focal_class.signature: boolean removeAccessToken(String token)
focal_method.body: public Token getAccessToken(OAuthCredentialsRest credentials) {
  		Token token = null;
  		ClientRequest request = new ClientRequest(casOAuthURL);
  		// String params = "username=" + credentials.getUsername() + "&password=" +
  		// credentials.getPassword() + "&clientId=" + credentials.getKey() + "&secret="
  		// + credentials.getSecret();
  		request.formParameter("username", credentials.getUsername());
  		request.formParameter("password", credentials.getPassword());
  		request.formParameter("clientId", credentials.getKey());
  		request.formParameter("secret", credentials.getSecret());
  		try {
  			ClientResponse<String> response = request.post(String.class);
  			// Read output in string format
  			log.debug("Status code: {}", response.getStatus());
  
  			if (response.getStatus() == STATUS_SUCCESS) {
  				Matcher matcher = Pattern.compile(".*action=\".*/(.*?)\".*").matcher(response.getEntity());
  				if (matcher.matches())
  					token = new Token(matcher.group(1), "");
  			} else {
  				log.warn("Invalid response code {} from CAS server!", response.getStatus());
  				log.info("Response: {}", response.getEntity());
  			}
  
  			response.releaseConnection();
  		} catch (Exception e) {
  			log.error("Error while retrieving access token", e);
  		}
  		return token;
  	}
focal_method.class_method_signature: RestfulOAuthService.getAccessToken(OAuthCredentialsRest credentials)
focal_method.full_signature: public Token getAccessToken(OAuthCredentialsRest credentials)
focal_method.identifier: getAccessToken
focal_method.invocations: formParameter getUsername formParameter getPassword formParameter getKey formParameter getSecret post debug getStatus getStatus matcher compile getEntity matches group warn getStatus info getEntity releaseConnection error
focal_method.modifiers: public
focal_method.parameters: (OAuthCredentialsRest credentials)
focal_method.return: Token
focal_method.signature: Token getAccessToken(OAuthCredentialsRest credentials)