def createClient(self, context): registerRequest = context.getRegisterRequest() configurationAttributes = context.getConfigurationAttibutes() client = context.getClient() print "Casa client registration. CreateClient method" redirectUris = client.getRedirectUris() print "Casa client registration. Redirect Uris: %s" % redirectUris credManagerClient = False for redirectUri in redirectUris: if self.clientRedirectUrisSet.contains(redirectUri): credManagerClient = True break if not credManagerClient: return True print "Casa client registration. Client is Janssen Casa" self.setClientScopes(client, configurationAttributes.get("scopes")) #Extend client lifetime for one year cal=GregorianCalendar() cal.add(1,10) client.setClientSecretExpiresAt(Date(cal.getTimeInMillis())) client.setTrustedClient(True) return True
def _to_timestamp(d): if isinstance(d, datetime.datetime): calendar = GregorianCalendar() calendar.set(d.year, d.month - 1, d.day, d.hour, d.minute, d.second) ts = Timestamp(calendar.getTimeInMillis()) ts.setNanos(d.microsecond * 1000) return ts else: return d
def testDateFormat(): textField = JFormattedTextField() installFormat(textField, SimpleDateFormat('yyyy-MM-dd')) textField.setText(u'2010-11-9') textField.commitEdit() assert type(textField.value) == Date cal = GregorianCalendar(time=textField.value) assert cal.get(GregorianCalendar.YEAR) == 2010 assert cal.get(GregorianCalendar.MONTH) == 10 # January = 0 assert cal.get(GregorianCalendar.DAY_OF_MONTH) == 9
def test_filter_with_java_dates(self): from java.util import GregorianCalendar, Calendar self.df['date'] = self.df['date'].apply(str_to_java_date) d3 = GregorianCalendar(2019, Calendar.JANUARY, 3).getTime() d4 = GregorianCalendar(2019, Calendar.JANUARY, 4).getTime() d5 = GregorianCalendar(2019, Calendar.JANUARY, 5).getTime() d6 = GregorianCalendar(2019, Calendar.JANUARY, 6).getTime() df = self.df[self.df['date'] >= '2019-01-03'] self.assertEqual(12, len(df)) self.assertListEqual( [d3]*3 + [d4]*3 + [d5]*3 + [d6]*3, list(df['date']), )
def timeString(millis): months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ] cal = GregorianCalendar() cal.setTimeInMillis(millis) yy = cal.get(GregorianCalendar.YEAR) mo = cal.get(GregorianCalendar.MONTH) da = cal.get(GregorianCalendar.DAY_OF_MONTH) ho = cal.get(GregorianCalendar.HOUR_OF_DAY) ms = cal.get(GregorianCalendar.MINUTE) sc = cal.get(GregorianCalendar.SECOND) return "%4d-%3s-%2d %2d:%2d:%2d" % (yy, months[mo], da, ho, ms, sc)
def getDate(self): calendar = GregorianCalendar() date = calendar.getTime() dayFormat = SimpleDateFormat("dd") monthFormat = SimpleDateFormat("MM") yearFormat = SimpleDateFormat("yyyy") DAY = int(dayFormat.format(date)) MONTH = int(monthFormat.format(date)) YEAR = int(yearFormat.format(date)) if MONTH < 10: TEMP1 = "%d0%d" % (YEAR, MONTH) else: TEMP1 = "%d%d" % (YEAR, MONTH) if DAY < 10: CURRENTDATE = "%d0%d" % (TEMP1, DAY) else: CURRENTDATE = "%d%d" % (TEMP1, DAY) return CURRENTDATE
def timeString(millis) : months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] cal=GregorianCalendar(); cal.setTimeInMillis(millis); yy=cal.get(GregorianCalendar.YEAR); mo=cal.get(GregorianCalendar.MONTH); da=cal.get(GregorianCalendar.DAY_OF_MONTH); ho=cal.get(GregorianCalendar.HOUR_OF_DAY); ms=cal.get(GregorianCalendar.MINUTE); sc=cal.get(GregorianCalendar.SECOND); return "%4d-%3s-%2d %2d:%2d:%2d" % (yy,months[mo],da,ho,ms,sc)
def updateClient(self, registerRequest, client, configurationAttributes): print "Casa client registration. UpdateClient method" redirectUris = client.getRedirectUris() print "Casa client registration. Redirect Uris: %s" % redirectUris credManagerClient = False for redirectUri in redirectUris: if (self.clientRedirectUrisSet.contains(redirectUri)): credManagerClient = True break if not credManagerClient: return True print "Casa client registration. Client is Cred-manager" newScopes = client.getScopes() scopeService = CdiUtil.bean(ScopeService) requiredScopes = [ "openid", "profile", "user_name", "clientinfo", "uma_protection" ] for scopeName in requiredScopes: scope = scopeService.getScopeByDisplayName(scopeName) if not scope.getIsDefault(): print "Casa client registration. Adding scope '%s'" % scopeName newScopes = ArrayHelper.addItemToStringArray( newScopes, scope.getDn()) print "Casa client registration. Result scopes: %s" % newScopes client.setScopes(newScopes) #Extend client lifetime for one year cal = GregorianCalendar() cal.add(1, 1) client.setClientSecretExpiresAt(Date(cal.getTimeInMillis())) #this style complains: client.setClientSecretExpiresAt(Date(Date().getTime + 31536000000)) return True
def createClient(self, registerRequest, client, configurationAttributes): print "Casa client registration. CreateClient method" redirectUris = client.getRedirectUris() print "Casa client registration. Redirect Uris: %s" % redirectUris credManagerClient = False for redirectUri in redirectUris: if self.clientRedirectUrisSet.contains(redirectUri): credManagerClient = True break if not credManagerClient: return True print "Casa client registration. Client is Gluu Casa" self.setClientScopes(client, configurationAttributes.get("scopes")) #Extend client lifetime for one year cal=GregorianCalendar() cal.add(1,1) client.setClientSecretExpiresAt(Date(cal.getTimeInMillis())) return True
def test_filter_with_java_date(self): from java.util import GregorianCalendar, Calendar self.df['date'] = self.df['date'].apply(str_to_dt) date = GregorianCalendar(2019, Calendar.JANUARY, 3).getTime() d3 = dt.datetime(2019, 1, 3, 0, 0) d4 = dt.datetime(2019, 1, 4, 0, 0) d5 = dt.datetime(2019, 1, 5, 0, 0) d6 = dt.datetime(2019, 1, 6, 0, 0) df = self.df[self.df['date'] >= date] self.assertEqual(12, len(df)) self.assertListEqual( [d3]*3 + [d4]*3 + [d5]*3 + [d6]*3, list(df['date']), )
def executeSSOTest(): reqInstant = dateFormat.format(GregorianCalendar(utctz).getTime()) reqId = UUID.randomUUID().toString() authnRequest = props.get('shib.sp.authnreq') % (idpSSOEndpoint, reqId, reqInstant, spId) webClient = WebClient() webClient.setUseInsecureSSL(True) listreq = ArrayList() listreq.add( NameValuePair( "SAMLRequest", String(Base64.encodeBase64(String(authnRequest).getBytes()), 'US-ASCII'))) wrs = WebRequestSettings(URL(idpSSOEndpoint), HttpMethod.POST) wrs.setRequestParameters(listreq) if props.get('shib.idp.auth') == 'FORM': webClient.setRedirectEnabled(True) if debug: log("sending SSO request to: " + idpSSOEndpoint, stdout) wr = webClient.loadWebResponse(wrs) if debug: log("Response content: \n" + wr.getContentAsString(), stdout) if wr.getStatusCode() != 200: raise Exception('Invalid HTTP response code: ' + str(wr.getStatusCode())) wrs.setHttpMethod(HttpMethod.POST) listauth = ArrayList() listauth.add(NameValuePair("j_username", props.get('shib.user.name'))) listauth.add(NameValuePair("j_password", props.get('shib.user.pass'))) wrs.setRequestParameters(listauth) wrs.setUrl(wr.getRequestUrl()) else: # BASIC auth webClient.setRedirectEnabled(False) if debug: log("sending SSO request to: " + idpSSOEndpoint, stdout) wr = webClient.loadWebResponse(wrs) if debug: log("Response content: \n" + wr.getContentAsString(), stdout) if wr.getStatusCode() != 302: raise Exception('Invalid HTTP response code: ' + str(wr.getStatusCode())) wrs.setHttpMethod(HttpMethod.GET) creds = DefaultCredentialsProvider() creds.addCredentials(props.get('shib.user.name'), props.get('shib.user.pass'), idpHost, idpPort, props.get('shib.user.realm')) wrs.setCredentialsProvider(creds) if debug: log( "sending BASIC auth to: " + wr.getResponseHeaderValue('Location'), stdout) wrs.setUrl(URL(wr.getResponseHeaderValue('Location'))) if debug: log("sending login request to: " + str(wr.getRequestUrl()), stdout) wr = webClient.loadWebResponse(wrs) if debug: log("Request URL = " + wr.getRequestUrl().toString(), stdout) log(wr.getContentAsString(), stdout) if wr.getStatusCode() not in [200, 301, 302]: if debug: log("error response: " + response.getText(), stdout) raise Exception('Invalid HTTP response code: ' + str(wr.getStatusCode())) return wr.getContentAsString()
def getPyObject(self, set, col, datatype): "Convert Java types into Python ones" if datatype in (Types.VARCHAR, Types.CHAR): return Py.newUnicode(set.getString(col)) elif datatype == Types.TIMESTAMP: # Convert java.sql.TimeStamp into datetime cal = GregorianCalendar() cal.time = set.getTimestamp(col) return datetime.datetime(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND) * 1000) elif datatype == Types.TIME: # Convert java.sql.Time into time cal = GregorianCalendar() cal.time = set.getTime(col) return datetime.time(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND) * 1000) elif datatype == Types.DATE: # Convert java.sql.Date into datetime cal = GregorianCalendar() cal.time = set.getDate(col) return datetime.date(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH)) else: return FilterDataHandler.getPyObject(self, set, col, datatype)
''' Created on 13/04/2010 @author: lm ''' from java.util import Calendar, Date, GregorianCalendar print Date() c = GregorianCalendar() dia = c.get(Calendar.DATE) mes = c.get(Calendar.MONTH) anyo = c.get(Calendar.YEAR) print dia, '/', mes, '/', anyo
def isDayTime(self, forecastDate, sunrise, sunset): # Only check the time, not the date, of the forecast against the # sunrise and sunset times. cal = GregorianCalendar(TimeZone.getTimeZone("UTC")) cal.setTime(forecastDate) riseCal = GregorianCalendar(TimeZone.getTimeZone("UTC")) riseCal.setTime(sunrise) riseCal.set(cal.get(cal.YEAR), cal.get(cal.MONTH), cal.get(cal.DATE)) setCal = GregorianCalendar(TimeZone.getTimeZone("UTC")) setCal.setTime(sunset) setCal.set(cal.get(cal.YEAR), cal.get(cal.MONTH), cal.get(cal.DATE)) if cal.compareTo(riseCal) == -1: return False elif cal.compareTo(setCal) == 1: return False return True
def authenticate(self, configurationAttributes, requestParameters, step): authenticationService = CdiUtil.bean(AuthenticationService) userService = CdiUtil.bean(UserService) identity = CdiUtil.bean(Identity) credentials = identity.getCredentials() if step == 1: print "Basic (with password update). Authenticate for step 1" user_name = credentials.getUsername() user_password = credentials.getPassword() logged_in = 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 find_user_by_uid = authenticationService.getAuthenticatedUser() user_expDate = find_user_by_uid.getAttribute( "oxPasswordExpirationDate", False) if user_expDate == None: print "Basic (with password update). Authenticate for step 1. User has no oxPasswordExpirationDate date" return False dt = StaticUtils.decodeGeneralizedTime(user_expDate) # Get Current Date calendar = GregorianCalendar(TimeZone.getTimeZone("UTC")) now = calendar.getTime() if now.compareTo(dt) > 0: # Add 90 Days to current date calendar.setTime(now) calendar.add(calendar.DATE, 90) dt_plus_90 = calendar.getTime() expDate = StaticUtils.encodeGeneralizedTime(dt_plus_90) identity.setWorkingParameter("expDate", expDate) return True elif step == 2: print "Basic (with password update). Authenticate for step 2" user = authenticationService.getAuthenticatedUser() 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) newExpDate = identity.getWorkingParameter("expDate") if find_user_by_uid == None: print "Basic (with password update). Authenticate for step 2. Failed to find user" return False print "Basic (with password update). Authenticate for step 2" update_button = requestParameters.get("loginForm:updateButton") if ArrayHelper.isEmpty(update_button): return True find_user_by_uid.setAttribute("oxPasswordExpirationDate", newExpDate) new_password_array = requestParameters.get("new_password") if ArrayHelper.isEmpty(new_password_array) or StringHelper.isEmpty( new_password_array[0]): print "Basic (with password update). Authenticate for step 2. New password is empty" return False new_password = new_password_array[0] 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" return True else: return False