Tags

Dec 26, 2011

Creating new project using maven acrhetype from commnad line

Link:
http://maven.apache.org/archetype/maven-archetype-plugin/usage.html

Steps :
  • Define environmental varible
M2_HOME    Software Foundation\apache-maven-2.2.1
                          path       %M2_HOME%\bin;   (%PATH%;%ANT_HOME%\bin;%JBOSS_HOME%    \bin;%JAVA_HOME%\bin;%JAVA_HOME%\lib;%M2_HOME%\bin;)

  • download maven bin from
                 http://maven.apache.org/download.html
  •       mvn archetype:generate
           It will listdown  all archetype
               Enter archetype ID
               Enter group id
               Enter archetype Id
               Enter version
               Enter package

Jul 5, 2011

Locking user account after max login attempts

Locking user account after max login attempts

@Component
     public class CustomAuthenticationEventListener implements
           ApplicationListener
     {
     public void onApplicationEvent(AbstractAuthenticationEvent event)
              throws LockedException {
           if (event instanceof AuthenticationFailureBadCredentialsEvent) {
              String username = event.getAuthentication().getName();
              UserDTO user = userService.getUserDetails(username);
              if (user != null) {
     int failedLoginAttempts =       user.getFailedLoginAttempts();
     userService.setLoginCounter(username, ++failedLoginAttempts);
     if (failedLoginAttempts == UserDTO.getMaxFailedLoginAttempts()) {
     throw new LockedException(messageSource.getMessage(
     "security.login.form.locked", null, null));
                 }
              }
           }
           if (event instanceof AuthenticationSuccessEvent) {
              String username = event.getAuthentication().getName();
              UserDTO user = userService.getUserDetails(username);
              if (user != null) {
                 userService.setLoginCounter(username, 0);
              }
           }      
        }
     } 

Retrieving ldap details using spring-ldap

  • Requirement of jar files
             Spring-ldap-core1.3.jar
  •  Define ldap properties in properties file 
# LDAP
ldap.server.url  =
ldap.rootDn      = o=stooges
ldap.userDn      = cn={0},ou=MemberGroupA,o=stooges
ldapTemplate.base=ou=MemberGroupA,o=stooges
ldapTemplate.userDn=uid=admin,ou=system
ldapTemplate.password=
  • Define ldap bean in securityContext.xml 
class="org.springframework.ldap.core.support.LdapContextSource">

  • Retrieving ldap details
            
import org.springframework.ldap.core.LdapTemplate;
      @Autowired
      private LdapTemplate ldapTemplate;
private class PersonAttributesMapper implements AttributesMapper {
            public Object mapFromAttributes(Attributes attrs)
                        throws NamingException {
                  Person userInfo = new Person ();
                  userInfo.setUsername((String) attrs.get("cn").get());
                  userInfo.setFirstName((String) attrs.get("givenname").get());
                  userInfo.setLastName((String) attrs.get("sn").get());
                  userInfo.setDisplayName((String) attrs.get("displayName").get());
                  userInfo.setApproved(true);
                  return userInfo;
            }
      }

          try {    
String dn=”login”
                  Person  userInfo = (Person) ldapTemplate.lookup(dn,
                              new PersonAttributesMapper());
            } catch (NameNotFoundException e) {
                  logger.info("Not Found in ldap " + loginId);
            }

Jun 20, 2011

How to create instances of JBOSS?


1.    Make copy of default folder from following directory (Note:use a fresh j-boss to copy the default folder not the j-boss of an already deployed instance ).
\server\
2.    Name the folder and place it in the same directory where default folder is present.
3.    Go into conf folder which is present in newly created folder in #2.
4.    Edit jboss-service.xml file.
5.    Uncomment following section, if it is commented and change the “ServerName” from port-01 to port-02 or port-03 (These server name should be present in "${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml file.You can search these content into the sample-bindings.xml file).By default ServerName is ports-01.If it is first instance then keep as it is.If is second instance change it to ports-02.Follow the same step for next instances you want to create.


     name="jboss.system:service=ServiceBindingManager">
     ports-01
     ${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml
    
       org.jboss.services.binding.XMLServicesStoreFactory
    
  

6.    Open sample-bindings.xml file from \docs\examples\binding-manager folder.
7.    Find ports-01 or   (Which is changed in step#5) in sample-bindings.xml file.
8.    Find the 8180 if your server name is ports-01 and replace it with your new port on which you want to run your new instance.You should do replace all instead of replace.If it is second instance or ServerName is ports-02 then find 8280 and replace it with your new port on which you want to run your new instance and 8380 for ports-3 etc..
9.    Save the file.
10.  Also make changes in the properties file of the application (such as .server name etc)
11.  Open command prompt.
12.  Go to bin directory of JBoss server. \bin
13.  Type run  –c