By: PIYUSH DUBEY user 09 Sep 2021 at 11:53 a.m. CDT

1 Response
PIYUSH DUBEY gravatar
When I try to login with my custom python script then i am getting this error: ``` TypeError: integer required at org.python.core.Py.TypeError(Py.java:236) at org.python.core.Py.py2int(Py.java:1955) at org.python.core.Py.py2int(Py.java:1946) at org.python.proxies.__main__$PersonAuthentication$5.getCountAuthenticationSteps(Unknown Source) at org.gluu.oxauth.service.external.ExternalAuthenticationService.executeExternalGetCountAuthenticationSteps(ExternalAuthenticationService.java:196) at org.gluu.oxauth.service.external.ExternalAuthenticationService$Proxy$_$$_WeldClientProxy.executeExternalGetCountAuthenticationSteps(Unknown Source) at org.gluu.oxauth.auth.Authenticator.userAuthenticationInteractive(Authenticator.java:381) at org.gluu.oxauth.auth.Authenticator.authenticateImpl(Authenticator.java:206) at org.gluu.oxauth.auth.Authenticator.authenticate(Authenticator.java:128) at jdk.internal.reflect.GeneratedMethodAccessor416.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.apache.el.parser.AstValue.invoke(AstValue.java:247) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267) at org.jboss.weld.module.web.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40) at org.jboss.weld.module.web.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:65) at com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:66) at com.sun.faces.application.ActionListenerImpl.getNavigationOutcome(ActionListenerImpl.java:82) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:71) at javax.faces.component.UICommand.broadcast(UICommand.java:222) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:847) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1396) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:58) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177) at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451) at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1452) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:791) at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1626) at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:228) at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193) at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601) at org.gluu.oxauth.audit.debug.ServletLoggingFilter.doFilter(ServletLoggingFilter.java:67) at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:201) at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1435) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1350) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:234) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:516) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:773) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:905) at java.base/java.lang.Thread.run(Thread.java:834) ==================Further details============================ TypeError: integer required ``` My Python code: ``` from org.gluu.service.cdi.util import CdiUtil from org.gluu.oxauth.security import Identity from org.gluu.model.custom.script.type.auth import PersonAuthenticationType from org.gluu.oxauth.service import UserService, AuthenticationService from org.gluu.service import CacheService from org.gluu.util import StringHelper, ArrayHelper from org.gluu.oxauth.util import ServerUtil from javax.faces.application import FacesMessage from org.gluu.jsf2.message import FacesMessages import java import re class PersonAuthentication(PersonAuthenticationType): print("Start script") def __init__(self, currentTimeMillis): self.currentTimeMillis = currentTimeMillis def init(self, customScript, configurationAttributes): print "Basic (with password update). Initialization" print "Basic (with password update). Initialized successfully" return True def destroy(self, configurationAttributes): print "Basic (with password update). Destroy" print "Basic (with password update). Destroyed successfully" return True def getApiVersion(self): return 11 def getAuthenticationMethodClaims(self, requestParameters): return None def isValidAuthenticationMethod(self, usageType, configurationAttributes): return True def getAlternativeAuthenticationMethod(self, usageType, configurationAttributes): return None def authenticate(self, configurationAttributes, requestParameters, step): userService = CdiUtil.bean(UserService) authenticationService = CdiUtil.bean(AuthenticationService) identity = CdiUtil.bean(Identity) credentials = identity.getCredentials() user_name = credentials.getUsername() if (step == 1): print "Basic (with password update). Authenticate for step 1" facesMessages = CdiUtil.bean(FacesMessages) facesMessages.setKeepMessages() user_password = credentials.getPassword() logged_in = False if (StringHelper.isNotEmptyString(user_name) and StringHelper.isEmptyString(user_password)): facesMessages.add(FacesMessage.SEVERITY_INFO, "Password is empty! Enter your password") print "Basic. Authenticate: Password is empty! Enter your password" return False if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)): find_user = userService.getUser(user_name) if (find_user == None): facesMessages.add(FacesMessage.SEVERITY_INFO, "User doesn't Exist") return False else: print "Basic . Authenticate for step 1-4-disablechecking" user_status = userService.getCustomAttribute(find_user, "gluuStatus") print "Basic . Authenticate for step 1-5-disablechecking" if (user_status != None): user_status_value = user_status.getValue() if (StringHelper.equals(user_status_value, "inactive")): facesMessages.add(FacesMessage.SEVERITY_INFO, "User is Disabled") return False if (StringHelper.isNotEmptyString(user_name) and StringHelper.isNotEmptyString(user_password)): logged_in = authenticationService.authenticate(user_name, user_password) if (not logged_in): return False return True elif (step == 2): print "Basic (with password update). Authenticate for step 2-see" user = authenticationService.getAuthenticatedUser() facesMessages = CdiUtil.bean(FacesMessages) facesMessages.setKeepMessages() if user == None: print "Basic (with password update). Authenticate for step 2. Failed to determine user name" return False user_name = user.getUserId() find_user_by_uid = userService.getUser(user_name) update_button = requestParameters.get("loginForm:updateButton") if ArrayHelper.isEmpty(update_button): return True new_password_array = requestParameters.get("loginForm:password") new_password = new_password_array[0] if ArrayHelper.isEmpty(new_password_array) or StringHelper.isEmpty(new_password): print "Basic (with password update). Authenticate for step 2. New password is empty" return False print "Basic (with password update). Authenticate for step 2. see the new password ================'%s'" % new_password reg="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{9,20}$" pat=re.compile(reg) mat=re.search(pat,new_password) # results = zxcvbn(new_password) if mat: find_user_by_uid.setAttribute("userPassword", new_password) print "Basic (with password update). Authenticate for step 2. Attempting to set new user '%s' password " % user_name userService.updateUser(find_user_by_uid) print "Basic (with password update). Authenticate for step 2. Password updated successfully" print "Its a weak Password, please increase the complexity." return True return True else: return False def prepareForStep(self, configurationAttributes, requestParameters, step): if (step == 1): print "Basic (with password update). Prepare for Step 1" return True elif (step == 2): print "Basic (with password update). Prepare for Step 2-confirm" return True else: return False def getExtraParametersForStep(self, configurationAttributes, step): return None def getCountAuthenticationSteps(self, configurationAttributes): return def getPageForStep(self, configurationAttributes, step): if (step == 2): print "Basic (with password update). Redirecting to password change page" return "/auth/pwd/newpassword.xhtml" return "" def getNextStep(self, configurationAttributes, requestParameters, step): return -1 def getLogoutExternalUrl(self, configurationAttributes, requestParameters): print "Get external logout URL call" return None def logout(self, configurationAttributes, requestParameters): return True ```

By Michael Schwartz Account Admin 09 Sep 2021 at 12:01 p.m. CDT

Michael Schwartz gravatar
This is your problem: ``` def getCountAuthenticationSteps(self, configurationAttributes): return ``` You must return an integer here. Not sure whether you should return 1 or 2, or a variable that species 1 or 2...