Friday, November 28, 2014

Wordpress add custom field to Add New User Page

Unfortunally i could not find a plugin for this purpose and could not write a new one because there is not a hook or filter method in Wordpress.  Altough you can easily write a new one for personel options update and user profile update as shown below:

add_action ( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action ( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

Finally, to be able to add a new field to Add New User  page, i decided to modify user-new.php file.

Before table end tag on line 428  i added the code below

 <tr class="form-field form-required">  
  <th scope="row"><label for="foundation"><?php _e('Kurum'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>  
  <td>  
   <select id="organizationSelection" name="organizationSelection">  
   <?php  
   $organizations = $wpdb->get_results("SELECT id, organization_name FROM organization ORDER BY organization_name ASC");  
   foreach ($organizations as &$organization) {?>  
    <option value="<?php echo $organization->id;?>"><?php echo $organization->organization_name;?></option>  
   <?php }  
   ?>  
   </select>  
  </td>  
  </tr>  

Then i changed the code as the following on line 94

 elseif ( isset($_REQUEST['action']) && 'createuser' == $_REQUEST['action'] ) {  
  check_admin_referer( 'create-user', '_wpnonce_create-user' );  
  if ( ! current_user_can('create_users') )  
  wp_die(__('Cheatin&#8217; uh?'));  
  if ( ! is_multisite() ) {  
  $user_id = edit_user();  
   if ( is_wp_error( $user_id ) ) {  
   $add_user_errors = $user_id;  
  } else {  
   if ( current_user_can( 'list_users' ) ){  
   //@info following line added by ozayd  
   update_user_meta($user_id, 'organization_id', $_POST['organizationSelection']);  
   $redirect = 'users.php?update=add&id=' . $user_id;}  
   else{  
   //@info following line added by ozayd  
   update_user_meta($user_id, 'organization_id', $_POST['organizationSelection']);  
   $redirect = add_query_arg( 'update', 'add', 'user-new.php' );  
   }  
   wp_redirect( $redirect );  
   die();  
  }  
  } else {  
..


Saturday, May 3, 2014

EJB 3 Web Service Implementation with HTTP Basic Authentication & Authhorization

Before run this sample you have to make neccasery realm configution in your EJB 3.0 compatible application server.


  1. First create a Stateless bean  as shown below:

@Stateless (mappedName = "TestSecureWebService")
@WebService (targetNamespace = "http://webservice.duman.ozay.com/", serviceName = "TestSecureWebService")
public class TestSecureWebService implements TestSecureWebServiceRemote {
@Resource
private WebServiceContext webServiceContext;


@Override
@RolesAllowed({"CallServiceAccessRight"})
@WebMethod(operationName = "sampleSecureServiceSorgula")
@WebResult(name = "TestSecureService")
public String secureServiceMethod(String name) {
 MessageContext messageContext = webServiceContext.getMessageContext();
 javax.servlet.http.HttpServletRequest httpRequest = (javax.servlet.http.HttpServletRequest) messageContext.get(MessageContext.SERVLET_REQUEST);
 String userName = httpRequest.getRemoteUser();


 return "http basic auth. web service method called by " + userName;
}

}
You can access httpRequest information (client ip, remoteuser etc.) by injecting WebServiceContext resource.

To test this service you can simply use SOAP UI passing the service credentials or write a web service client as  follows:

public class WSClientMain {

 public static void main(String[] args) {
 TestSecureWebService  service =new TestSecureWebService();
 TestSecureWebServicePort  port = service.getTestSecureWebServiceservicePort();
 Map<String, Object> rc = ((BindingProvider) port).getRequestContext();
 
 rc.put(BindingProvider.USERNAME_PROPERTY, "user1");
 rc.put(BindingProvider.PASSWORD_PROPERTY, "testuser");
 
 String result= port.secureServiceMethod("abc");
 
 System.err.println(result);
 
 }

}



Friday, April 4, 2014

Proxy Authentication Required Problem When Proxy Class Genarating Using wsdl.exe


Problem: Proxy Authentication Required Problem When Proxy class genarating using wsdl.exe

Solution 1:
wsdl.exe  /proxyusername:username /proxypassword:password /proxydomain:domain /language:CS /namespace:testservice /out:D:\VISIUAL_STD_WSDL_ARTIFACTS/ClassName.cs /protocol:SOAP http://.......:80/TestService?wsdl

Solution 2:
download wsdl and relating schema files to a local folder (D:\TestServiceProxyClasses\) and update the preceding command as shown below:

wsdl.exe   /language:CS /namespace:testservice /out:D:\VISIUAL_STD_WSDL_ARTIFACTS/ClassName.cs /protocol:SOAP D:\TestServiceProxyClasses\TestService?wsdl