9 Replies Latest reply on Dec 14, 2012 1:05 PM by pweldon

    getcallerprincipal().getname()=anonymous jboss 7.1.1 as

    longtqdayma

      File .WAR

       

      <p:commandButton value="Login" action="#{login.checkLogin()}"/>

       

      public String checkLogin() {

                          try {

                                    ServiceLocator.setUserAndPass(username, password);

                                    imDelegate = Delegate.getService(IIdentityManager.class);

                          } catch (Exception e) {

                                    e.printStackTrace();

                          }

                          if (imDelegate.checkLogin("admin", "123")) {

                          ....................

                      }

      }

       

      private ServiceLocator() throws ServiceLocatorException {

                          try {

                                    ResourceBundle resource = ResourcesFactory

                                                        .getConfigResource(ResourcesFactory.CONFIG.JNDI);

                                    Properties p = new Properties();

       

       

                                    earName = resource.getString("earName");

       

       

                                    p.put(Context.INITIAL_CONTEXT_FACTORY,

                                                        "org.jboss.naming.remote.client.InitialContextFactory");

                                    p.put(Context.PROVIDER_URL, "remote://localhost:4447");

                                    p.put(Context.SECURITY_PRINCIPAL, user);

                                    p.put(Context.SECURITY_CREDENTIALS, pass);

                                    initialContext = new InitialContext(p);

                                    cache = Collections.synchronizedMap(new HashMap());

                          } catch (NamingException ex) {

                                    throw new ServiceLocatorException(ex);

                          } catch (Exception ex) {

                                    throw new ServiceLocatorException(ex);

                          }

                }

       

      Run App call checkLogin();

       

      http://i1017.photobucket.com/albums/af292/longtqdayma/1-1.png

      http://i1017.photobucket.com/albums/af292/longtqdayma/2-3.png

       

      File .EAR

      @Stateless

      @SecurityDomain("FMISDomain")

      public class IdentityManagerFacade implements IIdentityManager,

                          IIdentityManagerLocal {

      @Resource

                SessionContext sessionContext;

                @PersistenceContext(unitName = "FMIS2")

                private EntityManager entityManager;

              ...........................

       

       

      public boolean checkLogin(String user, String pass) {

                          try {

                                    getUserID();

                                    UserService userService = new UserService(entityManager);

                                    Users users = userService.getByUserAndPass(user,

                                                        Security.calculateRFC2104HMAC(pass, Security.HMAC_KEY));

                                    Security.setUser(user);

                                    iMasterdataLocal = (IMasterdataLocal) sessionContext

                                                        .lookup(CommonUtil

                                                                            .getLocalFacadeName(IMasterdataLocal.class));

                                    if (users != null) {

                                              userId = sessionContext.getCallerPrincipal().getName();

                                              identityService = new IdentityService(entityManager,

                                                                  users.getId(), iLoggingFacade, iMasterdataLocal);

                                              identityService.refreshLoginUserInfo();

                                              // GVariable.ID_MACOP = identityService.getIdMaCopForOwner();

                                              return true;

                                    } else {

                                              return false;

                                    }

       

       

                          } catch (Exception e) {

                                    e.printStackTrace();

                                    throw CommonException.error(e,

                                                        "facade.identitymanager.IdentityManagerFacade.checkLogin");

                          }

                }      

       

       

      }

       

      standalone.xml

       

      <security-realm name="FMISRealm">

                      <authentication>

                          <jaas name="FMISDomain"/>

                      </authentication>

                  </security-realm>

       

       

      <datasource jta="true" jndi-name="java:jboss/datasources/fmis2Datasource" pool-name="fmis2Datasource" enabled="true" use-java-context="true" use-ccm="true">

      ....................

      </datasource>

      <subsystem xmlns="urn:jboss:domain:remoting:1.1">

                  <connector name="remoting-connector" socket-binding="remoting"/>

              </subsystem>

                      <security-domain name="FMISDomain" cache-type="default">

                          <authentication>

                              <login-module code="Remoting" flag="optional">

                                  <module-option name="password-stacking" value="useFirstPass"/>

                              </login-module>

                              <login-module code="Database" flag="required">

                                  <module-option name="dsJndiName" value="java:jboss/datasources/fmis2Datasource"/>

                                  <module-option name="principalsQuery" value="Select password_usr From im_users_usr Where  blocked_usr = 0 And id_usr = ?"/>

                                  <module-option name="rolesQuery" value="Select user, Roles From im_users_usr Where id_usr = ?"/>

                                   <module-option name="realm" value="FMISRealm"/>

                                  <module-option name="password-stacking" value="useFirstPass"/>

                              </login-module>

                          </authentication>

                      </security-domain>