你应该如何保存jwk?

时间:2018-01-23 19:57:55

标签: authentication jwt jwk

我希望这不是一个天真的问题,但是如果从.well-known / jwks.json域中获取jwk,你应该如何保存jwk。

目前我对模数和指数进行硬编码,但这似乎不是一个很好的解决方案。

将它添加到数据库似乎毫无意义,因为这是一个不合理的呼叫,因为e& n值不会改变。

在缓存中存储似乎是最好的解决方案之一。

对每一个请求进行.well-known / jwks.json的调用看起来也很有意义。

其他人的做法是什么?

1 个答案:

答案 0 :(得分:0)

通过GET调用获得的密钥集的存储应该依赖于HTTP标头,尤其是 public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoHolder> { private ArrayList<Video> mData; private ArrayList<Video> mData2; private Fragment mACtivity; private OnImageClickListener onImageClickListener; String iddd; int id_item; ArrayList<Integer> arrayListInteger; int c; String d = ""; ArrayList<String> arrayListString; int j; Context context; ArrayList<String>arrayList= new ArrayList<String>(); ; String []mDataset=new String[100]; Context mContext; //private static List<String> mDataset = new ArrayList<>(); public VideoAdapter(ArrayList<Video> data, ArrayList<Video> data2, Fragment fragment, OnImageClickListener onImageClickListener, String id, ArrayList<Integer> al,Context mContext) { this.mData = data; this.mData2 = data2; this.mACtivity = fragment; this.onImageClickListener = onImageClickListener; this.iddd = id; this.id_item = id_item; this.arrayListInteger = al; this.context=mContext; // arrayListInteger.clear(); System.out.println("NO O SI?" + arrayListInteger); System.out.println("SI O NO?" + arrayListString); } @Override public VideoHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.anteprima_list_item, parent, false); VideoHolder vh = new VideoHolder(view, new CustomEditTextListener()); return vh; } public interface OnImageClickListener { void onImageClick(String imageData); void onImageClick2(String imageData); void onPreferitiClick2(String imageData, String titolo, String sottotitolo, String data, String id); void onTogliPreferitiClick2(String imageData, String id); //void aggiungiCommento(String imageData, String id); } @Override public void onBindViewHolder(final VideoHolder holder, final int position) { final Video video = mData.get(position); final Video video2 = mData2.get(position); final int pos=position; holder.customEditTextListener.setPosition(holder.getAdapterPosition()); holder.tw.setText(mDataset[holder.getAdapterPosition()]); holder.button.setTag(position); holder.tw.setTag(position); // holder.tw.setText(mDataset.get(position)); holder.tw.setText(mDataset[position]); // <-- add this line // holder.lw.setTag(position); // holder.tw.setText(mDataset[position]); // holder.setCommento(holder.tw.get(position)); holder.setTitolo(video.getTitolo()); holder.setSottoTitolo(video.getSottotitolo()); holder.setData(video.getData()); System.out.println("ARRAYLISTINTEGER"+arrayListInteger.size()); for (int i = 0; i < arrayListInteger.size(); i++) { c = arrayListInteger.get(i); System.out.println("ARRAYLISTINTEGER"+c); if (c == position) { System.out.println("POSIZIONE:" + c + "VALORE:" + d); System.out.println("INDICE ARRAYLIST:" + c); holder.preferiti.setText("togli dai preferiti"); } } Glide.with(mACtivity) .load(video2.getPic()) .into(holder.videoImageView); holder.linearlayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onImageClickListener.onImageClick(video2.getPic()); } }); holder.iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onImageClickListener.onImageClick2(video2.getPic()); } }); /* holder.button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { holder.tt.setText(holder.tw.getText()); } });*/ //arrayList= new ArrayList<String>(); holder.button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int position = (int) v.getTag(); Toast.makeText(v.getContext(),Integer.toString(position), Toast.LENGTH_SHORT).show(); System.out.println("IDDD:"+iddd); System.out.println("IDDD:"+video2.getPic()); String commento= (holder.tw.getText().toString()); arrayList.add(commento); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, arrayList); holder.lw.setAdapter(adapter); adapter.notifyDataSetChanged(); // Toast.makeText(v.getContext(),adapter.getCount(), Toast.LENGTH_SHORT).show(); System.out.println("LISTVIEW:"+arrayList); System.out.println("LISTVIEW:"+arrayList.size()); System.out.println("LISTVIEW:"+adapter.getCount()); } }); public class VideoHolder extends RecyclerView.ViewHolder { ImageView videoImageView; TextView videoNameTextView; TextView subtitleVideoTextView; TextView dateTextView; LinearLayout linearlayout; ImageView iv; Button button; EditText tw; TextView tt; ListView lw; //ImageView preferiti_imageview; ToggleButton preferiti; public CustomEditTextListener customEditTextListener; public VideoHolder(View itemView, CustomEditTextListener customEditTextListener) { super(itemView); this.customEditTextListener = customEditTextListener; linearlayout = (LinearLayout) itemView.findViewById((R.id.linearlayout)); videoImageView = (ImageView) itemView.findViewById(R.id.videoImageView); videoNameTextView = (TextView) itemView.findViewById(R.id.videoNameTextView); subtitleVideoTextView = (TextView) itemView.findViewById(R.id.subtitleVideoTextView); dateTextView = (TextView) itemView.findViewById(R.id.dateTextView); iv=(ImageView) itemView.findViewById(R.id.shareButton2); //preferiti_imageview=(ImageView) itemView.findViewById(R.id.preferiti_imageview); preferiti=(ToggleButton) itemView.findViewById(R.id.preferiti); button=(Button)itemView.findViewById(R.id.button1); tw=(EditText)itemView.findViewById(R.id.et); // tt=(TextView)itemView.findViewById(R.id.list_entry_title); lw=(ListView)itemView.findViewById(R.id.mobile_list); this.tw.addTextChangedListener(customEditTextListener); } public void setTitolo(String titolo) { videoNameTextView.setText(titolo); } public void setSottoTitolo(String sottotitolo) { subtitleVideoTextView.setText(sottotitolo); } public void setCommento(ArrayList<String> commento) { tt.setText((CharSequence) commento); } public void setData(String data) { dateTextView.setText(data); } } private class CustomEditTextListener implements TextWatcher { private int position; public void setPosition(int position) { this.position = position; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mDataset[position] = s.toString(); } @Override public void afterTextChanged(Editable editable) { } } } 指令。 如果设置了cache-controlno-cache,那么您不应该保存密钥集,并在需要时使用它。

一般情况下,您将拥有no-store指令(例如,请参阅key set from Google)。我建议您尊重该指令并将密钥集存储在应用程序缓存中。

我不确定数据库的使用在这里是否相关;缓存存储通常比数据库存储更有效。