[JBoss Portal] - Re: Looking for Jar file for org.jboss.portal.identity.User
by cry4dawn
the UserPrinciple:
| package com.xxx.database;
|
| import java.security.Principal;
|
| /**
| *
| */
| public final class UserPrincipal implements Principal {
|
| private final String name;
|
| /**
| * @param nameIn
| *
| */
| public UserPrincipal(final String nameIn) {
| if (nameIn == null) {
| throw new IllegalArgumentException("No null principal name accepted");
| }
| this.name = nameIn;
| }
|
| /**
| * @param o
| * Object
| * @return boolean aanderson Aug 7, 2007
| * @see java.lang.Object#equals(java.lang.Object)
| */
| @Override
| public boolean equals(final Object o) {
| if (o == this) {
| return true;
| }
| if (o instanceof Principal) {
| final Principal that = (Principal) o;
| return this.name.equals(that.getName());
| }
| return false;
| }
|
| /**
| * @return String
| * @see java.security.Principal#getName()
| */
| public String getName() {
| return this.name;
| }
|
| /**
| * @return int
| * @see java.lang.Object#hashCode()
| */
| @Override
| public int hashCode() {
| return this.name.hashCode();
| }
|
| /**
| * @return String
| * @see java.lang.Object#toString()
| */
| @Override
| public String toString() {
| return "PortalPrincipal[" + this.name + "]";
| }
| }
|
|
and the custom module:
| /**
| * HMIDataBaseLoginModule
| *
| */
| package com.xxx.database;
|
| import java.io.IOException;
| import java.security.acl.Group;
| import java.sql.SQLException;
| import java.util.Map;
|
| import javax.security.auth.Subject;
| import javax.security.auth.callback.Callback;
| import javax.security.auth.callback.CallbackHandler;
| import javax.security.auth.callback.NameCallback;
| import javax.security.auth.callback.UnsupportedCallbackException;
| import javax.security.auth.login.FailedLoginException;
| import javax.security.auth.login.LoginException;
|
| import org.jboss.security.auth.spi.DatabaseServerLoginModule;
|
| /**
| *
| */
| public final class HMIDataBaseLoginModule extends DatabaseServerLoginModule {
|
| private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HMIDataBaseLoginModule.class);
| private String dsJndiName = "java:/OracleDS";
| // do not remove this field
| private UserPrincipal identity;
| //private long lockoutTime;;
| private int maxRetries;
|
| /**
| * @param subjectIn {@link Subject}
| * @param callbackHandlerIn {@link CallbackHandler}
| * @param sharedStateIn {@link Map}
| * @param optionsIn {@link Map}
| * @see org.jboss.security.auth.spi.DatabaseServerLoginModule#initialize(javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map)
| */
| @Override
| public void initialize(final Subject subjectIn, final CallbackHandler callbackHandlerIn, final Map sharedStateIn, final Map optionsIn) {
| super.initialize(subjectIn, callbackHandlerIn, sharedStateIn, optionsIn);
| LOG.info("Initializing LoginModule");
| try {
| this.maxRetries = Integer.valueOf((String) optionsIn.get("maxRetries")).intValue();
| this.dsJndiName = (String) optionsIn.get("dsJndiName");
| //this.lockoutTime = Long.valueOf((String) optionsIn.get("lockTimeMillies")).longValue();
| this.callbackHandler = callbackHandlerIn;
| if (this.callbackHandler == null) {
| this.callbackHandler = new HMICallbackHandler();
| }
| } catch (final Throwable e) {
| HMIDataBaseLoginModule.LOG.error("Error initializing", e);
| }
| HMIDataBaseLoginModule.LOG.debug("LoginModule initialized");
| }
|
| /**
| * @return boolean
| * @throws LoginException le
| *
| * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#login()
| */
| @Override
| public boolean login() throws LoginException {
| HMIDataBaseLoginModule.LOG.debug("in HMIDataBaseLoginModule.login");
| if (this.callbackHandler == null) {
| throw new LoginException("No callback handler is available");
| }
| if (super.login()) {
| // do not remove this line, super implementation needs it
| final Object username = this.sharedState.get("javax.security.auth.login.name");
| }
| final String name = this.getUsername();
| User user = null;
| try {
| user = DatabaseLoginDAO.getDAO(this.dsJndiName).getThisUser(name);
| } catch (SQLException e) {
| super.loginOk = false;
| throw new FailedLoginException("Database lookup failed");
| }
| if (user == null) {
| super.loginOk = false;
| throw new FailedLoginException("No such user");
| }
| if (user.isUserTermed()) {
| super.loginOk = false;
| throw new FailedLoginException("User is Termed");
| }
| final Callback[] callbacks = new Callback[1];
| callbacks[0] = new NameCallback("hmiLogin", name);
| String named = null;
| try {
| this.callbackHandler.handle(callbacks);
| named = ((NameCallback) callbacks[0]).getName();
| } catch (final IOException ioe) {
| throw new LoginException(ioe.toString());
| } catch (final UnsupportedCallbackException ce) {
| throw new LoginException("Error: " + ce.getCallback().toString());
| }
| user = this.incrementCounter(user);
| if (this.getCounter(user) > this.maxRetries) {
| super.loginOk = false;
| throw new FailedLoginException("Account Locked, to many failed attempts");
| }
| super.loginOk = true;
| this.incrementLoginCount(user);
| LOG.info("User succesfully logged in");
| return true;
| }
|
| /**
| * Subclass to use the PortalPrincipal to make the username easier to retrieve by the portal.
| * @param username String
| * @return {@link UserPrincipal}
| * @throws Exception e
| * @see org.jboss.security.auth.spi.AbstractServerLoginModule#createIdentity(java.lang.String)
| */
| @Override
| protected UserPrincipal createIdentity(final String username) throws Exception {
| HMIDataBaseLoginModule.LOG.debug("LoginModule.createIdentity(" + username + ")");
| return new UserPrincipal(username);
| }
|
| /**
| * @return Group[]
| * @throws LoginException le
| * @see org.jboss.security.auth.spi.DatabaseServerLoginModule#getRoleSets()
| */
| @Override
| protected Group[] getRoleSets() throws LoginException {
| HMIDataBaseLoginModule.LOG.debug("LoginModule.getRoleSets");
| return DatabaseLoginDAO.getDAO(this.dsJndiName).getRoleSets(this.getUsername());
| }
|
| /**
| * this method must be maintained do to super implementation
| * @return String the users password
| * @throws LoginException le
| * @see org.jboss.security.auth.spi.DatabaseServerLoginModule#getUsersPassword()
| */
| @Override
| protected String getUsersPassword() throws LoginException {
| HMIDataBaseLoginModule.LOG.debug("LoginModule.getUsersPassword");
| return DatabaseLoginDAO.getDAO(this.dsJndiName).getUsersPassword(this.getUsername());
| }
|
| /**
| * @param inputPassword String
| * @param expectedPassword String
| * @return boolean
| * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#validatePassword(java.lang.String, java.lang.String)
| */
| @Override
| protected boolean validatePassword(final String inputPassword, final String expectedPassword) {
| return super.validatePassword(PasswordEncrypter.encrypt(inputPassword), expectedPassword);
| }
|
| private int getCounter(final User user) {
| return user.getLoginAttempts();
| }
|
| private User incrementCounter(final User user) {
| HMIDataBaseLoginModule.LOG.debug("LoginModule.incrementCounter");
| try {
| return DatabaseLoginDAO.getDAO(this.dsJndiName).incrementLoginAttempts(user);
| } catch (final SQLException e) {
| HMIDataBaseLoginModule.LOG.error("Query failed" + e.getMessage());
| }
| // don't ask why
| return user;
| }
|
| private void incrementLoginCount(final User user) {
| HMIDataBaseLoginModule.LOG.debug("LoginModule.incrementLoginCount");
| DatabaseLoginDAO.getDAO(this.dsJndiName).incrementLoginCount(user);
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4096762#4096762
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4096762
18Â years, 9Â months
[JBoss Portal] - Re: Looking for Jar file for org.jboss.portal.identity.User
by cry4dawn
i beilive you would have to find the jbosssx.jar source.
as an example here is an example User i created that i use with our custom Login module:
| /**
| * com.xxx.databaseUser
| */
| package com.xxx.database;
|
| import java.sql.Date;
| import java.sql.ResultSet;
| import java.sql.SQLException;
|
| /**
| *
| */
| final class User {
|
| private final long userID;
| private final String loginName;
| private final String encryptedPassword;
| private final Date fromDate;
| private final Date termDate;
| private final long loginCount;
| private final Date lastLoginDate;
| private int loginAttempts;
|
| /**
| * @param rs {@link ResultSet}
| * @throws SQLException se
| * aanderson Sep 24, 2007
| */
| User(final ResultSet rs) throws SQLException {
| this.userID = rs.getLong("USER_ID");
| this.loginName = rs.getString("LOGIN_NAME");
| this.encryptedPassword = rs.getString("PASSWORD");
| this.fromDate = rs.getDate("FROM_DATE");
| this.termDate = rs.getDate("TERM_DATE");
| this.loginCount = rs.getLong("LOGIN_CNT");
| this.lastLoginDate = rs.getDate("LAST_LOGIN_DATE");
| this.loginAttempts = rs.getInt("LOGIN_ATTEMPTS");
| }
|
| /**
| * @return the encryptedPassword
| */
| String getEncryptedPassword() {
| return this.encryptedPassword;
| }
|
| /**
| * @return the fromDate
| */
| Date getFromDate() {
| return this.fromDate;
| }
|
| /**
| * @return the lastLoginDate
| */
| Date getLastLoginDate() {
| return this.lastLoginDate;
| }
|
| /**
| * @return the loginAttempts
| */
| int getLoginAttempts() {
| return this.loginAttempts;
| }
|
| /**
| * @return the loginCount
| */
| long getLoginCount() {
| return this.loginCount;
| }
|
| /**
| * @return the loginName
| */
| String getLoginName() {
| return this.loginName;
| }
|
| /**
| * @return the termDate
| */
| Date getTermDate() {
| return this.termDate;
| }
|
| /**
| * @return the userID
| */
| long getUserID() {
| return this.userID;
| }
|
| /**
| * increments the login attempts and returns the incremented value
| * @param loginAttemptsIn int
| */
| void incrementLoginAttempts(final int loginAttemptsIn) {
| this.loginAttempts = loginAttemptsIn;
| }
|
| /**
| * @return true if this users term date is before today
| */
| boolean isUserTermed() {
| if (this.termDate == null) {
| return false;
| }
| return this.termDate.before(new java.sql.Date(System.currentTimeMillis()));
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4096761#4096761
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4096761
18Â years, 9Â months
[JBoss Seam] - Seam built-in components not working with Woodstock !!!
by b.reeve
I found that Seam built-in components wont work if you have Woodstock libraries in your classpath.
I tried removing the Woodstock libraries and everything works fine.
These are the jar files that i have
1. dataprovider.jar
| 2. dojo-0.4.3-ajax.jar
| 3. json.jar
| 4. prototype-1.5.0.jar
| 5. webui-jsf.jar
| 6. webui-jsf-suntheme.jar
|
| Below is the stacktrace
|
|
| | java.lang.UnsupportedOperationException
| | at org.jboss.seam.Namespace.entrySet(Namespace.java:23)
| | at java.util.AbstractMap.toString(Unknown Source)
| | at java.lang.String.valueOf(Unknown Source)
| | at java.lang.StringBuilder.append(Unknown Source)
| | at com.sun.webui.jsf.faces.UIComponentELResolver.getValue(UIComponentELResolver.java:72)
| | at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
| | at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
| | at org.apache.el.parser.AstValue.getValue(AstValue.java:97)
| | at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
| | at com.sun.faces.application.ValueBindingValueExpressionAdapter.getValue(ValueBindingValueExpressionAdapter.java:102)
| | at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:69)
| | at org.jboss.seam.Component.getInstanceFromFactory(Component.java:1684)
| | at org.jboss.seam.Component.getInstance(Component.java:1633)
| | at org.jboss.seam.Component.getInstance(Component.java:1610)
| | at org.jboss.seam.Component.getInstance(Component.java:1604)
| | at org.jboss.seam.jsf.SeamELResolver.getValue(SeamELResolver.java:49)
| | at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
| | at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
| | at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
| | at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
| | at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
| | at javax.faces.component.UIOutput.getValue(UIOutput.java:173)
| | at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:189)
| | at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:320)
| | at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
| | at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
| | at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
| | at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
| | at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:577)
| | at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
| | at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:256)
| | at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
| | at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
| | at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
| | at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
| | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
| | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
| | at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
| | at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
| | at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
| | at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
| | at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
| | at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
| | at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
| | at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
| | at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
| | at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
| | at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
| | at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
| | at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
| | at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
| | at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
| | at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
| | at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
| | at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
| | at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
| | at java.lang.Thread.run(Unknown Source)
| |
|
| I have no other configurations for Woodstock in my workspace.
|
| Does this mean that Seam cannot be used in combination with Woodstock.
|
| Thanks !
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4096759#4096759
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4096759
18Â years, 9Â months